Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ createSchemaTemplate
;

templateMeasurementClause
: nodeNameWithoutWildcard attributeClauses #nonAlignedTemplateMeasurement
| alignedDevice=nodeNameWithoutWildcard LR_BRACKET nodeNameWithoutWildcard attributeClauses
: suffixPath attributeClauses #nonAlignedTemplateMeasurement
| suffixPath LR_BRACKET nodeNameWithoutWildcard attributeClauses
(COMMA nodeNameWithoutWildcard attributeClauses)+ RR_BRACKET #alignedTemplateMeasurement
;

Expand Down
10 changes: 5 additions & 5 deletions docs/UserGuide/Appendix/SQL-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ Note: It is not currently supported to set an alias, tag, and attribute for alig
```
CREATE SCHEMA TEMPLATE <TemplateName> LR_BRACKET <TemplateMeasurementClause> (COMMA plateMeasurementClause>)* RR_BRACKET
templateMeasurementClause
: nodeNameWithoutWildcard attributeClauses #nonAlignedTemplateMeasurement
| alignedDevice=nodeNameWithoutWildcard LR_BRACKET nodeNameWithoutWildcard attributeClauses
: suffixPath attributeClauses #nonAlignedTemplateMeasurement
| suffixPath LR_BRACKET nodeNameWithoutWildcard attributeClauses
(COMMA nodeNameWithoutWildcard attributeClauses)+ RR_BRACKET #alignedTemplateMeasurement
;
Eg: CREATE SCHEMA TEMPLATE temp1(
Expand All @@ -158,19 +158,19 @@ Eg: CREATE SCHEMA TEMPLATE temp1(

* Set Schema Template Statement
```
SET SCHEMA TEMPLATE <TemplateName> TO <STORAGE_GROUP_NAME>
SET SCHEMA TEMPLATE <TemplateName> TO <PrefixPath>
Eg: SET SCHEMA TEMPLATE temp1 TO root.beijing
```

* Create Timeseries Of Schema Template Statement
```
CREATE TIMESERIES OF SCHEMA TEMPLATE ON <STORAGE_GROUP_NAME>
CREATE TIMESERIES OF SCHEMA TEMPLATE ON <PrefixPath>
Eg: CREATE TIMESERIES OF SCHEMA TEMPLATE ON root.beijing
```

* Unset Schema Template Statement
```
UNSET SCHEMA TEMPLATE <TemplateName> FROM <STORAGE_GROUP_NAME>
UNSET SCHEMA TEMPLATE <TemplateName> FROM <PrefixPath>
Eg: UNSET SCHEMA TEMPLATE temp1 FROM root.beijing
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,11 @@ IoTDB supports the schema template function, enabling different entities of the
The SQL Statement for creating schema template is as follow:

```
IoTDB> create schema template temp1(GPS(lat FLOAT encoding=Gorilla, lon FLOAT encoding=Gorilla) compression=SNAPPY, status BOOLEAN encoding=PLAIN compression=SNAPPY)
IoTDB> create schema template temp1(GPS(lat FLOAT encoding=Gorilla, lon FLOAT encoding=Gorilla compression=SNAPPY), status BOOLEAN encoding=PLAIN compression=SNAPPY)
```

The` lat` and `lon` measurements under the `GPS` device are aligned.

### Set Schema Template

