Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support new data type: DATE, TIMESTAMP, BLOB and STRING #12576

Merged
merged 36 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8fd1bc9
save
Cpaulyz Apr 19, 2024
ccce3cb
save
Cpaulyz Apr 23, 2024
1e27376
save
Cpaulyz May 6, 2024
7d23883
save
Cpaulyz May 10, 2024
8cdcb15
merge master
Cpaulyz May 13, 2024
2523ba8
save
Cpaulyz May 16, 2024
42cdf58
adapt
Cpaulyz May 17, 2024
36ecf11
solve conflict
Cpaulyz May 17, 2024
18154d9
Resolve compilie error
Cpaulyz May 17, 2024
036c084
add license
Cpaulyz May 17, 2024
1d61af4
add jdbc it
Cpaulyz May 17, 2024
5707037
fix review1
Cpaulyz May 21, 2024
228bba7
fix text
Cpaulyz May 21, 2024
fd89986
fix jdbc zone
Cpaulyz May 21, 2024
281d951
fix ci
Cpaulyz May 21, 2024
0f6322c
fix ci
Cpaulyz May 21, 2024
6cab0d0
fix ut
Cpaulyz May 22, 2024
0bd8a64
fix it
Cpaulyz May 23, 2024
e5a1b0a
resolve conflict
Cpaulyz May 23, 2024
e810e0d
done
Cpaulyz May 23, 2024
7af89d1
fix it
Cpaulyz May 23, 2024
0e3ba33
add infer type and related it
Cpaulyz May 24, 2024
f5308fc
fix ut
Cpaulyz May 24, 2024
fbb5ee3
fix it
Cpaulyz May 24, 2024
4f280a5
fix it
Cpaulyz May 24, 2024
1a8b564
fix it
Cpaulyz May 25, 2024
0f395b5
done
Cpaulyz May 26, 2024
247505d
Merge branch 'master' into new_data_type
Cpaulyz May 27, 2024
87f0c19
add tsfile version
Cpaulyz May 27, 2024
5acecc4
try fix pipe IT
Cpaulyz May 27, 2024
c4540f9
New data type query
lancelly May 27, 2024
5ba07d8
Fix New data type query IT
lancelly May 27, 2024
06c8c09
resolve conflict
Cpaulyz May 27, 2024
312e749
Add support for node-commons, some udfs and export、import-csv
JackieTien97 May 28, 2024
c32c6fd
Empty-Commit
JackieTien97 May 28, 2024
1f25051
change pom version
JackieTien97 May 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions example/jdbc/src/main/java/org/apache/iotdb/JDBCExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.time.LocalDate;

public class JDBCExample {
private static final Logger LOGGER = LoggerFactory.getLogger(JDBCExample.class);
Expand All @@ -51,9 +52,17 @@ public static void main(String[] args) throws ClassNotFoundException, SQLExcepti
"CREATE TIMESERIES root.sg1.d1.s2 WITH DATATYPE=INT64, ENCODING=RLE, COMPRESSOR=SNAPPY");
statement.execute(
"CREATE TIMESERIES root.sg1.d1.s3 WITH DATATYPE=INT64, ENCODING=RLE, COMPRESSOR=SNAPPY");
statement.execute(
"CREATE TIMESERIES root.sg1.d1.s4 WITH DATATYPE=DATE, ENCODING=PLAIN, COMPRESSOR=SNAPPY");
statement.execute(
"CREATE TIMESERIES root.sg1.d1.s5 WITH DATATYPE=TIMESTAMP, ENCODING=PLAIN, COMPRESSOR=SNAPPY");
statement.execute(
"CREATE TIMESERIES root.sg1.d1.s6 WITH DATATYPE=BLOB, ENCODING=PLAIN, COMPRESSOR=SNAPPY");
statement.execute(
"CREATE TIMESERIES root.sg1.d1.s7 WITH DATATYPE=STRING, ENCODING=PLAIN, COMPRESSOR=SNAPPY");

for (int i = 0; i <= 100; i++) {
statement.addBatch(prepareInsertStatment(i));
statement.addBatch(prepareInsertStatement(i));
}
statement.executeBatch();
statement.clearBatch();
Expand Down Expand Up @@ -96,15 +105,9 @@ private static void outputResult(ResultSet resultSet) throws SQLException {
}
}

