This is an automated email from the ASF dual-hosted git repository. haonan pushed a commit to branch remove_storage_engine_old in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 492caa2215443583cb172d1cb763749bfafb93f3 Author: HTHou <[email protected]> AuthorDate: Tue Nov 8 15:32:34 2022 +0800 delete more code --- .../iotdb/db/qp/physical/ConcatOptimizerTest.java | 140 -- .../qp/physical/InsertRowsOfOneDevicePlanTest.java | 75 - .../db/qp/physical/PhysicalPlanSerializeTest.java | 326 ----- .../iotdb/db/qp/physical/PhysicalPlanTest.java | 1490 -------------------- .../iotdb/db/qp/physical/SerializationTest.java | 151 -- .../iotdb/db/qp/physical/SerializedSizeTest.java | 130 -- .../org/apache/iotdb/db/utils/MemUtilsTest.java | 35 +- 7 files changed, 21 insertions(+), 2326 deletions(-) diff --git a/server/src/test/java/org/apache/iotdb/db/qp/physical/ConcatOptimizerTest.java b/server/src/test/java/org/apache/iotdb/db/qp/physical/ConcatOptimizerTest.java deleted file mode 100644 index 7f63328147..0000000000 --- a/server/src/test/java/org/apache/iotdb/db/qp/physical/ConcatOptimizerTest.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.iotdb.db.qp.physical; - -import org.apache.iotdb.commons.exception.MetadataException; -import org.apache.iotdb.commons.path.PartialPath; -import org.apache.iotdb.db.exception.query.QueryProcessException; -import org.apache.iotdb.db.qp.Planner; -import org.apache.iotdb.db.qp.physical.crud.RawDataQueryPlan; -import org.apache.iotdb.db.qp.strategy.optimizer.ConcatPathOptimizer; -import org.apache.iotdb.db.service.IoTDB; -import org.apache.iotdb.db.utils.EnvironmentUtils; -import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType; -import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; -import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding; -import org.apache.iotdb.tsfile.read.common.Path; -import org.apache.iotdb.tsfile.read.expression.IExpression; -import org.apache.iotdb.tsfile.read.expression.impl.BinaryExpression; -import org.apache.iotdb.tsfile.read.expression.impl.SingleSeriesExpression; -import org.apache.iotdb.tsfile.read.filter.ValueFilter; - -import org.antlr.v4.runtime.RecognitionException; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import java.io.IOException; - -import static org.junit.Assert.assertEquals; - -/** test the correctness of {@linkplain ConcatPathOptimizer ConcatPathOptimizer} */ -public class ConcatOptimizerTest { - - private Planner processor; - - @Before - public void before() throws MetadataException { - processor = new Planner(); - IoTDB.configManager.init(); - IoTDB.schemaProcessor.setStorageGroup(new PartialPath("root.laptop")); - IoTDB.schemaProcessor.createTimeseries( - new PartialPath("root.laptop.d1.s1"), - TSDataType.INT64, - TSEncoding.PLAIN, - CompressionType.UNCOMPRESSED, - null); - IoTDB.schemaProcessor.createTimeseries( - new PartialPath("root.laptop.d1.s2"), - TSDataType.INT64, - TSEncoding.PLAIN, - CompressionType.UNCOMPRESSED, - null); - IoTDB.schemaProcessor.createTimeseries( - new PartialPath("root.laptop.d2.s1"), - TSDataType.INT64, - TSEncoding.PLAIN, - CompressionType.UNCOMPRESSED, - null); - IoTDB.schemaProcessor.createTimeseries( - new PartialPath("root.laptop.d2.s2"), - TSDataType.INT64, - TSEncoding.PLAIN, - CompressionType.UNCOMPRESSED, - null); - IoTDB.schemaProcessor.createTimeseries( - new PartialPath("root.laptop.d3.s1"), - TSDataType.INT64, - TSEncoding.PLAIN, - CompressionType.UNCOMPRESSED, - null); - IoTDB.schemaProcessor.createTimeseries( - new PartialPath("root.laptop.d3.s2"), - TSDataType.INT64, - TSEncoding.PLAIN, - CompressionType.UNCOMPRESSED, - null); - } - - @After - public void after() throws IOException { - IoTDB.configManager.clear(); - EnvironmentUtils.cleanAllDir(); - } - - @Test - public void testConcat1() throws QueryProcessException, RecognitionException { - String inputSQL = "select s1 from root.laptop.d1"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(inputSQL); - assertEquals("root.laptop.d1.s1", plan.getPaths().get(0).getFullPath()); - } - - @Test - public void testConcat2() throws QueryProcessException, RecognitionException { - String inputSQL = "select s1 from root.laptop.*"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(inputSQL); - assertEquals("root.laptop.d1.s1", plan.getPaths().get(0).getFullPath()); - assertEquals("root.laptop.d2.s1", plan.getPaths().get(1).getFullPath()); - assertEquals("root.laptop.d3.s1", plan.getPaths().get(2).getFullPath()); - } - - @Test - public void testConcat3() throws QueryProcessException, RecognitionException { - String inputSQL = "select s1 from root.laptop.d1 where s1 < 10"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(inputSQL); - SingleSeriesExpression seriesExpression = - new SingleSeriesExpression(new Path("root.laptop.d1", "s1", true), ValueFilter.lt(10)); - assertEquals(seriesExpression.toString(), ((RawDataQueryPlan) plan).getExpression().toString()); - } - - @Test - public void testConcatMultipleDeviceInFilter() throws QueryProcessException { - String inputSQL = "select s1 from root.laptop.* where s1 < 10"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(inputSQL); - IExpression expression = - BinaryExpression.and( - BinaryExpression.and( - new SingleSeriesExpression( - new Path("root.laptop.d1", "s1", true), ValueFilter.lt(10)), - new SingleSeriesExpression( - new Path("root.laptop.d2", "s1", true), ValueFilter.lt(10))), - new SingleSeriesExpression(new Path("root.laptop.d3", "s1", true), ValueFilter.lt(10))); - assertEquals(expression.toString(), ((RawDataQueryPlan) plan).getExpression().toString()); - } -} diff --git a/server/src/test/java/org/apache/iotdb/db/qp/physical/InsertRowsOfOneDevicePlanTest.java b/server/src/test/java/org/apache/iotdb/db/qp/physical/InsertRowsOfOneDevicePlanTest.java deleted file mode 100644 index 13c2b8503d..0000000000 --- a/server/src/test/java/org/apache/iotdb/db/qp/physical/InsertRowsOfOneDevicePlanTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.iotdb.db.qp.physical; - -import org.apache.iotdb.commons.exception.IllegalPathException; -import org.apache.iotdb.commons.path.PartialPath; -import org.apache.iotdb.db.qp.physical.crud.InsertRowPlan; -import org.apache.iotdb.db.qp.physical.crud.InsertRowsOfOneDevicePlan; -import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; - -import org.junit.Assert; -import org.junit.Test; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.nio.ByteBuffer; - -public class InsertRowsOfOneDevicePlanTest { - - @Test - public void testSerializable() throws IllegalPathException, IOException { - - PartialPath device = new PartialPath("root.sg.d"); - InsertRowPlan[] rowPlans = - new InsertRowPlan[] { - new InsertRowPlan( - device, - 1000L, - new String[] {"s1", "s2", "s3"}, - new TSDataType[] {TSDataType.DOUBLE, TSDataType.FLOAT, TSDataType.INT64}, - new String[] {"1.0", "2", "300"}, - true), - new InsertRowPlan( - device, - 2000L, - new String[] {"s1", "s4"}, - new TSDataType[] {TSDataType.DOUBLE, TSDataType.TEXT}, - new String[] {"2.0", "abc"}, - true), - }; - - InsertRowsOfOneDevicePlan p = new InsertRowsOfOneDevicePlan(device, rowPlans, new int[] {0, 1}); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutputStream w = new DataOutputStream(baos); - p.serialize(w); - w.flush(); - byte[] res = baos.toByteArray(); - ByteBuffer buf = ByteBuffer.wrap(res); - InsertRowsOfOneDevicePlan p2 = (InsertRowsOfOneDevicePlan) PhysicalPlan.Factory.create(buf); - Assert.assertEquals(p, p2); - res = new byte[1024]; - p.serialize(ByteBuffer.wrap(res)); - buf = ByteBuffer.wrap(res); - p2 = (InsertRowsOfOneDevicePlan) PhysicalPlan.Factory.create(buf); - Assert.assertEquals(p, p2); - } -} diff --git a/server/src/test/java/org/apache/iotdb/db/qp/physical/PhysicalPlanSerializeTest.java b/server/src/test/java/org/apache/iotdb/db/qp/physical/PhysicalPlanSerializeTest.java deleted file mode 100644 index f313e048d6..0000000000 --- a/server/src/test/java/org/apache/iotdb/db/qp/physical/PhysicalPlanSerializeTest.java +++ /dev/null @@ -1,326 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.iotdb.db.qp.physical; - -import org.apache.iotdb.commons.auth.AuthException; -import org.apache.iotdb.commons.exception.IllegalPathException; -import org.apache.iotdb.commons.path.PartialPath; -import org.apache.iotdb.db.exception.query.QueryProcessException; -import org.apache.iotdb.db.qp.logical.Operator.OperatorType; -import org.apache.iotdb.db.qp.logical.sys.AlterTimeSeriesOperator.AlterType; -import org.apache.iotdb.db.qp.logical.sys.AuthorOperator.AuthorType; -import org.apache.iotdb.db.qp.physical.PhysicalPlan.Factory; -import org.apache.iotdb.db.qp.physical.sys.AlterTimeSeriesPlan; -import org.apache.iotdb.db.qp.physical.sys.AuthorPlan; -import org.apache.iotdb.db.qp.physical.sys.CreateAlignedTimeSeriesPlan; -import org.apache.iotdb.db.qp.physical.sys.CreateMultiTimeSeriesPlan; -import org.apache.iotdb.db.qp.physical.sys.CreateTimeSeriesPlan; -import org.apache.iotdb.db.qp.physical.sys.DataAuthPlan; -import org.apache.iotdb.db.qp.physical.sys.DeleteStorageGroupPlan; -import org.apache.iotdb.db.qp.physical.sys.DeleteTimeSeriesPlan; -import org.apache.iotdb.db.qp.physical.sys.LoadConfigurationPlan; -import org.apache.iotdb.db.qp.physical.sys.LoadConfigurationPlan.LoadConfigurationPlanType; -import org.apache.iotdb.db.qp.physical.sys.SetStorageGroupPlan; -import org.apache.iotdb.db.qp.physical.sys.SetTTLPlan; -import org.apache.iotdb.db.qp.physical.sys.ShowTimeSeriesPlan; -import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType; -import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; -import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding; - -import org.junit.Assert; -import org.junit.Test; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.Arrays; -import java.util.Collections; -import java.util.Properties; - -public class PhysicalPlanSerializeTest { - - public ByteBuffer serializePlan(PhysicalPlan plan) { - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); - - try { - plan.serialize(dataOutputStream); - } catch (IOException e) { - e.printStackTrace(); - Assert.fail(e.getMessage()); - } - - return ByteBuffer.wrap(byteArrayOutputStream.toByteArray()); - } - - public PhysicalPlan testTwoSerializeMethodAndDeserialize(PhysicalPlan plan) - throws IOException, IllegalPathException { - ByteBuffer byteBuffer1 = serializePlan(plan); - ByteBuffer byteBuffer2 = ByteBuffer.allocate(byteBuffer1.limit()); - - plan.serialize(byteBuffer2); - byteBuffer2.flip(); - Assert.assertEquals(byteBuffer1, byteBuffer2); - - return Factory.create(byteBuffer1); - } - - @Test - public void showTimeSeriesPlanSerializeTest() throws IllegalPathException, IOException { - ShowTimeSeriesPlan timeSeriesPlan = - new ShowTimeSeriesPlan(new PartialPath("root.sg.d1.s1"), true, "unit", "10", 0, 0, false); - ByteBuffer byteBuffer = serializePlan(timeSeriesPlan); - PhysicalPlan result = Factory.create(byteBuffer); - Assert.assertEquals("root.sg.d1.s1", ((ShowTimeSeriesPlan) result).getPath().getFullPath()); - Assert.assertEquals(true, ((ShowTimeSeriesPlan) result).isContains()); - Assert.assertEquals("unit", ((ShowTimeSeriesPlan) result).getKey()); - Assert.assertEquals("10", ((ShowTimeSeriesPlan) result).getValue()); - Assert.assertEquals(0, ((ShowTimeSeriesPlan) result).getLimit()); - Assert.assertEquals(0, ((ShowTimeSeriesPlan) result).getOffset()); - Assert.assertEquals(false, ((ShowTimeSeriesPlan) result).isOrderByHeat()); - } - - @Test - public void setTTLPlanSerializeTest() throws IllegalPathException, IOException { - SetTTLPlan setTTLPlan = new SetTTLPlan(new PartialPath("root.sg"), 1000000L); - - PhysicalPlan result = testTwoSerializeMethodAndDeserialize(setTTLPlan); - - Assert.assertEquals(OperatorType.TTL, result.getOperatorType()); - Assert.assertEquals("root.sg", ((SetTTLPlan) result).getStorageGroup().getFullPath()); - Assert.assertEquals(1000000L, ((SetTTLPlan) result).getDataTTL()); - } - - @Test - public void setStorageGroupPlanTest() throws IllegalPathException, IOException { - SetStorageGroupPlan setStorageGroupPlan = new SetStorageGroupPlan(new PartialPath("root.sg")); - - PhysicalPlan result = testTwoSerializeMethodAndDeserialize(setStorageGroupPlan); - - Assert.assertEquals(OperatorType.SET_STORAGE_GROUP, result.getOperatorType()); - Assert.assertEquals("root.sg", ((SetStorageGroupPlan) result).getPath().getFullPath()); - Assert.assertEquals(result, setStorageGroupPlan); - } - - @Test - public void deleteTimeSeriesPlanSerializeTest() throws IllegalPathException, IOException { - DeleteTimeSeriesPlan deleteTimeSeriesPlan = - new DeleteTimeSeriesPlan(Collections.singletonList(new PartialPath("root.sg.d1.s1"))); - - PhysicalPlan result = testTwoSerializeMethodAndDeserialize(deleteTimeSeriesPlan); - - Assert.assertEquals(OperatorType.DELETE_TIMESERIES, result.getOperatorType()); - Assert.assertEquals("root.sg.d1.s1", result.getPaths().get(0).getFullPath()); - } - - @Test - public void deleteStorageGroupPlanSerializeTest() throws IllegalPathException, IOException { - DeleteStorageGroupPlan deleteStorageGroupPlan = - new DeleteStorageGroupPlan(Collections.singletonList(new PartialPath("root.sg"))); - - PhysicalPlan result = testTwoSerializeMethodAndDeserialize(deleteStorageGroupPlan); - - Assert.assertEquals(OperatorType.DELETE_STORAGE_GROUP, result.getOperatorType()); - Assert.assertEquals("root.sg", result.getPaths().get(0).getFullPath()); - } - - @Test - public void dataAuthPlanSerializeTest() throws IOException, IllegalPathException { - DataAuthPlan dataAuthPlan = - new DataAuthPlan(OperatorType.GRANT_WATERMARK_EMBEDDING, Arrays.asList("user1", "user2")); - - PhysicalPlan result = testTwoSerializeMethodAndDeserialize(dataAuthPlan); - - Assert.assertEquals(Arrays.asList("user1", "user2"), ((DataAuthPlan) result).getUsers()); - } - - @Test - public void createTimeSeriesPlanSerializeTest1() throws IOException, IllegalPathException { - CreateTimeSeriesPlan createTimeSeriesPlan = - new CreateTimeSeriesPlan( - new PartialPath("root.sg.d1.s1"), - TSDataType.DOUBLE, - TSEncoding.RLE, - CompressionType.SNAPPY, - Collections.singletonMap("prop1", "propValue1"), - Collections.singletonMap("tag1", "tagValue1"), - Collections.singletonMap("attr1", "attrValue1"), - "temperature"); - - PhysicalPlan result = testTwoSerializeMethodAndDeserialize(createTimeSeriesPlan); - - Assert.assertEquals(OperatorType.CREATE_TIMESERIES, result.getOperatorType()); - Assert.assertEquals(createTimeSeriesPlan, result); - } - - @Test - public void createTimeSeriesPlanSerializeTest2() throws IOException, IllegalPathException { - CreateTimeSeriesPlan createTimeSeriesPlan = - new CreateTimeSeriesPlan( - new PartialPath("root.sg.d1.s1"), - TSDataType.DOUBLE, - TSEncoding.RLE, - CompressionType.SNAPPY, - null, - null, - null, - null); - - PhysicalPlan result = testTwoSerializeMethodAndDeserialize(createTimeSeriesPlan); - - Assert.assertEquals(OperatorType.CREATE_TIMESERIES, result.getOperatorType()); - Assert.assertEquals(createTimeSeriesPlan, result); - } - - @Test - public void createAlignedTimeSeriesPlanSerializeTest() throws IOException, IllegalPathException { - CreateAlignedTimeSeriesPlan createAlignedTimeSeriesPlan = - new CreateAlignedTimeSeriesPlan( - new PartialPath("root.sg.d1"), - Arrays.asList("s1", "s2"), - Arrays.asList(TSDataType.DOUBLE, TSDataType.INT32), - Arrays.asList(TSEncoding.RLE, TSEncoding.RLE), - Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY), - null, - null, - null); - - PhysicalPlan result = testTwoSerializeMethodAndDeserialize(createAlignedTimeSeriesPlan); - - Assert.assertEquals(OperatorType.CREATE_ALIGNED_TIMESERIES, result.getOperatorType()); - Assert.assertEquals(createAlignedTimeSeriesPlan, result); - } - - @Test - public void createMuSerializeTest1() throws IOException, IllegalPathException { - CreateMultiTimeSeriesPlan plan = new CreateMultiTimeSeriesPlan(); - plan.setPaths( - Arrays.asList(new PartialPath("root.sg.d1.s1"), new PartialPath("root.sg.d1.s2"))); - plan.setDataTypes(Arrays.asList(TSDataType.DOUBLE, TSDataType.INT64)); - plan.setEncodings(Arrays.asList(TSEncoding.GORILLA, TSEncoding.GORILLA)); - plan.setCompressors(Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY)); - plan.setProps( - Arrays.asList( - Collections.singletonMap("prop1", "propValue1"), - Collections.singletonMap("prop2", "propValue2"))); - plan.setTags( - Arrays.asList( - Collections.singletonMap("tag1", "tagValue1"), - Collections.singletonMap("tag2", "tagValue2"))); - plan.setAttributes( - Arrays.asList( - Collections.singletonMap("attr1", "attrValue1"), - Collections.singletonMap("attr2", "attrValue2"))); - plan.setAlias(Arrays.asList("temperature", "speed")); - - PhysicalPlan result = testTwoSerializeMethodAndDeserialize(plan); - - Assert.assertEquals(OperatorType.CREATE_MULTI_TIMESERIES, result.getOperatorType()); - Assert.assertEquals(plan, result); - } - - @Test - public void createMuSerializeTest2() throws IOException, IllegalPathException { - CreateMultiTimeSeriesPlan plan = new CreateMultiTimeSeriesPlan(); - plan.setPaths( - Arrays.asList(new PartialPath("root.sg.d1.s1"), new PartialPath("root.sg.d1.s2"))); - plan.setDataTypes(Arrays.asList(TSDataType.DOUBLE, TSDataType.INT64)); - plan.setEncodings(Arrays.asList(TSEncoding.GORILLA, TSEncoding.GORILLA)); - plan.setCompressors(Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY)); - plan.setProps(null); - plan.setTags(null); - plan.setAttributes(null); - plan.setAlias(null); - - PhysicalPlan result = testTwoSerializeMethodAndDeserialize(plan); - - Assert.assertEquals(OperatorType.CREATE_MULTI_TIMESERIES, result.getOperatorType()); - Assert.assertEquals(plan, result); - } - - @Test - public void createMuSerializeTest3() throws IOException, IllegalPathException { - CreateMultiTimeSeriesPlan plan = new CreateMultiTimeSeriesPlan(); - plan.setPaths( - Arrays.asList(new PartialPath("root.sg.d1.s0"), new PartialPath("root.sg.d1.s1"))); - plan.setDataTypes( - Arrays.asList(TSDataType.DOUBLE, TSDataType.INT64, TSDataType.DOUBLE, TSDataType.INT64)); - plan.setEncodings( - Arrays.asList( - TSEncoding.GORILLA, TSEncoding.GORILLA, TSEncoding.GORILLA, TSEncoding.GORILLA)); - plan.setCompressors(Arrays.asList(CompressionType.SNAPPY, CompressionType.SNAPPY)); - plan.setProps(null); - plan.setTags(null); - plan.setAttributes(null); - plan.setAlias(null); - - PhysicalPlan result = testTwoSerializeMethodAndDeserialize(plan); - - Assert.assertEquals(OperatorType.CREATE_MULTI_TIMESERIES, result.getOperatorType()); - Assert.assertEquals(plan, result); - } - - @Test - public void AlterTimeSeriesPlanSerializeTest() throws IOException, IllegalPathException { - AlterTimeSeriesPlan alterTimeSeriesPlan = - new AlterTimeSeriesPlan( - new PartialPath("root.sg.d1.s1"), - AlterType.RENAME, - Collections.singletonMap("root.sg.d1.s1", "root.sg.device1.temperature"), - null, - null, - null); - - ByteBuffer byteBuffer = serializePlan(alterTimeSeriesPlan); - PhysicalPlan result = Factory.create(byteBuffer); - Assert.assertEquals(alterTimeSeriesPlan, result); - } - - @Test - public void loadConfigurationPlanSerializeTest() - throws QueryProcessException, IOException, IllegalPathException { - Properties[] properties = new Properties[2]; - properties[0] = new Properties(); - properties[0].setProperty("prop1", "value1"); - properties[1] = null; - - LoadConfigurationPlan loadConfigurationPlan = - new LoadConfigurationPlan(LoadConfigurationPlanType.GLOBAL, properties); - ByteBuffer byteBuffer = serializePlan(loadConfigurationPlan); - PhysicalPlan result = Factory.create(byteBuffer); - Assert.assertEquals(OperatorType.LOAD_CONFIGURATION, result.getOperatorType()); - Assert.assertEquals( - LoadConfigurationPlanType.GLOBAL, - ((LoadConfigurationPlan) result).getLoadConfigurationPlanType()); - Assert.assertEquals(properties[0], ((LoadConfigurationPlan) result).getIoTDBProperties()); - Assert.assertEquals(properties[1], ((LoadConfigurationPlan) result).getClusterProperties()); - } - - @Test - public void authorPlanSerializeTest() throws IOException, AuthException, IllegalPathException { - AuthorPlan authorPlan = - new AuthorPlan(AuthorType.CREATE_ROLE, "root", "root", "root", "", null, null); - - PhysicalPlan result = testTwoSerializeMethodAndDeserialize(authorPlan); - - Assert.assertEquals(result, authorPlan); - } -} diff --git a/server/src/test/java/org/apache/iotdb/db/qp/physical/PhysicalPlanTest.java b/server/src/test/java/org/apache/iotdb/db/qp/physical/PhysicalPlanTest.java deleted file mode 100644 index d37e5f5f42..0000000000 --- a/server/src/test/java/org/apache/iotdb/db/qp/physical/PhysicalPlanTest.java +++ /dev/null @@ -1,1490 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.iotdb.db.qp.physical; - -import org.apache.iotdb.commons.exception.IllegalPathException; -import org.apache.iotdb.commons.exception.MetadataException; -import org.apache.iotdb.commons.path.PartialPath; -import org.apache.iotdb.commons.udf.UDFInformation; -import org.apache.iotdb.commons.udf.service.UDFManagementService; -import org.apache.iotdb.db.conf.IoTDBDescriptor; -import org.apache.iotdb.db.engine.trigger.executor.TriggerEvent; -import org.apache.iotdb.db.exception.StorageEngineException; -import org.apache.iotdb.db.exception.query.QueryProcessException; -import org.apache.iotdb.db.exception.sql.SQLParserException; -import org.apache.iotdb.db.qp.Planner; -import org.apache.iotdb.db.qp.logical.Operator.OperatorType; -import org.apache.iotdb.db.qp.physical.crud.AggregationPlan; -import org.apache.iotdb.db.qp.physical.crud.DeletePlan; -import org.apache.iotdb.db.qp.physical.crud.FillQueryPlan; -import org.apache.iotdb.db.qp.physical.crud.GroupByTimeFillPlan; -import org.apache.iotdb.db.qp.physical.crud.GroupByTimePlan; -import org.apache.iotdb.db.qp.physical.crud.InsertRowPlan; -import org.apache.iotdb.db.qp.physical.crud.LastQueryPlan; -import org.apache.iotdb.db.qp.physical.crud.QueryPlan; -import org.apache.iotdb.db.qp.physical.crud.RawDataQueryPlan; -import org.apache.iotdb.db.qp.physical.crud.UDTFPlan; -import org.apache.iotdb.db.qp.physical.sys.AuthorPlan; -import org.apache.iotdb.db.qp.physical.sys.CreateContinuousQueryPlan; -import org.apache.iotdb.db.qp.physical.sys.CreateFunctionPlan; -import org.apache.iotdb.db.qp.physical.sys.CreateTimeSeriesPlan; -import org.apache.iotdb.db.qp.physical.sys.CreateTriggerPlan; -import org.apache.iotdb.db.qp.physical.sys.DataAuthPlan; -import org.apache.iotdb.db.qp.physical.sys.DropContinuousQueryPlan; -import org.apache.iotdb.db.qp.physical.sys.DropFunctionPlan; -import org.apache.iotdb.db.qp.physical.sys.DropTriggerPlan; -import org.apache.iotdb.db.qp.physical.sys.LoadConfigurationPlan; -import org.apache.iotdb.db.qp.physical.sys.OperateFilePlan; -import org.apache.iotdb.db.qp.physical.sys.SetStorageGroupPlan; -import org.apache.iotdb.db.qp.physical.sys.ShowContinuousQueriesPlan; -import org.apache.iotdb.db.qp.physical.sys.ShowDevicesPlan; -import org.apache.iotdb.db.qp.physical.sys.ShowFunctionsPlan; -import org.apache.iotdb.db.qp.physical.sys.ShowPlan; -import org.apache.iotdb.db.qp.physical.sys.ShowTriggersPlan; -import org.apache.iotdb.db.qp.physical.sys.StartTriggerPlan; -import org.apache.iotdb.db.qp.physical.sys.StopTriggerPlan; -import org.apache.iotdb.db.query.executor.fill.PreviousFill; -import org.apache.iotdb.db.service.IoTDB; -import org.apache.iotdb.db.utils.EnvironmentUtils; -import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType; -import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; -import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding; -import org.apache.iotdb.tsfile.read.common.Path; -import org.apache.iotdb.tsfile.read.expression.IExpression; -import org.apache.iotdb.tsfile.read.expression.impl.GlobalTimeExpression; -import org.apache.iotdb.tsfile.read.expression.impl.SingleSeriesExpression; -import org.apache.iotdb.tsfile.read.filter.TimeFilter; -import org.apache.iotdb.tsfile.read.filter.ValueFilter; -import org.apache.iotdb.tsfile.read.filter.factory.FilterFactory; -import org.apache.iotdb.tsfile.read.filter.operator.AndFilter; -import org.apache.iotdb.tsfile.read.filter.operator.OrFilter; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -@Ignore -public class PhysicalPlanTest { - - private final Planner processor = new Planner(); - - @Before - public void before() throws MetadataException { - EnvironmentUtils.envSetUp(); - IoTDB.schemaProcessor.setStorageGroup(new PartialPath("root.vehicle")); - IoTDB.schemaProcessor.createTimeseries( - new PartialPath("root.vehicle.d1.s1"), - TSDataType.FLOAT, - TSEncoding.PLAIN, - CompressionType.UNCOMPRESSED, - null); - IoTDB.schemaProcessor.createTimeseries( - new PartialPath("root.vehicle.d2.s1"), - TSDataType.FLOAT, - TSEncoding.PLAIN, - CompressionType.UNCOMPRESSED, - null); - IoTDB.schemaProcessor.createTimeseries( - new PartialPath("root.vehicle.d3.s1"), - TSDataType.FLOAT, - TSEncoding.PLAIN, - CompressionType.UNCOMPRESSED, - null); - IoTDB.schemaProcessor.createTimeseries( - new PartialPath("root.vehicle.d4.s1"), - TSDataType.FLOAT, - TSEncoding.PLAIN, - CompressionType.UNCOMPRESSED, - null); - } - - @After - public void clean() throws IOException, StorageEngineException { - EnvironmentUtils.cleanEnv(); - } - - @Test - public void testMetadata() throws QueryProcessException { - String metadata = "create timeseries root.vehicle.d1.s2 with datatype=INT32,encoding=RLE"; - Planner processor = new Planner(); - CreateTimeSeriesPlan plan = (CreateTimeSeriesPlan) processor.parseSQLToPhysicalPlan(metadata); - assertEquals( - "seriesPath: root.vehicle.d1.s2, resultDataType: INT32, encoding: RLE, compression: SNAPPY, tagOffset: -1", - plan.toString()); - } - - @Test - public void testMetadata2() throws QueryProcessException { - String metadata = "create timeseries root.vehicle.d1.s2 with datatype=int32,encoding=rle"; - Planner processor = new Planner(); - CreateTimeSeriesPlan plan = (CreateTimeSeriesPlan) processor.parseSQLToPhysicalPlan(metadata); - assertEquals( - "seriesPath: root.vehicle.d1.s2, resultDataType: INT32, encoding: RLE, compression: SNAPPY, tagOffset: -1", - plan.toString()); - } - - @Test - public void testMetadata3() throws QueryProcessException { - String metadata = - "create timeseries root.vehicle.d1.s2(温度) with datatype=int32,encoding=rle, compression=SNAPPY " - + "tags('tag1'='v1', 'tag2'='v2') attributes('attr1'='v1', 'attr2'='v2')"; - System.out.println(metadata.length()); - Planner processor = new Planner(); - CreateTimeSeriesPlan plan = (CreateTimeSeriesPlan) processor.parseSQLToPhysicalPlan(metadata); - assertEquals( - "seriesPath: root.vehicle.d1.s2, resultDataType: INT32, encoding: RLE, compression: SNAPPY, tagOffset: -1", - plan.toString()); - } - - // TODO @Steve SU - // @Test - // public void testMetadata4() throws QueryProcessException { - // String metadata = - // "create aligned timeseries root.vehicle.d1.(s1 INT32, s2 FLOAT) with encoding=(RLE, RLE) - // compression=SNAPPY"; - // Planner processor = new Planner(); - // CreateAlignedTimeSeriesPlan plan = - // (CreateAlignedTimeSeriesPlan) processor.parseSQLToPhysicalPlan(metadata); - // assertEquals( - // "devicePath: root.vehicle.d1, measurements: [s1, s2], dataTypes: [INT32, FLOAT], - // encoding: [RLE, RLE], compression: SNAPPY", - // plan.toString()); - // } - - @Test - public void testAuthor() throws QueryProcessException { - String sql = - "grant role xm privileges SET_STORAGE_GROUP,DELETE_TIMESERIES on root.vehicle.d1.s1"; - Planner processor = new Planner(); - AuthorPlan plan = (AuthorPlan) processor.parseSQLToPhysicalPlan(sql); - assertEquals( - "userName: null\n" - + "roleName: xm\n" - + "password: null\n" - + "newPassword: null\n" - + "permissions: [0, 5]\n" - + "nodeName: [root.vehicle.d1.s1]\n" - + "authorType: GRANT_ROLE", - plan.toString()); - } - - @Test - public void testAggregation() throws QueryProcessException { - String sqlStr = - "select sum(d1.s1) " - + "from root.vehicle " - + "where time <= 51 or !(time != 100 and time < 460)"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - if (!plan.isQuery()) { - fail(); - } - AggregationPlan mergePlan = (AggregationPlan) plan; - assertEquals("sum", mergePlan.getAggregations().get(0)); - } - - @Test - public void testGroupBy1() throws QueryProcessException { - String sqlStr = - "select count(s1) " - + "from root.vehicle.d1 " - + "where s1 < 20 and time <= now() " - + "group by([8,737), 3ms)"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - if (!plan.isQuery()) { - fail(); - } - GroupByTimePlan mergePlan = (GroupByTimePlan) plan; - assertEquals(3L, mergePlan.getInterval()); - assertEquals(3L, mergePlan.getSlidingStep()); - assertEquals(8L, mergePlan.getStartTime()); - assertEquals(737L, mergePlan.getEndTime()); - } - - @Test - public void testGroupBy2() throws QueryProcessException { - String sqlStr = - "select count(s1) " - + "from root.vehicle.d1 " - + "where s1 < 20 and time <= now() " - + "group by([123,2017-6-2T12:00:12+07:00), 111ms)"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - if (!plan.isQuery()) { - fail(); - } - GroupByTimePlan mergePlan = (GroupByTimePlan) plan; - assertEquals(111, mergePlan.getInterval()); - } - - @Test - public void testGroupBy3() throws QueryProcessException { - String sqlStr = - "select count(s1) " - + "from root.vehicle.d1 " - + "where s1 < 20 and time <= now() " - + "group by([2017-6-2T12:00:12+07:00,2017-6-12T12:00:12+07:00), 3h, 24h)"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - if (!plan.isQuery()) { - fail(); - } - GroupByTimePlan mergePlan = (GroupByTimePlan) plan; - assertEquals(3 * 60 * 60 * 1000, mergePlan.getInterval()); - assertEquals(24 * 60 * 60 * 1000, mergePlan.getSlidingStep()); - assertEquals(1496379612000L, mergePlan.getStartTime()); - assertEquals(1497243612000L, mergePlan.getEndTime()); - } - - @Test - public void testFill1() throws QueryProcessException { - String sqlStr = - "SELECT s1 FROM root.vehicle.d1 WHERE time = 5000 Fill(int32[linear, 5m, 5m], boolean[previous, 5m])"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - if (!plan.isQuery()) { - fail(); - } - FillQueryPlan mergePlan = (FillQueryPlan) plan; - assertEquals(5000, mergePlan.getQueryTime()); - assertEquals(300000, mergePlan.getFillType().get(TSDataType.INT32).getBeforeRange()); - assertEquals(300000, mergePlan.getFillType().get(TSDataType.INT32).getAfterRange()); - assertEquals(300000, mergePlan.getFillType().get(TSDataType.BOOLEAN).getBeforeRange()); - } - - @Test - public void testFill2() throws QueryProcessException { - String sqlStr = - "SELECT s1 FROM root.vehicle.d1 WHERE time = 5000 Fill(int32[linear], boolean[previous])"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - if (!plan.isQuery()) { - fail(); - } - int defaultFillInterval = IoTDBDescriptor.getInstance().getConfig().getDefaultFillInterval(); - FillQueryPlan mergePlan = (FillQueryPlan) plan; - assertEquals(5000, mergePlan.getQueryTime()); - assertEquals( - defaultFillInterval, mergePlan.getFillType().get(TSDataType.INT32).getBeforeRange()); - assertEquals( - defaultFillInterval, mergePlan.getFillType().get(TSDataType.INT32).getAfterRange()); - assertEquals( - defaultFillInterval, mergePlan.getFillType().get(TSDataType.BOOLEAN).getBeforeRange()); - } - - @Test - public void testFill3() { - String sqlStr = - "SELECT s1 FROM root.vehicle.d1 WHERE time = 5000 Fill(int32[linear, 5m], boolean[previous])"; - try { - processor.parseSQLToPhysicalPlan(sqlStr); - fail(); - } catch (Exception e) { - assertTrue(true); - } - } - - @Test - public void testFill4() { - String sqlStr = - "SELECT s1 FROM root.vehicle.d1 WHERE time > 5000 Fill(int32[linear], boolean[previous])"; - try { - processor.parseSQLToPhysicalPlan(sqlStr); - fail(); - } catch (Exception e) { - assertEquals("The condition of WHERE clause must be like time=constant", e.getMessage()); - } - } - - @Test - public void testGroupByFill1() { - String sqlStr = - "select last_value(s1) " - + " from root.vehicle.d1 " - + "group by([8,737), 3ms) fill(int32[previous])"; - try { - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - if (!plan.isQuery()) { - fail(); - } - if (!(plan instanceof GroupByTimeFillPlan)) { - fail(); - } - GroupByTimeFillPlan groupByFillPlan = (GroupByTimeFillPlan) plan; - assertEquals(3L, groupByFillPlan.getInterval()); - assertEquals(3L, groupByFillPlan.getSlidingStep()); - assertEquals(8L, groupByFillPlan.getStartTime()); - assertEquals(737L, groupByFillPlan.getEndTime()); - assertEquals(1, groupByFillPlan.getFillType().size()); - assertTrue(groupByFillPlan.getFillType().containsKey(TSDataType.INT32)); - assertTrue(groupByFillPlan.getFillType().get(TSDataType.INT32) instanceof PreviousFill); - PreviousFill previousFill = - (PreviousFill) groupByFillPlan.getFillType().get(TSDataType.INT32); - assertFalse(previousFill.isUntilLast()); - } catch (Exception e) { - e.printStackTrace(); - fail(); - } - } - - // TODO: @CRZbulabula - // support VECTOR in group by fill - // @Test - // public void testGroupByFill2() { - // String sqlStr = - // "select last_value(s1) " - // + " from root.vehicle.d1 " - // + "group by([8,737), 3ms) fill(ALL[previousuntillast])"; - // try { - // PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - // if (!plan.isQuery()) { - // fail(); - // } - // if (!(plan instanceof GroupByTimeFillPlan)) { - // fail(); - // } - // GroupByTimeFillPlan groupByFillPlan = (GroupByTimeFillPlan) plan; - // assertEquals(3L, groupByFillPlan.getInterval()); - // assertEquals(3L, groupByFillPlan.getSlidingStep()); - // assertEquals(8L, groupByFillPlan.getStartTime()); - // assertEquals(737L, groupByFillPlan.getEndTime()); - // assertEquals(TSDataType.values().length, groupByFillPlan.getFillType().size()); - // for (TSDataType tsDataType : TSDataType.values()) { - // assertTrue(groupByFillPlan.getFillType().containsKey(tsDataType)); - // assertTrue(groupByFillPlan.getFillType().get(tsDataType) instanceof PreviousFill); - // PreviousFill previousFill = (PreviousFill) - // groupByFillPlan.getFillType().get(tsDataType); - // assertTrue(previousFill.isUntilLast()); - // } - // } catch (Exception e) { - // e.printStackTrace(); - // fail(); - // } - // } - - @Test - public void testGroupByFill3() { - String sqlStr = - "select last_value(d1.s1), last_value(d2.s1)" - + " from root.vehicle " - + "group by([8,737), 3ms) fill(int32[previousuntillast], int64[previous])"; - try { - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - if (!plan.isQuery()) { - fail(); - } - if (!(plan instanceof GroupByTimeFillPlan)) { - fail(); - } - GroupByTimeFillPlan groupByFillPlan = (GroupByTimeFillPlan) plan; - assertEquals(3L, groupByFillPlan.getInterval()); - assertEquals(3L, groupByFillPlan.getSlidingStep()); - assertEquals(8L, groupByFillPlan.getStartTime()); - assertEquals(737L, groupByFillPlan.getEndTime()); - assertEquals(2, groupByFillPlan.getDeduplicatedPaths().size()); - assertEquals(2, groupByFillPlan.getFillType().size()); - - assertTrue(groupByFillPlan.getFillType().containsKey(TSDataType.INT32)); - assertTrue(groupByFillPlan.getFillType().get(TSDataType.INT32) instanceof PreviousFill); - PreviousFill previousFill = - (PreviousFill) groupByFillPlan.getFillType().get(TSDataType.INT32); - assertTrue(previousFill.isUntilLast()); - - assertTrue(groupByFillPlan.getFillType().containsKey(TSDataType.INT64)); - assertTrue(groupByFillPlan.getFillType().get(TSDataType.INT64) instanceof PreviousFill); - previousFill = (PreviousFill) groupByFillPlan.getFillType().get(TSDataType.INT64); - assertFalse(previousFill.isUntilLast()); - } catch (Exception e) { - e.printStackTrace(); - fail(); - } - } - - @Test - public void testGroupByFill4() { - String sqlStr = - "select last_value(d1.s1), last_value(d2.s1)" - + " from root.vehicle " - + "group by([8,737), 3ms) fill(boolean[linear])"; - try { - processor.parseSQLToPhysicalPlan(sqlStr); - fail(); - } catch (SQLParserException e) { - assertEquals("type BOOLEAN cannot use linear fill function", e.getMessage()); - } catch (Exception e) { - e.printStackTrace(); - fail(); - } - } - - @Test - public void testGroupByFill5() { - String sqlStr = - "select last_value(d1.s1), count(d2.s1)" - + " from root.vehicle " - + "group by([8,737), 3ms) fill(text[linear])"; - try { - processor.parseSQLToPhysicalPlan(sqlStr); - fail(); - } catch (SQLParserException e) { - assertEquals("type TEXT cannot use linear fill function", e.getMessage()); - } catch (Exception e) { - e.printStackTrace(); - fail(); - } - } - - @Test - public void testGroupByFill6() { - String sqlStr = - "select last_value(d1.s1), last_value(d2.s1)" - + " from root.vehicle " - + "group by([8,737), 3ms) fill(int32[previousuntillast,10ms], int64[previous,10ms])"; - try { - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - if (!plan.isQuery()) { - fail(); - } - if (!(plan instanceof GroupByTimeFillPlan)) { - fail(); - } - } catch (Exception e) { - e.printStackTrace(); - fail(); - } - } - - @Test - public void testCreateFunctionPlan1() { // create function - try { - PhysicalPlan plan = - processor.parseSQLToPhysicalPlan( - "create function udf as 'org.apache.iotdb.db.query.udf.example.Adder'"); - if (plan.isQuery() || !(plan instanceof CreateFunctionPlan)) { - fail(); - } - CreateFunctionPlan createFunctionPlan = (CreateFunctionPlan) plan; - assertEquals("udf", createFunctionPlan.getUdfName()); - assertEquals( - "org.apache.iotdb.db.query.udf.example.Adder", createFunctionPlan.getClassName()); - } catch (QueryProcessException e) { - fail(e.toString()); - } - } - - @Test - public void testUDTFQuery1() { - try { - CreateFunctionPlan createFunctionPlan = - (CreateFunctionPlan) - processor.parseSQLToPhysicalPlan( - "create function udf as 'org.apache.iotdb.db.query.udf.example.Adder'"); - UDFManagementService.getInstance() - .register( - new UDFInformation( - createFunctionPlan.getUdfName(), createFunctionPlan.getClassName())); - - String sqlStr = - "select udf(d2.s1, d1.s1), udf(d1.s1, d2.s1), d1.s1, d2.s1, udf(d1.s1, d2.s1), udf(d2.s1, d1.s1), d1.s1, d2.s1 from root.vehicle"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - - UDFManagementService.getInstance().deregister(createFunctionPlan.getUdfName(), false); - - if (!(plan instanceof UDTFPlan)) { - fail(); - } - - UDTFPlan udtfPlan = (UDTFPlan) plan; - - assertTrue(udtfPlan.isAlignByTime()); - - assertEquals(8, udtfPlan.getPaths().size()); - assertEquals(8, udtfPlan.getDataTypes().size()); - - assertEquals(2, udtfPlan.getDeduplicatedPaths().size()); - assertEquals(2, udtfPlan.getDeduplicatedDataTypes().size()); - - assertEquals(4, udtfPlan.getPathToIndex().size()); - assertTrue( - udtfPlan.getPathToIndex().containsKey("udf(root.vehicle.d2.s1, root.vehicle.d1.s1)")); - assertTrue( - udtfPlan.getPathToIndex().containsKey("udf(root.vehicle.d1.s1, root.vehicle.d2.s1)")); - assertTrue(udtfPlan.getPathToIndex().containsKey("root.vehicle.d1.s1")); - assertTrue(udtfPlan.getPathToIndex().containsKey("root.vehicle.d2.s1")); - } catch (Exception e) { - fail(e.toString()); - } - } - - @Test - public void testUDTFQuery2() { - try { - CreateFunctionPlan createFunctionPlan = - (CreateFunctionPlan) - processor.parseSQLToPhysicalPlan( - "create function udf as 'org.apache.iotdb.db.query.udf.example.Adder'"); - UDFManagementService.getInstance() - .register( - new UDFInformation( - createFunctionPlan.getUdfName(), createFunctionPlan.getClassName())); - - String sqlStr = - "select udf(d2.s1, d1.s1, 'addend'='100'), udf(d1.s1, d2.s1), d1.s1, d2.s1, udf(d2.s1, d1.s1) from root.vehicle"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - - UDFManagementService.getInstance().deregister(createFunctionPlan.getUdfName(), false); - if (!(plan instanceof UDTFPlan)) { - fail(); - } - - UDTFPlan udtfPlan = (UDTFPlan) plan; - - assertTrue(udtfPlan.isAlignByTime()); - - assertEquals(5, udtfPlan.getPaths().size()); - assertEquals(5, udtfPlan.getDataTypes().size()); - - assertEquals(2, udtfPlan.getDeduplicatedPaths().size()); - assertEquals(2, udtfPlan.getDeduplicatedDataTypes().size()); - - assertEquals(5, udtfPlan.getPathToIndex().size()); - assertTrue( - udtfPlan - .getPathToIndex() - .containsKey("udf(root.vehicle.d2.s1, root.vehicle.d1.s1, \"addend\"=\"100\")")); - assertTrue( - udtfPlan.getPathToIndex().containsKey("udf(root.vehicle.d2.s1, root.vehicle.d1.s1)")); - assertTrue( - udtfPlan.getPathToIndex().containsKey("udf(root.vehicle.d1.s1, root.vehicle.d2.s1)")); - assertTrue(udtfPlan.getPathToIndex().containsKey("root.vehicle.d1.s1")); - assertTrue(udtfPlan.getPathToIndex().containsKey("root.vehicle.d2.s1")); - } catch (Exception e) { - fail(e.toString()); - } - } - - @Test - public void testUDTFQuery3() { - try { - CreateFunctionPlan createFunctionPlan = - (CreateFunctionPlan) - processor.parseSQLToPhysicalPlan( - "create function udf as 'org.apache.iotdb.db.query.udf.example.Adder'"); - UDFManagementService.getInstance() - .register( - new UDFInformation( - createFunctionPlan.getUdfName(), createFunctionPlan.getClassName())); - - String sqlStr = "select *, udf(*, *), *, udf(*, *), * from root.vehicle.**"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - - UDFManagementService.getInstance().deregister(createFunctionPlan.getUdfName(), false); - if (!(plan instanceof UDTFPlan)) { - fail(); - } - - UDTFPlan udtfPlan = (UDTFPlan) plan; - - assertTrue(udtfPlan.isAlignByTime()); - - assertEquals(44, udtfPlan.getPaths().size()); - assertEquals(44, udtfPlan.getDataTypes().size()); - - assertEquals(4, udtfPlan.getDeduplicatedPaths().size()); - assertEquals(4, udtfPlan.getDeduplicatedDataTypes().size()); - - assertEquals(20, udtfPlan.getPathToIndex().size()); - } catch (Exception e) { - fail(e.toString()); - } - } - - @Test - public void testDropFunctionPlan() { // drop function - try { - DropFunctionPlan dropFunctionPlan = - (DropFunctionPlan) processor.parseSQLToPhysicalPlan("drop function udf"); - assertEquals("udf", dropFunctionPlan.getUdfName()); - } catch (QueryProcessException e) { - fail(e.toString()); - } - } - - @Test - public void testQuery1() throws QueryProcessException { - String sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE time > 5000"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - IExpression expect = new GlobalTimeExpression(TimeFilter.gt(5000L)); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test - public void testQuery2() throws QueryProcessException { - String sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE time > 50 and time <= 100"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - IExpression expect = - new GlobalTimeExpression(FilterFactory.and(TimeFilter.gt(50L), TimeFilter.ltEq(100L))); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test - public void testQuery3() throws QueryProcessException { - String sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE time > 50 and time <= 100 or s1 < 10"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - IExpression expect = - new SingleSeriesExpression( - new Path("root.vehicle.d1", "s1", true), - new OrFilter( - new AndFilter(TimeFilter.gt(50), TimeFilter.ltEq(100)), ValueFilter.lt(10.0))); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test - public void testQuery4() throws QueryProcessException, IllegalPathException { - String sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE time > 50 and time <= 100 and s1 < 10"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - - IExpression expect = - new SingleSeriesExpression( - new Path("root.vehicle.d1", "s1", true), - new AndFilter( - ValueFilter.lt(10.0), new AndFilter(TimeFilter.gt(50), TimeFilter.ltEq(100)))); - - assertEquals(expect.toString(), queryFilter.toString()); - - PartialPath path = new PartialPath("root.vehicle.d1.s1"); - assertEquals(path, plan.getPaths().get(0)); - } - - @Test - public void testQuery5() throws QueryProcessException { - String sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE s1 > 20 or s1 < 10"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - IExpression expect = - new SingleSeriesExpression( - new Path("root.vehicle.d1", "s1", true), - FilterFactory.or(ValueFilter.gt(20.0), ValueFilter.lt(10.0))); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test - public void testQuery6() throws QueryProcessException { - String sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE time > 20 or time < 10"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - IExpression expect = - new GlobalTimeExpression(FilterFactory.or(TimeFilter.gt(20L), TimeFilter.lt(10L))); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test - public void testQuery7() throws QueryProcessException { - String sqlStr = - "SELECT s1 FROM root.vehicle.d1 WHERE time > 2019-10-16 10:59:00+08:00 - 1d5h or time < 10"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - IExpression expect = - new GlobalTimeExpression( - FilterFactory.or(TimeFilter.gt(1571090340000L), TimeFilter.lt(10L))); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test - public void testLimitOffset() throws QueryProcessException { - String sqlStr = - "SELECT s1 FROM root.vehicle.d1,root.vehicle.d2 WHERE time < 10 " - + "limit 100 offset 10 slimit 1 soffset 1"; - QueryPlan plan = (QueryPlan) processor.parseSQLToPhysicalPlan(sqlStr); - assertEquals(100, plan.getRowLimit()); - assertEquals(10, plan.getRowOffset()); - // NOTE that the parameters of the SLIMIT clause is not stored in the physicalPlan, - // because the SLIMIT clause takes effect before the physicalPlan is finally generated. - } - - @Test - public void testOffsetLimit() throws QueryProcessException { - String sqlStr = - "SELECT s1 FROM root.vehicle.d1,root.vehicle.d2 WHERE time < 10 " - + "offset 10 limit 100 soffset 1 slimit 1"; - QueryPlan plan = (QueryPlan) processor.parseSQLToPhysicalPlan(sqlStr); - assertEquals(100, plan.getRowLimit()); - assertEquals(10, plan.getRowOffset()); - // NOTE that the parameters of the SLIMIT clause is not stored in the physicalPlan, - // because the SLIMIT clause takes effect before the physicalPlan is finally generated. - } - - @Test - public void testQueryFloat1() throws QueryProcessException { - String sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE s1 > 20.5e3"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - IExpression expect = - new SingleSeriesExpression(new Path("root.vehicle.d1", "s1", true), ValueFilter.gt(20.5e3)); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test - public void testQueryFloat2() throws QueryProcessException { - String sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE s1 > 20.5E-3"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - IExpression expect = - new SingleSeriesExpression( - new Path("root.vehicle.d1", "s1", true), ValueFilter.gt(20.5e-3)); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test - public void testQueryFloat3() throws QueryProcessException { - String sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE s1 > 2.5"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - IExpression expect = - new SingleSeriesExpression(new Path("root.vehicle.d1", "s1", true), ValueFilter.gt(2.5)); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test - public void testQueryFloat4() throws QueryProcessException { - String sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE s1 > 2.5"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - IExpression expect = - new SingleSeriesExpression(new Path("root.vehicle.d1", "s1", true), ValueFilter.gt(2.5)); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test - public void testQueryFloat5() throws QueryProcessException { - String sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE s1 > -2.5"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - IExpression expect = - new SingleSeriesExpression(new Path("root.vehicle.d1", "s1", true), ValueFilter.gt(-2.5)); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test - public void testQueryFloat6() throws QueryProcessException { - String sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE s1 > -2.5E-1"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - IExpression expect = - new SingleSeriesExpression( - new Path("root.vehicle.d1", "s1", true), ValueFilter.gt(-2.5e-1)); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test - public void testQueryFloat7() throws QueryProcessException { - String sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE s1 > 2.5E2"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - IExpression expect = - new SingleSeriesExpression(new Path("root.vehicle.d1", "s1", true), ValueFilter.gt(2.5e+2)); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test - public void testQueryFloat8() throws QueryProcessException { - String sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE s1 > .2e2"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - IExpression expect = - new SingleSeriesExpression(new Path("root.vehicle.d1", "s1", true), ValueFilter.gt(0.2e+2)); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test - public void testQueryFloat9() throws QueryProcessException { - String sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE s1 > .2"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - IExpression expect = - new SingleSeriesExpression(new Path("root.vehicle.d1", "s1", true), ValueFilter.gt(0.2)); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test - public void testQueryFloat10() throws QueryProcessException { - String sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE s1 > 2."; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - IExpression expect = - new SingleSeriesExpression(new Path("root.vehicle.d1", "s1", true), ValueFilter.gt(2.0)); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test - public void testQueryFloat11() throws QueryProcessException { - String sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE s1 > 2."; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - IExpression expect = - new SingleSeriesExpression(new Path("root.vehicle.d1", "s1", true), ValueFilter.gt(2.0)); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test - public void testQueryFloat12() throws QueryProcessException { - String sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE s1 > -2."; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - IExpression expect = - new SingleSeriesExpression(new Path("root.vehicle.d1", "s1", true), ValueFilter.gt(-2.0)); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test - public void testQueryFloat13() throws QueryProcessException { - String sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE s1 > -.2"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - IExpression expect = - new SingleSeriesExpression(new Path("root.vehicle.d1", "s1", true), ValueFilter.gt(-0.2)); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test - public void testQueryFloat14() throws QueryProcessException { - String sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE s1 > -.2e2"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - IExpression expect = - new SingleSeriesExpression(new Path("root.vehicle.d1", "s1", true), ValueFilter.gt(-20.0)); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test - public void testInOperator() throws QueryProcessException { - String sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE s1 in (25, 30, 40)"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - Set<Float> values = new HashSet<>(); - values.add(25.0f); - values.add(30.0f); - values.add(40.0f); - IExpression expect = - new SingleSeriesExpression( - new Path("root.vehicle.d1", "s1", true), ValueFilter.in(values, false)); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test - public void testNotInOperator() throws QueryProcessException { - String sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE s1 not in (25, 30, 40)"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - Set<Float> values = new HashSet<>(); - values.add(25.0f); - values.add(30.0f); - values.add(40.0f); - IExpression expect = - new SingleSeriesExpression( - new Path("root.vehicle.d1", "s1", true), ValueFilter.in(values, true)); - assertEquals(expect.toString(), queryFilter.toString()); - - sqlStr = "SELECT s1 FROM root.vehicle.d1 WHERE not(s1 not in (25, 30, 40))"; - plan = processor.parseSQLToPhysicalPlan(sqlStr); - queryFilter = ((RawDataQueryPlan) plan).getExpression(); - expect = - new SingleSeriesExpression( - new Path("root.vehicle.d1", "s1", true), ValueFilter.in(values, false)); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test - public void testGrantWatermarkEmbedding() throws QueryProcessException { - String sqlStr = "GRANT WATERMARK_EMBEDDING to a,b"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - DataAuthPlan dataAuthPlan = (DataAuthPlan) plan; - Assert.assertEquals(2, dataAuthPlan.getUsers().size()); - Assert.assertEquals(OperatorType.GRANT_WATERMARK_EMBEDDING, dataAuthPlan.getOperatorType()); - } - - @Test - public void testRevokeWatermarkEmbedding() throws QueryProcessException { - String sqlStr = "REVOKE WATERMARK_EMBEDDING from a,b"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - DataAuthPlan dataAuthPlan = (DataAuthPlan) plan; - Assert.assertEquals(2, dataAuthPlan.getUsers().size()); - Assert.assertEquals(OperatorType.REVOKE_WATERMARK_EMBEDDING, dataAuthPlan.getOperatorType()); - } - - @Test - public void testConfiguration() throws QueryProcessException { - String metadata = "load configuration"; - Planner processor = new Planner(); - LoadConfigurationPlan plan = (LoadConfigurationPlan) processor.parseSQLToPhysicalPlan(metadata); - assertEquals("LOAD_CONFIGURATION", plan.toString()); - } - - @Test - public void testShowFlushInfo() throws QueryProcessException { - String metadata = "SHOW FLUSH INFO"; - Planner processor = new Planner(); - ShowPlan plan = (ShowPlan) processor.parseSQLToPhysicalPlan(metadata); - assertEquals("SHOW FLUSH_TASK_INFO", plan.toString()); - } - - @Test - public void testLoadFiles() throws QueryProcessException { - String filePath = "data" + File.separator + "213213441243-1-2.tsfile"; - String metadata = String.format("load '%s'", filePath); - Planner processor = new Planner(); - OperateFilePlan plan = (OperateFilePlan) processor.parseSQLToPhysicalPlan(metadata); - assertEquals( - String.format( - "OperateFilePlan{file=%s, targetDir=null, autoCreateSchema=true, sgLevel=1, verify=true, " - + "operatorType=LOAD_FILES}", - filePath), - plan.toString()); - - metadata = String.format("load '%s'", filePath); - processor = new Planner(); - plan = (OperateFilePlan) processor.parseSQLToPhysicalPlan(metadata); - assertEquals( - String.format( - "OperateFilePlan{file=%s, targetDir=null, autoCreateSchema=true, sgLevel=1, verify=true, " - + "operatorType=LOAD_FILES}", - filePath), - plan.toString()); - - metadata = String.format("load '%s'", filePath); - processor = new Planner(); - plan = (OperateFilePlan) processor.parseSQLToPhysicalPlan(metadata); - assertEquals( - String.format( - "OperateFilePlan{file=%s, targetDir=null, autoCreateSchema=true, sgLevel=1, verify=true, " - + "operatorType=LOAD_FILES}", - filePath), - plan.toString()); - - metadata = String.format("load '%s' sglevel=3", filePath); - processor = new Planner(); - plan = (OperateFilePlan) processor.parseSQLToPhysicalPlan(metadata); - assertEquals( - String.format( - "OperateFilePlan{file=%s, targetDir=null, autoCreateSchema=true, sgLevel=3, verify=true, " - + "operatorType=LOAD_FILES}", - filePath), - plan.toString()); - - metadata = String.format("load '%s' sglevel=3 verify=false", filePath); - processor = new Planner(); - plan = (OperateFilePlan) processor.parseSQLToPhysicalPlan(metadata); - assertEquals( - String.format( - "OperateFilePlan{file=%s, targetDir=null, autoCreateSchema=true, sgLevel=3, verify=false, " - + "operatorType=LOAD_FILES}", - filePath), - plan.toString()); - - metadata = String.format("load '%s' sglevel=3 verify=true", filePath); - processor = new Planner(); - plan = (OperateFilePlan) processor.parseSQLToPhysicalPlan(metadata); - assertEquals( - String.format( - "OperateFilePlan{file=%s, targetDir=null, autoCreateSchema=true, sgLevel=3, verify=true, " - + "operatorType=LOAD_FILES}", - filePath), - plan.toString()); - } - - @Test - public void testRemoveFile() throws QueryProcessException { - String filePath = "data" + File.separator + "213213441243-1-2.tsfile"; - String metadata = String.format("remove '%s'", filePath); - Planner processor = new Planner(); - OperateFilePlan plan = (OperateFilePlan) processor.parseSQLToPhysicalPlan(metadata); - assertEquals( - String.format( - "OperateFilePlan{file=%s, targetDir=null, autoCreateSchema=false, sgLevel=0, verify=false, operatorType=REMOVE_FILE}", - filePath), - plan.toString()); - } - - @Test - public void testUnloadFile() throws QueryProcessException { - String filePath = "data" + File.separator + "213213441243-1-2.tsfile"; - String targetDir = "user" + File.separator + "backup"; - String metadata = String.format("unload '%s' '%s'", filePath, targetDir); - Planner processor = new Planner(); - OperateFilePlan plan = (OperateFilePlan) processor.parseSQLToPhysicalPlan(metadata); - assertEquals( - String.format( - "OperateFilePlan{file=%s, targetDir=%s, autoCreateSchema=false, sgLevel=0, verify=false, operatorType=UNLOAD_FILE}", - filePath, targetDir), - plan.toString()); - } - - @Test - public void testDeduplicatedPath() throws Exception { - String sqlStr = "select * from root.vehicle.d1,root.vehicle.d1,root.vehicle.d1"; - RawDataQueryPlan plan = (RawDataQueryPlan) processor.parseSQLToPhysicalPlan(sqlStr); - Assert.assertEquals(1, plan.getDeduplicatedPaths().size()); - Assert.assertEquals(1, plan.getDeduplicatedDataTypes().size()); - Assert.assertEquals( - new Path("root.vehicle.d1", "s1", true), plan.getDeduplicatedPaths().get(0)); - - sqlStr = "select count(*) from root.vehicle.d1,root.vehicle.d1,root.vehicle.d1"; - plan = (RawDataQueryPlan) processor.parseSQLToPhysicalPlan(sqlStr); - Assert.assertEquals(1, plan.getDeduplicatedPaths().size()); - Assert.assertEquals(1, plan.getDeduplicatedDataTypes().size()); - Assert.assertEquals( - new Path("root.vehicle.d1", "s1", true), plan.getDeduplicatedPaths().get(0)); - } - - @Test - public void testLastPlanPaths() throws QueryProcessException { - String sqlStr1 = "SELECT last s1 FROM root.vehicle.d1"; - String sqlStr2 = "SELECT last s1 FROM root.vehicle.d1, root.vehicle.d2"; - PhysicalPlan plan1 = processor.parseSQLToPhysicalPlan(sqlStr1); - PhysicalPlan plan2 = processor.parseSQLToPhysicalPlan(sqlStr2); - Path path1 = new Path("root.vehicle.d1", "s1", true); - Path path2 = new Path("root.vehicle.d2", "s1", true); - assertEquals(1, plan1.getPaths().size()); - assertEquals(path1.toString(), plan1.getPaths().get(0).getFullPath()); - assertEquals(2, plan2.getPaths().size()); - assertEquals(path1.toString(), plan2.getPaths().get(0).getFullPath()); - assertEquals(path2.toString(), plan2.getPaths().get(1).getFullPath()); - } - - @Test - public void testLastPlanDataTypes() throws QueryProcessException { - String sqlStr1 = "SELECT last s1 FROM root.vehicle.d1"; - String sqlStr2 = "SELECT last s1 FROM root.vehicle.d2, root.vehicle.d3, root.vehicle.d4"; - - PhysicalPlan plan1 = processor.parseSQLToPhysicalPlan(sqlStr1); - PhysicalPlan plan2 = processor.parseSQLToPhysicalPlan(sqlStr2); - - assertEquals(1, ((LastQueryPlan) plan1).getDataTypes().size()); - TSDataType dataType = ((LastQueryPlan) plan1).getDataTypes().get(0); - assertEquals(TSDataType.FLOAT, dataType); - - assertEquals(3, ((LastQueryPlan) plan2).getDataTypes().size()); - for (TSDataType dt : ((LastQueryPlan) plan2).getDataTypes()) { - assertEquals(TSDataType.FLOAT, dt); - } - } - - @Test - public void testDelete1() throws QueryProcessException, IllegalPathException { - PartialPath path = new PartialPath("root.vehicle.d1.s1"); - List<PartialPath> pathList = new ArrayList<>(Collections.singletonList(path)); - String sqlStr = "delete FROM root.vehicle.d1.s1 WHERE time < 5000"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - assertEquals(OperatorType.DELETE, plan.getOperatorType()); - assertEquals(pathList, plan.getPaths()); - } - - @Test - public void testDelete2() throws QueryProcessException, IllegalPathException { - PartialPath path1 = new PartialPath("root.vehicle.d1.s1"); - PartialPath path2 = new PartialPath("root.vehicle.d1.s2"); - List<PartialPath> pathList = new ArrayList<>(Arrays.asList(path1, path2)); - String sqlStr = "delete FROM root.vehicle.d1.s1,root.vehicle.d1.s2 WHERE time < 5000"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - assertEquals(OperatorType.DELETE, plan.getOperatorType()); - assertEquals(pathList, plan.getPaths()); - } - - @Test - public void testDelete3() throws QueryProcessException, IllegalPathException { - PartialPath path1 = new PartialPath("root.vehicle.d1.s1"); - PartialPath path2 = new PartialPath("root.vehicle.d2.s3"); - List<PartialPath> pathList = new ArrayList<>(Arrays.asList(path1, path2)); - String sqlStr = "delete FROM root.vehicle.d1.s1,root.vehicle.d2.s3 WHERE time < 5000"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - assertEquals(OperatorType.DELETE, plan.getOperatorType()); - assertEquals(pathList, plan.getPaths()); - } - - @Test - public void testSpecialCharacters() throws QueryProcessException { - String sqlStr1 = - "create timeseries root.`3e-3`.`-1+1/2`.`SNAPPY`.`RLE`.`81+12+2s/io`.`in[jack]`.`hel[jjj[]s[1]`.`desc` with " - + "datatype=FLOAT, encoding=RLE, compression=SNAPPY tags('tag1'='v1', 'tag2'='v2')" - + " attributes('attr1'='v1', 'attr2'='v2')"; - PhysicalPlan plan1 = processor.parseSQLToPhysicalPlan(sqlStr1); - Assert.assertEquals(OperatorType.CREATE_TIMESERIES, plan1.getOperatorType()); - } - - @Test - public void testTimeRangeDelete() throws QueryProcessException, IllegalPathException { - String sqlStr1 = "DELETE FROM root.vehicle.d1 where time >= 1 and time <= 2"; - - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr1); - Assert.assertFalse(plan.isQuery()); - Assert.assertEquals( - plan.getPaths(), Collections.singletonList(new PartialPath("root.vehicle.d1"))); - Assert.assertEquals(1, ((DeletePlan) plan).getDeleteStartTime()); - Assert.assertEquals(2, ((DeletePlan) plan).getDeleteEndTime()); - } - - @Test - public void testCreateTrigger1() throws QueryProcessException { - String sql = - "CREATE TRIGGER trigger1 BEFORE INSERT ON root.sg1.d1.s1 AS 'org.apache.iotdb.engine.trigger.Example'"; - - CreateTriggerPlan plan = (CreateTriggerPlan) processor.parseSQLToPhysicalPlan(sql); - Assert.assertFalse(plan.isQuery()); - Assert.assertEquals("trigger1", plan.getTriggerName()); - Assert.assertEquals(TriggerEvent.BEFORE_INSERT, plan.getEvent()); - Assert.assertEquals("root.sg1.d1.s1", plan.getFullPath().getFullPath()); - Assert.assertEquals("org.apache.iotdb.engine.trigger.Example", plan.getClassName()); - } - - @Test - public void testCreateTrigger2() throws QueryProcessException { - String sql = - "CREATE TRIGGER trigger2 AFTER INSERT ON root.sg1.d1.s2 AS 'org.apache.iotdb.engine.trigger.Example'" - + "WITH ('key1'='value1', 'key2'='value2')"; - - CreateTriggerPlan plan = (CreateTriggerPlan) processor.parseSQLToPhysicalPlan(sql); - Assert.assertFalse(plan.isQuery()); - Assert.assertEquals("trigger2", plan.getTriggerName()); - Assert.assertEquals(TriggerEvent.AFTER_INSERT, plan.getEvent()); - Assert.assertEquals("root.sg1.d1.s2", plan.getFullPath().getFullPath()); - Assert.assertEquals("org.apache.iotdb.engine.trigger.Example", plan.getClassName()); - Map<String, String> expectedAttributes = new HashMap<>(); - expectedAttributes.put("key1", "value1"); - expectedAttributes.put("key2", "value2"); - Assert.assertEquals(expectedAttributes, plan.getAttributes()); - } - - @Test - public void testDropTrigger() throws QueryProcessException { - String sql = "DROP TRIGGER trigger1"; - - DropTriggerPlan plan = (DropTriggerPlan) processor.parseSQLToPhysicalPlan(sql); - Assert.assertFalse(plan.isQuery()); - Assert.assertEquals("trigger1", plan.getTriggerName()); - } - - @Test - public void testStartTrigger() throws QueryProcessException { - String sql = "START TRIGGER `my-trigger`"; - - StartTriggerPlan plan = (StartTriggerPlan) processor.parseSQLToPhysicalPlan(sql); - Assert.assertFalse(plan.isQuery()); - Assert.assertEquals("my-trigger", plan.getTriggerName()); - } - - @Test - public void testStopTrigger() throws QueryProcessException { - String sql = "STOP TRIGGER `my-trigger`"; - - StopTriggerPlan plan = (StopTriggerPlan) processor.parseSQLToPhysicalPlan(sql); - Assert.assertFalse(plan.isQuery()); - Assert.assertEquals("my-trigger", plan.getTriggerName()); - } - - @Test - public void testShowTriggers() throws QueryProcessException { - String sql = "SHOW TRIGGERS"; - - ShowTriggersPlan plan = (ShowTriggersPlan) processor.parseSQLToPhysicalPlan(sql); - Assert.assertTrue(plan.isQuery()); - Assert.assertEquals(ShowPlan.ShowContentType.TRIGGERS, plan.getShowContentType()); - } - - @Test - public void testCreateCQ1() throws QueryProcessException { - String sql = - "CREATE CONTINUOUS QUERY cq1 BEGIN SELECT max_value(temperature) INTO temperature_max FROM root.ln.*.*.* GROUP BY time(10s) END"; - - CreateContinuousQueryPlan plan = - (CreateContinuousQueryPlan) processor.parseSQLToPhysicalPlan(sql); - Assert.assertFalse(plan.isQuery()); - Assert.assertEquals("cq1", plan.getContinuousQueryName()); - Assert.assertEquals(10000, plan.getEveryInterval()); - Assert.assertEquals(10000, plan.getForInterval()); - Assert.assertEquals( - "root.${1}.${2}.${3}.${4}.temperature_max", plan.getTargetPath().getFullPath()); - Assert.assertEquals( - "select max_value(temperature) from root.ln.*.*.* group by ([now() - 10s, now()), 10s)", - plan.getQuerySql()); - } - - @Test - public void testCreateCQ2() throws QueryProcessException { - String sql = - "CREATE CONTINUOUS QUERY cq1 BEGIN SELECT max_value(temperature) INTO temperature_max FROM root.ln.*.*.* GROUP BY time(10s), level = 3 END"; - - CreateContinuousQueryPlan plan = - (CreateContinuousQueryPlan) processor.parseSQLToPhysicalPlan(sql); - Assert.assertFalse(plan.isQuery()); - Assert.assertEquals("cq1", plan.getContinuousQueryName()); - Assert.assertEquals(10000, plan.getEveryInterval()); - Assert.assertEquals(10000, plan.getForInterval()); - Assert.assertEquals("root.${1}.${2}.${3}.temperature_max", plan.getTargetPath().getFullPath()); - Assert.assertEquals( - "select max_value(temperature) from root.ln.*.*.* group by ([now() - 10s, now()), 10s), level = 3", - plan.getQuerySql()); - } - - @Test - public void testCreateCQ3() throws QueryProcessException { - String sql = - "CREATE CONTINUOUS QUERY cq1 RESAMPLE EVERY 20s BEGIN SELECT max_value(temperature) INTO temperature_max FROM root.ln.*.*.* GROUP BY time(10s), level = 3 END"; - - CreateContinuousQueryPlan plan = - (CreateContinuousQueryPlan) processor.parseSQLToPhysicalPlan(sql); - Assert.assertFalse(plan.isQuery()); - Assert.assertEquals("cq1", plan.getContinuousQueryName()); - Assert.assertEquals(20000, plan.getEveryInterval()); - Assert.assertEquals(10000, plan.getForInterval()); - Assert.assertEquals("root.${1}.${2}.${3}.temperature_max", plan.getTargetPath().getFullPath()); - Assert.assertEquals( - "select max_value(temperature) from root.ln.*.*.* group by ([now() - 10s, now()), 10s), level = 3", - plan.getQuerySql()); - } - - @Test - public void testCreateCQ4() throws QueryProcessException { - String sql = - "CREATE CONTINUOUS QUERY cq1 RESAMPLE EVERY 20s FOR 10s BEGIN SELECT max_value(temperature) INTO temperature_max FROM root.ln.*.*.* GROUP BY time(10s), level = 3 END"; - - CreateContinuousQueryPlan plan = - (CreateContinuousQueryPlan) processor.parseSQLToPhysicalPlan(sql); - Assert.assertFalse(plan.isQuery()); - Assert.assertEquals("cq1", plan.getContinuousQueryName()); - Assert.assertEquals(20000, plan.getEveryInterval()); - Assert.assertEquals(10000, plan.getForInterval()); - Assert.assertEquals("root.${1}.${2}.${3}.temperature_max", plan.getTargetPath().getFullPath()); - Assert.assertEquals( - "select max_value(temperature) from root.ln.*.*.* group by ([now() - 10s, now()), 10s), level = 3", - plan.getQuerySql()); - } - - @Test - public void testCreateCQ5() throws QueryProcessException { - String sql = - "CREATE CONTINUOUS QUERY cq1 RESAMPLE FOR 20s BEGIN SELECT max_value(temperature) INTO temperature_max FROM root.ln.*.*.* GROUP BY time(10s), level = 3 END"; - - CreateContinuousQueryPlan plan = - (CreateContinuousQueryPlan) processor.parseSQLToPhysicalPlan(sql); - Assert.assertFalse(plan.isQuery()); - Assert.assertEquals("cq1", plan.getContinuousQueryName()); - Assert.assertEquals(10000, plan.getEveryInterval()); - Assert.assertEquals(20000, plan.getForInterval()); - Assert.assertEquals("root.${1}.${2}.${3}.temperature_max", plan.getTargetPath().getFullPath()); - Assert.assertEquals( - "select max_value(temperature) from root.ln.*.*.* group by ([now() - 20s, now()), 10s), level = 3", - plan.getQuerySql()); - } - - @Test - public void testCreateCQ6() throws QueryProcessException { - - String sql = - "CREATE CQ cq1 RESAMPLE FOR 20s BEGIN SELECT max_value(temperature) INTO root.${a4}.${3}.temperature_max FROM root.ln.*.*.* GROUP BY time(10s), level = 3 END"; - try { - CreateContinuousQueryPlan plan = - (CreateContinuousQueryPlan) processor.parseSQLToPhysicalPlan(sql); - fail(); - } catch (SQLParserException e) { - assertTrue(e.getMessage().contains("the x of ${x} should be an integer.")); - } - } - - @Test - public void testCreateCQ7() throws QueryProcessException { - - String sql = - "CREATE CQ cq1 RESAMPLE FOR 20s BEGIN SELECT max_value(temperature) INTO root.${4}.${3}.temperature_max FROM root.ln.*.*.* GROUP BY time(10s), level = 3 END"; - try { - CreateContinuousQueryPlan plan = - (CreateContinuousQueryPlan) processor.parseSQLToPhysicalPlan(sql); - fail(); - } catch (SQLParserException e) { - assertTrue( - e.getMessage() - .contains( - "the x of ${x} should be greater than 0 and equal to or less than <level> or the length of queried path prefix.")); - } - } - - @Test - public void testCreateCQ8() throws QueryProcessException { - String sql = - "CREATE CONTINUOUS QUERY cq1 BEGIN SELECT max_value(temperature) INTO root.${1}_cq.${2}.${3}.temperature_max FROM root.ln.*.*.* GROUP BY time(10s), level = 3 END"; - - CreateContinuousQueryPlan plan = - (CreateContinuousQueryPlan) processor.parseSQLToPhysicalPlan(sql); - Assert.assertFalse(plan.isQuery()); - Assert.assertEquals("cq1", plan.getContinuousQueryName()); - Assert.assertEquals(10000, plan.getEveryInterval()); - Assert.assertEquals(10000, plan.getForInterval()); - Assert.assertEquals( - "root.${1}_cq.${2}.${3}.temperature_max", plan.getTargetPath().getFullPath()); - Assert.assertEquals( - "select max_value(temperature) from root.ln.*.*.* group by ([now() - 10s, now()), 10s), level = 3", - plan.getQuerySql()); - } - - @Test - public void testCreateCQ9() throws QueryProcessException { - - String sql = - "CREATE CQ cq1 RESAMPLE FOR 20s BEGIN SELECT max_value(temperature) INTO root.${0}.${3}.temperature_max FROM root.ln.*.*.* GROUP BY time(10s), level = 3 END"; - try { - CreateContinuousQueryPlan plan = - (CreateContinuousQueryPlan) processor.parseSQLToPhysicalPlan(sql); - fail(); - } catch (SQLParserException e) { - assertTrue( - e.getMessage() - .contains( - "the x of ${x} should be greater than 0 and equal to or less than <level> or the length of queried path prefix.")); - } - } - - @Test - public void testCreateCQ10() throws QueryProcessException { - - String sql = - "CREATE CQ cq1 RESAMPLE FOR 20s BEGIN SELECT max_value(temperature), avg(temperature) INTO root.${0}.${3}.temperature_max FROM root.ln.*.*.* GROUP BY time(10s), level = 3 END"; - try { - CreateContinuousQueryPlan plan = - (CreateContinuousQueryPlan) processor.parseSQLToPhysicalPlan(sql); - fail(); - } catch (SQLParserException e) { - assertEquals("CQ: CQ currently does not support multiple result columns.", e.getMessage()); - } - } - - @Test - public void testCreateCQ11() throws QueryProcessException { - long minEveryInterval = - IoTDBDescriptor.getInstance().getConfig().getContinuousQueryMinimumEveryInterval(); - long everyInterval = minEveryInterval / 2; - String sql = - String.format( - "CREATE CQ cq1 RESAMPLE EVERY %dms FOR 20s BEGIN SELECT max_value(temperature) INTO temperature_max FROM root.ln.*.*.* GROUP BY time(10s), level = 3 END", - everyInterval); - try { - CreateContinuousQueryPlan plan = - (CreateContinuousQueryPlan) processor.parseSQLToPhysicalPlan(sql); - fail(); - } catch (SQLParserException e) { - assertEquals( - "CQ: every interval should not be lower than the minimum value you configured.", - e.getMessage()); - } - } - - @Test - public void testDropCQ() throws QueryProcessException { - String sql = "DROP CONTINUOUS QUERY cq1"; - - DropContinuousQueryPlan plan = (DropContinuousQueryPlan) processor.parseSQLToPhysicalPlan(sql); - Assert.assertFalse(plan.isQuery()); - Assert.assertEquals("cq1", plan.getContinuousQueryName()); - } - - @Test - public void testShowCQs() throws QueryProcessException { - String sql = "SHOW CONTINUOUS QUERIES"; - - ShowContinuousQueriesPlan plan = - (ShowContinuousQueriesPlan) processor.parseSQLToPhysicalPlan(sql); - Assert.assertTrue(plan.isQuery()); - } - - @Test - public void testShowFunction() throws QueryProcessException { - String sql = "SHOW FUNCTIONS"; - - ShowFunctionsPlan plan = (ShowFunctionsPlan) processor.parseSQLToPhysicalPlan(sql); - Assert.assertTrue(plan.isQuery()); - Assert.assertEquals(ShowPlan.ShowContentType.FUNCTIONS, plan.getShowContentType()); - } - - @Test - public void testCreateStorageGroup() throws QueryProcessException { - String sqlStr = "CREATE STORAGE GROUP root.sg"; - SetStorageGroupPlan plan = (SetStorageGroupPlan) processor.parseSQLToPhysicalPlan(sqlStr); - assertEquals("SetStorageGroup{root.sg}", plan.toString()); - } - - @Test - public void testRegexpQuery() throws QueryProcessException, MetadataException { - IoTDB.schemaProcessor.createTimeseries( - new PartialPath("root.vehicle.d5.s1"), - TSDataType.TEXT, - TSEncoding.PLAIN, - CompressionType.UNCOMPRESSED, - null); - - String sqlStr = "SELECT * FROM root.vehicle.d5 WHERE s1 REGEXP 'string*'"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - IExpression queryFilter = ((RawDataQueryPlan) plan).getExpression(); - IExpression expect = - new SingleSeriesExpression( - new Path("root.vehicle.d5", "s1", true), ValueFilter.like("string*")); - assertEquals(expect.toString(), queryFilter.toString()); - } - - @Test(expected = UnsupportedOperationException.class) - public void testSerializationError() { - ShowDevicesPlan plan = new ShowDevicesPlan(); - - ByteBuffer byteBuffer = ByteBuffer.allocate(10); - plan.serialize(byteBuffer); - } - - @Test(expected = NullPointerException.class) - public void testSerializationRollback() { - InsertRowPlan plan = new InsertRowPlan(); - // only serialize time - plan.setTime(0L); - - ByteBuffer byteBuffer = ByteBuffer.allocate(10000); - byteBuffer.putInt(0); - long position = byteBuffer.position(); - - try { - plan.serialize(byteBuffer); - } catch (NullPointerException e) { - Assert.assertEquals(position, byteBuffer.position()); - throw e; - } - } -} diff --git a/server/src/test/java/org/apache/iotdb/db/qp/physical/SerializationTest.java b/server/src/test/java/org/apache/iotdb/db/qp/physical/SerializationTest.java deleted file mode 100644 index 29078b2241..0000000000 --- a/server/src/test/java/org/apache/iotdb/db/qp/physical/SerializationTest.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.iotdb.db.qp.physical; - -import org.apache.iotdb.commons.exception.IllegalPathException; -import org.apache.iotdb.commons.exception.MetadataException; -import org.apache.iotdb.commons.path.PartialPath; -import org.apache.iotdb.db.exception.query.QueryProcessException; -import org.apache.iotdb.db.qp.Planner; -import org.apache.iotdb.db.qp.physical.sys.FlushPlan; -import org.apache.iotdb.db.service.IoTDB; -import org.apache.iotdb.db.utils.EnvironmentUtils; -import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType; -import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; -import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding; -import org.apache.iotdb.tsfile.utils.Pair; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; - -import static org.junit.Assert.assertEquals; - -public class SerializationTest { - - private Planner processor = new Planner(); - - @Before - public void before() throws MetadataException { - IoTDB.configManager.init(); - IoTDB.schemaProcessor.setStorageGroup(new PartialPath("root.vehicle")); - IoTDB.schemaProcessor.createTimeseries( - new PartialPath("root.vehicle.d1.s1"), - TSDataType.FLOAT, - TSEncoding.PLAIN, - CompressionType.UNCOMPRESSED, - null); - IoTDB.schemaProcessor.createTimeseries( - new PartialPath("root.vehicle.d2.s1"), - TSDataType.FLOAT, - TSEncoding.PLAIN, - CompressionType.UNCOMPRESSED, - null); - IoTDB.schemaProcessor.createTimeseries( - new PartialPath("root.vehicle.d3.s1"), - TSDataType.FLOAT, - TSEncoding.PLAIN, - CompressionType.UNCOMPRESSED, - null); - IoTDB.schemaProcessor.createTimeseries( - new PartialPath("root.vehicle.d4.s1"), - TSDataType.FLOAT, - TSEncoding.PLAIN, - CompressionType.UNCOMPRESSED, - null); - } - - @After - public void clean() throws IOException { - IoTDB.configManager.clear(); - EnvironmentUtils.cleanAllDir(); - } - - @Test - public void testInsert() throws QueryProcessException, IOException, IllegalPathException { - String sqlStr = "INSERT INTO root.vehicle.d1(timestamp, s1) VALUES (1, 5.0)"; - PhysicalPlan plan = processor.parseSQLToPhysicalPlan(sqlStr); - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - try (DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream)) { - plan.serialize(dataOutputStream); - ByteBuffer buffer = ByteBuffer.wrap(byteArrayOutputStream.toByteArray()); - PhysicalPlan planB = PhysicalPlan.Factory.create(buffer); - assertEquals(plan, planB); - } - - ByteBuffer buffer = ByteBuffer.allocate(4096); - plan.serialize(buffer); - buffer.flip(); - PhysicalPlan planB = PhysicalPlan.Factory.create(buffer); - assertEquals(plan, planB); - } - - @Test - public void testFlush() throws IOException, IllegalPathException { - Map<PartialPath, List<Pair<Long, Boolean>>> storageGroupPartitionIds = new HashMap<>(); - - Boolean[] isSeqArray = new Boolean[] {null, true}; - boolean[] isSyncArray = new boolean[] {true, false}; - Random random = new Random(); - for (int i = 0; i < 10; i++) { - List<Pair<Long, Boolean>> partitionIdPairs = new ArrayList<>(); - for (int j = 0; j < 10; j++) { - partitionIdPairs.add(new Pair<Long, Boolean>((long) i + j, isSyncArray[random.nextInt(1)])); - } - - storageGroupPartitionIds.put(new PartialPath(new String[] {"path_" + i}), partitionIdPairs); - } - for (Boolean isSeq : isSeqArray) { - for (boolean isSync : isSyncArray) { - FlushPlan plan = new FlushPlan(isSeq, isSync, storageGroupPartitionIds); - - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - try (DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream)) { - plan.serialize(dataOutputStream); - ByteBuffer buffer = ByteBuffer.wrap(byteArrayOutputStream.toByteArray()); - FlushPlan planB = (FlushPlan) PhysicalPlan.Factory.create(buffer); - assertEquals(plan.getPaths(), planB.getPaths()); - assertEquals(plan.getStorageGroupPartitionIds(), planB.getStorageGroupPartitionIds()); - assertEquals(plan.isSeq(), planB.isSeq()); - assertEquals(plan.isSync(), planB.isSync()); - } - - ByteBuffer buffer = ByteBuffer.allocate(4096); - plan.serialize(buffer); - buffer.flip(); - FlushPlan planB = (FlushPlan) PhysicalPlan.Factory.create(buffer); - assertEquals(plan.getPaths(), planB.getPaths()); - assertEquals(plan.getStorageGroupPartitionIds(), planB.getStorageGroupPartitionIds()); - assertEquals(plan.isSeq(), planB.isSeq()); - assertEquals(plan.isSync(), planB.isSync()); - } - } - } -} diff --git a/server/src/test/java/org/apache/iotdb/db/qp/physical/SerializedSizeTest.java b/server/src/test/java/org/apache/iotdb/db/qp/physical/SerializedSizeTest.java deleted file mode 100644 index 70f9a2a24f..0000000000 --- a/server/src/test/java/org/apache/iotdb/db/qp/physical/SerializedSizeTest.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.iotdb.db.qp.physical; - -import org.apache.iotdb.commons.exception.IllegalPathException; -import org.apache.iotdb.commons.path.PartialPath; -import org.apache.iotdb.db.qp.physical.crud.InsertRowPlan; -import org.apache.iotdb.db.qp.physical.crud.InsertTabletPlan; -import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; -import org.apache.iotdb.tsfile.utils.Binary; -import org.apache.iotdb.tsfile.utils.BitMap; - -import org.junit.Test; - -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.List; - -import static org.junit.Assert.assertEquals; - -public class SerializedSizeTest { - private final String devicePath = "root.test_sg.test_d"; - - @Test - public void testInsertRowPlan() throws IllegalPathException { - InsertRowPlan insertRowPlan = getInsertRowPlan(); - ByteBuffer buffer = ByteBuffer.allocate(insertRowPlan.serializedSize()); - insertRowPlan.serialize(buffer); - assertEquals(0, buffer.remaining()); - } - - private InsertRowPlan getInsertRowPlan() throws IllegalPathException { - long time = 110L; - TSDataType[] dataTypes = - new TSDataType[] { - TSDataType.DOUBLE, - TSDataType.FLOAT, - TSDataType.INT64, - TSDataType.INT32, - TSDataType.BOOLEAN, - TSDataType.TEXT - }; - - String[] columns = new String[6]; - columns[0] = 1.0 + ""; - columns[1] = 2 + ""; - columns[2] = 10000 + ""; - columns[3] = 100 + ""; - columns[4] = false + ""; - columns[5] = "hh" + 0; - - return new InsertRowPlan( - new PartialPath(devicePath), - time, - new String[] {"s1", "s2", "s3", "s4", "s5", "s6"}, - dataTypes, - columns); - } - - @Test - public void testInsertTabletPlan() throws IllegalPathException { - InsertTabletPlan insertTabletPlan = getInsertTabletPlan(); - ByteBuffer buffer = ByteBuffer.allocate(insertTabletPlan.serializedSize()); - insertTabletPlan.serialize(buffer); - assertEquals(0, buffer.remaining()); - } - - private InsertTabletPlan getInsertTabletPlan() throws IllegalPathException { - long[] times = new long[] {110L, 111L, 112L, 113L}; - List<Integer> dataTypes = new ArrayList<>(); - dataTypes.add(TSDataType.DOUBLE.ordinal()); - dataTypes.add(TSDataType.FLOAT.ordinal()); - dataTypes.add(TSDataType.INT64.ordinal()); - dataTypes.add(TSDataType.INT32.ordinal()); - dataTypes.add(TSDataType.BOOLEAN.ordinal()); - dataTypes.add(TSDataType.TEXT.ordinal()); - - Object[] columns = new Object[6]; - columns[0] = new double[4]; - columns[1] = new float[4]; - columns[2] = new long[4]; - columns[3] = new int[4]; - columns[4] = new boolean[4]; - columns[5] = new Binary[4]; - - for (int r = 0; r < 4; r++) { - ((double[]) columns[0])[r] = 1.0 + r; - ((float[]) columns[1])[r] = 2 + r; - ((long[]) columns[2])[r] = 10000 + r; - ((int[]) columns[3])[r] = 100 + r; - ((boolean[]) columns[4])[r] = (r % 2 == 0); - ((Binary[]) columns[5])[r] = new Binary("hh" + r); - } - - BitMap[] bitMaps = new BitMap[dataTypes.size()]; - for (int i = 0; i < dataTypes.size(); i++) { - if (bitMaps[i] == null) { - bitMaps[i] = new BitMap(times.length); - } - bitMaps[i].mark(i % times.length); - } - - InsertTabletPlan insertTabletPlan = - new InsertTabletPlan( - new PartialPath(devicePath), - new String[] {"s1", "s2", "s3", "s4", "s5", "s6"}, - dataTypes); - insertTabletPlan.setTimes(times); - insertTabletPlan.setColumns(columns); - insertTabletPlan.setRowCount(times.length); - insertTabletPlan.setBitMaps(bitMaps); - return insertTabletPlan; - } -} diff --git a/server/src/test/java/org/apache/iotdb/db/utils/MemUtilsTest.java b/server/src/test/java/org/apache/iotdb/db/utils/MemUtilsTest.java index ada8d39f69..ac54b83dd9 100644 --- a/server/src/test/java/org/apache/iotdb/db/utils/MemUtilsTest.java +++ b/server/src/test/java/org/apache/iotdb/db/utils/MemUtilsTest.java @@ -20,7 +20,8 @@ package org.apache.iotdb.db.utils; import org.apache.iotdb.commons.exception.IllegalPathException; import org.apache.iotdb.commons.path.PartialPath; -import org.apache.iotdb.db.qp.physical.crud.InsertTabletPlan; +import org.apache.iotdb.db.mpp.plan.planner.plan.node.PlanNodeId; +import org.apache.iotdb.db.mpp.plan.planner.plan.node.write.InsertTabletNode; import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; import org.apache.iotdb.tsfile.utils.Binary; import org.apache.iotdb.tsfile.write.record.TSRecord; @@ -35,9 +36,6 @@ import org.apache.iotdb.tsfile.write.record.datapoint.StringDataPoint; import org.junit.Assert; import org.junit.Test; -import java.util.ArrayList; -import java.util.List; - public class MemUtilsTest { @Test @@ -50,7 +48,7 @@ public class MemUtilsTest { } @Test - public void getRecordSizeWithInsertPlanTest() throws IllegalPathException { + public void getRecordSizeWithInsertNodeTest() throws IllegalPathException { PartialPath device = new PartialPath("root.sg.d1"); String[] measurements = {"s1", "s2", "s3", "s4", "s5"}; Object[] columns = { @@ -60,21 +58,30 @@ public class MemUtilsTest { new double[] {4}, new Binary[] {new Binary("5")} }; - List<Integer> dataTypes = new ArrayList<>(); + TSDataType[] dataTypes = new TSDataType[6]; int sizeSum = 0; - dataTypes.add(TSDataType.INT32.ordinal()); + dataTypes[0] = TSDataType.INT32; sizeSum += 8 + TSDataType.INT32.getDataTypeSize(); - dataTypes.add(TSDataType.INT64.ordinal()); + dataTypes[1] = TSDataType.INT64; sizeSum += 8 + TSDataType.INT64.getDataTypeSize(); - dataTypes.add(TSDataType.FLOAT.ordinal()); + dataTypes[2] = TSDataType.FLOAT; sizeSum += 8 + TSDataType.FLOAT.getDataTypeSize(); - dataTypes.add(TSDataType.DOUBLE.ordinal()); + dataTypes[3] = TSDataType.DOUBLE; sizeSum += 8 + TSDataType.DOUBLE.getDataTypeSize(); - dataTypes.add(TSDataType.TEXT.ordinal()); + dataTypes[4] = TSDataType.TEXT; sizeSum += 8 + TSDataType.TEXT.getDataTypeSize(); - InsertTabletPlan insertPlan = new InsertTabletPlan(device, measurements, dataTypes); - insertPlan.setColumns(columns); - Assert.assertEquals(sizeSum, MemUtils.getTabletSize(insertPlan, 0, 1, false)); + InsertTabletNode insertNode = + new InsertTabletNode( + new PlanNodeId(""), + device, + false, + measurements, + dataTypes, + new long[1], + null, + columns, + 1); + Assert.assertEquals(sizeSum, MemUtils.getTabletSize(insertNode, 0, 1, false)); } /** This method tests MemUtils.getStringMem() and MemUtils.getDataPointMem() */
