Skip to content

[IOTDB-1883] Extension of schema template to tree-structured#4326

Merged
qiaojialin merged 17 commits intoapache:masterfrom
bigreybear:tree_template
Nov 8, 2021
Merged

[IOTDB-1883] Extension of schema template to tree-structured#4326
qiaojialin merged 17 commits intoapache:masterfrom
bigreybear:tree_template

Conversation

@bigreybear
Copy link
Copy Markdown
Contributor

No description provided.

@coveralls
Copy link
Copy Markdown

coveralls commented Nov 4, 2021

Coverage Status

Coverage decreased (-0.2%) to 66.818% when pulling 3e50d4a on bigreybear:tree_template into 25fefb5 on apache:master.

@bigreybear bigreybear force-pushed the tree_template branch 4 times, most recently from 3f2d824 to 744ec33 Compare November 5, 2021 03:13
Comment on lines +2136 to +2149
public Template getTemplate(String templateName) throws MetadataException {
try {
return templateManager.getTemplate(templateName);
} catch (UndefinedTemplateException e) {
throw new MetadataException(e);
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method maybe unnecessary. MManager could use templateManager.getTemplate directly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method has been removed now. TSServiceImpl now should access Templates via MManager methods.

Comment on lines +101 to +110
public void addToTemplate(Node child) throws StatementExecutionException {
if (moutedNode.getChildren().containsKey(child.getName()))
throw new StatementExecutionException("Duplicated child of node in template.");
moutedNode.getChildren().put(child.getName(), child);
}

public void deleteFromTemplate(String name) throws StatementExecutionException {
if (moutedNode.getChildren().containsKey(name)) moutedNode.getChildren().remove(name);
else throw new StatementExecutionException("It is not a direct child of the template: " + name);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap if-else body with { }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines +67 to +70
COUNT_MEA,
IS_MEA,
IS_SERIES,
SHOW_MEA
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is MEA the abbreviation of Measurement? I'think it's better to use full name.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed with full name

Comment on lines +61 to +67
private List<String> allSeriesPaths;
private Map<String, IMeasurementSchema> schemaMap;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is allSeriesPaths duplicated since it can be acquired by invoking schemaMap.keySet().

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Comment on lines +376 to +426
public void appendTemplate(AppendTemplatePlan plan) throws IOException {
StringBuilder buf = new StringBuilder();
for (int i = 0; i < plan.getMeasurements().size(); i++) {
buf.append(
String.format(
"%s,%s,%s,%s,%s,%s,%s",
MetadataOperationType.APPEND_TEMPLATE,
plan.getName(),
plan.isAligned() ? 1 : 0,
plan.getMeasurements().get(i),
plan.getDataTypes().get(i).serialize(),
plan.getEncodings().get(i).serialize(),
plan.getCompressors().get(i).serialize()));
buf.append(LINE_SEPARATOR);
lineNumber.incrementAndGet();
}
ByteBuffer buff = ByteBuffer.wrap(buf.toString().getBytes());
channel.write(buff);
}

public void pruneTemplate(PruneTemplatePlan plan) throws IOException {
StringBuilder buf = new StringBuilder();

for (int i = 0; i < plan.getPrunedMeasurements().size(); i++) {
buf.append(
String.format(
"%s,%s,%s,%s",
MetadataOperationType.PRUNE_TEMPLATE,
plan.getName(),
plan.getPrunedMeasurements().get(i),
""));
buf.append(LINE_SEPARATOR);
lineNumber.incrementAndGet();
}

for (int i = 0; i < plan.getPrunedPrefix().size(); i++) {
buf.append(
String.format(
"%s,%s,%s,%s",
MetadataOperationType.PRUNE_TEMPLATE,
plan.getName(),
"",
plan.getPrunedPrefix().get(i)));
buf.append(LINE_SEPARATOR);
lineNumber.incrementAndGet();
}

ByteBuffer buff = ByteBuffer.wrap(buf.toString().getBytes());
channel.write(buff);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MLogTxtReader and MLogTxtWriter is only used for MLogParser. One plan should be presented in one line.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TxtWriter will print only one line for plans about templates now.

Comment on lines +588 to +609
// region unimplemented interfaces
public boolean updateSeriesDataType(String path, TSDataType dataType) {
return true;
}

public boolean updateSeriesEncoding(String path, TSEncoding encoding) {
return true;
}

public boolean updateSeriesCompression(String path, CompressionType compressor) {
return true;
}

public boolean updateAlignedPrefixCompression(String prefix, CompressionType compressor) {
return true;
}

public boolean upsertSeries(
String path, TSDataType dataType, TSEncoding encoding, CompressionType compressionType) {
return true;
}
// endregion
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'don't think we need to support schema modification. If users want to alter the schema of one timeseries, they should delete target timeseries first and create what they want.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all removed

Comment on lines 145 to 153
@Deprecated
public boolean isCompatible(PartialPath path) {
return !(schemaMap.containsKey(path.getMeasurement())
|| schemaMap.containsKey(path.getDevicePath().getMeasurement()));
if (mountedNode.hasChild(path.getMeasurement())
&& mountedNode.getChild(path.getMeasurement()).isMeasurement()) return false;
if (mountedNode.hasChild(path.getDevicePath().getMeasurement())
&& mountedNode.getChild(path.getDevicePath().getMeasurement()).isMeasurement())
return false;
return true;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If no more usage, delete this method directly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's removed and substituted with a new method:
public boolean isDirectNodeInTemplate(String nodeName);

Comment on lines +57 to +65
private IMNode mountedNode;
private Set<String> alignedPrefix;
private List<String> mountedPath;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is designed that one template can be set on one mnode and the descendants of this mnode can use this template, which we call template instantiation.
I think the mountedNode in your code is the mnode this template set to and the mountedPath represents the mnode using this template.
It's better to use different terms to distinguish such two kinds mnodes. Or generating your mountedPath at runtime via a new traverse method in MTree.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed to templateRoot now

Copy link
Copy Markdown
Member

@qiaojialin qiaojialin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update UserGuide in docs/UserGuide


// sync with metadata.Template
public enum TemplateQueryType {
NULL,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this for?

Comment on lines +2128 to +2130
List<TSDataType> dataTypes = new ArrayList<>();
List<TSEncoding> encodings = new ArrayList<>();
List<CompressionType> compressionTypes = new ArrayList<>();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use array TSDatatType[]
Also change the field type in Plan

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All plan maintains arrays rather than lists, but getters will return still return lists. Constructors support both list and array parameters.
interfaces in TSServiceImpl uses arrays now.

Copy link
Copy Markdown
Contributor

@SilverNarcissus SilverNarcissus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic feature and I'm looking forward using it. There are some issues, please have a look.

TSEncoding[] encodings,
CompressionType[] compressors);

// Add one alinged measurement to a template
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(1) typo: 'alinged'
(2) we really need add one aligned measurement?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!
I think may be used to add an aligned measurement to an exsiting parent?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and typo fixed


// region construct template tree
/** Construct aligned measurements, checks prefix equality, path duplication and conflict */
private void constructTemplateTree(String[] alignedPaths, IMeasurementSchema[] schemas)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method contains too much if else. Could you simplify it? Or you can add some comments for each path
suggestion: exception case should as front of the method as they can

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks and now it is simplified than last commit

assertEquals("to", template.getDirectNode("to").getName());

try {
template.deleteMeasurements("a.single");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add a fail() after this line

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

assertEquals(
"[vehicle.GPS.y, x, vehicle.GPS.x, y, GPS.x, vehicle.x, GPS.y, vehicle.y]",
session.showMeasurementsInTemplate("treeTemplate").toString());
assertEquals(8, session.countMeasurementsInTemplate("treeTemplate"));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add some insert and select test after change the template

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more add and delete now

Copy link
Copy Markdown
Contributor

@SilverNarcissus SilverNarcissus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are failing test. Please have a look.
Please use

mvn spotless:apply

to format your code.

Comment on lines +2149 to +2152
} catch (UndefinedTemplateException e) {
e.printStackTrace();
}
return -1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw exception rather than return -1 or e.printStackTrace()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed now

Copy link
Copy Markdown
Contributor

@SilverNarcissus SilverNarcissus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 2 small issues, please have a check.

defaultSessionConnection.createSchemaTemplate(req);
}

public void addAlignedMeasurementsInTemplate(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public interface should add java doc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

java docs about create, prune and query the template has been added now.

}

public List<String> getAllMeasurementsPaths() {
// traverse();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment line

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its removed now

Copy link
Copy Markdown
Contributor

@SilverNarcissus SilverNarcissus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants