This is an automated email from the ASF dual-hosted git repository.
jackietien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new e0c6cf63821 Fix bug in inner join of table model (#14198)
e0c6cf63821 is described below
commit e0c6cf63821f73336d427da90163396c9d6ea12b
Author: Beyyes <[email protected]>
AuthorDate: Tue Nov 26 14:14:02 2024 +0800
Fix bug in inner join of table model (#14198)
---
.../db/it/IoTDBMultiIDsWithAttributesTableIT.java | 57 ++++++++++++++++++----
.../source/relational/TableInnerJoinOperator.java | 7 +--
2 files changed, 51 insertions(+), 13 deletions(-)
diff --git
a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBMultiIDsWithAttributesTableIT.java
b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBMultiIDsWithAttributesTableIT.java
index 110fc343b39..e0a7dad4dc5 100644
---
a/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBMultiIDsWithAttributesTableIT.java
+++
b/integration-test/src/test/java/org/apache/iotdb/relational/it/db/it/IoTDBMultiIDsWithAttributesTableIT.java
@@ -133,18 +133,34 @@ public class IoTDBMultiIDsWithAttributesTableIT {
+
"(6,1113,10000003,6,55),(7,1114,10000004,7,60),(8,1115,10000005,8,100),(9,1114,10000001,2,99),(10,1115,10000002,1,95)"
};
- // public static void main(String[] args) {
- // for (String sql : sql1) {
- // System.out.println(sql+";");
- // }
- // for (String sql : sql2) {
- // System.out.println(sql+";");
- // }
- // }
+ private static final String[] sql5 =
+ new String[] {
+ "create table tableA(device STRING ID, value INT32 MEASUREMENT)",
+ "create table tableB(device STRING ID, value INT32 MEASUREMENT)",
+ "insert into tableA(time,device,value) values('2020-01-01
00:00:01.000', 'd1', 1)",
+ "insert into tableA(time,device,value) values('2020-01-01
00:00:03.000', 'd1', 3)",
+ "flush",
+ "insert into tableA(time,device,value) values('2020-01-01
00:00:05.000', 'd2', 5)",
+ "insert into tableA(time,device,value) values('2020-01-01
00:00:07.000', 'd2', 7)",
+ "flush",
+ "insert into tableB(time,device,value) values('2020-01-01
00:00:02.000', 'd1', 20)",
+ "insert into tableB(time,device,value) values('2020-01-01
00:00:03.000', 'd1', 30)",
+ "flush",
+ "insert into tableB(time,device,value) values('2020-01-01
00:00:04.000', 'd2', 40)",
+ "insert into tableB(time,device,value) values('2020-01-01
00:00:05.000', 'd2', 50)"
+ };
String[] expectedHeader;
String[] retArray;
- String sql;
+ static String sql;
+
+ // public static void main(String[] args) {
+ // for (String[] sqlList : Arrays.asList(sql4, sql5)) {
+ // for (String sql : sqlList) {
+ // System.out.println(sql);
+ // }
+ // }
+ // }
@BeforeClass
public static void setUp() throws Exception {
@@ -166,7 +182,7 @@ public class IoTDBMultiIDsWithAttributesTableIT {
private static void insertData() {
try (Connection connection = EnvFactory.getEnv().getTableConnection();
Statement statement = connection.createStatement()) {
- for (String[] sqlList : Arrays.asList(sql1, sql2, sql3, sql4)) {
+ for (String[] sqlList : Arrays.asList(sql1, sql2, sql3, sql4, sql5)) {
for (String sql : sqlList) {
statement.execute(sql);
}
@@ -1665,6 +1681,7 @@ public class IoTDBMultiIDsWithAttributesTableIT {
"1970-01-01T00:00:00.002Z,2,Jack,2015-09-24,1002,10000002,语文,1112,90,",
"1970-01-01T00:00:00.003Z,3,Sam,2014-07-20,1003,10000003,英语,1113,85,",
"1970-01-01T00:00:00.004Z,4,Lily,2015-03-28,1004,10000004,体育,1114,89,",
+
"1970-01-01T00:00:00.005Z,5,Helen,2016-01-22,1005,10000005,历史,1115,98,",
};
sql =
"select s.time,"
@@ -1690,6 +1707,26 @@ public class IoTDBMultiIDsWithAttributesTableIT {
DATABASE_NAME);
}
+ @Test
+ public void innerJoinTest() {
+ expectedHeader = new String[] {"time", "device1", "value1", "device2",
"value2"};
+ sql =
+ "SELECT "
+ + " t1.time, "
+ + " t1.device as device1, "
+ + " t1.value as value1, "
+ + " t2.device as device2, "
+ + " t2.value as value2 "
+ + "FROM "
+ + " tableA t1 JOIN tableB t2 "
+ + "ON t1.time = t2.time";
+ retArray =
+ new String[] {
+ "2020-01-01T00:00:03.000Z,d1,3,d1,30,",
"2020-01-01T00:00:05.000Z,d2,5,d2,50,",
+ };
+ tableResultSetEqualTest(sql, expectedHeader, retArray, DATABASE_NAME);
+ }
+
public static String[] buildHeaders(int length) {
String[] expectedHeader = new String[length];
for (int i = 0; i < length; i++) {
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/TableInnerJoinOperator.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/TableInnerJoinOperator.java
index 73963c2359b..ac8d18962a2 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/TableInnerJoinOperator.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/source/relational/TableInnerJoinOperator.java
@@ -311,9 +311,10 @@ public class TableInnerJoinOperator extends
AbstractOperator {
}
private boolean rightBlockNotEmpty() {
- return !rightBlockList.isEmpty()
- && rightBlockListIdx < rightBlockList.size()
- && rightIndex <
rightBlockList.get(rightBlockListIdx).getPositionCount();
+ return (!rightBlockList.isEmpty()
+ && rightBlockListIdx < rightBlockList.size()
+ && rightIndex <
rightBlockList.get(rightBlockListIdx).getPositionCount())
+ || (hasCachedNextRightBlock && cachedNextRightBlock != null);
}
private void appendValueToResult(int tmpRightBlockListIdx, int
tmpRightIndex) {