Skip to content

Commit b28786b

Browse files
authored
[OBJECT] Support OBJECT type in iotdb (#16925)
1 parent 5e34c3c commit b28786b

File tree

244 files changed

+5186
-197
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

244 files changed

+5186
-197
lines changed

example/session/src/main/java/org/apache/iotdb/TableModelSessionPoolExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public static void main(String[] args) {
113113
int rowIndex = tablet.getRowSize();
114114
tablet.addTimestamp(rowIndex, timestamp);
115115
tablet.addValue("region_id", rowIndex, "1");
116-
tablet.addValue("plant_id", rowIndex, "5");
116+
tablet.addValue("plant_id", rowIndex, null);
117117
tablet.addValue("device_id", rowIndex, "3");
118118
tablet.addValue("model", rowIndex, "A");
119119
tablet.addValue("temperature", rowIndex, 37.6F);

integration-test/src/main/java/org/apache/iotdb/it/env/cluster/config/MppCommonConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,12 @@ public CommonConfig setAuditableOperationResult(String auditableOperationResult)
651651
return this;
652652
}
653653

654+
@Override
655+
public CommonConfig setRestrictObjectLimit(boolean restrictObjectLimit) {
656+
setProperty("restrict_object_limit", String.valueOf(restrictObjectLimit));
657+
return this;
658+
}
659+
654660
// For part of the log directory
655661
public String getClusterConfigStr() {
656662
return fromConsensusFullNameToAbbr(properties.getProperty(CONFIG_NODE_CONSENSUS_PROTOCOL_CLASS))

integration-test/src/main/java/org/apache/iotdb/it/env/cluster/config/MppSharedCommonConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,4 +684,11 @@ public CommonConfig setAuditableOperationResult(String auditableOperationResult)
684684
cnConfig.setAuditableOperationResult(auditableOperationResult);
685685
return this;
686686
}
687+
688+
@Override
689+
public CommonConfig setRestrictObjectLimit(boolean restrictObjectLimit) {
690+
cnConfig.setRestrictObjectLimit(restrictObjectLimit);
691+
dnConfig.setRestrictObjectLimit(restrictObjectLimit);
692+
return this;
693+
}
687694
}

integration-test/src/main/java/org/apache/iotdb/it/env/cluster/node/DataNodeWrapper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ public String getSystemDir() {
169169
return getDataNodeDir() + File.separator + "system";
170170
}
171171