The SQL Statement for setting schema template is as follow:
Expand Down
18 changes: 9 additions & 9 deletions docs/zh/UserGuide/Appendix/SQL-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ Note: It is not supported to set different compression for a group of aligned ti
Note: It is not currently supported to set an alias, tag, and attribute for aligned timeseries.
```

* 创建设备模板语句
* 创建元数据模板语句
```
CREATE SCHEMA TEMPLATE <TemplateName> LR_BRACKET <TemplateMeasurementClause> (COMMA plateMeasurementClause>)* RR_BRACKET
templateMeasurementClause
: nodeNameWithoutWildcard attributeClauses #nonAlignedTemplateMeasurement
| alignedDevice=nodeNameWithoutWildcard LR_BRACKET nodeNameWithoutWildcard attributeClauses
: suffixPath attributeClauses #nonAlignedTemplateMeasurement
| suffixPath LR_BRACKET nodeNameWithoutWildcard attributeClauses
(COMMA nodeNameWithoutWildcard attributeClauses)+ RR_BRACKET #alignedTemplateMeasurement
;
Eg: CREATE SCHEMA TEMPLATE temp1(
Expand All @@ -145,21 +145,21 @@ Eg: CREATE SCHEMA TEMPLATE temp1(
)
```

* 挂载设备模板语句
* 挂载元数据模板语句
```
SET SCHEMA TEMPLATE <TemplateName> TO <STORAGE_GROUP_NAME>
SET SCHEMA TEMPLATE <TemplateName> TO <PrefixPath>
Eg: SET SCHEMA TEMPLATE temp1 TO root.beijing
```

* 创建模板时间序列语句
* 根据元数据模板创建时间序列语句
```
CREATE TIMESERIES OF SCHEMA TEMPLATE ON <STORAGE_GROUP_NAME>
CREATE TIMESERIES OF SCHEMA TEMPLATE ON <PrefixPath>
Eg: CREATE TIMESERIES OF SCHEMA TEMPLATE ON root.beijing
```

* 卸载设备模板语句
* 卸载元数据模板语句
```
UNSET SCHEMA TEMPLATE <TemplateName> FROM <STORAGE_GROUP_NAME>
UNSET SCHEMA TEMPLATE <TemplateName> FROM <PrefixPath>
Eg: UNSET SCHEMA TEMPLATE temp1 FROM root.beijing
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,37 +537,39 @@ Total line number = 2
It costs 0.001s
```

## 物理量模板
## 元数据模板

IoTDB 支持物理量模板功能,实现同类型不同实体的物理量元数据共享,减少元数据内存占用,同时简化同类型实体的管理。
IoTDB 支持元数据模板功能,实现同类型不同实体的物理量元数据共享,减少元数据内存占用,同时简化同类型实体的管理。

### 创建物理量模板
### 创建元数据模板

创建物理量模板的 SQL 语句如下所示:
创建元数据模板的 SQL 语句如下所示:

```
IoTDB> create schema template temp1(GPS(lat FLOAT encoding=Gorilla, lon FLOAT encoding=Gorilla) compression=SNAPPY, status BOOLEAN encoding=PLAIN compression=SNAPPY)
IoTDB> create schema template temp1(GPS(lat FLOAT encoding=Gorilla, lon FLOAT encoding=Gorilla compression=SNAPPY), status BOOLEAN encoding=PLAIN compression=SNAPPY)
```

### 挂载物理量模板
其中,`GPS` 设备下的物理量 `lat` 和 `lon` 是对齐的。

挂载物理量模板的 SQL 语句如下所示:
### 挂载元数据模板

挂载元数据模板的 SQL 语句如下所示:

```
IoTDB> set schema template temp1 to root.ln.wf01
```

挂载好物理量模板后,即可进行数据的写入。例如存储组为root.ln,模板temp1被挂载到了节点root.ln.wf01,那么可直接向时间序列(如root.ln.wf01.GPS.lat和root.ln.wf01.status)写入时间序列数据,该时间序列已可被当作正常创建的序列使用。
挂载好元数据模板后,即可进行数据的写入。例如存储组为root.ln,模板temp1被挂载到了节点root.ln.wf01,那么可直接向时间序列(如root.ln.wf01.GPS.lat和root.ln.wf01.status)写入时间序列数据,该时间序列已可被当作正常创建的序列使用。

**注意**:在插入数据之前,模板定义的时间序列不会被创建。可以使用如下SQL语句在插入数据前创建时间序列:

```
IoTDB> create timeseries of schema template on root.ln.wf01
```

### 卸载物理量模板
### 卸载元数据模板

卸载物理量模板的 SQL 语句如下所示:
卸载元数据模板的 SQL 语句如下所示:

```
IoTDB> unset schema template temp1 from root.beijing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public void tearDown() throws Exception {
}

@Test
@Ignore
public void testCreateTemplateAndCreateTimeseries() throws SQLException {
statement.execute("CREATE STORAGE GROUP root.sg1");

Expand All @@ -72,24 +71,24 @@ public void testCreateTemplateAndCreateTimeseries() throws SQLException {
}

// set schema template
statement.execute("SET SCHEMA TEMPLATE temp1 TO root.sg1");
statement.execute("SET SCHEMA TEMPLATE temp1 TO root.sg1.d1");

statement.execute("SHOW TIMESERIES root.sg1.**");
try (ResultSet resultSet = statement.getResultSet()) {
Assert.assertFalse(resultSet.next());
}

// create timeseries of schema template
statement.execute("CREATE TIMESERIES OF SCHEMA TEMPLATE ON root.sg1");
statement.execute("CREATE TIMESERIES OF SCHEMA TEMPLATE ON root.sg1.d1");

boolean hasResult = statement.execute("SHOW TIMESERIES root.sg1.**");
Assert.assertTrue(hasResult);

String[] expectedResult =
new String[] {
"root.sg1.vector1.s1,FLOAT,GORILLA,SNAPPY",
"root.sg1.vector1.s2,INT64,RLE,SNAPPY",
"root.sg1.s1,INT64,RLE,SNAPPY"
"root.sg1.d1.vector1.s1,FLOAT,GORILLA,SNAPPY",
"root.sg1.d1.vector1.s2,INT64,RLE,SNAPPY",
"root.sg1.d1.s1,INT64,RLE,SNAPPY"
};

int count = 0;
Expand All @@ -109,15 +108,30 @@ public void testCreateTemplateAndCreateTimeseries() throws SQLException {
}
Assert.assertEquals(3, count);

hasResult = statement.execute("SHOW DEVICES");
Assert.assertTrue(hasResult);

expectedResult = new String[] {"root.sg1.d1,false", "root.sg1.d1.vector1,true"};

count = 0;
try (ResultSet resultSet = statement.getResultSet()) {
while (resultSet.next()) {
String ActualResult =
resultSet.getString("devices") + "," + resultSet.getString("isAligned");
Assert.assertEquals(expectedResult[count], ActualResult);
count++;
}
}
Assert.assertEquals(2, count);

try {
statement.execute("UNSET SCHEMA TEMPLATE temp1 FROM root.sg1");
statement.execute("UNSET SCHEMA TEMPLATE temp1 FROM root.sg1.d1");
} catch (IoTDBSQLException e) {
Assert.assertEquals("326: Template is in use on root.sg1", e.getMessage());
Assert.assertEquals("326: Template is in use on root.sg1.d1", e.getMessage());
}
}

@Test
@Ignore
public void testCreateAndSetSchemaTemplate() throws SQLException {
statement.execute("CREATE STORAGE GROUP root.sg1");

Expand All @@ -134,7 +148,7 @@ public void testCreateAndSetSchemaTemplate() throws SQLException {
}

// set schema template
statement.execute("SET SCHEMA TEMPLATE temp1 TO root.sg1");
statement.execute("SET SCHEMA TEMPLATE temp1 TO root.sg1.d1");

statement.execute("SHOW TIMESERIES root.sg1.**");
try (ResultSet resultSet = statement.getResultSet()) {
Expand Down Expand Up @@ -171,8 +185,24 @@ public void testCreateAndSetSchemaTemplate() throws SQLException {
}
Assert.assertEquals(3, count);

hasResult = statement.execute("SHOW DEVICES");
Assert.assertTrue(hasResult);

expectedResult = new String[] {"root.sg1.d1,false", "root.sg1.d1.vector1,true"};

count = 0;
try (ResultSet resultSet = statement.getResultSet()) {
while (resultSet.next()) {
String ActualResult =
resultSet.getString("devices") + "," + resultSet.getString("isAligned");
Assert.assertEquals(expectedResult[count], ActualResult);
count++;
}
}
Assert.assertEquals(2, count);

try {
statement.execute("UNSET SCHEMA TEMPLATE temp1 FROM root.sg1");
statement.execute("UNSET SCHEMA TEMPLATE temp1 FROM root.sg1.d1");
} catch (IoTDBSQLException e) {
Assert.assertEquals("326: Template is in use on root.sg1.d1", e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
public class CreateTemplateOperator extends Operator {

String name;
List<String> schemaNames = new ArrayList<>();
List<List<String>> measurements = new ArrayList<>();
List<List<TSDataType>> dataTypes = new ArrayList<>();
List<List<TSEncoding>> encodings = new ArrayList<>();
Expand All @@ -53,18 +52,6 @@ public void setName(String name) {
this.name = name;
}

public List<String> getSchemaNames() {
return schemaNames;
}

public void setSchemaNames(List<String> schemaNames) {
this.schemaNames = schemaNames;
}

public void addSchemaName(String schemaName) {
this.schemaNames.add(schemaName);
}

public List<List<String>> getMeasurements() {
return measurements;
}
Expand Down Expand Up @@ -116,7 +103,6 @@ public void addCompressor(List<CompressionType> compressors) {
@Override
public PhysicalPlan generatePhysicalPlan(PhysicalGenerator generator)
throws QueryProcessException {
return new CreateTemplatePlan(
name, schemaNames, measurements, dataTypes, encodings, compressors);
return new CreateTemplatePlan(name, measurements, dataTypes, encodings, compressors);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -333,36 +333,34 @@ public Operator visitCreateSchemaTemplate(IoTDBSqlParser.CreateSchemaTemplateCon
private void parseTemplateMeasurementClause(
IoTDBSqlParser.TemplateMeasurementClauseContext ctx,
CreateTemplateOperator createTemplateOperator) {
String schemaName;
List<String> measurements = new ArrayList<>();
List<TSDataType> dataTypes = new ArrayList<>();
List<TSEncoding> encodings = new ArrayList<>();
List<CompressionType> compressors = new ArrayList<>();
if (ctx instanceof IoTDBSqlParser.AlignedTemplateMeasurementContext) {
// aligned measurement
String alignedSuffixPath =
((IoTDBSqlParser.AlignedTemplateMeasurementContext) ctx).suffixPath().getText();
List<IoTDBSqlParser.NodeNameWithoutWildcardContext> measurementList =
((IoTDBSqlParser.AlignedTemplateMeasurementContext) ctx).nodeNameWithoutWildcard();
List<IoTDBSqlParser.AttributeClausesContext> attributeList =
((IoTDBSqlParser.AlignedTemplateMeasurementContext) ctx).attributeClauses();
schemaName = measurementList.get(0).getText();
for (int i = 0; i < attributeList.size(); i++) {
measurements.add(measurementList.get(i + 1).getText());
measurements.add(
alignedSuffixPath.concat(
TsFileConstant.PATH_SEPARATOR + measurementList.get(i).getText()));
parseAttributeClause(attributeList.get(i), dataTypes, encodings, compressors);
}
} else {
// non-aligned template measurement
schemaName =
((IoTDBSqlParser.NonAlignedTemplateMeasurementContext) ctx)
.nodeNameWithoutWildcard()
.getText();
measurements.add(schemaName);
measurements.add(
((IoTDBSqlParser.NonAlignedTemplateMeasurementContext) ctx).suffixPath().getText());
parseAttributeClause(
((IoTDBSqlParser.NonAlignedTemplateMeasurementContext) ctx).attributeClauses(),
dataTypes,
encodings,
compressors);
}
createTemplateOperator.addSchemaName(schemaName);
createTemplateOperator.addMeasurements(measurements);
createTemplateOperator.addDataTypes(dataTypes);
createTemplateOperator.addEncodings(encodings);
Expand Down