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

Fix error in string/timestamp/date/blob data type + sort + limit usage in version 1.3.x #14323

Merged
merged 6 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.sql.Statement;
import java.util.Objects;

import static org.apache.iotdb.db.it.utils.TestUtils.resultSetEqualTest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
Expand Down Expand Up @@ -97,6 +98,12 @@ public class IoTDBOrderByIT {
"insert into root.sg.d2(timestamp,num,bigNum,floatNum,str,bool) values(51536000000,15,3147483648,235.213,\"watermelon\",TRUE)"
};

private static final String[] sql3 =
new String[] {
"create aligned timeseries root.test.dev (v_timestamp TIMESTAMP, v_string STRING, v_date DATE, v_blob BLOB encoding=PLAIN, v_int32 INT32);",
"insert into root.test.dev(timestamp, v_timestamp, v_string, v_date, v_blob, v_int32) aligned values(1, 2024-09-20T06:15:35.000+00:00, 'e1', '2012-12-12', X'108DCD62', 1);"
};

@BeforeClass
public static void setUp() throws Exception {
EnvFactory.getEnv().getConfig().getDataNodeCommonConfig().setSortBufferSize(1024 * 1024L);
Expand All @@ -112,12 +119,13 @@ public static void tearDown() throws Exception {
protected static void insertData() {
try (Connection connection = EnvFactory.getEnv().getConnection();
Statement statement = connection.createStatement()) {
for (String sql : sql) {
statement.execute(sql);
}
for (String sql : sql2) {
statement.execute(sql);

for (String[] sqlList : java.util.Arrays.asList(sql, sql2, sql3)) {
for (String sql : sqlList) {
statement.execute(sql);
}
}

} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -192,6 +200,23 @@ private void testNormalOrderBy(String sql, int[] ans) {
}
}

@Test
public void newDataTypeTest() {
String[] expectedHeader =
new String[] {"Time,Device,v_int32,v_blob,v_date,v_timestamp,v_string"};
String[] retArray =
new String[] {
"1,root.test.dev,1,0x108dcd62,2012-12-12,1726812935000,e1,",
};

for (String key : new String[] {"time", "v_int32", "v_date", "v_timestamp", "v_string"}) {
resultSetEqualTest(
String.format("SELECT * FROM root.test.dev ORDER BY %s LIMIT 1 ALIGN BY DEVICE", key),
expectedHeader,
retArray);
}
}

// 1. One-level order by test
@Test
public void orderByTest1() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,13 @@ private void initResultTsBlock() {
new boolean[positionCount]);
break;
case INT32:
case DATE:
columns[i] =
new IntColumn(
positionCount, Optional.of(new boolean[positionCount]), new int[positionCount]);
break;
case INT64:
case TIMESTAMP:
columns[i] =
new LongColumn(
positionCount, Optional.of(new boolean[positionCount]), new long[positionCount]);
Expand All @@ -303,6 +305,8 @@ private void initResultTsBlock() {
new double[positionCount]);
break;
case TEXT:
case STRING:
case BLOB:
columns[i] =
new BinaryColumn(
positionCount,
Expand Down Expand Up @@ -366,14 +370,18 @@ private long getMemoryUsageOfOneMergeSortKey() {
break;
case INT32:
case FLOAT:
case DATE:
memory += 4;
break;
case INT64:
case DOUBLE:
case VECTOR:
case TIMESTAMP:
memory += 8;
break;
case TEXT:
case STRING:
case BLOB:
memory += 16;
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ public static Comparator<SortKey> getComparator(TSDataType dataType, int index,
Comparator<SortKey> comparator;
switch (dataType) {
case INT32:
case DATE:
comparator =
Comparator.comparingInt(
(SortKey sortKey) -> sortKey.tsBlock.getColumn(index).getInt(sortKey.rowIndex));
break;
case INT64:
case TIMESTAMP:
comparator =
Comparator.comparingLong(
(SortKey sortKey) -> sortKey.tsBlock.getColumn(index).getLong(sortKey.rowIndex));
Expand All @@ -90,6 +92,8 @@ public static Comparator<SortKey> getComparator(TSDataType dataType, int index,
(SortKey sortKey) -> sortKey.tsBlock.getColumn(index).getDouble(sortKey.rowIndex));
break;
case TEXT:
case BLOB:
case STRING:
comparator =
Comparator.comparing(
(SortKey sortKey) -> sortKey.tsBlock.getColumn(index).getBinary(sortKey.rowIndex));
Expand Down
Loading