未验证 提交 e45636ec 编写于 作者: Z ZhaoXin 提交者: GitHub

[IOTDB-2440] Fix the query result is incorrect when using Template with aligned timeseries (#4902)

上级 6724bb3b
......@@ -26,6 +26,7 @@ import org.apache.iotdb.db.metadata.mnode.IEntityMNode;
import org.apache.iotdb.db.metadata.mnode.IMNode;
import org.apache.iotdb.db.metadata.mnode.IMeasurementMNode;
import org.apache.iotdb.db.metadata.mnode.MeasurementMNode;
import org.apache.iotdb.db.metadata.path.PartialPath;
import org.apache.iotdb.db.metadata.utils.MetaUtils;
import org.apache.iotdb.db.qp.physical.sys.CreateTemplatePlan;
import org.apache.iotdb.db.utils.SerializeUtils;
......@@ -248,10 +249,16 @@ public class Template {
String[] nodeNames,
TSDataType[] dataTypes,
TSEncoding[] encodings,
CompressionType[] compressors) {
CompressionType[] compressors)
throws IllegalPathException {
MeasurementSchema[] schemas = new MeasurementSchema[nodeNames.length];
for (int i = 0; i < nodeNames.length; i++) {
schemas[i] = new MeasurementSchema(nodeNames[i], dataTypes[i], encodings[i], compressors[i]);
schemas[i] =
new MeasurementSchema(
new PartialPath(nodeNames[i]).getMeasurement(),
dataTypes[i],
encodings[i],
compressors[i]);
}
return schemas;
}
......
......@@ -894,13 +894,14 @@ public class MManagerBasicTest {
Set<String> allSchema = new HashSet<>();
for (IMeasurementSchema schema : node.getSchemaTemplate().getSchemaMap().values()) {
allSchema.add("root.sg1.d1" + TsFileConstant.PATH_SEPARATOR + schema.getMeasurementId());
allSchema.add(
"root.sg1.d1.vector" + TsFileConstant.PATH_SEPARATOR + schema.getMeasurementId());
}
for (MeasurementPath measurementPath :
manager.getMeasurementPaths(new PartialPath("root.sg1.d1.**"))) {
manager.getMeasurementPaths(new PartialPath("root.sg1.**"))) {
allSchema.remove(measurementPath.toString());
}
allSchema.remove("root.sg1.d1.vector.s11");
assertTrue(allSchema.isEmpty());
IMeasurementMNode mNode = manager.getMeasurementMNode(new PartialPath("root.sg1.d1.s11"));
......
......@@ -106,6 +106,89 @@ public class InsertRowPlanTest {
}
}
@Test
public void testInsertRowPlanWithTreeSchemaTemplate()
throws QueryProcessException, MetadataException, InterruptedException,
QueryFilterOptimizationException, StorageEngineException, IOException {
List<List<String>> measurementList = new ArrayList<>();
List<String> v1 = Arrays.asList("GPS.s1", "GPS.s2", "GPS.s3");
measurementList.add(v1);
List<String> v2 = Arrays.asList("GPS2.s4", "GPS2.s5");
measurementList.add(v2);
measurementList.add(Collections.singletonList("s6"));
List<List<TSDataType>> dataTypesList = new ArrayList<>();
List<TSDataType> d1 = Arrays.asList(TSDataType.DOUBLE, TSDataType.FLOAT, TSDataType.INT64);
dataTypesList.add(d1);
List<TSDataType> d2 = Arrays.asList(TSDataType.INT32, TSDataType.BOOLEAN);
dataTypesList.add(d2);
dataTypesList.add(Collections.singletonList(TSDataType.TEXT));
List<List<TSEncoding>> encodingList = new ArrayList<>();
List<TSEncoding> e1 = Arrays.asList(TSEncoding.PLAIN, TSEncoding.PLAIN, TSEncoding.PLAIN);
encodingList.add(e1);
List<TSEncoding> e2 = Arrays.asList(TSEncoding.PLAIN, TSEncoding.PLAIN);
encodingList.add(e2);
encodingList.add(Collections.singletonList(TSEncoding.PLAIN));
List<List<CompressionType>> compressionTypes = new ArrayList<>();
compressionTypes.add(
Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY, CompressionType.SNAPPY));
compressionTypes.add(Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY));
compressionTypes.add(Arrays.asList(CompressionType.SNAPPY));
CreateTemplatePlan plan =
new CreateTemplatePlan(
"templateN", measurementList, dataTypesList, encodingList, compressionTypes);
IoTDB.metaManager.createSchemaTemplate(plan);
IoTDB.metaManager.setSchemaTemplate(new SetTemplatePlan("templateN", "root.isp.d1"));
IoTDBDescriptor.getInstance().getConfig().setAutoCreateSchemaEnabled(false);
InsertRowPlan rowPlan = getInsertAlignedRowPlan(111L);
PlanExecutor executor = new PlanExecutor();
executor.insert(rowPlan);
rowPlan = getInsertAlignedRowPlan(112L);
executor.insert(rowPlan);
rowPlan = getInsertAlignedRowPlan(113L);
executor.insert(rowPlan);
QueryPlan queryPlan =
(QueryPlan) processor.parseSQLToPhysicalPlan("select * from root.isp.d1.GPS");
QueryDataSet dataSet = executor.processQuery(queryPlan, EnvironmentUtils.TEST_QUERY_CONTEXT);
Assert.assertEquals(1, dataSet.getPaths().size());
int resSize = 0;
while (dataSet.hasNext()) {
Assert.assertEquals(3, dataSet.next().getFields().size());
resSize++;
}
Assert.assertEquals(3, resSize);
TSDataType[] dataTypes = new TSDataType[] {TSDataType.TEXT};
String[] columns = new String[1];
columns[0] = "a";
rowPlan =
new InsertRowPlan(
new PartialPath("root.isp.d1"), 1111L, new String[] {"s6"}, dataTypes, columns, false);
executor.insert(rowPlan);
queryPlan = (QueryPlan) processor.parseSQLToPhysicalPlan("select * from root.isp.d1");
dataSet = executor.processQuery(queryPlan, EnvironmentUtils.TEST_QUERY_CONTEXT);
Assert.assertEquals(1, dataSet.getPaths().size());
Assert.assertEquals(true, dataSet.hasNext());
queryPlan = (QueryPlan) processor.parseSQLToPhysicalPlan("select * from root.isp.d1.**");
dataSet = executor.processQuery(queryPlan, EnvironmentUtils.TEST_QUERY_CONTEXT);
Assert.assertEquals(2, dataSet.getPaths().size());
Assert.assertEquals(true, dataSet.hasNext());
Assert.assertEquals(5, dataSet.next().getFields().size());
}
@Test
public void testInsertRowPlanWithSchemaTemplate()
throws QueryProcessException, MetadataException, InterruptedException,
......@@ -250,9 +333,10 @@ public class InsertRowPlanTest {
executor.insert(rowPlan);
QueryPlan queryPlan =
(QueryPlan) processor.parseSQLToPhysicalPlan("select s1 from root.isp.d1.GPS");
(QueryPlan) processor.parseSQLToPhysicalPlan("select * from root.isp.d1.GPS");
QueryDataSet dataSet = executor.processQuery(queryPlan, EnvironmentUtils.TEST_QUERY_CONTEXT);
Assert.assertEquals(1, dataSet.getPaths().size());
Assert.assertEquals(true, dataSet.hasNext());
while (dataSet.hasNext()) {
RowRecord record = dataSet.next();
Assert.assertEquals(3, record.getFields().size());
......@@ -288,7 +372,10 @@ public class InsertRowPlanTest {
}
private InsertRowPlan getInsertAlignedRowPlan() throws IllegalPathException {
long time = 110L;
return getInsertAlignedRowPlan(110L);
}
private InsertRowPlan getInsertAlignedRowPlan(long time) throws IllegalPathException {
TSDataType[] dataTypes =
new TSDataType[] {TSDataType.DOUBLE, TSDataType.FLOAT, TSDataType.INT64};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册