172+
public String getDataNodeObjectDir() {
173+
return getDataNodeDir() + File.separator + "data" + File.separator + "object";
174+
}
175+
172176
@Override
173177
protected MppJVMConfig initVMConfig() {
174178
return MppJVMConfig.builder()

integration-test/src/main/java/org/apache/iotdb/it/env/remote/config/RemoteCommonConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,4 +477,9 @@ public CommonConfig setAuditableOperationLevel(String auditableOperationLevel) {
477477
public CommonConfig setAuditableOperationResult(String auditableOperationResult) {
478478
return this;
479479
}
480+
481+
@Override
482+
public CommonConfig setRestrictObjectLimit(boolean restrictObjectLimit) {
483+
return this;
484+
}
480485
}

integration-test/src/main/java/org/apache/iotdb/itbase/env/CommonConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,4 +211,6 @@ default CommonConfig setDefaultDatabaseLevel(int defaultDatabaseLevel) {
211211
CommonConfig setAuditableOperationLevel(String auditableOperationLevel);
212212

213213
CommonConfig setAuditableOperationResult(String auditableOperationResult);
214+
215+
CommonConfig setRestrictObjectLimit(boolean restrictObjectLimit);
214216
}

integration-test/src/main/java/org/apache/iotdb/itbase/runtime/ClusterTestResultSet.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,12 @@ public Ref getRef(int columnIndex) {
781781
}
782782

783783
@Override
784-
public Blob getBlob(int columnIndex) {
785-
throw new UnsupportedOperationException();
784+
public Blob getBlob(int columnIndex) throws SQLException {
785+
RequestDelegate<Blob> delegate = createLocalRequestDelegate();
786+
for (ResultSet rs : resultSets) {
787+
delegate.addRequest(() -> rs.getBlob(columnIndex));
788+
}
789+
return delegate.requestAllAndCompare();
786790
}
787791

788792
@Override
@@ -806,8 +810,12 @@ public Ref getRef(String columnLabel) {
806810
}
807811

808812
@Override
809-
public Blob getBlob(String columnLabel) {
810-
throw new UnsupportedOperationException();
813+
public Blob getBlob(String columnLabel) throws SQLException {
814+
RequestDelegate<Blob> delegate = createLocalRequestDelegate();
815+
for (ResultSet rs : resultSets) {
816+
delegate.addRequest(() -> rs.getBlob(columnLabel));
817+
}
818+
return delegate.requestAllAndCompare();
811819
}
812820

813821
@Override
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
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.object;
21+
22+
import org.apache.iotdb.isession.ITableSession;
23+
import org.apache.iotdb.isession.SessionConfig;
24+
import org.apache.iotdb.isession.SessionDataSet;
25+
import org.apache.iotdb.it.env.EnvFactory;
26+
import org.apache.iotdb.it.framework.IoTDBTestRunner;
27+
import org.apache.iotdb.itbase.category.TableClusterIT;
28+
import org.apache.iotdb.itbase.category.TableLocalStandaloneIT;
29+
import org.apache.iotdb.itbase.env.BaseEnv;
30+
import org.apache.iotdb.rpc.IoTDBConnectionException;
31+
import org.apache.iotdb.rpc.StatementExecutionException;
32+
33+
import org.apache.tsfile.enums.TSDataType;
34+
import org.apache.tsfile.read.common.Field;
35+
import org.apache.tsfile.read.common.RowRecord;
36+
import org.junit.AfterClass;
37+
import org.junit.BeforeClass;
38+
import org.junit.Test;
39+
import org.junit.experimental.categories.Category;
40+
import org.junit.runner.RunWith;
41+
42+
import java.sql.Connection;
43+
import java.sql.ResultSet;
44+
import java.sql.SQLException;
45+
import java.sql.Statement;
46+
47+
import static org.apache.iotdb.db.it.utils.TestUtils.prepareTableData;
48+
import static org.apache.iotdb.jdbc.IoTDBJDBCResultSet.OBJECT_ERR_MSG;
49+
import static org.junit.Assert.assertEquals;
50+
import static org.junit.Assert.assertTrue;
51+
import static org.junit.Assert.fail;
52+
53+
@RunWith(IoTDBTestRunner.class)
54+
@Category({TableLocalStandaloneIT.class, TableClusterIT.class})
55+
public class IoTDBObjectQueryIT {
56+
57+
private static final String DATABASE_NAME = "test_db";
58+
59+
private static final String TIME_ZONE = "+00:00";
60+
61+
private static final String[] createSqls =
62+
new String[] {
63+
"CREATE DATABASE " + DATABASE_NAME,
64+
"USE " + DATABASE_NAME,
65+
"CREATE TABLE t1(device_id STRING TAG, o1 OBJECT, b1 BLOB, s1 STRING)",
66+
"INSERT INTO t1(time, device_id, b1, o1, s1) VALUES(1, 'd1', X'cafebabe01', to_object(true, 0, X'cafebabe01'), 'cafebabe01')",
67+
"INSERT INTO t1(time, device_id, b1, o1, s1) VALUES(2, 'd1', X'cafebabe0202', to_object(true, 0, X'cafebabe02'), 'cafebabe02')",
68+
"INSERT INTO t1(time, device_id, b1, o1, s1) VALUES(3, 'd1', X'cafebabe0303', to_object(true, 0, X'cafebabe03'), 'cafebabe03')",
69+
"INSERT INTO t1(time, device_id, b1, o1, s1) VALUES(4, 'd1', X'cafebabe04', to_object(true, 0, X'cafebabe04'), 'cafebabe04')",
70+
"INSERT INTO t1(time, device_id, b1, o1, s1) VALUES(1, 'd2', X'cafebade01', to_object(true, 0, X'cafebade01'), 'cafebade01')",
71+
"INSERT INTO t1(time, device_id, b1, o1, s1) VALUES(2, 'd2', X'cafebade0202', to_object(true, 0, X'cafebade02'), 'cafebade02')",
72+
"INSERT INTO t1(time, device_id, b1, o1, s1) VALUES(3, 'd2', X'cafebade0302', to_object(true, 0, X'cafebade03'), 'cafebade03')",
73+
"INSERT INTO t1(time, device_id, b1, o1, s1) VALUES(4, 'd2', X'cafebade04', to_object(true, 0, X'cafebade04'), 'cafebade04')",
74+
"FLUSH",
75+
};
76+
77+
@BeforeClass
78+
public static void classSetUp() {
79+
EnvFactory.getEnv().initClusterEnvironment();
80+
prepareTableData(createSqls);
81+
}
82+
83+
@AfterClass
84+
public static void classTearDown() {
85+
EnvFactory.getEnv().cleanClusterEnvironment();
86+
}
87+
88+
@Test
89+
public void jdbcTest() {
90+
try (Connection connection =
91+
EnvFactory.getEnv()
92+
.getConnection(
93+
SessionConfig.DEFAULT_USER,
94+
SessionConfig.DEFAULT_PASSWORD,
95+
BaseEnv.TABLE_SQL_DIALECT)) {
96+
connection.setClientInfo("time_zone", TIME_ZONE);
97+
try (Statement statement = connection.createStatement()) {
98+
statement.execute("use " + DATABASE_NAME);
99+
try (ResultSet resultSet =
100+
statement.executeQuery(
101+
"SELECT time, b1, o1, s1 FROM t1 WHERE device_id = 'd1' ORDER BY time")) {
102+
int cnt = 0;
103+
while (resultSet.next()) {
104+
cnt++;
105+
try {
106+
resultSet.getBlob(3);
107+
fail();
108+
} catch (SQLException e) {
109+
assertEquals(OBJECT_ERR_MSG, e.getMessage());
110+
}
111+
112+
try {
113+
resultSet.getBytes("o1");
114+
fail();
115+
} catch (SQLException e) {
116+
assertEquals(OBJECT_ERR_MSG, e.getMessage());
117+
}
118+
119+
String s = resultSet.getString(3);
120+
assertEquals("(Object) 5 B", s);
121+
}
122+
assertEquals(4, cnt);
123+
}
124+
125+
try (ResultSet resultSet =
126+
statement.executeQuery(
127+
"SELECT time, b1, READ_OBJECT(o1), s1 FROM t1 WHERE device_id = 'd2' AND READ_OBJECT(o1)=b1 ORDER BY time")) {
128+
int cnt = 0;
129+
String[] ans = {"0xcafebade01", "0xcafebade04"};
130+
while (resultSet.next()) {
131+
String s = resultSet.getString(3);
132+
assertEquals(ans[cnt], s);
133+
cnt++;
134+
}
135+
assertEquals(2, cnt);
136+
}
137+
}
138+
} catch (SQLException e) {
139+
e.printStackTrace();
140+
fail(e.getMessage());
141+
}
142+
}
143+
144+
@Test
145+
public void sessionTest() {
146+
try (ITableSession session = EnvFactory.getEnv().getTableSessionConnection()) {
147+
session.executeNonQueryStatement("USE " + DATABASE_NAME);
148+
149+
// SessionDataSet
150+
try (SessionDataSet dataSet =
151+
session.executeQueryStatement(
152+
"SELECT time, b1, o1, s1 FROM t1 WHERE device_id = 'd1' ORDER BY time")) {
153+
int cnt = 0;
154+
while (dataSet.hasNext()) {
155+
cnt++;
156+
RowRecord rowRecord = dataSet.next();
157+
Field field = rowRecord.getField(2);
158+
String s = field.getStringValue();
159+
assertEquals("(Object) 5 B", s);
160+
Object blob = field.getObjectValue(TSDataType.OBJECT);
161+
assertTrue(blob instanceof String);
162+
assertEquals("(Object) 5 B", blob);
163+
164+
try {
165+
field.getBinaryV();
166+
fail();
167+
} catch (UnsupportedOperationException e) {
168+
assertEquals("OBJECT Type only support getStringValue", e.getMessage());
169+
}
170+
}
171+
assertEquals(4, cnt);
172+
}
173+
174+
// SessionDataSet.DataIterator
175+
try (SessionDataSet dataSet =
176+
session.executeQueryStatement(
177+
"SELECT time, b1, o1, s1 FROM t1 WHERE device_id = 'd2' ORDER BY time")) {
178+
SessionDataSet.DataIterator iterator = dataSet.iterator();
179+
int cnt = 0;
180+
while (iterator.next()) {
181+
cnt++;
182+
Object o = iterator.getObject(3);
183+
assertTrue(o instanceof String);
184+
assertEquals("(Object) 5 B", o);
185+
String s = iterator.getString("o1");
186+
assertEquals("(Object) 5 B", s);
187+
try {
188+
iterator.getBlob(3);
189+
fail();
190+
} catch (StatementExecutionException e) {
191+
assertEquals("OBJECT Type only support getString", e.getMessage());
192+
}
193+
}
194+
assertEquals(4, cnt);
195+
}
196+
} catch (IoTDBConnectionException | StatementExecutionException e) {
197+
fail(e.getMessage());
198+
}
199+
}
200+
}

0 commit comments

Comments
 (0)