Skip to content

Commit 67f63e0

Browse files
authored
Implement Extract expression in TableModel
1 parent c17ca38 commit 67f63e0

File tree

35 files changed

+1135
-34
lines changed

35 files changed

+1135
-34
lines changed

integration-test/src/test/java/org/apache/iotdb/db/it/utils/TestUtils.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,24 @@ public static void tableResultSetEqualTest(
229229
expectedRetArray,
230230
SessionConfig.DEFAULT_USER,
231231
SessionConfig.DEFAULT_PASSWORD,
232-
database);
232+
database,
233+
"+00:00");
234+
}
235+
236+
public static void tableResultSetEqualTest(
237+
String sql,
238+
String timeZone,
239+
String[] expectedHeader,
240+
String[] expectedRetArray,
241+
String database) {
242+
tableResultSetEqualTest(
243+
sql,
244+
expectedHeader,
245+
expectedRetArray,
246+
SessionConfig.DEFAULT_USER,
247+
SessionConfig.DEFAULT_PASSWORD,
248+
database,
249+
timeZone);
233250
}
234251

235252
public static void tableResultSetEqualTest(
@@ -239,9 +256,21 @@ public static void tableResultSetEqualTest(
239256
String userName,
240257
String password,
241258
String database) {
259+
tableResultSetEqualTest(
260+
sql, expectedHeader, expectedRetArray, userName, password, database, "+00:00");
261+
}
262+
263+
public static void tableResultSetEqualTest(
264+
String sql,
265+
String[] expectedHeader,
266+
String[] expectedRetArray,
267+
String userName,
268+
String password,
269+
String database,
270+
String timeZone) {
242271
try (Connection connection =
243272
EnvFactory.getEnv().getConnection(userName, password, BaseEnv.TABLE_SQL_DIALECT)) {
244-
connection.setClientInfo("time_zone", "+00:00");
273+
connection.setClientInfo("time_zone", timeZone);
245274
try (Statement statement = connection.createStatement()) {
246275
statement.execute("use " + database);
247276
try (ResultSet resultSet = statement.executeQuery(sql)) {
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.relational.it.query.recent.extract;
21+
22+
import org.apache.iotdb.it.env.EnvFactory;
23+
import org.apache.iotdb.itbase.category.TableClusterIT;
24+
import org.apache.iotdb.itbase.category.TableLocalStandaloneIT;
25+
26+
import org.junit.BeforeClass;
27+
import org.junit.Test;
28+
import org.junit.experimental.categories.Category;
29+
30+
import static org.apache.iotdb.db.it.utils.TestUtils.prepareTableData;
31+
import static org.apache.iotdb.db.it.utils.TestUtils.tableResultSetEqualTest;
32+
33+
@Category({TableLocalStandaloneIT.class, TableClusterIT.class})
34+
public class IoTDBExtractTable2IT extends IoTDBExtractTableIT {
35+
public IoTDBExtractTable2IT() {
36+
this.decimal = "123456";
37+
}
38+
39+
@BeforeClass
40+
public static void setUp() throws Exception {
41+
EnvFactory.getEnv().getConfig().getCommonConfig().setTimestampPrecision("us");
42+
EnvFactory.getEnv().initClusterEnvironment();
43+
prepareTableData(createSqls);
44+
}
45+
46+
@Test
47+
public void extractUsNsTest() {
48+
String[] expectedHeader = new String[] {"time", "_col1", "_col2"};
49+
String[] retArray =
50+
new String[] {
51+
getTimeStrUTC("2025-07-08T01:18:51") + ",456,0,",
52+
};
53+
tableResultSetEqualTest(
54+
"SELECT time, extract(us from time),extract(ns from time)"
55+
+ " FROM table1 order by time limit 1",
56+
expectedHeader,
57+
retArray,
58+
DATABASE_NAME);
59+
60+
retArray =
61+
new String[] {
62+
getTimeStrUTC8("2025-07-08T09:18:51") + ",456,0,",
63+
};
64+
tableResultSetEqualTest(
65+
"SELECT time, extract(us from time),extract(ns from time)"
66+
+ " FROM table1 order by time limit 1",
67+
"+08:00",
68+
expectedHeader,
69+
retArray,
70+
DATABASE_NAME);
71+
}
72+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.iotdb.relational.it.query.recent.extract;
21+
22+
import org.apache.iotdb.it.env.EnvFactory;
23+
import org.apache.iotdb.itbase.category.TableClusterIT;
24+
import org.apache.iotdb.itbase.category.TableLocalStandaloneIT;
25+
26+
import org.junit.BeforeClass;
27+
import org.junit.Test;
28+
import org.junit.experimental.categories.Category;
29+
30+
import static org.apache.iotdb.db.it.utils.TestUtils.prepareTableData;
31+
import static org.apache.iotdb.db.it.utils.TestUtils.tableResultSetEqualTest;
32+
33+
@Category({TableLocalStandaloneIT.class, TableClusterIT.class})
34+
public class IoTDBExtractTable3IT extends IoTDBExtractTableIT {
35+
public IoTDBExtractTable3IT() {
36+
this.decimal = "123456789";
37+
}
38+
39+
@BeforeClass
40+
public static void setUp() throws Exception {
41+
EnvFactory.getEnv().getConfig().getCommonConfig().setTimestampPrecision("ns");
42+
EnvFactory.getEnv().initClusterEnvironment();
43+
prepareTableData(createSqls);
44+
}
45+
46+
@Test
47+
public void extractUsNsTest() {
48+
String[] expectedHeader = new String[] {"time", "_col1", "_col2"};
49+
String[] retArray =
50+
new String[] {
51+
getTimeStrUTC("2025-07-08T01:18:51") + ",456,789,",
52+
};
53+
tableResultSetEqualTest(
54+
"SELECT time, extract(us from time),extract(ns from time)"
55+
+ " FROM table1 order by time limit 1",
56+
expectedHeader,
57+
retArray,
58+
DATABASE_NAME);
59+
60+
retArray =
61+
new String[] {
62+
getTimeStrUTC8("2025-07-08T09:18:51") + ",456,789,",
63+
};
64+
tableResultSetEqualTest(
65+
"SELECT time, extract(us from time),extract(ns from time)"
66+
+ " FROM table1 order by time limit 1",
67+
"+08:00",
68+
expectedHeader,
69+
retArray,
70+
DATABASE_NAME);
71+
}
72+
}

0 commit comments

Comments
 (0)