This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch ty/TableIT
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/ty/TableIT by this push:
new 3823ba3a445 partial
3823ba3a445 is described below
commit 3823ba3a44593dad11877f1aaf1c02963e2ed068
Author: JackieTien97 <[email protected]>
AuthorDate: Tue Jul 23 19:46:38 2024 +0800
partial
---
.../org/apache/iotdb/db/it/utils/TestUtils.java | 8 +-
.../old/alignbydevice/IoTDBAlignByDeviceIT.java | 33 +-
.../IoTDBAlignByDeviceWithTemplateIT.java | 67 +-
.../IoTDBOrderByLimitOffsetAlignByDeviceIT.java | 5 +-
.../IoTDBOrderByWithAlignByDeviceIT.java | 82 +--
.../scalar/IoTDBCastFunctionIT.java | 780 +++++++++++++++++++++
.../scalar/IoTDBReplaceFunctionIT.java | 182 +++++
.../scalar/IoTDBRoundFunctionIT.java | 311 ++++++++
.../scalar/IoTDBSubStringFunctionIT.java | 219 ++++++
.../relational/metadata/TableMetadataImpl.java | 6 +-
.../plan/relational/sql/ast/CreateDB.java | 9 +-
.../plan/relational/sql/ast/QualifiedName.java | 2 +-
.../plan/relational/sql/parser/AstBuilder.java | 33 +-
.../apache/iotdb/commons/schema/table/TsTable.java | 2 +-
14 files changed, 1626 insertions(+), 113 deletions(-)
diff --git
a/integration-test/src/test/java/org/apache/iotdb/db/it/utils/TestUtils.java
b/integration-test/src/test/java/org/apache/iotdb/db/it/utils/TestUtils.java
index d664ec07671..e59c397db89 100644
--- a/integration-test/src/test/java/org/apache/iotdb/db/it/utils/TestUtils.java
+++ b/integration-test/src/test/java/org/apache/iotdb/db/it/utils/TestUtils.java
@@ -233,15 +233,17 @@ public class TestUtils {
}
}
- public static void tableAssertTestFail(String sql, String errMsg) {
- tableAssertTestFail(sql, errMsg, SessionConfig.DEFAULT_USER,
SessionConfig.DEFAULT_PASSWORD);
+ public static void tableAssertTestFail(String sql, String errMsg, String
databaseName) {
+ tableAssertTestFail(
+ sql, errMsg, SessionConfig.DEFAULT_USER,
SessionConfig.DEFAULT_PASSWORD, databaseName);
}
public static void tableAssertTestFail(
- String sql, String errMsg, String userName, String password) {
+ String sql, String errMsg, String userName, String password, String
databaseName) {
try (Connection connection =
EnvFactory.getEnv().getConnection(userName, password,
BaseEnv.TABLE_SQL_DIALECT);
Statement statement = connection.createStatement()) {
+ statement.execute("use " + databaseName);
statement.executeQuery(sql);
fail("No exception!");
} catch (SQLException e) {
diff --git
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/alignbydevice/IoTDBAlignByDeviceIT.java
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/alignbydevice/IoTDBAlignByDeviceIT.java
index c28bb9ca582..57028e6d9ea 100644
---
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/alignbydevice/IoTDBAlignByDeviceIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/alignbydevice/IoTDBAlignByDeviceIT.java
@@ -23,6 +23,7 @@ import org.apache.iotdb.it.env.EnvFactory;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.ClusterIT;
import org.apache.iotdb.itbase.category.LocalStandaloneIT;
+import org.apache.iotdb.itbase.env.BaseEnv;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -101,7 +102,7 @@ public class IoTDBAlignByDeviceIT {
}
protected static void insertData() {
- try (Connection connection = EnvFactory.getEnv().getConnection();
+ try (Connection connection =
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
Statement statement = connection.createStatement()) {
for (String sql : sqls) {
@@ -114,7 +115,7 @@ public class IoTDBAlignByDeviceIT {
@Test
public void selectTest() {
- String[] expectedHeader = new String[] {"Time", "device_id", "s0", "s1",
"s2", "s3", "s4"};
+ String[] expectedHeader = new String[] {"time", "device_id", "s0", "s1",
"s2", "s3", "s4"};
String[] retArray =
new String[] {
"1997-01-01T08:00:00.001Z,d0,101,1101,null,null,null,",
@@ -144,7 +145,7 @@ public class IoTDBAlignByDeviceIT {
@Test
public void selectTestWithLimitOffset1() {
- String[] expectedHeader = new String[] {"Time", "device_id", "s0", "s1",
"s2", "s3", "s4"};
+ String[] expectedHeader = new String[] {"time", "device_id", "s0", "s1",
"s2", "s3", "s4"};
String[] retArray =
new String[] {
"1997-01-01T08:00:00.001Z,d1,999,null,null,null,null,",
@@ -163,7 +164,7 @@ public class IoTDBAlignByDeviceIT {
@Test
public void selectTestWithLimitOffset2() {
- String[] expectedHeader = new String[] {"Time", "device_id", "s0", "s1",
"s2", "s3", "s4"};
+ String[] expectedHeader = new String[] {"time", "device_id", "s0", "s1",
"s2", "s3", "s4"};
String[] retArray =
new String[] {
"1997-01-01T08:00:00.001Z,d1,999,null,null,null,null,",
@@ -181,7 +182,7 @@ public class IoTDBAlignByDeviceIT {
@Test
public void selectWithDuplicatedPathsTest() {
- String[] expectedHeader = new String[] {"Time", "device_id", "s0", "s0",
"s1"};
+ String[] expectedHeader = new String[] {"time", "device_id", "s0", "s0",
"s1"};
String[] retArray =
new String[] {
"1997-01-01T08:00:00.001Z,d0,101,101,1101,",
@@ -200,7 +201,7 @@ public class IoTDBAlignByDeviceIT {
"1997-01-01T08:00:01.000Z,d1,888,888,null,",
};
tableResultSetEqualTest(
- "select s0,s0,s1 from vehicle where device_id = 'd0' or device_id =
'd1' order by device_id",
+ "select time, device_id, s0,s0,s1 from vehicle where device_id = 'd0'
or device_id = 'd1' order by device_id",
expectedHeader,
retArray,
DATABASE_NAME);
@@ -208,7 +209,7 @@ public class IoTDBAlignByDeviceIT {
@Test
public void selectLimitTest() {
- String[] expectedHeader = new String[] {"Time", "device_id", "s0", "s0",
"s1"};
+ String[] expectedHeader = new String[] {"time", "device_id", "s0", "s0",
"s1"};
String[] retArray =
new String[] {
"1997-01-01T08:00:00.002Z,d0,101,10000,40000,",
@@ -223,7 +224,7 @@ public class IoTDBAlignByDeviceIT {
"1997-01-01T08:00:01.000Z,d0,22222,22222,55555,",
};
tableResultSetEqualTest(
- "select s0,s0,s1 from vehicle order by device_id offset 1 limit 10",
+ "select time, device_id, s0,s0,s1 from vehicle order by device_id
offset 1 limit 10",
expectedHeader,
retArray,
DATABASE_NAME);
@@ -232,7 +233,7 @@ public class IoTDBAlignByDeviceIT {
@Test
public void selectWithValueFilterTest() {
- String[] expectedHeader = new String[] {"Time", "device_id", "s0", "s1",
"s2", "s3", "s4"};
+ String[] expectedHeader = new String[] {"time", "device_id", "s0", "s1",
"s2", "s3", "s4"};
String[] retArray =
new String[] {
"1997-01-01T08:00:00.100Z,d0,99,199,null,null,true,",
@@ -252,7 +253,7 @@ public class IoTDBAlignByDeviceIT {
@Test
public void selectDifferentSeriesWithValueFilterWithoutCacheTest() {
- String[] expectedHeader = new String[] {"Time", "device_id", "s0"};
+ String[] expectedHeader = new String[] {"time", "device_id", "s0"};
String[] retArray =
new String[] {
"1997-01-01T08:00:00.100Z,d0,99,",
@@ -264,7 +265,7 @@ public class IoTDBAlignByDeviceIT {
"2000-01-01T00:00:00.000Z,d0,null",
};
tableResultSetEqualTest(
- "select s0 from root.vehicle.d0 where s1 < 200 order by device_id",
+ "select time, device_id, s0 from root.vehicle.d0 where s1 < 200 order
by device_id",
expectedHeader,
retArray,
DATABASE_NAME);
@@ -273,13 +274,13 @@ public class IoTDBAlignByDeviceIT {
@Test
public void selectDifferentSeriesWithBinaryValueFilterWithoutCacheTest() {
- String[] expectedHeader = new String[] {"Time", "device_id", "s0"};
+ String[] expectedHeader = new String[] {"time", "device_id", "s0"};
String[] retArray =
new String[] {
"1997-01-01T08:00:00.105Z,d0,99,",
};
tableResultSetEqualTest(
- "select s0 from root.vehicle.d0 where s1 < 200 and s2 > 10 order by
device_id",
+ "select time, device_id, s0 from root.vehicle.d0 where s1 < 200 and s2
> 10 order by device_id",
expectedHeader,
retArray,
DATABASE_NAME);
@@ -438,7 +439,7 @@ public class IoTDBAlignByDeviceIT {
public void unusualCaseTest2() {
String[] expectedHeader =
- new String[] {"Time", "device_id", "s0", "s0", "s1", "s0", "s1", "s2",
"s3", "s4"};
+ new String[] {"time", "device_id", "s0", "s0", "s1", "s0", "s1", "s2",
"s3", "s4"};
String[] retArray =
new String[] {
"1997-01-01T08:00:00.001Z,d0,101,101,1101,101,1101,null,null,null,",
@@ -456,7 +457,7 @@ public class IoTDBAlignByDeviceIT {
@Test
public void selectWithRegularExpressionTest() {
- String[] expectedHeader = new String[] {"Time", "device_id", "s0", "s1",
"s2", "s3", "s4"};
+ String[] expectedHeader = new String[] {"time", "device_id", "s0", "s1",
"s2", "s3", "s4"};
String[] retArray =
new String[] {
"1997-01-01T08:00:00.001Z,d0,101,1101,null,null,null,",
@@ -487,7 +488,7 @@ public class IoTDBAlignByDeviceIT {
@Test
public void selectWithNonExistMeasurementInWhereClause() {
- String[] expectedHeader = new String[] {"Time", "device_id", "s0", "s1",
"s2", "s3", "s4"};
+ String[] expectedHeader = new String[] {"time", "device_id", "s0", "s1",
"s2", "s3", "s4"};
String[] retArray =
new String[] {
"1997-01-01T08:00:00.001Z,d0,101,1101,null,null,null,",
diff --git
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/alignbydevice/IoTDBAlignByDeviceWithTemplateIT.java
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/alignbydevice/IoTDBAlignByDeviceWithTemplateIT.java
index 59942d3acc1..af8448ae30c 100644
---
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/alignbydevice/IoTDBAlignByDeviceWithTemplateIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/alignbydevice/IoTDBAlignByDeviceWithTemplateIT.java
@@ -69,7 +69,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
@Test
public void selectWildcardNoFilterTest() {
// 1. order by device_id
- String[] expectedHeader = new String[] {"Time", "device_id", "s3", "s1",
"s2"};
+ String[] expectedHeader = new String[] {"time", "device_id", "s3", "s1",
"s2"};
String[] retArray =
new String[] {
"1997-01-01T08:00:00.001Z,d1,1,1.1,false,",
@@ -82,12 +82,12 @@ public class IoTDBAlignByDeviceWithTemplateIT {
"1997-01-01T08:00:00.005Z,d4,5555,5555.5,false,",
};
tableResultSetEqualTest(
- "SELECT Time, device_id, s3, s1, s2 FROM table1 order by device_id;",
+ "SELECT time, device_id, s3, s1, s2 FROM table1 order by device_id;",
expectedHeader,
retArray,
DATABASE_NAME);
- expectedHeader = new String[] {"Time", "device_id", "s1", "s2", "s3",
"s1"};
+ expectedHeader = new String[] {"time", "device_id", "s1", "s2", "s3",
"s1"};
retArray =
new String[] {
"1997-01-01T08:00:00.001Z,d1,1.1,false,1,1.1,",
@@ -102,7 +102,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
tableResultSetEqualTest(
"SELECT *, s1 FROM table1 order by device_id;", expectedHeader,
retArray, DATABASE_NAME);
- expectedHeader = new String[] {"Time", "device_id", "s1", "s2", "s3"};
+ expectedHeader = new String[] {"time", "device_id", "s1", "s2", "s3"};
retArray =
new String[] {
"1997-01-01T08:00:00.001Z,d1,1.1,false,1,",
@@ -117,7 +117,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
DATABASE_NAME);
// 2. order by device_id + limit/offset
- expectedHeader = new String[] {"Time", "device_id", "s1", "s2", "s3"};
+ expectedHeader = new String[] {"time", "device_id", "s1", "s2", "s3"};
retArray =
new String[] {
"1997-01-01T08:00:00.002Z,d1,2.2,false,2,",
"1997-01-01T08:00:00.001Z,d2,11.1,false,11,",
@@ -141,7 +141,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
"1997-01-01T08:00:00.001Z,d4,1111.1,true,1111,",
};
tableResultSetEqualTest(
- "SELECT * FROM table1 ORDER BY Time DESC, device_id ASC;",
+ "SELECT * FROM table1 ORDER BY time DESC, device_id ASC;",
expectedHeader,
retArray,
DATABASE_NAME);
@@ -155,7 +155,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
"1997-01-01T08:00:00.002Z,d2,22.2,false,22,",
};
tableResultSetEqualTest(
- "SELECT * FROM table1 ORDER BY TIME DESC, device_id LIMIT 4;",
+ "SELECT * FROM table1 ORDER BY time DESC, device_id LIMIT 4;",
expectedHeader,
retArray,
DATABASE_NAME);
@@ -164,7 +164,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
@Test
public void selectMeasurementNoFilterTest() {
// 1. order by device_id
- String[] expectedHeader = new String[] {"Time", "device_id", "s3", "s1"};
+ String[] expectedHeader = new String[] {"time", "device_id", "s3", "s1"};
String[] retArray =
new String[] {
"1997-01-01T08:00:00.001Z,d1,1,1.1,",
@@ -177,7 +177,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
"1997-01-01T08:00:00.005Z,d4,5555,5555.5,",
};
tableResultSetEqualTest(
- "SELECT Time, device_id, s3, s1 FROM table1 order by device_id;",
+ "SELECT time, device_id, s3, s1 FROM table1 order by device_id;",
expectedHeader,
retArray,
DATABASE_NAME);
@@ -203,7 +203,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
"1997-01-01T08:00:00.002Z,d1,2,2.2,",
"1997-01-01T08:00:00.001Z,d2,11,11.1,",
};
tableResultSetEqualTest(
- "SELECT Time, device_id, s3,s1 FROM table1 order by device_id OFFSET 1
LIMIT 2;",
+ "SELECT time, device_id, s3,s1 FROM table1 order by device_id OFFSET 1
LIMIT 2;",
expectedHeader,
retArray,
DATABASE_NAME);
@@ -221,7 +221,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
"1997-01-01T08:00:00.001Z,d4,1111,1111.1,",
};
tableResultSetEqualTest(
- "SELECT Time, device_id, s3,s1 FROM table1 ORDER BY TIME DESC,
device_id;",
+ "SELECT time, device_id, s3,s1 FROM table1 ORDER BY TIME DESC,
device_id;",
expectedHeader,
retArray,
DATABASE_NAME);
@@ -235,7 +235,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
"1997-01-01T08:00:00.002Z,d2,22,22.2,",
};
tableResultSetEqualTest(
- "SELECT Time, device_id, s3,s1 FROM table1 ORDER BY TIME DESC,
device_id LIMIT 4;",
+ "SELECT time, device_id, s3,s1 FROM table1 ORDER BY time DESC,
device_id LIMIT 4;",
expectedHeader,
retArray,
DATABASE_NAME);
@@ -244,7 +244,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
@Test
public void selectWildcardWithFilterOrderByTimeTest() {
// 1. order by time + time filter
- String[] expectedHeader = new String[] {"Time", "device_id", "s1", "s2",
"s3"};
+ String[] expectedHeader = new String[] {"time", "device_id", "s1", "s2",
"s3"};
String[] retArray =
new String[] {
"1997-01-01T08:00:00.004Z,d3,444.4,true,44,",
@@ -266,7 +266,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
};
tableResultSetEqualTest(
"SELECT * FROM table1 where time > 1 and time < 5 and s3>=11 and
s3<=1111 and s1 != 11.1 "
- + "ORDER BY TIME DESC, device_id",
+ + "ORDER BY time DESC, device_id",
expectedHeader,
retArray,
DATABASE_NAME);
@@ -291,7 +291,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
@Test
public void selectWildcardWithFilterOrderByDeviceTest() {
// 1. order by device + time filter
- String[] expectedHeader = new String[] {"Time", "device_id", "s1", "s2",
"s3"};
+ String[] expectedHeader = new String[] {"time", "device_id", "s1", "s2",
"s3"};
String[] retArray =
new String[] {
@@ -323,7 +323,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
@Test
public void selectMeasurementWithFilterOrderByTimeTest() {
// 1. order by time + time filter
- String[] expectedHeader = new String[] {"Time", "device_id", "s3", "s2"};
+ String[] expectedHeader = new String[] {"time", "device_id", "s3", "s2"};
String[] retArray =
new String[] {
"1997-01-01T08:00:00.004Z,d3,44,true,",
@@ -332,7 +332,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
"1997-01-01T08:00:00.001Z,d1,1,false,",
};
tableResultSetEqualTest(
- "SELECT Time, device_id, s3, s2 FROM table1 WHERE time < 5 ORDER BY
TIME DESC, device_id LIMIT 4;",
+ "SELECT time, device_id, s3, s2 FROM table1 WHERE time < 5 ORDER BY
time DESC, device_id LIMIT 4;",
expectedHeader,
retArray,
DATABASE_NAME);
@@ -343,7 +343,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
"1997-01-01T08:00:00.004Z,d3,44,true,",
"1997-01-01T08:00:00.002Z,d2,22,false,",
};
tableResultSetEqualTest(
- "SELECT s3,s2 FROM table1 where time > 1 and time < 5 and s3>=11 and
s3<=1111 and s1 != 11.1 "
+ "SELECT time, device_id, s3,s2 FROM table1 where time > 1 and time < 5
and s3>=11 and s3<=1111 and s1 != 11.1 "
+ "ORDER BY TIME DESC, device_id;",
expectedHeader,
retArray,
@@ -353,7 +353,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
@Test
public void selectMeasurementWithFilterOrderByDeviceTest() {
// 1. order by device + time filter
- String[] expectedHeader = new String[] {"Time", "device_id", "s3", "s2"};
+ String[] expectedHeader = new String[] {"time", "device_id", "s3", "s2"};
String[] retArray =
new String[] {
"1997-01-01T08:00:00.001Z,d4,1111,true,",
@@ -362,7 +362,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
"1997-01-01T08:00:00.001Z,d2,11,false,",
};
tableResultSetEqualTest(
- "SELECT s3,s2 FROM table1 WHERE time < 5 ORDER BY DEVICE DESC, Time
LIMIT 4",
+ "SELECT time, device_id, s3,s2 FROM table1 WHERE time < 5 ORDER BY
DEVICE DESC, time LIMIT 4",
expectedHeader,
retArray,
DATABASE_NAME);
@@ -373,7 +373,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
"1997-01-01T08:00:00.004Z,d3,44,true,",
"1997-01-01T08:00:00.002Z,d2,22,false,",
};
tableResultSetEqualTest(
- "SELECT s3,s2 FROM table1 where time > 1 and time < 5 and s3>=11 and
s3<=1111 and s1 != 11.1 "
+ "SELECT time, device_id, s3,s2 FROM table1 where time > 1 and time < 5
and s3>=11 and s3<=1111 and s1 != 11.1 "
+ "ORDER BY DEVICE DESC, Time asc",
expectedHeader,
retArray,
@@ -382,7 +382,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
@Test
public void aliasTest() {
- String[] expectedHeader = new String[] {"aa", "bb", "s3", "s2", "Time",
"device_id"};
+ String[] expectedHeader = new String[] {"aa", "bb", "s3", "s2", "time",
"device_id"};
String[] retArray =
new String[] {
@@ -396,12 +396,12 @@ public class IoTDBAlignByDeviceWithTemplateIT {
"5555.5,false,5555,false,1997-01-01T08:00:00.005Z,d4,",
};
tableResultSetEqualTest(
- "SELECT s1 as aa, s2 as bb, s3, s2, Time, device_id FROM table1;",
+ "SELECT s1 as aa, s2 as bb, s3, s2, time, device_id FROM table1;",
expectedHeader,
retArray,
DATABASE_NAME);
- expectedHeader = new String[] {"Time", "device_id", "a", "b"};
+ expectedHeader = new String[] {"time", "device_id", "a", "b"};
retArray =
new String[] {
@@ -415,7 +415,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
"1997-01-01T08:00:00.005Z,d4,5555.5,5555.5,",
};
tableResultSetEqualTest(
- "SELECT Time, device_id, s1 as a, s1 as b FROM table1",
+ "SELECT time, device_id, s1 as a, s1 as b FROM table1",
expectedHeader,
retArray,
DATABASE_NAME);
@@ -424,7 +424,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
@Test
public void orderByExpressionTest() {
// 1. order by basic measurement
- String[] expectedHeader = new String[] {"Time", "device_id", "s3", "s1",
"s2"};
+ String[] expectedHeader = new String[] {"time", "device_id", "s3", "s1",
"s2"};
String[] retArray =
new String[] {
"1997-01-01T08:00:00.005Z,d4,5555,5555.5,false,",
@@ -437,13 +437,13 @@ public class IoTDBAlignByDeviceWithTemplateIT {
"1997-01-01T08:00:00.001Z,d3,null,111.1,true,",
};
tableResultSetEqualTest(
- "SELECT Time, device_id, s3, s1, s2 FROM table1 order by s2 asc, s1
desc, device_id;",
+ "SELECT time, device_id, s3, s1, s2 FROM table1 order by s2 asc, s1
desc, device_id;",
expectedHeader,
retArray,
DATABASE_NAME);
// 2. select measurement is different with order by measurement
- expectedHeader = new String[] {"Time", "device_id", "s3"};
+ expectedHeader = new String[] {"time", "device_id", "s3"};
retArray =
new String[] {
"1997-01-01T08:00:00.005Z,d4,5555,",
@@ -456,7 +456,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
"1997-01-01T08:00:00.001Z,d3,null,",
};
tableResultSetEqualTest(
- "SELECT Time, device_id, s3 FROM table1 order by s2 asc, s1 desc",
+ "SELECT time, device_id, s3 FROM table1 order by s2 asc, s1 desc",
expectedHeader,
retArray,
DATABASE_NAME);
@@ -474,7 +474,7 @@ public class IoTDBAlignByDeviceWithTemplateIT {
"1997-01-01T08:00:00.001Z,d3,null,",
};
tableResultSetEqualTest(
- "SELECT Time, device_id, s3 FROM root.sg1.** order by s1+s3 desc",
+ "SELECT time, device_id, s3 FROM root.sg1.** order by s1+s3 desc",
expectedHeader,
retArray,
DATABASE_NAME);
@@ -485,16 +485,17 @@ public class IoTDBAlignByDeviceWithTemplateIT {
tableAssertTestFail(
"select s1 from table1 where s1",
- "701: WHERE clause must evaluate to a boolean: actual type FLOAT");
+ "701: WHERE clause must evaluate to a boolean: actual type FLOAT",
+ DATABASE_NAME);
}
@Test
public void emptyResultTest() {
- String[] expectedHeader = new String[] {"Time", "device_id", "s1", "s2",
"s3"};
+ String[] expectedHeader = new String[] {"time", "device_id", "s1", "s2",
"s3"};
String[] retArray = new String[] {};
tableResultSetEqualTest(
- "SELECT * FROM table1 where time>=now()-1d and time<=now() " + "ORDER
BY TIME DESC",
+ "SELECT * FROM table1 where time>=now()-1d and time<=now() " + "ORDER
BY time DESC",
expectedHeader,
retArray,
DATABASE_NAME);
diff --git
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/alignbydevice/IoTDBOrderByLimitOffsetAlignByDeviceIT.java
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/alignbydevice/IoTDBOrderByLimitOffsetAlignByDeviceIT.java
index 3eb24bf86dc..f94f7a5eb7f 100644
---
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/alignbydevice/IoTDBOrderByLimitOffsetAlignByDeviceIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/alignbydevice/IoTDBOrderByLimitOffsetAlignByDeviceIT.java
@@ -23,6 +23,7 @@ import org.apache.iotdb.it.env.EnvFactory;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.ClusterIT;
import org.apache.iotdb.itbase.category.LocalStandaloneIT;
+import org.apache.iotdb.itbase.env.BaseEnv;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -53,7 +54,7 @@ public class IoTDBOrderByLimitOffsetAlignByDeviceIT {
@Test
public void orderByCanNotPushLimitTest() {
// 1. value filter, can not push down LIMIT
- String[] expectedHeader = new String[] {"Time", "device_id", "s1"};
+ String[] expectedHeader = new String[] {"time", "device_id", "s1"};
String[] retArray = new String[] {"1997-01-01T08:00:00.003Z,d1,111,"};
tableResultSetEqualTest(
"SELECT * FROM table1 WHERE s1>40 ORDER BY Time LIMIT 1",
@@ -134,7 +135,7 @@ public class IoTDBOrderByLimitOffsetAlignByDeviceIT {
};
protected static void insertData3() {
- try (Connection iotDBConnection = EnvFactory.getEnv().getConnection();
+ try (Connection iotDBConnection =
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
Statement statement = iotDBConnection.createStatement()) {
for (String sql : SQL_LIST) {
statement.execute(sql);
diff --git
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/alignbydevice/IoTDBOrderByWithAlignByDeviceIT.java
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/alignbydevice/IoTDBOrderByWithAlignByDeviceIT.java
index 1df91102278..da9b6faba72 100644
---
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/alignbydevice/IoTDBOrderByWithAlignByDeviceIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/alignbydevice/IoTDBOrderByWithAlignByDeviceIT.java
@@ -212,7 +212,7 @@ public class IoTDBOrderByWithAlignByDeviceIT {
@Test
public void overFlowTest() {
- String[] expectedHeader = new String[] {"Time", "value"};
+ String[] expectedHeader = new String[] {"time", "value"};
String[] retArray = new String[20];
long startTime = 1;
@@ -228,14 +228,14 @@ public class IoTDBOrderByWithAlignByDeviceIT {
}
tableResultSetEqualTest(
- "SELECT Time, value FROM overflow", expectedHeader, retArray,
DATABASE_NAME);
+ "SELECT time, value FROM overflow", expectedHeader, retArray,
DATABASE_NAME);
}
// ORDER BY DEVICE
@Test
public void orderByDeviceTest1() {
- String[] expectedHeader = new String[] {"Time", "city", "precipitation",
"temperature"};
+ String[] expectedHeader = new String[] {"time", "city", "precipitation",
"temperature"};
String[] expectedDevice =
Arrays.stream(places.clone()).sorted().toArray(String[]::new);
@@ -282,7 +282,7 @@ public class IoTDBOrderByWithAlignByDeviceIT {
@Test
public void orderByDeviceTest2() {
- String[] expectedHeader = new String[] {"Time", "city", "precipitation",
"temperature"};
+ String[] expectedHeader = new String[] {"time", "city", "precipitation",
"temperature"};
String[] expectedDevice =
Arrays.stream(places.clone()).sorted().toArray(String[]::new);
@@ -330,7 +330,7 @@ public class IoTDBOrderByWithAlignByDeviceIT {
@Test
public void orderByDeviceTest3() {
- String[] expectedHeader = new String[] {"Time", "city", "precipitation",
"temperature"};
+ String[] expectedHeader = new String[] {"time", "city", "precipitation",
"temperature"};
String[] expectedDevice =
Arrays.stream(places.clone()).sorted(Comparator.reverseOrder()).toArray(String[]::new);
@@ -380,58 +380,58 @@ public class IoTDBOrderByWithAlignByDeviceIT {
@Test
public void orderByTimeTest1() {
- String[] expectedHeader = new String[] {"Time", "city", "precipitation",
"temperature"};
+ String[] expectedHeader = new String[] {"time", "city", "precipitation",
"temperature"};
orderByTimeTest1(
- "SELECT * FROM weather ORDER BY TIME, city",
+ "SELECT * FROM weather ORDER BY time, city",
numOfPointsInDevice * places.length,
expectedHeader);
- orderByTimeTest1("SELECT * FROM weather ORDER BY TIME, city LIMIT 100",
100, expectedHeader);
+ orderByTimeTest1("SELECT * FROM weather ORDER BY time, city LIMIT 100",
100, expectedHeader);
}
@Test
public void orderByTimeTest2() {
- String[] expectedHeader = new String[] {"Time", "city", "precipitation",
"temperature"};
+ String[] expectedHeader = new String[] {"time", "city", "precipitation",
"temperature"};
orderByTimeTest1(
"SELECT * FROM weather ORDER BY TIME ASC, city",
numOfPointsInDevice * places.length,
expectedHeader);
orderByTimeTest1(
- "SELECT * FROM weather ORDER BY TIME ASC, city ASC LIMIT 100E", 100,
expectedHeader);
+ "SELECT * FROM weather ORDER BY time ASC, city ASC LIMIT 100E", 100,
expectedHeader);
}
@Test
public void orderByTimeTest3() {
- String[] expectedHeader = new String[] {"Time", "city", "precipitation",
"temperature"};
+ String[] expectedHeader = new String[] {"time", "city", "precipitation",
"temperature"};
orderByTimeTest3(
- "SELECT * FROM weather ORDER BY TIME DESC, city ASC",
+ "SELECT * FROM weather ORDER BY time DESC, city ASC",
numOfPointsInDevice * places.length,
expectedHeader);
orderByTimeTest3(
- "SELECT * FROM weather ORDER BY TIME DESC, city LIMIT 100", 100,
expectedHeader);
+ "SELECT * FROM weather ORDER BY time DESC, city LIMIT 100", 100,
expectedHeader);
}
@Test
public void orderByTimeExpressionTest1() {
- String[] expectedHeader = new String[] {"Time", "city", "precipitation",
"temperature"};
+ String[] expectedHeader = new String[] {"time", "city", "precipitation",
"temperature"};
orderByTimeExpressionTest1(
- "SELECT * FROM weather ORDER BY TIME DESC, precipitation DESC, city",
+ "SELECT * FROM weather ORDER BY time DESC, precipitation DESC, city",
numOfPointsInDevice * places.length,
expectedHeader);
orderByTimeExpressionTest1(
- "SELECT * FROM weather ORDER BY TIME DESC, precipitation DESC, city
asc LIMIT 100",
+ "SELECT * FROM weather ORDER BY time DESC, precipitation DESC, city
asc LIMIT 100",
100,
expectedHeader);
}
@Test
public void orderExpressionTest1() {
- String[] expectedHeader = new String[] {"Time", "city", "precipitation",
"temperature"};
+ String[] expectedHeader = new String[] {"time", "city", "precipitation",
"temperature"};
orderByExpressionTest1(
"SELECT * FROM weather ORDER BY precipitation DESC, time DESC, city
asc",
@@ -444,19 +444,19 @@ public class IoTDBOrderByWithAlignByDeviceIT {
@Test
public void orderByDeviceTimeTest1() {
- String[] expectedHeader = new String[] {"Time", "city", "precipitation",
"temperature"};
+ String[] expectedHeader = new String[] {"time", "city", "precipitation",
"temperature"};
- orderByDeviceTimeTest1("SELECT * FROM weather ORDER BY city ASC,Time
DESC", 10, expectedHeader);
+ orderByDeviceTimeTest1("SELECT * FROM weather ORDER BY city ASC,time
DESC", 10, expectedHeader);
orderByDeviceTimeTest1(
- "SELECT * FROM weather ORDER BY city ASC,Time DESC LIMIT 100", 5,
expectedHeader);
+ "SELECT * FROM weather ORDER BY city ASC,time DESC LIMIT 100", 5,
expectedHeader);
}
@Test
public void orderByDeviceTimeTest2() {
- String[] expectedHeader = new String[] {"Time", "city", "precipitation",
"temperature"};
+ String[] expectedHeader = new String[] {"time", "city", "precipitation",
"temperature"};
- orderByDeviceTimeTest2("SELECT * FROM weather ORDER BY city ASC,Time ASC",
10, expectedHeader);
+ orderByDeviceTimeTest2("SELECT * FROM weather ORDER BY city ASC,time ASC",
10, expectedHeader);
orderByDeviceTimeTest2(
"SELECT * FROM weather ORDER BY city ASC,Time ASC LIMIT 100", 5,
expectedHeader);
@@ -464,75 +464,75 @@ public class IoTDBOrderByWithAlignByDeviceIT {
@Test
public void orderByDeviceTimeTest3() {
- String[] expectedHeader = new String[] {"Time", "city", "precipitation",
"temperature"};
+ String[] expectedHeader = new String[] {"time", "city", "precipitation",
"temperature"};
orderByDeviceTimeTest3(
- "SELECT * FROM weather ORDER BY city DESC,Time DESC", 10,
expectedHeader);
+ "SELECT * FROM weather ORDER BY city DESC,time DESC", 10,
expectedHeader);
orderByDeviceTimeTest3(
- "SELECT * FROM weather ORDER BY city DESC,Time DESC LIMIT 100", 5,
expectedHeader);
+ "SELECT * FROM weather ORDER BY city DESC,time DESC LIMIT 100", 5,
expectedHeader);
}
@Test
public void orderByDeviceTimeTest4() {
- String[] expectedHeader = new String[] {"Time", "city", "precipitation",
"temperature"};
+ String[] expectedHeader = new String[] {"time", "city", "precipitation",
"temperature"};
- orderByDeviceTimeTest4("SELECT * FROM weather ORDER BY city DESC,Time
ASC", 10, expectedHeader);
+ orderByDeviceTimeTest4("SELECT * FROM weather ORDER BY city DESC,time
ASC", 10, expectedHeader);
orderByDeviceTimeTest4(
- "SELECT * FROM weather ORDER BY city DESC,Time ASC LIMIT 100", 5,
expectedHeader);
+ "SELECT * FROM weather ORDER BY city DESC,time ASC LIMIT 100", 5,
expectedHeader);
}
@Test
public void orderByTimeDeviceTest1() {
- String[] expectedHeader = new String[] {"Time", "city", "precipitation",
"temperature"};
+ String[] expectedHeader = new String[] {"time", "city", "precipitation",
"temperature"};
orderByTimeDeviceTest1(
- "SELECT * FROM weather ORDER BY Time ASC,city DESC",
+ "SELECT * FROM weather ORDER BY time ASC,city DESC",
numOfPointsInDevice * places.length,
expectedHeader);
orderByTimeDeviceTest1(
- "SELECT * FROM weather ORDER BY Time ASC,city DESC LIMIT 100", 100,
expectedHeader);
+ "SELECT * FROM weather ORDER BY time ASC,city DESC LIMIT 100", 100,
expectedHeader);
}
@Test
public void orderByTimeDeviceTest2() {
- String[] expectedHeader = new String[] {"Time", "city", "precipitation",
"temperature"};
+ String[] expectedHeader = new String[] {"time", "city", "precipitation",
"temperature"};
orderByTimeDeviceTest2(
- "SELECT * FROM weather ORDER BY Time ASC,city ASC",
+ "SELECT * FROM weather ORDER BY time ASC,city ASC",
numOfPointsInDevice * places.length,
expectedHeader);
orderByTimeDeviceTest2(
- "SELECT * FROM weather ORDER BY Time ASC,city ASC LIMIT 100", 100,
expectedHeader);
+ "SELECT * FROM weather ORDER BY time ASC,city ASC LIMIT 100", 100,
expectedHeader);
}
@Test
public void orderByTimeDeviceTest3() {
- String[] expectedHeader = new String[] {"Time", "city", "precipitation",
"temperature"};
+ String[] expectedHeader = new String[] {"time", "city", "precipitation",
"temperature"};
orderByTimeDeviceTest3(
- "SELECT * FROM weather ORDER BY Time DESC,city DESC",
+ "SELECT * FROM weather ORDER BY time DESC,city DESC",
numOfPointsInDevice * places.length,
expectedHeader);
orderByTimeDeviceTest3(
- "SELECT * FROM weather ORDER BY Time DESC,city DESC LIMIT 100", 100,
expectedHeader);
+ "SELECT * FROM weather ORDER BY time DESC,city DESC LIMIT 100", 100,
expectedHeader);
}
@Test
public void orderByTimeDeviceTest4() {
- String[] expectedHeader = new String[] {"Time", "city", "precipitation",
"temperature"};
+ String[] expectedHeader = new String[] {"time", "city", "precipitation",
"temperature"};
orderByTimeDeviceTest4(
- "SELECT * FROM weather ORDER BY Time DESC,DEVICE ASC",
+ "SELECT * FROM weather ORDER BY time DESC,DEVICE ASC",
numOfPointsInDevice * places.length,
expectedHeader);
orderByTimeDeviceTest4(
- "SELECT * FROM weather ORDER BY Time DESC,DEVICE ASC LIMIT 100", 100,
expectedHeader);
+ "SELECT * FROM weather ORDER BY time DESC,DEVICE ASC LIMIT 100", 100,
expectedHeader);
}
public static void orderByTimeTest1(String sql, int count, String[]
expectedHeader) {
@@ -1544,7 +1544,7 @@ public class IoTDBOrderByWithAlignByDeviceIT {
public void optimizedPlanTest() {
String[] expectedHeader =
- new String[] {"Time", "plant_id", "device_id", "temperature",
"status", "hardware"};
+ new String[] {"time", "plant_id", "device_id", "temperature",
"status", "hardware"};
String[] retArray =
new String[] {
"2017-10-31T16:01:00.000Z,wf02,wt02,null,true,v2",
diff --git
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBCastFunctionIT.java
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBCastFunctionIT.java
new file mode 100644
index 00000000000..dbce7468d0a
--- /dev/null
+++
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBCastFunctionIT.java
@@ -0,0 +1,780 @@
+/*
+ * 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.relational.it.query.old.builtinfunction.scalar;
+
+import org.apache.iotdb.it.env.EnvFactory;
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.ClusterIT;
+import org.apache.iotdb.itbase.category.LocalStandaloneIT;
+import org.apache.iotdb.itbase.env.BaseEnv;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.apache.iotdb.db.it.utils.TestUtils.tableResultSetEqualTest;
+import static org.apache.iotdb.itbase.constant.TestConstant.TIMESTAMP_STR;
+import static org.junit.Assert.fail;
+
+@RunWith(IoTDBTestRunner.class)
+@Category({LocalStandaloneIT.class, ClusterIT.class})
+public class IoTDBCastFunctionIT {
+
+ private static final String DATABASE_NAME = "db";
+
+ private static final String[] SQLs =
+ new String[] {
+ // normal cases
+ "CREATE DATABASE " + DATABASE_NAME,
+ "USE " + DATABASE_NAME,
+ "create table normal(device_id STRING ID, s1 INT32 MEASUREMENT, s2
INT64 MEASUREMENT, s3 FLOAT MEASUREMENT, s4 DOUBLE MEASUREMENT, s5 BOOLEAN
MEASUREMENT, s6 STRING MEASUREMENT);",
+ // data for int series
+ "INSERT INTO normal(Time, device_id ,s1) values(0, 'd1', 0)",
+ "INSERT INTO normal(Time, device_id ,s1) values(1, 'd1', 1)",
+ "INSERT INTO normal(Time, device_id ,s1) values(2, 'd1', 2)",
+ "INSERT INTO normal(Time, device_id ,s1) values(3, 'd1', 3)",
+ // data for long series
+ "INSERT INTO normal(Time, device_id ,s2) values(0, 'd1', 0)",
+ "INSERT INTO normal(Time, device_id ,s2) values(1, 'd1', 1)",
+ "INSERT INTO normal(Time, device_id ,s2) values(2, 'd1', 2)",
+ "INSERT INTO normal(Time, device_id ,s2) values(3, 'd1', 3)",
+ // data for float series
+ "INSERT INTO normal(Time, device_id ,s3) values(0, 'd1', 0)",
+ "INSERT INTO normal(Time, device_id ,s3) values(1, 'd1', 1)",
+ "INSERT INTO normal(Time, device_id ,s3) values(2, 'd1', 2.7)",
+ "INSERT INTO normal(Time, device_id ,s3) values(3, 'd1', 3.33)",
+ // data for double series
+ "INSERT INTO normal(Time, device_id ,s3) values(0, 'd1', 0)",
+ "INSERT INTO normal(Time, device_id ,s3) values(1, 'd1', 1.0)",
+ "INSERT INTO normal(Time, device_id ,s3) values(2, 'd1', 2.7)",
+ "INSERT INTO normal(Time, device_id ,s3) values(3, 'd1', 3.33)",
+ // data for boolean series
+ "INSERT INTO normal(Time, device_id ,s3) values(0, 'd1', false)",
+ "INSERT INTO normal(Time, device_id ,s3) values(1, 'd1', false)",
+ "INSERT INTO normal(Time, device_id ,s3) values(2, 'd1', true)",
+ "INSERT INTO normal(Time, device_id ,s3) values(3, 'd1', true)",
+ // data for text series
+ "INSERT INTO normal(Time, device_id ,s3) values(0, 'd1', '10000')",
+ "INSERT INTO normal(Time, device_id ,s3) values(1, 'd1', 3)",
+ "INSERT INTO normal(Time, device_id ,s3) values(2, 'd1', 'TRue')",
+ "INSERT INTO normal(Time, device_id ,s3) values(3, 'd1', 'faLse')",
+ "flush",
+
+ // special cases
+ "create table special(device_id STRING ID, s1 INT32 MEASUREMENT, s2
INT64 MEASUREMENT, s3 FLOAT MEASUREMENT, s4 DOUBLE MEASUREMENT, s5 BOOLEAN
MEASUREMENT, s6 STRING MEASUREMENT);",
+ "INSERT INTO normal(Time, device_id ,s2) values(1, 'd1', 2147483648)",
+ "INSERT INTO normal(Time, device_id ,s3) values(1, 'd1',
2147483648.0)",
+ "INSERT INTO normal(Time, device_id ,s3) values(2, 'd1', 2e38)",
+ "INSERT INTO normal(Time, device_id ,s4) values(1, 'd1', 4e50)",
+ "INSERT INTO normal(Time, device_id ,s6) values(1, 'd1', 'test')",
+ "INSERT INTO normal(Time, device_id ,s6) values(2, 'd1', '1.1')",
+ "INSERT INTO normal(Time, device_id ,s6) values(3, 'd1', '4e60')",
+ "INSERT INTO normal(Time, device_id ,s6) values(4, 'd1', '4e60000')",
+ };
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ EnvFactory.getEnv().initClusterEnvironment();
+ insertData();
+ }
+
+ protected static void insertData() {
+ try (Connection connection =
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
+ Statement statement = connection.createStatement()) {
+
+ for (String sql : SQLs) {
+ statement.execute(sql);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ EnvFactory.getEnv().cleanClusterEnvironment();
+ }
+
+ // region ================== New Transformer ==================
+ @Test
+ public void testNewTransformerWithIntSource() {
+ // cast to int
+ String[] expectedHeader = new String[] {TIMESTAMP_STR, "cast_s1"};
+ String[] intRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0,",
+ "1997-01-01T08:00:00.001Z,1,",
+ "1997-01-01T08:00:00.002Z,2,",
+ "1997-01-01T08:00:00.003Z,3,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s1 AS INT32) as cast_s1 from normal where
device_id='d1'",
+ expectedHeader,
+ intRetArray,
+ DATABASE_NAME);
+
+ // cast to long
+ String[] longRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0,",
+ "1997-01-01T08:00:00.001Z,1,",
+ "1997-01-01T08:00:00.002Z,2,",
+ "1997-01-01T08:00:00.003Z,3,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s1 AS INT64) as cast_s1 from normal where
device_id='d1'",
+ expectedHeader,
+ longRetArray,
+ DATABASE_NAME);
+
+ // cast to float
+ String[] floatRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0.0,",
+ "1997-01-01T08:00:00.001Z,1.0,",
+ "1997-01-01T08:00:00.002Z,2.0,",
+ "1997-01-01T08:00:00.003Z,3.0,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s1 AS FLOAT) as cast_s1 from normal where
device_id='d1'",
+ expectedHeader,
+ floatRetArray,
+ DATABASE_NAME);
+
+ // cast to double
+ String[] doubleRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0.0,",
+ "1997-01-01T08:00:00.001Z,1.0,",
+ "1997-01-01T08:00:00.002Z,2.0,",
+ "1997-01-01T08:00:00.003Z,3.0,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s1 AS DOUBLE) as cast_s1 from normal where
device_id='d1'",
+ expectedHeader,
+ doubleRetArray,
+ DATABASE_NAME);
+
+ // cast to boolean
+ String[] booleanRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,false,",
+ "1997-01-01T08:00:00.001Z,true,",
+ "1997-01-01T08:00:00.002Z,true,",
+ "1997-01-01T08:00:00.003Z,true,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s1 AS BOOLEAN) as cast_s1 from normal where
device_id='d1'",
+ expectedHeader,
+ booleanRetArray,
+ DATABASE_NAME);
+
+ // cast to string
+ String[] stringRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0,",
+ "1997-01-01T08:00:00.001Z,1,",
+ "1997-01-01T08:00:00.002Z,2,",
+ "1997-01-01T08:00:00.003Z,3,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s1 AS STRING) as cast_s1 from normal where
device_id='d1'",
+ expectedHeader,
+ stringRetArray,
+ DATABASE_NAME);
+ }
+
+ @Test
+ public void testNewTransformerWithLongSource() {
+ // cast to int
+ String[] expectedHeader = new String[] {TIMESTAMP_STR, "cast_s2"};
+ String[] intRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0,",
+ "1997-01-01T08:00:00.001Z,1,",
+ "1997-01-01T08:00:00.002Z,2,",
+ "1997-01-01T08:00:00.003Z,3,",
+ };
+
+ tableResultSetEqualTest(
+ "select Time, CAST(s2 AS INT32) as cast_s2 from normal where
device_id='d1'",
+ expectedHeader,
+ intRetArray,
+ DATABASE_NAME);
+
+ // cast to long
+ String[] longRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0,",
+ "1997-01-01T08:00:00.001Z,1,",
+ "1997-01-01T08:00:00.002Z,2,",
+ "1997-01-01T08:00:00.003Z,3,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s2 AS INT64) as cast_s2 from normal where
device_id='d1'",
+ expectedHeader,
+ longRetArray,
+ DATABASE_NAME);
+
+ // cast to float
+ String[] floatRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0.0,",
+ "1997-01-01T08:00:00.001Z,1.0,",
+ "1997-01-01T08:00:00.002Z,2.0,",
+ "1997-01-01T08:00:00.003Z,3.0,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s2 AS FLOAT) as cast_s2 from normal where
device_id='d1'",
+ expectedHeader,
+ floatRetArray,
+ DATABASE_NAME);
+
+ // cast to double
+ String[] doubleRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0.0,",
+ "1997-01-01T08:00:00.001Z,1.0,",
+ "1997-01-01T08:00:00.002Z,2.0,",
+ "1997-01-01T08:00:00.003Z,3.0,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s2 AS DOUBLE) as cast_s2 from normal where
device_id='d1'",
+ expectedHeader,
+ doubleRetArray,
+ DATABASE_NAME);
+
+ // cast to boolean
+ String[] booleanRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,false,",
+ "1997-01-01T08:00:00.001Z,true,",
+ "1997-01-01T08:00:00.002Z,true,",
+ "1997-01-01T08:00:00.003Z,true,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s2 AS BOOLEAN) as cast_s2 from normal where
device_id='d1'",
+ expectedHeader,
+ booleanRetArray,
+ DATABASE_NAME);
+
+ // cast to text
+ String[] stringRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0,",
+ "1997-01-01T08:00:00.001Z,1,",
+ "1997-01-01T08:00:00.002Z,2,",
+ "1997-01-01T08:00:00.003Z,3,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s2 AS STRING) as cast_s2 from normal where
device_id='d1'",
+ expectedHeader,
+ stringRetArray,
+ DATABASE_NAME);
+ }
+
+ @Test
+ public void testNewTransformerWithFloatSource() {
+ // cast to int
+ String[] expectedHeader = new String[] {TIMESTAMP_STR, "cast_s3"};
+ String[] intRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0,",
+ "1997-01-01T08:00:00.001Z,1,",
+ "1997-01-01T08:00:00.002Z,2,",
+ "1997-01-01T08:00:00.003Z,3,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s3 AS INT32) as cast_s3 from normal where
device_id='d1'",
+ expectedHeader,
+ intRetArray,
+ DATABASE_NAME);
+
+ // cast to long
+ String[] longRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0,",
+ "1997-01-01T08:00:00.001Z,1,",
+ "1997-01-01T08:00:00.002Z,2,",
+ "1997-01-01T08:00:00.003Z,3,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s3 AS INT64) as cast_s3 from normal where
device_id='d1'",
+ expectedHeader,
+ longRetArray,
+ DATABASE_NAME);
+
+ // cast to float
+ String[] floatRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0.0,",
+ "1997-01-01T08:00:00.001Z,1.0,",
+ "1997-01-01T08:00:00.002Z,2.7,",
+ "1997-01-01T08:00:00.003Z,3.33,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s3 AS FLOAT) as cast_s3 from normal where
device_id='d1'",
+ expectedHeader,
+ floatRetArray,
+ DATABASE_NAME);
+
+ // cast to double
+ String[] doubleRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0.0,",
+ "1997-01-01T08:00:00.001Z,1.0,",
+ "1997-01-01T08:00:00.002Z,2.700000047683716,",
+ "1997-01-01T08:00:00.003Z,3.3299999237060547,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s3 AS DOUBLE) as cast_s3 from normal where
device_id='d1'",
+ expectedHeader,
+ doubleRetArray,
+ DATABASE_NAME);
+
+ // cast to boolean
+ String[] booleanRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,false,",
+ "1997-01-01T08:00:00.001Z,true,",
+ "1997-01-01T08:00:00.002Z,true,",
+ "1997-01-01T08:00:00.003Z,true,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s3 AS BOOLEAN) as cast_s3 from normal where
device_id='d1'",
+ expectedHeader,
+ booleanRetArray,
+ DATABASE_NAME);
+
+ // cast to text
+ String[] stringRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0.0,",
+ "1997-01-01T08:00:00.001Z,1.0,",
+ "1997-01-01T08:00:00.002Z,2.7,",
+ "1997-01-01T08:00:00.003Z,3.33,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s3 AS STRING) as cast_s3 from normal where
device_id='d1'",
+ expectedHeader,
+ stringRetArray,
+ DATABASE_NAME);
+ }
+
+ @Test
+ public void testNewTransformerWithDoubleSource() {
+ // cast to int
+ String[] expectedHeader = new String[] {TIMESTAMP_STR, "cast_s4"};
+ String[] intRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0,",
+ "1997-01-01T08:00:00.001Z,1,",
+ "1997-01-01T08:00:00.002Z,2,",
+ "1997-01-01T08:00:00.003Z,3,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s4 AS INT32) as cast_s4 from normal where
device_id='d1'",
+ expectedHeader,
+ intRetArray,
+ DATABASE_NAME);
+
+ // cast to long
+ String[] longRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0,",
+ "1997-01-01T08:00:00.001Z,1,",
+ "1997-01-01T08:00:00.002Z,2,",
+ "1997-01-01T08:00:00.003Z,3,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s4 AS INT64) as cast_s4 from normal where
device_id='d1'",
+ expectedHeader,
+ longRetArray,
+ DATABASE_NAME);
+
+ // cast to float
+ String[] floatRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0。0,",
+ "1997-01-01T08:00:00.001Z,1.0,",
+ "1997-01-01T08:00:00.002Z,2.7,",
+ "1997-01-01T08:00:00.003Z,3.33,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s4 AS FLOAT) as cast_s4 from normal where
device_id='d1'",
+ expectedHeader,
+ floatRetArray,
+ DATABASE_NAME);
+
+ // cast to double
+ String[] doubleRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0。0,",
+ "1997-01-01T08:00:00.001Z,1.0,",
+ "1997-01-01T08:00:00.002Z,2.7,",
+ "1997-01-01T08:00:00.003Z,3.33,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s4 AS DOUBLE) as cast_s4 from normal where
device_id='d1'",
+ expectedHeader,
+ doubleRetArray,
+ DATABASE_NAME);
+
+ // cast to boolean
+ String[] booleanRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,false,",
+ "1997-01-01T08:00:00.001Z,true,",
+ "1997-01-01T08:00:00.002Z,true,",
+ "1997-01-01T08:00:00.003Z,true,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s4 AS BOOLEAN) as cast_s4 from normal where
device_id='d1'",
+ expectedHeader,
+ booleanRetArray,
+ DATABASE_NAME);
+
+ // cast to string
+ String[] stringRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0。0,",
+ "1997-01-01T08:00:00.001Z,1.0,",
+ "1997-01-01T08:00:00.002Z,2.7,",
+ "1997-01-01T08:00:00.003Z,3.33,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s4 AS STRING) as cast_s4 from normal where
device_id='d1'",
+ expectedHeader,
+ stringRetArray,
+ DATABASE_NAME);
+ }
+
+ @Test
+ public void testNewTransformerWithBooleanSource() {
+ // cast to int
+ String[] expectedHeader = new String[] {TIMESTAMP_STR, "cast_s5"};
+ String[] intRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0,",
+ "1997-01-01T08:00:00.001Z,0,",
+ "1997-01-01T08:00:00.002Z,1,",
+ "1997-01-01T08:00:00.003Z,1,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s5 AS INT32) as cast_s5 from normal where
device_id='d1'",
+ expectedHeader,
+ intRetArray,
+ DATABASE_NAME);
+
+ // cast to long
+ String[] longRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0,",
+ "1997-01-01T08:00:00.001Z,0,",
+ "1997-01-01T08:00:00.002Z,1,",
+ "1997-01-01T08:00:00.003Z,1,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s5 AS INT64) as cast_s5 from normal where
device_id='d1'",
+ expectedHeader,
+ longRetArray,
+ DATABASE_NAME);
+
+ // cast to float
+ String[] floatRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0.0,",
+ "1997-01-01T08:00:00.001Z,0.0,",
+ "1997-01-01T08:00:00.002Z,1.0,",
+ "1997-01-01T08:00:00.003Z,1.0,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s5 AS FLOAT) as cast_s5 from normal where
device_id='d1'",
+ expectedHeader,
+ floatRetArray,
+ DATABASE_NAME);
+
+ // cast to double
+ String[] doubleRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,0.0,",
+ "1997-01-01T08:00:00.001Z,0.0,",
+ "1997-01-01T08:00:00.002Z,1.0,",
+ "1997-01-01T08:00:00.003Z,1.0,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s5 AS DOUBLE) as cast_s5 from normal where
device_id='d1'",
+ expectedHeader,
+ doubleRetArray,
+ DATABASE_NAME);
+
+ // cast to boolean
+ String[] booleanRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,false,",
+ "1997-01-01T08:00:00.001Z,false,",
+ "1997-01-01T08:00:00.002Z,true,",
+ "1997-01-01T08:00:00.003Z,true,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s5 AS BOOLEAN) as cast_s5 from normal where
device_id='d1'",
+ expectedHeader,
+ booleanRetArray,
+ DATABASE_NAME);
+
+ // cast to text
+ String[] stringRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,false,",
+ "1997-01-01T08:00:00.001Z,false,",
+ "1997-01-01T08:00:00.002Z,true,",
+ "1997-01-01T08:00:00.003Z,true,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s5 AS STRING) as cast_s5 from normal where
device_id='d1'",
+ expectedHeader,
+ stringRetArray,
+ DATABASE_NAME);
+ }
+
+ @Test
+ public void testNewTransformerWithTextSource() {
+ // cast to int
+ String[] expectedHeader = new String[] {TIMESTAMP_STR, "cast_s6"};
+ String[] intRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,10000,", "1997-01-01T08:00:00.001Z,3,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s6 AS INT32) as cast_s6 from normal where
device_id='d1' and Time < 2",
+ expectedHeader,
+ intRetArray,
+ DATABASE_NAME);
+
+ // cast to long
+ String[] longRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,10000,", "1997-01-01T08:00:00.001Z,3,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s6 AS INT64) as cast_s6 from normal where
device_id='d1' and Time < 2",
+ expectedHeader,
+ longRetArray,
+ DATABASE_NAME);
+
+ // cast to float
+ String[] floatRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,10000.0,", "1997-01-01T08:00:00.001Z,3.0,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s6 AS FLOAT) as cast_s6 from normal where
device_id='d1' and Time < 2",
+ expectedHeader,
+ floatRetArray,
+ DATABASE_NAME);
+
+ // cast to double
+ String[] doubleRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,10000.0,", "1997-01-01T08:00:00.001Z,3.0,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s6 AS DOUBLE) as cast_s6 from normal where
device_id='d1' and Time < 2",
+ expectedHeader,
+ doubleRetArray,
+ DATABASE_NAME);
+
+ // cast to boolean
+ String[] booleanRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.002Z,true,", "1997-01-01T08:00:00.003Z,false,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s6 AS BOOLEAN) as cast_s6 from normal where
device_id='d1' and Time >= 2",
+ expectedHeader,
+ booleanRetArray,
+ DATABASE_NAME);
+
+ // cast to text
+ String[] stringRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.000Z,10000,", "1997-01-01T08:00:00.001Z,3,",
+ "1997-01-01T08:00:00.002Z,TRue,", "1997-01-01T08:00:00.003Z,faLse,",
+ };
+ tableResultSetEqualTest(
+ "select Time, CAST(s6 AS STRING) as cast_s6 from normal where
device_id='d1'",
+ expectedHeader,
+ stringRetArray,
+ DATABASE_NAME);
+ }
+
+ // endregion
+
+ // region special cases
+
+ @Test
+ public void testCastWithLongSource() {
+ try (Connection connection =
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
+ Statement statement = connection.createStatement()) {
+ try {
+ statement.execute("USE " + DATABASE_NAME);
+ statement.execute("select CAST(s2 AS INT32) from special where
device_id='d1'");
+ fail();
+ } catch (Exception ignored) {
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ @Test
+ public void testCastWithFloatSource() {
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+ try {
+ statement.execute("USE " + DATABASE_NAME);
+ statement.execute("select CAST(s3 AS INT32) from special where
device_id='d1'");
+ fail();
+ } catch (Exception ignored) {
+ }
+
+ try {
+ statement.execute("USE " + DATABASE_NAME);
+ statement.execute("select CAST(s3 AS INT64) from special where
device_id='d1'");
+ fail();
+ } catch (Exception ignored) {
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ @Test
+ public void testCastWithDoubleSource() {
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+ try {
+ statement.execute("USE " + DATABASE_NAME);
+ statement.execute("select CAST(s4 AS INT32) from special where
device_id='d1'");
+ fail();
+ } catch (Exception ignored) {
+ }
+
+ try {
+ statement.execute("USE " + DATABASE_NAME);
+ statement.execute("select CAST(s4 AS INT64) from special where
device_id='d1'");
+ fail();
+ } catch (Exception ignored) {
+ }
+
+ try {
+ statement.execute("USE " + DATABASE_NAME);
+ statement.execute("select CAST(s4 AS Float) from special where
device_id='d1'");
+ fail();
+ } catch (Exception ignored) {
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ @Test
+ public void testCastWithTextSource() {
+ try (Connection connection = EnvFactory.getEnv().getConnection();
+ Statement statement = connection.createStatement()) {
+ statement.execute("USE " + DATABASE_NAME);
+ try {
+ statement.execute(
+ "select CAST(s6 AS INT32) from special where device_id='d1' and
time = 1");
+ fail();
+ } catch (Exception ignored) {
+ }
+
+ try {
+ statement.execute(
+ "select CAST(s6 AS INT32) from special where device_id='d1' and
time = 2");
+ fail();
+ } catch (Exception ignored) {
+ }
+
+ try {
+ statement.execute(
+ "select CAST(s6 AS INT64) from special where device_id='d1' and
time = 1");
+ fail();
+ } catch (Exception ignored) {
+ }
+
+ try {
+ statement.execute(
+ "select CAST(s6 AS INT64) from special where device_id='d1' and
time = 2");
+ fail();
+ } catch (Exception ignored) {
+ }
+
+ try {
+ statement.execute("select CAST(s6 AS FLOAT) from special where
device_id='d1' and time=3");
+ fail();
+ } catch (Exception ignored) {
+ }
+
+ try {
+ statement.execute("select CAST(s6 AS FLOAT) from special where
device_id='d1' and time=1");
+ fail();
+ } catch (Exception ignored) {
+ }
+
+ try {
+ statement.execute(
+ "select CAST(s6 AS DOUBLE) from special where device_id='d1' and
time = 1");
+ fail();
+ } catch (Exception ignored) {
+ }
+
+ try {
+ statement.execute(
+ "select CAST(s6 AS DOUBLE) from special where device_id='d1' and
time = 4");
+ fail();
+ } catch (Exception ignored) {
+ }
+
+ try {
+ statement.execute(
+ "select CAST(s6 AS BOOLEAN) from special where device_id='d1' and
time = 1");
+ fail();
+ } catch (Exception ignored) {
+ }
+
+ } catch (SQLException e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+ // endregion
+}
diff --git
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBReplaceFunctionIT.java
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBReplaceFunctionIT.java
new file mode 100644
index 00000000000..8d17c5507f1
--- /dev/null
+++
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBReplaceFunctionIT.java
@@ -0,0 +1,182 @@
+/*
+ * 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.relational.it.query.old.builtinfunction.scalar;
+
+import org.apache.iotdb.it.env.EnvFactory;
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.ClusterIT;
+import org.apache.iotdb.itbase.category.LocalStandaloneIT;
+import org.apache.iotdb.itbase.env.BaseEnv;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import static org.apache.iotdb.db.it.utils.TestUtils.tableResultSetEqualTest;
+import static org.apache.iotdb.itbase.constant.TestConstant.TIMESTAMP_STR;
+import static org.junit.Assert.fail;
+
+@RunWith(IoTDBTestRunner.class)
+@Category({LocalStandaloneIT.class, ClusterIT.class})
+public class IoTDBReplaceFunctionIT {
+
+ private static final String DATABASE_NAME = "db";
+ private static final String[] SQLs =
+ new String[] {
+ "CREATE DATABASE " + DATABASE_NAME,
+ "use " + DATABASE_NAME,
+ "create table table1(device_id STRING ID, s1 TEXT MEASUREMENT, s2
INT32 MEASUREMENT, s3 INT64 MEASUREMENT, s4 FLOAT MEASUREMENT, s5 DOUBLE
MEASUREMENT, s6 BOOLEAN MEASUREMENT, s7 DATE MEASUREMENT, s8 TIMESTAMP
MEASUREMENT, s9 STRING MEASUREMENT, s10 BLOB MEASUREMENT);",
+ "INSERT INTO table1(Time,device_id,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10)
values(1, 'd1', 'abcd', 1, 1, 1, 1, true, '2021-10-01', 1633046400000,
'abcd','abcd')",
+ "INSERT INTO table1(Time,device_id,s1) values(2, 'd1', 'test\\\\')",
+ "INSERT INTO table1(Time,device_id,s1) values(3, 'd1', 'abcd\\\\')",
+ "INSERT INTO table1(Time,device_id,s9)) values(2, 'd1', 'test\\\\')",
+ "INSERT INTO table1(Time,device_id,s9)) values(3, 'd1', 'abcd\\\\')",
+ "flush"
+ };
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ EnvFactory.getEnv().initClusterEnvironment();
+ insertData();
+ }
+
+ protected static void insertData() {
+ try (Connection connection =
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
+ Statement statement = connection.createStatement()) {
+
+ for (String sql : SQLs) {
+ statement.execute(sql);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ EnvFactory.getEnv().cleanClusterEnvironment();
+ }
+
+ @Test
+ public void testNewTransformer() {
+ String[] expectedHeader = new String[] {TIMESTAMP_STR, "_col1", "_col2"};
+ String[] retArray =
+ new String[] {
+ "1997-01-01T08:00:00.001Z,ABcd,abcd,",
+ "1997-01-01T08:00:00.002Z,test\\\\,testaa,",
+ "1997-01-01T08:00:00.003Z,ABcd\\\\,abcdaa,"
+ };
+ tableResultSetEqualTest(
+ "select Time, REPLACE(s1, 'ab', 'AB'), REPLACE(s1, '\\', 'a') from
table1",
+ expectedHeader,
+ retArray,
+ DATABASE_NAME);
+
+ String[] retArray2 =
+ new String[] {
+ "1997-01-01T08:00:00.001Z,ABcd,abcd,",
+ "1997-01-01T08:00:00.002Z,test\\\\,testaa,",
+ "1997-01-01T08:00:00.003Z,ABcd\\\\,abcdaa,"
+ };
+ tableResultSetEqualTest(
+ "select Time, REPLACE(s9, 'ab', 'AB'), REPLACE(s9, '\\', 'a') from
table1",
+ expectedHeader,
+ retArray2,
+ DATABASE_NAME);
+ }
+
+ @Test
+ public void testWithoutTo() {
+ String[] expectedHeader = new String[] {TIMESTAMP_STR, "_col1"};
+ String[] retArray =
+ new String[] {
+ "1997-01-01T08:00:00.001Z,acd,",
+ "1997-01-01T08:00:00.002Z,test\\\\,",
+ "1997-01-01T08:00:00.003Z,acd\\\\,"
+ };
+ tableResultSetEqualTest(
+ "select Time, REPLACE(s1, 'b') from table1", expectedHeader, retArray,
DATABASE_NAME);
+ }
+
+ @Test
+ public void testWrongInputType() {
+ try (Connection connection =
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
+ Statement statement = connection.createStatement()) {
+ statement.execute("USE " + DATABASE_NAME);
+ try {
+ statement.execute("select REPLACE(s2, 'a', 'b') from table1");
+ fail();
+ } catch (Exception ignored) {
+ }
+
+ try {
+ statement.execute("select REPLACE(s3, 'a', 'b') from table1");
+ fail();
+ } catch (Exception ignored) {
+ }
+
+ try {
+ statement.execute("select REPLACE(s4, 'a', 'b') from table1");
+ fail();
+ } catch (Exception ignored) {
+ }
+
+ try {
+ statement.execute("select REPLACE(s5, 'a', 'b') from table1");
+ fail();
+ } catch (Exception ignored) {
+ }
+
+ try {
+ statement.execute("select REPLACE(s6, 'a', 'b') from table1");
+ fail();
+ } catch (Exception ignored) {
+ }
+
+ try {
+ statement.execute("select REPLACE(s7, 'a', 'b') from table1");
+ fail();
+ } catch (Exception ignored) {
+ }
+
+ try {
+ statement.execute("select REPLACE(s8, 'a', 'b') from table1");
+ fail();
+ } catch (Exception ignored) {
+ }
+
+ try {
+ statement.execute("select REPLACE(s10, 'a', 'b') from table1");
+ fail();
+ } catch (Exception ignored) {
+ }
+
+ } catch (SQLException e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+}
diff --git
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBRoundFunctionIT.java
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBRoundFunctionIT.java
new file mode 100644
index 00000000000..a3986167d3d
--- /dev/null
+++
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBRoundFunctionIT.java
@@ -0,0 +1,311 @@
+/*
+ * 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.relational.it.query.old.builtinfunction.scalar;
+
+import org.apache.iotdb.it.env.EnvFactory;
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.ClusterIT;
+import org.apache.iotdb.itbase.category.LocalStandaloneIT;
+import org.apache.iotdb.itbase.env.BaseEnv;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import java.sql.Connection;
+import java.sql.Statement;
+
+import static org.apache.iotdb.db.it.utils.TestUtils.tableAssertTestFail;
+import static org.apache.iotdb.db.it.utils.TestUtils.tableResultSetEqualTest;
+
+@RunWith(IoTDBTestRunner.class)
+@Category({LocalStandaloneIT.class, ClusterIT.class})
+public class IoTDBRoundFunctionIT {
+
+ private static final String DATABASE_NAME = "db";
+
+ protected static final String[] SQLs =
+ new String[] {
+ "CREATE DATABASE " + DATABASE_NAME,
+ "use " + DATABASE_NAME,
+ "create table table1(device_id STRING ID s1 INT32 MEASUREMENT, s2
INT64 MEASUREMENT, s3 DOUBLE MEASUREMENT, s4 FLOAT MEASUREMENT, s5 BOOLEAN
MEASUREMENT, s6 STRING MEASUREMENT)",
+ "INSERT INTO table1(time,device_id,s1,s2,s3,s4,s5,s6) values(1, 'd1',
2, 3, 0.11234, 101.143445345,true,null)",
+ "INSERT INTO table1(time,device_id,s1,s2,s3,s4,s5,s6) values(2, 'd1',
2, 4, 10.11234, 20.1443465345,true,'sss')",
+ "INSERT INTO table1(time,device_id,s1,s2,s3,s4,s5,s6) values(3, 'd1',
2, 555, 120.161234, 20.61437245345,true,'sss')",
+ "INSERT INTO table1(time,device_id,s1,s2,s3,s4,s5,s6) values(4, 'd1',
2, 12341234, 101.131234, null,true,'sss')",
+ "INSERT INTO table1(time,device_id,s1,s2,s3,s4,s5,s6) values(5, 'd1',
2, 55678, 90.116234, 20.8143454345,true,'sss')",
+ "INSERT INTO table1(time,device_id,s1,s2,s3,s4,s5,s6) values(6, 'd1',
2, 12355, null, 60.71443345345,true,'sss')",
+ "INSERT INTO table1(time,device_id,s1,s2,s3,s4,s5,s6)
values(1678695379764, 'd1', 2, 12345, 120.511234, 10.143425345,null,'sss')",
+ "flush"
+ };
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+
EnvFactory.getEnv().getConfig().getCommonConfig().setPartitionInterval(1000);
+ EnvFactory.getEnv().initClusterEnvironment();
+ insertData();
+ }
+
+ protected static void insertData() {
+ try (Connection connection =
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
+ Statement statement = connection.createStatement()) {
+
+ for (String sql : SQLs) {
+ statement.execute(sql);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ EnvFactory.getEnv().cleanClusterEnvironment();
+ }
+
+ @Test
+ public void testRound() {
+ String[] expectedHeader = new String[] {"time", "_col1"};
+ String[] intRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.001Z,2.0,",
+ "1997-01-01T08:00:00.002Z,2.0,",
+ "1997-01-01T08:00:00.003Z,2.0,",
+ "1997-01-01T08:00:00.004Z,2.0,",
+ "1997-01-01T08:00:00.005Z,2.0,",
+ "1997-01-01T08:00:00.006Z,2.0,",
+ "2023-03-13T08:16:19.764Z,2.0"
+ };
+ tableResultSetEqualTest(
+ "select time, round(s1) from table1", expectedHeader, intRetArray,
DATABASE_NAME);
+
+ intRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.001Z,3.0,",
+ "1997-01-01T08:00:00.002Z,4.0,",
+ "1997-01-01T08:00:00.003Z,555.0,",
+ "1997-01-01T08:00:00.004Z,1.2341234E7,",
+ "1997-01-01T08:00:00.005Z,55678.0,",
+ "1997-01-01T08:00:00.006Z,12355.0,",
+ "2023-03-13T08:16:19.764Z,12345.0,"
+ };
+ tableResultSetEqualTest(
+ "select time, round(s2) from table1", expectedHeader, intRetArray,
DATABASE_NAME);
+
+ intRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.001Z,0.0,",
+ "1997-01-01T08:00:00.002Z,10.0,",
+ "1997-01-01T08:00:00.003Z,120.0,",
+ "1997-01-01T08:00:00.004Z,101.0,",
+ "1997-01-01T08:00:00.005Z,90.0,",
+ "2023-03-13T08:16:19.764Z,121.0,"
+ };
+ tableResultSetEqualTest(
+ "select time, round(s3) from table1", expectedHeader, intRetArray,
DATABASE_NAME);
+
+ intRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.001Z,101.0,",
+ "1997-01-01T08:00:00.002Z,20.0,",
+ "1997-01-01T08:00:00.003Z,21.0,",
+ "1997-01-01T08:00:00.005Z,21.0,",
+ "1997-01-01T08:00:00.006Z,61.0,",
+ "2023-03-13T08:16:19.764Z,10.0,"
+ };
+ tableResultSetEqualTest(
+ "select time, round(s4) from table1", expectedHeader, intRetArray,
DATABASE_NAME);
+ }
+
+ @Test
+ public void testRoundWithPlaces() {
+ String[] expectedHeader = new String[] {"time", "_col1"};
+ String[] intRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.001Z,2.0,",
+ "1997-01-01T08:00:00.002Z,2.0,",
+ "1997-01-01T08:00:00.003Z,2.0,",
+ "1997-01-01T08:00:00.004Z,2.0,",
+ "1997-01-01T08:00:00.005Z,2.0,",
+ "1997-01-01T08:00:00.006Z,2.0,",
+ "2023-03-13T08:16:19.764Z,2.0"
+ };
+ tableResultSetEqualTest(
+ "select time, round(s1, 1) from table1", expectedHeader, intRetArray,
DATABASE_NAME);
+
+ intRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.001Z,3.0,",
+ "1997-01-01T08:00:00.002Z,4.0,",
+ "1997-01-01T08:00:00.003Z,555.0,",
+ "1997-01-01T08:00:00.004Z,1.2341234E7,",
+ "1997-01-01T08:00:00.005Z,55678.0,",
+ "1997-01-01T08:00:00.006Z,12355.0,",
+ "2023-03-13T08:16:19.764Z,12345.0"
+ };
+ tableResultSetEqualTest(
+ "select time, round(s2, 1) from table1", expectedHeader, intRetArray,
DATABASE_NAME);
+
+ intRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.001Z,0.1,",
+ "1997-01-01T08:00:00.002Z,10.1,",
+ "1997-01-01T08:00:00.003Z,120.2,",
+ "1997-01-01T08:00:00.004Z,101.1,",
+ "1997-01-01T08:00:00.005Z,90.1,",
+ "2023-03-13T08:16:19.764Z,120.5"
+ };
+ tableResultSetEqualTest(
+ "select time, round(s3, 1) from table1", expectedHeader, intRetArray,
DATABASE_NAME);
+
+ intRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.001Z,0.11,",
+ "1997-01-01T08:00:00.002Z,10.11,",
+ "1997-01-01T08:00:00.003Z,120.16,",
+ "1997-01-01T08:00:00.004Z,101.13,",
+ "1997-01-01T08:00:00.005Z,90.12,",
+ "2023-03-13T08:16:19.764Z,120.51"
+ };
+ tableResultSetEqualTest(
+ "select time, round(s4, 1) from table1", expectedHeader, intRetArray,
DATABASE_NAME);
+
+ intRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.001Z,0.112,",
+ "1997-01-01T08:00:00.002Z,10.112,",
+ "1997-01-01T08:00:00.003Z,120.161,",
+ "1997-01-01T08:00:00.004Z,101.131,",
+ "1997-01-01T08:00:00.005Z,90.116,",
+ "2023-03-13T08:16:19.764Z,120.511"
+ };
+ tableResultSetEqualTest(
+ "select time, round(s3, 3) from table1", expectedHeader, intRetArray,
DATABASE_NAME);
+
+ intRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.001Z,0.1123,",
+ "1997-01-01T08:00:00.002Z,10.1123,",
+ "1997-01-01T08:00:00.003Z,120.1612,",
+ "1997-01-01T08:00:00.004Z,101.1312,",
+ "1997-01-01T08:00:00.005Z,90.1162,",
+ "2023-03-13T08:16:19.764Z,102.5112"
+ };
+ tableResultSetEqualTest(
+ "select time, round(s3, 4) from table1", expectedHeader, intRetArray,
DATABASE_NAME);
+
+ intRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.001Z,101.14345,",
+ "1997-01-01T08:00:00.002Z,20.14435,",
+ "1997-01-01T08:00:00.003Z,20.61437,",
+ "1997-01-01T08:00:00.005Z,20.81435,",
+ "1997-01-01T08:00:00.006Z,60.71443,",
+ "2023-03-13T08:16:19.764Z,10.14342"
+ };
+ tableResultSetEqualTest(
+ "select time, round(s4, 5) from table1", expectedHeader, intRetArray,
DATABASE_NAME);
+
+ intRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.001Z,101.1,",
+ "1997-01-01T08:00:00.002Z,20.1,",
+ "1997-01-01T08:00:00.003Z,20.6,",
+ "1997-01-01T08:00:00.005Z,20.8,",
+ "1997-01-01T08:00:00.006Z,60.7,",
+ "2023-03-13T08:16:19.764Z,10.1"
+ };
+ tableResultSetEqualTest(
+ "select time, round(4, 1) from table1", expectedHeader, intRetArray,
DATABASE_NAME);
+ }
+
+ @Test
+ public void testRoundWithNegativePlaces() {
+
+ String[] expectedHeader = new String[] {"time", "_col1"};
+ String[] intRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.001Z,0.0,",
+ "1997-01-01T08:00:00.002Z,0.0,",
+ "1997-01-01T08:00:00.003Z,0.0,",
+ "1997-01-01T08:00:00.004Z,0.0,",
+ "1997-01-01T08:00:00.005Z,0.0,",
+ "1997-01-01T08:00:00.006Z,0.0,",
+ "2023-03-13T08:16:19.764Z,0.0"
+ };
+ tableResultSetEqualTest(
+ "select time, round(s1, -1) from table1", expectedHeader, intRetArray,
DATABASE_NAME);
+
+ intRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.001Z,0.0,",
+ "1997-01-01T08:00:00.002Z,0.0,",
+ "1997-01-01T08:00:00.003Z,560.0,",
+ "1997-01-01T08:00:00.004Z,1.234123E7,",
+ "1997-01-01T08:00:00.005Z,55680.0,",
+ "1997-01-01T08:00:00.006Z,12360.0,",
+ "2023-03-13T08:16:19.764Z,12340.0,"
+ };
+ tableResultSetEqualTest(
+ "select time, round(s2, -1) from table1", expectedHeader, intRetArray,
DATABASE_NAME);
+
+ intRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.001Z,0.0,",
+ "1997-01-01T08:00:00.002Z,10.0,",
+ "1997-01-01T08:00:00.003Z,120.0,",
+ "1997-01-01T08:00:00.004Z,100.0,",
+ "1997-01-01T08:00:00.005Z,90.0,",
+ "2023-03-13T08:16:19.764Z,120.0,"
+ };
+ tableResultSetEqualTest(
+ "select time, round(s3,-1) from table1", expectedHeader, intRetArray,
DATABASE_NAME);
+
+ intRetArray =
+ new String[] {
+ "1997-01-01T08:00:00.001Z,100.0,",
+ "1997-01-01T08:00:00.002Z,20.0,",
+ "1997-01-01T08:00:00.003Z,20.0,",
+ "1997-01-01T08:00:00.005Z,20.0,",
+ "1997-01-01T08:00:00.006Z,60.0,",
+ "2023-03-13T08:16:19.764Z,10.0,"
+ };
+ tableResultSetEqualTest(
+ "select time, round(s4, -1) from table1", expectedHeader, intRetArray,
DATABASE_NAME);
+ }
+
+ @Test
+ public void testRoundBooleanAndText() {
+ tableAssertTestFail(
+ "select round(s5) from table1",
+ TSStatusCode.SEMANTIC_ERROR.getStatusCode()
+ + ": Scalar function round only supports two numeric data types
[INT32, INT64, FLOAT, DOUBLE]",
+ DATABASE_NAME);
+
+ tableAssertTestFail(
+ "select round(s6) from table1",
+ TSStatusCode.SEMANTIC_ERROR.getStatusCode()
+ + ": Scalar function round only supports two numeric data types
[INT32, INT64, FLOAT, DOUBLE]",
+ DATABASE_NAME);
+ }
+}
diff --git
a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBSubStringFunctionIT.java
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBSubStringFunctionIT.java
new file mode 100644
index 00000000000..0419f22d583
--- /dev/null
+++
b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/builtinfunction/scalar/IoTDBSubStringFunctionIT.java
@@ -0,0 +1,219 @@
+/*
+ * 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.relational.it.query.old.builtinfunction.scalar;
+
+import org.apache.iotdb.it.env.EnvFactory;
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.ClusterIT;
+import org.apache.iotdb.itbase.category.LocalStandaloneIT;
+import org.apache.iotdb.itbase.env.BaseEnv;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
+import java.sql.Connection;
+import java.sql.Statement;
+
+import static org.apache.iotdb.db.it.utils.TestUtils.tableAssertTestFail;
+import static org.apache.iotdb.db.it.utils.TestUtils.tableResultSetEqualTest;
+
+@RunWith(IoTDBTestRunner.class)
+@Category({LocalStandaloneIT.class, ClusterIT.class})
+public class IoTDBSubStringFunctionIT {
+
+ private static final String DATABASE_NAME = "db";
+
+ private static final String[] SQLs =
+ new String[] {
+ "CREATE DATABASE " + DATABASE_NAME,
+ "use " + DATABASE_NAME,
+ "create table table1(device_id STRING ID, s1 TEXT MEASUREMENT, s2
INT32 MEASUREMENT, s3 INT64 MEASUREMENT, s4 FLOAT MEASUREMENT, s5 DOUBLE
MEASUREMENT, s6 BOOLEAN MEASUREMENT, s7 DATE MEASUREMENT, s8 TIMESTAMP
MEASUREMENT, s9 STRING MEASUREMENT, s10 BLOB MEASUREMENT);",
+ "INSERT INTO table1(Time,device_id,s1,s2,s3,s4,s5,s6,s7,s8,s9,s10)
values(1, 'd1', 'abcd', 1, 1, 1, 1, true, '2021-10-01', 1633046400000, 'abcd',
'abcd')",
+ "INSERT INTO table1(Time,device_id,s1) values(2, 'd1', 'test')",
+ "INSERT INTO table1(Time,device_id,s1) values(3, 'd1', 'abcdefg')",
+ "INSERT INTO table1(Time,device_id,s9)) values(2, 'd1', 'test')",
+ "INSERT INTO table1(Time,device_id,s9)) values(3, 'd1', 'abcdefg')",
+ "flush"
+ };
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ EnvFactory.getEnv().initClusterEnvironment();
+ insertData();
+ }
+
+ protected static void insertData() {
+ try (Connection connection =
EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
+ Statement statement = connection.createStatement()) {
+
+ for (String sql : SQLs) {
+ statement.execute(sql);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ EnvFactory.getEnv().cleanClusterEnvironment();
+ }
+
+ @Test
+ public void testNewTransformer() {
+ // Normal
+ String[] expectedHeader = new String[] {"time", "s1", "_col1", "_col2"};
+ String[] retArray =
+ new String[] {
+ "1997-01-01T08:00:00.001Z,abcd,abcd,abc,",
+ "1997-01-01T08:00:00.002Z,test,test,tes,",
+ "1997-01-01T08:00:00.003Z,abcdefg,abcdefg,abc,",
+ };
+ tableResultSetEqualTest(
+ "select time,s1,SUBSTRING(s1 FROM 1),SUBSTRING(s1 FROM 1 FOR 3) from
table1",
+ expectedHeader,
+ retArray,
+ DATABASE_NAME);
+
+ // Param 1 greater than input series length
+ retArray =
+ new String[] {
+ "1997-01-01T08:00:00.001Z,abcd,,,",
+ "1997-01-01T08:00:00.002Z,test,,,",
+ "1997-01-01T08:00:00.003Z,abcdefg,,,",
+ };
+ tableResultSetEqualTest(
+ "select time,s1,SUBSTRING(s1 from 11),SUBSTRING(s1 from 11 for 13)
from table1",
+ expectedHeader,
+ retArray,
+ DATABASE_NAME);
+
+ // Normal
+ expectedHeader = new String[] {"time", "s9", "_col1", "_col2"};
+ String[] retArray2 =
+ new String[] {
+ "1997-01-01T08:00:00.001Z,abcd,abcd,abc,",
+ "1997-01-01T08:00:00.002Z,test,test,tes,",
+ "1997-01-01T08:00:00.003Z,abcdefg,abcdefg,abc,",
+ };
+ tableResultSetEqualTest(
+ "select time,s9,SUBSTRING(s9 from 1),SUBSTRING(s9 from 1 for 3) from
table1",
+ expectedHeader,
+ retArray2,
+ DATABASE_NAME);
+ }
+
+ @Test
+ public void testRoundBooleanAndText() {
+ // Using substring without start and end position.
+ tableAssertTestFail(
+ "select s1,SUBSTRING(s1) from table1",
+ TSStatusCode.SEMANTIC_ERROR.getStatusCode()
+ + ": Argument exception,the scalar function [SUBSTRING] needs at
least one argument,it must be a signed integer",
+ DATABASE_NAME);
+
+ // Wrong input type
+ tableAssertTestFail(
+ "select SUBSTRING(s2 FROM 1 FOR 1) from table1",
+ TSStatusCode.SEMANTIC_ERROR.getStatusCode()
+ + ": Unsupported data type INT32 for function SUBSTRING.",
+ DATABASE_NAME);
+
+ // Wrong input type
+ tableAssertTestFail(
+ "select SUBSTRING(s3 FROM 1 FOR 1) from table1",
+ TSStatusCode.SEMANTIC_ERROR.getStatusCode()
+ + ": Unsupported data type INT64 for function SUBSTRING.",
+ DATABASE_NAME);
+
+ // Wrong input type
+ tableAssertTestFail(
+ "select SUBSTRING(s4 FROM 1 FOR 1) from table1",
+ TSStatusCode.SEMANTIC_ERROR.getStatusCode()
+ + ": Unsupported data type FLOAT for function SUBSTRING.",
+ DATABASE_NAME);
+
+ // Wrong input type
+ tableAssertTestFail(
+ "select SUBSTRING(s5 FROM 1 FOR 1) from table1",
+ TSStatusCode.SEMANTIC_ERROR.getStatusCode()
+ + ": Unsupported data type DOUBLE for function SUBSTRING.",
+ DATABASE_NAME);
+
+ // Wrong input type
+ tableAssertTestFail(
+ "select SUBSTRING(s6 FROM 1 FOR 1) from table1",
+ TSStatusCode.SEMANTIC_ERROR.getStatusCode()
+ + ": Unsupported data type BOOLEAN for function SUBSTRING.",
+ DATABASE_NAME);
+
+ // Wrong input type
+ tableAssertTestFail(
+ "select SUBSTRING(s7 FROM 1 FOR 1) from table1",
+ TSStatusCode.SEMANTIC_ERROR.getStatusCode()
+ + ": Unsupported data type DATE for function SUBSTRING.",
+ DATABASE_NAME);
+ // Wrong input type
+ tableAssertTestFail(
+ "select SUBSTRING(s8 FROM 1 FOR 1) from table1",
+ TSStatusCode.SEMANTIC_ERROR.getStatusCode()
+ + ": Unsupported data type TIMESTAMP for function SUBSTRING.",
+ DATABASE_NAME);
+
+ // Wrong input type
+ tableAssertTestFail(
+ "select SUBSTRING(s10 FROM 1 FOR 1) from table1",
+ TSStatusCode.SEMANTIC_ERROR.getStatusCode()
+ + ": Unsupported data type BLOB for function SUBSTRING.",
+ DATABASE_NAME);
+
+ // Using substring with float start position
+ tableAssertTestFail(
+ "select SUBSTRING(s1 FROM 1.0 FOR 1) from table1",
+ TSStatusCode.SEMANTIC_ERROR.getStatusCode()
+ + ": Argument exception,the scalar function [SUBSTRING] needs at
least one argument,it must be a signed integer",
+ DATABASE_NAME);
+
+ // Using substring with float start and length
+ tableAssertTestFail(
+ "select SUBSTRING(s1 FROM 1.0 FOR 1.1) from table1",
+ TSStatusCode.SEMANTIC_ERROR.getStatusCode()
+ + ": Argument exception,the scalar function [SUBSTRING] needs at
least one argument,it must be a signed integer",
+ DATABASE_NAME);
+
+ // Negative characters length
+ tableAssertTestFail(
+ "select SUBSTRING(s1 FROM 1 FOR -10) from table1",
+ TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode()
+ + ": Argument exception,the scalar function [SUBSTRING]
beginPosition and length must be greater than 0",
+ DATABASE_NAME);
+
+ // Negative characters begin
+ tableAssertTestFail(
+ "select SUBSTRING(s1 FROM -1 FOR 10) from table1",
+ TSStatusCode.EXECUTE_STATEMENT_ERROR.getStatusCode()
+ + ": Argument exception,the scalar function [SUBSTRING]
beginPosition and length must be greater than 0",
+ DATABASE_NAME);
+ }
+}
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java
index 12a9bd73bab..2452c7dbfc1 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java
@@ -159,7 +159,7 @@ public class TableMetadataImpl implements Metadata {
} else if
(BuiltinScalarFunction.ROUND.getFunctionName().equalsIgnoreCase(functionName)) {
if (!isOneNumericType(argumentTypes) &&
!isTwoNumericType(argumentTypes)) {
throw new SemanticException(
- "Scalar function"
+ "Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only supports two numeric data types [INT32, INT64, FLOAT,
DOUBLE]");
}
@@ -168,7 +168,7 @@ public class TableMetadataImpl implements Metadata {
if (!isTwoCharType(argumentTypes) && !isThreeCharType(argumentTypes)) {
throw new SemanticException(
- "Scalar function: "
+ "Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only supports text or string data type.");
}
@@ -182,7 +182,7 @@ public class TableMetadataImpl implements Metadata {
&& isNumericType(argumentTypes.get(1))
&& isNumericType(argumentTypes.get(2)))) {
throw new SemanticException(
- "Scalar function"
+ "Scalar function "
+ functionName.toLowerCase(Locale.ENGLISH)
+ " only supports text or string data type.");
}
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/CreateDB.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/CreateDB.java
index 3daa12f0728..02dd25c19bf 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/CreateDB.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/CreateDB.java
@@ -22,6 +22,7 @@ package
org.apache.iotdb.db.queryengine.plan.relational.sql.ast;
import com.google.common.collect.ImmutableList;
import java.util.List;
+import java.util.Locale;
import java.util.Objects;
import static com.google.common.base.MoreObjects.toStringHelper;
@@ -36,21 +37,21 @@ public class CreateDB extends Statement {
public CreateDB(boolean ifNotExists, String dbName) {
super(null);
this.ifNotExists = ifNotExists;
- this.dbName = requireNonNull(dbName, "dbName is null");
+ this.dbName = requireNonNull(dbName, "dbName is
null").toLowerCase(Locale.ENGLISH);
this.properties = null;
}
public CreateDB(NodeLocation location, boolean ifNotExists, String dbName) {
super(requireNonNull(location, "location is null"));
this.ifNotExists = ifNotExists;
- this.dbName = requireNonNull(dbName, "dbName is null");
+ this.dbName = requireNonNull(dbName, "dbName is
null").toLowerCase(Locale.ENGLISH);
this.properties = null;
}
public CreateDB(boolean ifNotExists, String dbName, List<Property>
properties) {
super(null);
this.ifNotExists = ifNotExists;
- this.dbName = requireNonNull(dbName, "dbName is null");
+ this.dbName = requireNonNull(dbName, "dbName is
null").toLowerCase(Locale.ENGLISH);
this.properties = ImmutableList.copyOf(requireNonNull(properties,
"properties is null"));
}
@@ -58,7 +59,7 @@ public class CreateDB extends Statement {
NodeLocation location, boolean ifNotExists, String dbName,
List<Property> properties) {
super(requireNonNull(location, "location is null"));
this.ifNotExists = ifNotExists;
- this.dbName = requireNonNull(dbName, "dbName is null");
+ this.dbName = requireNonNull(dbName, "dbName is
null").toLowerCase(Locale.ENGLISH);
this.properties = ImmutableList.copyOf(requireNonNull(properties,
"properties is null"));
}
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/QualifiedName.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/QualifiedName.java
index 6b687145b96..4a28dcae728 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/QualifiedName.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/ast/QualifiedName.java
@@ -101,7 +101,7 @@ public class QualifiedName {
}
}
- private static String mapIdentifier(Identifier identifier) {
+ public static String mapIdentifier(Identifier identifier) {
return identifier.getValue().toLowerCase(ENGLISH);
}
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
index 02ca1c4a6f0..ae9b8bf1d7a 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/sql/parser/AstBuilder.java
@@ -175,6 +175,7 @@ import static
org.apache.iotdb.db.queryengine.plan.parser.ASTVisitor.parseDateTi
import static
org.apache.iotdb.db.queryengine.plan.relational.sql.ast.GroupingSets.Type.CUBE;
import static
org.apache.iotdb.db.queryengine.plan.relational.sql.ast.GroupingSets.Type.EXPLICIT;
import static
org.apache.iotdb.db.queryengine.plan.relational.sql.ast.GroupingSets.Type.ROLLUP;
+import static
org.apache.iotdb.db.queryengine.plan.relational.sql.ast.QualifiedName.mapIdentifier;
public class AstBuilder extends RelationalSqlBaseVisitor<Node> {
@@ -207,7 +208,16 @@ public class AstBuilder extends
RelationalSqlBaseVisitor<Node> {
// ******************* statements **********************
@Override
public Node
visitUseDatabaseStatement(RelationalSqlParser.UseDatabaseStatementContext ctx) {
- return new Use(getLocation(ctx), (Identifier) visit(ctx.database));
+ return new Use(getLocation(ctx), lowerIdentifier((Identifier)
visit(ctx.database)));
+ }
+
+ private static Identifier lowerIdentifier(Identifier identifier) {
+ if (identifier.getLocation().isPresent()) {
+ return new Identifier(
+ identifier.getLocation().get(), mapIdentifier(identifier),
identifier.isDelimited());
+ } else {
+ return new Identifier(mapIdentifier(identifier),
identifier.isDelimited());
+ }
}
@Override
@@ -231,7 +241,8 @@ public class AstBuilder extends
RelationalSqlBaseVisitor<Node> {
@Override
public Node visitDropDbStatement(RelationalSqlParser.DropDbStatementContext
ctx) {
- return new DropDB(getLocation(ctx), (Identifier) visit(ctx.database),
ctx.EXISTS() != null);
+ return new DropDB(
+ getLocation(ctx), lowerIdentifier((Identifier) visit(ctx.database)),
ctx.EXISTS() != null);
}
@Override
@@ -255,7 +266,7 @@ public class AstBuilder extends
RelationalSqlBaseVisitor<Node> {
public Node
visitColumnDefinition(RelationalSqlParser.ColumnDefinitionContext ctx) {
return new ColumnDefinition(
getLocation(ctx),
- (Identifier) visit(ctx.identifier()),
+ lowerIdentifier((Identifier) visit(ctx.identifier())),
(DataType) visit(ctx.type()),
getColumnCategory(ctx.columnCategory),
ctx.charsetName() == null
@@ -274,7 +285,7 @@ public class AstBuilder extends
RelationalSqlBaseVisitor<Node> {
if (ctx.database == null) {
return new ShowTables(getLocation(ctx));
} else {
- return new ShowTables(getLocation(ctx), (Identifier)
visit(ctx.database));
+ return new ShowTables(getLocation(ctx), lowerIdentifier((Identifier)
visit(ctx.database)));
}
}
@@ -286,7 +297,7 @@ public class AstBuilder extends
RelationalSqlBaseVisitor<Node> {
@Override
public Node visitRenameTable(RelationalSqlParser.RenameTableContext ctx) {
return new RenameTable(
- getLocation(ctx), getQualifiedName(ctx.from), (Identifier)
visit(ctx.to));
+ getLocation(ctx), getQualifiedName(ctx.from),
lowerIdentifier((Identifier) visit(ctx.to)));
}
@Override
@@ -306,7 +317,9 @@ public class AstBuilder extends
RelationalSqlBaseVisitor<Node> {
@Override
public Node visitDropColumn(RelationalSqlParser.DropColumnContext ctx) {
return new DropColumn(
- getLocation(ctx), getQualifiedName(ctx.tableName), (Identifier)
visit(ctx.column));
+ getLocation(ctx),
+ getQualifiedName(ctx.tableName),
+ lowerIdentifier((Identifier) visit(ctx.column)));
}
@Override
@@ -327,14 +340,16 @@ public class AstBuilder extends
RelationalSqlBaseVisitor<Node> {
return new CreateIndex(
getLocation(ctx),
getQualifiedName(ctx.tableName),
- (Identifier) visit(ctx.indexName),
+ lowerIdentifier((Identifier) visit(ctx.indexName)),
visit(ctx.identifierList().identifier(), Identifier.class));
}
@Override
public Node
visitDropIndexStatement(RelationalSqlParser.DropIndexStatementContext ctx) {
return new DropIndex(
- getLocation(ctx), getQualifiedName(ctx.tableName), (Identifier)
visit(ctx.indexName));
+ getLocation(ctx),
+ getQualifiedName(ctx.tableName),
+ lowerIdentifier((Identifier) visit(ctx.indexName)));
}
@Override
@@ -1410,7 +1425,7 @@ public class AstBuilder extends
RelationalSqlBaseVisitor<Node> {
public Node visitSubstring(RelationalSqlParser.SubstringContext ctx) {
return new FunctionCall(
getLocation(ctx),
- QualifiedName.of("substr"),
+ QualifiedName.of("substring"),
visit(ctx.valueExpression(), Expression.class));
}
diff --git
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java
index adc8be23135..76078e61e33 100644
---
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java
+++
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/table/TsTable.java
@@ -50,7 +50,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
@ThreadSafe
public class TsTable {
- public static final String TIME_COLUMN_NAME = "Time";
+ public static final String TIME_COLUMN_NAME = "time";
private static final TimeColumnSchema TIME_COLUMN_SCHEMA =
new TimeColumnSchema(TIME_COLUMN_NAME, TSDataType.TIMESTAMP);