[IOTDB-1883] Extension of schema template to tree-structured#4326
[IOTDB-1883] Extension of schema template to tree-structured#4326qiaojialin merged 17 commits intoapache:masterfrom
Conversation
3f2d824 to
744ec33
Compare
| public Template getTemplate(String templateName) throws MetadataException { | ||
| try { | ||
| return templateManager.getTemplate(templateName); | ||
| } catch (UndefinedTemplateException e) { | ||
| throw new MetadataException(e); | ||
| } | ||
| } |
There was a problem hiding this comment.
This method maybe unnecessary. MManager could use templateManager.getTemplate directly.
There was a problem hiding this comment.
This method has been removed now. TSServiceImpl now should access Templates via MManager methods.
| 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); | ||
| } |
There was a problem hiding this comment.
wrap if-else body with { }
| COUNT_MEA, | ||
| IS_MEA, | ||
| IS_SERIES, | ||
| SHOW_MEA |
There was a problem hiding this comment.
Is MEA the abbreviation of Measurement? I'think it's better to use full name.
There was a problem hiding this comment.
fixed with full name
| private List<String> allSeriesPaths; | ||
| private Map<String, IMeasurementSchema> schemaMap; |
There was a problem hiding this comment.
Is allSeriesPaths duplicated since it can be acquired by invoking schemaMap.keySet().
| 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); | ||
| } | ||
|
|
There was a problem hiding this comment.
MLogTxtReader and MLogTxtWriter is only used for MLogParser. One plan should be presented in one line.
There was a problem hiding this comment.
TxtWriter will print only one line for plans about templates now.
| // 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 |
There was a problem hiding this comment.
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.
| @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; | ||
| } |
There was a problem hiding this comment.
If no more usage, delete this method directly.
There was a problem hiding this comment.
it's removed and substituted with a new method:
public boolean isDirectNodeInTemplate(String nodeName);
| private IMNode mountedNode; | ||
| private Set<String> alignedPrefix; | ||
| private List<String> mountedPath; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
renamed to templateRoot now
qiaojialin
left a comment
There was a problem hiding this comment.
update UserGuide in docs/UserGuide
server/src/main/java/org/apache/iotdb/db/service/TSServiceImpl.java
Outdated
Show resolved
Hide resolved
session/src/test/java/org/apache/iotdb/session/template/TemplateUT.java
Outdated
Show resolved
Hide resolved
session/src/test/java/org/apache/iotdb/session/template/TemplateUT.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/apache/iotdb/db/metadata/template/Template.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/apache/iotdb/db/metadata/template/Template.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/apache/iotdb/db/metadata/template/Template.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/apache/iotdb/db/metadata/template/Template.java
Outdated
Show resolved
Hide resolved
session/src/main/java/org/apache/iotdb/session/template/Template.java
Outdated
Show resolved
Hide resolved
744ec33 to
d17a4a8
Compare
d17a4a8 to
f4c44ef
Compare
…agaer to query template information
session/src/test/java/org/apache/iotdb/session/template/TemplateUT.java
Outdated
Show resolved
Hide resolved
|
|
||
| // sync with metadata.Template | ||
| public enum TemplateQueryType { | ||
| NULL, |
session/src/main/java/org/apache/iotdb/session/template/Template.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/apache/iotdb/db/metadata/template/Template.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/apache/iotdb/db/qp/physical/crud/CreateTemplatePlan.java
Outdated
Show resolved
Hide resolved
| List<TSDataType> dataTypes = new ArrayList<>(); | ||
| List<TSEncoding> encodings = new ArrayList<>(); | ||
| List<CompressionType> compressionTypes = new ArrayList<>(); |
There was a problem hiding this comment.
use array TSDatatType[]
Also change the field type in Plan
There was a problem hiding this comment.
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.
SilverNarcissus
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
(1) typo: 'alinged'
(2) we really need add one aligned measurement?
There was a problem hiding this comment.
Thanks!
I think may be used to add an aligned measurement to an exsiting parent?
|
|
||
| // region construct template tree | ||
| /** Construct aligned measurements, checks prefix equality, path duplication and conflict */ | ||
| private void constructTemplateTree(String[] alignedPaths, IMeasurementSchema[] schemas) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Thanks and now it is simplified than last commit
| assertEquals("to", template.getDirectNode("to").getName()); | ||
|
|
||
| try { | ||
| template.deleteMeasurements("a.single"); |
There was a problem hiding this comment.
we should add a fail() after this line
| 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")); |
There was a problem hiding this comment.
Maybe we should add some insert and select test after change the template
There was a problem hiding this comment.
more add and delete now
SilverNarcissus
left a comment
There was a problem hiding this comment.
There are failing test. Please have a look.
Please use
mvn spotless:apply
to format your code.
| } catch (UndefinedTemplateException e) { | ||
| e.printStackTrace(); | ||
| } | ||
| return -1; |
There was a problem hiding this comment.
throw exception rather than return -1 or e.printStackTrace()
SilverNarcissus
left a comment
There was a problem hiding this comment.
There are 2 small issues, please have a check.
| defaultSessionConnection.createSchemaTemplate(req); | ||
| } | ||
|
|
||
| public void addAlignedMeasurementsInTemplate( |
There was a problem hiding this comment.
public interface should add java doc
There was a problem hiding this comment.
java docs about create, prune and query the template has been added now.
| } | ||
|
|
||
| public List<String> getAllMeasurementsPaths() { | ||
| // traverse(); |
There was a problem hiding this comment.
remove comment line
No description provided.