private static String prepareInsertStatment(int time) {
return "insert into root.sg1.d1(timestamp, s1, s2, s3) values("
+ time
+ ","
+ 1
+ ","
+ 1
+ ","
+ 1
+ ")";
private static String prepareInsertStatement(int time) {
return String.format(
"insert into root.sg1.d1(timestamp, s1, s2, s3, s4, s5, s6, s7) values(%d, %d, %d, %d, \"%s\", %d, %s, \"%s\")",
time, 1, 1, 1, LocalDate.of(2024, 5, time % 31 + 1), time, "X'cafebabe'", time);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public Void call() {
tablet.addValue(schemaList.get(j).getMeasurementId(), row, dataIter.getInt(j + 2));
break;
case INT64:
case TIMESTAMP:
tablet.addValue(schemaList.get(j).getMeasurementId(), row, dataIter.getLong(j + 2));
break;
case FLOAT:
Expand All @@ -166,9 +167,15 @@ public Void call() {
schemaList.get(j).getMeasurementId(), row, dataIter.getDouble(j + 2));
break;
case TEXT:
case STRING:
tablet.addValue(
schemaList.get(j).getMeasurementId(), row, dataIter.getString(j + 2));
break;
case DATE:
case BLOB:
tablet.addValue(
schemaList.get(j).getMeasurementId(), row, dataIter.getObject(j + 2));
break;
default:
LOGGER.info("Migration of this type of data is not supported");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ public class ClusterConstant {
public static final int NODE_START_TIMEOUT = 100;
public static final int PROBE_TIMEOUT_MS = 2000;
public static final int NODE_NETWORK_TIMEOUT_MS = 0;
public static final String ZERO_TIME_ZONE = "GMT+0";

public static final String DELIMITER = ",";
public static final String TAB = " ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,9 @@ protected NodeConnection getWriteConnectionWithSpecifiedDataNode(
String endpoint = dataNode.getIp() + ":" + dataNode.getPort();
Connection writeConnection =
DriverManager.getConnection(
Config.IOTDB_URL_PREFIX + endpoint + getParam(version, NODE_NETWORK_TIMEOUT_MS),
Config.IOTDB_URL_PREFIX
+ endpoint
+ getParam(version, NODE_NETWORK_TIMEOUT_MS, ZERO_TIME_ZONE),
System.getProperty("User", username),
System.getProperty("Password", password));
return new NodeConnection(
Expand Down Expand Up @@ -521,7 +523,9 @@ protected List<NodeConnection> getReadConnections(
() -> {
Connection readConnection =
DriverManager.getConnection(
Config.IOTDB_URL_PREFIX + endpoint + getParam(version, NODE_NETWORK_TIMEOUT_MS),
Config.IOTDB_URL_PREFIX
+ endpoint
+ getParam(version, NODE_NETWORK_TIMEOUT_MS, ZERO_TIME_ZONE),
System.getProperty("User", username),
System.getProperty("Password", password));
return new NodeConnection(
Expand Down Expand Up @@ -559,7 +563,7 @@ protected void testJDBCConnection() {
DriverManager.getConnection(
Config.IOTDB_URL_PREFIX
+ dataNodeEndpoint
+ getParam(null, NODE_NETWORK_TIMEOUT_MS),
+ getParam(null, NODE_NETWORK_TIMEOUT_MS, ZERO_TIME_ZONE),
System.getProperty("User", "root"),
System.getProperty("Password", "root"))) {
logger.info("Successfully connecting to DataNode: {}.", dataNodeEndpoint);
Expand All @@ -584,12 +588,15 @@ protected void testJDBCConnection() {
}
}

private String getParam(Constant.Version version, int timeout) {
private String getParam(Constant.Version version, int timeout, String timeZone) {
StringBuilder sb = new StringBuilder("?");
sb.append(Config.NETWORK_TIMEOUT).append("=").append(timeout);
if (version != null) {
sb.append("&").append(VERSION).append("=").append(version);
}
if (timeZone != null) {
sb.append("&").append(Config.TIME_ZONE).append("=").append(timeZone);
}
return sb.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ private static void createTimeSeries() {
statement.execute("CREATE TIMESERIES root.vehicle.d1.s1 with datatype=INT32,encoding=PLAIN");
statement.execute("CREATE TIMESERIES root.vehicle.d1.s2 with datatype=INT32,encoding=PLAIN");
statement.execute("CREATE TIMESERIES root.vehicle.d1.s3 with datatype=TEXT,encoding=PLAIN");
statement.execute("CREATE TIMESERIES root.vehicle.d1.s4 with datatype=STRING,encoding=PLAIN");
statement.execute("CREATE TIMESERIES root.vehicle.d1.s5 with datatype=DATE,encoding=PLAIN");
statement.execute(
"CREATE TIMESERIES root.vehicle.d1.s6 with datatype=TIMESTAMP,encoding=PLAIN");
statement.execute("CREATE TIMESERIES root.vehicle.d2.s1 with datatype=FLOAT,encoding=PLAIN");
statement.execute("CREATE TIMESERIES root.vehicle.d2.s2 with datatype=DOUBLE,encoding=PLAIN");
statement.execute(
Expand All @@ -92,11 +96,15 @@ private static void generateData() {
for (int i = 1; i <= ITERATION_TIMES; ++i) {
statement.execute(
String.format(
"insert into root.vehicle.d1(timestamp,s1,s2,s3) values(%d,%d,%d,%s)", i, i, i, i));
"insert into root.vehicle.d1(timestamp,s1,s2,s3,s4,s6) values(%d,%d,%d,%s,%s,%d)",
i, i, i, i, i, i));
statement.execute(
(String.format(
"insert into root.vehicle.d2(timestamp,s1,s2) values(%d,%d,%d)", i, i, i)));
}
statement.execute("insert into root.vehicle.d1(timestamp,s5) values(1,'2024-01-01')");
statement.execute("insert into root.vehicle.d1(timestamp,s5) values(2,'2024-01-02')");
statement.execute("insert into root.vehicle.d1(timestamp,s5) values(3,'2024-01-03')");
} catch (SQLException throwable) {
fail(throwable.getMessage());
}
Expand Down Expand Up @@ -624,6 +632,36 @@ public void testRegularLikeInExpressions() {
}
Assert.assertFalse(rs.next());
}

String query2 =
"SELECT s1 FROM root.vehicle.d1 WHERE s4 LIKE '_' && s4 REGEXP '[0-9]' && s4 IN ('4', '2', '3')";
try (ResultSet rs = statement.executeQuery(query2)) {
for (int i = 2; i <= 4; i++) {
Assert.assertTrue(rs.next());
Assert.assertEquals(i, rs.getLong(1));
}
Assert.assertFalse(rs.next());
}

String query3 =
"SELECT s1 FROM root.vehicle.d1 WHERE s5 IN ('2024-01-01', '2024-01-02', '2024-01-03')";
try (ResultSet rs = statement.executeQuery(query3)) {
for (int i = 1; i <= 3; i++) {
Assert.assertTrue(rs.next());
Assert.assertEquals(i, rs.getLong(1));
}
Assert.assertFalse(rs.next());
}

String query4 = "SELECT s1 FROM root.vehicle.d1 WHERE s6 IN (1, 2, 3)";
try (ResultSet rs = statement.executeQuery(query4)) {
for (int i = 1; i <= 3; i++) {
Assert.assertTrue(rs.next());
Assert.assertEquals(i, rs.getLong(1));
}
Assert.assertFalse(rs.next());
}

} catch (SQLException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.iotdb.itbase.category.LocalStandaloneIT;
import org.apache.iotdb.rpc.TSStatusCode;

import org.apache.tsfile.enums.TSDataType;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand All @@ -38,12 +39,17 @@
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.sql.Types;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
Expand Down Expand Up @@ -1125,4 +1131,62 @@ public void testFromFuzzyMatching() {
fail();
}
}

@Test
public void testNewDataType() {
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {

statement.execute("CREATE DATABASE root.sg1");
statement.execute(
"CREATE TIMESERIES root.sg1.d1.s4 WITH DATATYPE=DATE, ENCODING=PLAIN, COMPRESSOR=SNAPPY");
statement.execute(
"CREATE TIMESERIES root.sg1.d1.s5 WITH DATATYPE=TIMESTAMP, ENCODING=PLAIN, COMPRESSOR=SNAPPY");
statement.execute(
"CREATE TIMESERIES root.sg1.d1.s6 WITH DATATYPE=BLOB, ENCODING=PLAIN, COMPRESSOR=SNAPPY");
statement.execute(
"CREATE TIMESERIES root.sg1.d1.s7 WITH DATATYPE=STRING, ENCODING=PLAIN, COMPRESSOR=SNAPPY");
for (int i = 1; i <= 10; i++) {
statement.execute(
String.format(
"insert into root.sg1.d1(timestamp, s4, s5, s6, s7) values(%d, \"%s\", %d, %s, \"%s\")",
i, LocalDate.of(2024, 5, i % 31 + 1), i, "X'cafebabe'", i));
}

try (ResultSet resultSet = statement.executeQuery("select * from root.**")) {
final ResultSetMetaData metaData = resultSet.getMetaData();
final int columnCount = metaData.getColumnCount();
assertEquals(5, columnCount);
HashMap<Integer, TSDataType> columnType = new HashMap<>();
for (int i = 1; i < columnCount; i++) {
if (metaData.getColumnLabel(i).endsWith("s4")) {
columnType.put(i, TSDataType.DATE);
} else if (metaData.getColumnLabel(i).endsWith("s5")) {
columnType.put(i, TSDataType.TIMESTAMP);
} else if (metaData.getColumnLabel(i).endsWith("s6")) {
columnType.put(i, TSDataType.BLOB);
} else if (metaData.getColumnLabel(i).endsWith("s7")) {
columnType.put(i, TSDataType.TEXT);
}
}
byte[] byteArray = new byte[] {(byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE};
while (resultSet.next()) {
long time = resultSet.getLong(1);
Date date = resultSet.getDate(2);
Timestamp timestamp = resultSet.getTimestamp(3);
byte[] blob = resultSet.getBytes(4);
String text = resultSet.getString(5);
assertEquals(2024 - 1900, date.getYear());
assertEquals(5 - 1, date.getMonth());
assertEquals(time % 31 + 1, date.getDate());
assertEquals(time, timestamp.getTime());
assertArrayEquals(byteArray, blob);
assertEquals(String.valueOf(time), text);
}
}

} catch (SQLException e) {
fail();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public void testStringLiteralIllegalCase() {
String errorMsg =
TSStatusCode.SQL_PARSE_ERROR.getStatusCode()
+ ": Error occurred while parsing SQL to physical plan: "
+ "line 1:45 mismatched input 'string' expecting {FALSE, NAN, NOW, NULL, TRUE, '-', '+', '/', '.', STRING_LITERAL, DATETIME_LITERAL, INTEGER_LITERAL, EXPONENT_NUM_PART}";
+ "line 1:45 mismatched input 'string' expecting {FALSE, NAN, NOW, NULL, TRUE, '-', '+', '/', '.', STRING_LITERAL, BINARY_LITERAL, DATETIME_LITERAL, INTEGER_LITERAL, EXPONENT_NUM_PART}";
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
statement.execute("CREATE TIMESERIES root.sg1.d1.s1 TEXT");
Expand All @@ -198,7 +198,7 @@ public void testStringLiteralIllegalCase() {
String errorMsg1 =
TSStatusCode.SQL_PARSE_ERROR.getStatusCode()
+ ": Error occurred while parsing SQL to physical plan: "
+ "line 1:45 mismatched input '`string`' expecting {FALSE, NAN, NOW, NULL, TRUE, '-', '+', '/', '.', STRING_LITERAL, DATETIME_LITERAL, INTEGER_LITERAL, EXPONENT_NUM_PART}";
+ "line 1:45 mismatched input '`string`' expecting {FALSE, NAN, NOW, NULL, TRUE, '-', '+', '/', '.', STRING_LITERAL, BINARY_LITERAL, DATETIME_LITERAL, INTEGER_LITERAL, EXPONENT_NUM_PART}";
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
// wrap STRING_LITERAL with ``
Expand Down
Loading
Loading