Skip to content

Commit b2cdbe0

Browse files
authored
Fix display of Blob type in last query
1 parent 1f24444 commit b2cdbe0

9 files changed

Lines changed: 66 additions & 19 deletions

File tree

integration-test/src/test/java/org/apache/iotdb/db/it/last/IoTDBLastQueryLastCacheIT.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ public class IoTDBLastQueryLastCacheIT {
7777
"insert into root.ln_1.tb_6141(time,`switch_BOOLEAN`) aligned values(1675995566000,false);",
7878
"create aligned timeseries root.sg(风机退出_BOOLEAN BOOLEAN encoding=RLE,`NH4-N_DOUBLE` DOUBLE encoding=GORILLA,膜产水状态_BOOLEAN BOOLEAN encoding=RLE,11_TEXT TEXT encoding=PLAIN,产水间歇运行时间设置_DOUBLE DOUBLE encoding=GORILLA,文本_TEXT TEXT encoding=PLAIN, 风机投入_BOOLEAN BOOLEAN encoding=RLE,枚举_INT32 INT32 encoding=RLE,出水TP_DOUBLE DOUBLE encoding=GORILLA,水管流速_DOUBLE DOUBLE encoding=GORILLA,CO2_DOUBLE DOUBLE encoding=GORILLA,`开关量-运行_BOOLEAN` BOOLEAN encoding=RLE,code_DOUBLE DOUBLE encoding=GORILLA);",
7979
"insert into root.sg(time,code_DOUBLE) aligned values(1679477545000,2.0);",
80-
"insert into root.sg(time,`NH4-N_DOUBLE`) aligned values(1679365910000,12.0);"
80+
"insert into root.sg(time,`NH4-N_DOUBLE`) aligned values(1679365910000,12.0);",
81+
"create timeseries root.sg.d1.s1 with datatype=BLOB;",
82+
"insert into root.sg.d1(time,s1) values(1,X'cafebabe')",
8183
};
8284

8385
@BeforeClass
@@ -179,4 +181,15 @@ public void testLastQuerySortWithLimit() {
179181
expectedHeader,
180182
retArray);
181183
}
184+
185+
@Test
186+
public void testLastQuerySortWithBlobType() {
187+
String[] expectedHeader =
188+
new String[] {TIMESTAMP_STR, TIMESERIES_STR, VALUE_STR, DATA_TYPE_STR};
189+
String[] retArray =
190+
new String[] {
191+
"1,root.sg.d1.s1,0xcafebabe,BLOB,",
192+
};
193+
resultSetEqualTest("select last s1 from root.sg.d1;", expectedHeader, retArray);
194+
}
182195
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/thrift/impl/ClientRPCServiceImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -981,11 +981,11 @@ public TSExecuteStatementResp executeFastLastDataQueryForOnePrefixPath(
981981
device2MeasurementLastEntry.getValue().entrySet()) {
982982
final TimeValuePair tvPair = measurementLastEntry.getValue().getRight();
983983
if (tvPair != TableDeviceLastCache.EMPTY_TIME_VALUE_PAIR) {
984-
LastQueryUtil.appendLastValue(
984+
LastQueryUtil.appendLastValueRespectBlob(
985985
builder,
986986
tvPair.getTimestamp(),
987987
deviceWithSeparator + measurementLastEntry.getKey(),
988-
tvPair.getValue().getStringValue(),
988+
tvPair.getValue(),
989989
measurementLastEntry.getValue().getLeft().name());
990990
}
991991
}
@@ -1116,11 +1116,11 @@ public TSExecuteStatementResp executeFastLastDataQueryForOneDeviceV2(
11161116
}
11171117
} else {
11181118
// we don't consider TTL
1119-
LastQueryUtil.appendLastValue(
1119+
LastQueryUtil.appendLastValueRespectBlob(
11201120
builder,
11211121
timeValuePair.getTimestamp(),
11221122
new Binary(fullPath.getFullPath(), TSFileConfig.STRING_CHARSET),
1123-
timeValuePair.getValue().getStringValue(),
1123+
timeValuePair.getValue(),
11241124
timeValuePair.getValue().getDataType().name());
11251125
}
11261126
}

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/last/AlignedUpdateLastCacheOperator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ public TsBlock next() throws Exception {
101101

102102
protected void appendLastValueToTsBlockBuilder(
103103
long lastTime, TsPrimitiveType lastValue, MeasurementPath measurementPath, String type) {
104-
LastQueryUtil.appendLastValue(
105-
tsBlockBuilder, lastTime, measurementPath.getFullPath(), lastValue.getStringValue(), type);
104+
LastQueryUtil.appendLastValueRespectBlob(
105+
tsBlockBuilder, lastTime, measurementPath.getFullPath(), lastValue, type);
106106
}
107107

108108
@Override

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/last/AlignedUpdateViewPathLastCacheOperator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ public AlignedUpdateViewPathLastCacheOperator(
5858
@Override
5959
protected void appendLastValueToTsBlockBuilder(
6060
long lastTime, TsPrimitiveType lastValue, MeasurementPath measurementPath, String type) {
61-
LastQueryUtil.appendLastValue(
62-
tsBlockBuilder, lastTime, outputViewPath, lastValue.getStringValue(), type);
61+
LastQueryUtil.appendLastValueRespectBlob(
62+
tsBlockBuilder, lastTime, outputViewPath, lastValue, type);
6363
}
6464

6565
@Override

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/last/LastQueryTransformOperator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ public TsBlock next() throws Exception {
7474
if (tsBlock.getColumn(1).isNull(0)) {
7575
return null;
7676
}
77-
LastQueryUtil.appendLastValue(
77+
LastQueryUtil.appendLastValueRespectBlob(
7878
tsBlockBuilder,
7979
tsBlock.getColumn(0).getLong(0),
8080
viewPath,
81-
tsBlock.getColumn(1).getTsPrimitiveType(0).getStringValue(),
81+
tsBlock.getColumn(1).getTsPrimitiveType(0),
8282
dataType);
8383
}
8484
} else {

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/last/LastQueryUtil.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import org.apache.tsfile.read.filter.operator.TimeFilterOperators.TimeGt;
3737
import org.apache.tsfile.read.filter.operator.TimeFilterOperators.TimeGtEq;
3838
import org.apache.tsfile.utils.Binary;
39+
import org.apache.tsfile.utils.BytesUtils;
40+
import org.apache.tsfile.utils.TsPrimitiveType;
3941

4042
import java.util.ArrayList;
4143
import java.util.Collections;
@@ -65,6 +67,38 @@ public static Binary getTimeSeries(TsBlock tsBlock, int index) {
6567
return tsBlock.getColumn(0).getBinary(index);
6668
}
6769

70+
public static void appendLastValueRespectBlob(
71+
TsBlockBuilder builder,
72+
long lastTime,
73+
String fullPath,
74+
TsPrimitiveType lastValue,
75+
String dataType) {
76+
appendLastValue(
77+
builder,
78+
lastTime,
79+
fullPath,
80+
dataType.equals(TSDataType.BLOB.name())
81+
? BytesUtils.parseBlobByteArrayToString(lastValue.getBinary().getValues())
82+
: lastValue.getStringValue(),
83+
dataType);
84+
}
85+
86+
public static void appendLastValueRespectBlob(
87+
TsBlockBuilder builder,
88+
long lastTime,
89+
Binary fullPath,
90+
TsPrimitiveType lastValue,
91+
String dataType) {
92+
appendLastValue(
93+
builder,
94+
lastTime,
95+
fullPath,
96+
dataType.equals(TSDataType.BLOB.name())
97+
? BytesUtils.parseBlobByteArrayToString(lastValue.getBinary().getValues())
98+
: lastValue.getStringValue(),
99+
dataType);
100+
}
101+
68102
public static void appendLastValue(
69103
TsBlockBuilder builder, long lastTime, String fullPath, String lastValue, String dataType) {
70104
// Time

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/last/UpdateLastCacheOperator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ public TsBlock next() throws Exception {
115115
}
116116

117117
protected void appendLastValueToTsBlockBuilder(long lastTime, TsPrimitiveType lastValue) {
118-
LastQueryUtil.appendLastValue(
119-
tsBlockBuilder, lastTime, fullPath.getFullPath(), lastValue.getStringValue(), dataType);
118+
LastQueryUtil.appendLastValueRespectBlob(
119+
tsBlockBuilder, lastTime, fullPath.getFullPath(), lastValue, dataType);
120120
}
121121

122122
@Override

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/operator/process/last/UpdateViewPathLastCacheOperator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public UpdateViewPathLastCacheOperator(
5454

5555
@Override
5656
protected void appendLastValueToTsBlockBuilder(long lastTime, TsPrimitiveType lastValue) {
57-
LastQueryUtil.appendLastValue(
58-
tsBlockBuilder, lastTime, outputViewPath, lastValue.getStringValue(), dataType);
57+
LastQueryUtil.appendLastValueRespectBlob(
58+
tsBlockBuilder, lastTime, outputViewPath, lastValue, dataType);
5959
}
6060

6161
@Override

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/OperatorTreeGenerator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3106,11 +3106,11 @@ public Operator visitLastQuery(LastQueryNode node, LocalExecutionPlanContext con
31063106
TsBlockBuilder builder = LastQueryUtil.createTsBlockBuilder(initSize);
31073107
for (int i = 0; i < initSize; i++) {
31083108
TimeValuePair timeValuePair = cachedLastValueAndPathList.get(i).left;
3109-
LastQueryUtil.appendLastValue(
3109+
LastQueryUtil.appendLastValueRespectBlob(
31103110
builder,
31113111
timeValuePair.getTimestamp(),
31123112
cachedLastValueAndPathList.get(i).right,
3113-
timeValuePair.getValue().getStringValue(),
3113+
timeValuePair.getValue(),
31143114
timeValuePair.getValue().getDataType().name());
31153115
}
31163116
OperatorContext operatorContext =
@@ -3133,11 +3133,11 @@ public Operator visitLastQuery(LastQueryNode node, LocalExecutionPlanContext con
31333133
TsBlockBuilder builder = LastQueryUtil.createTsBlockBuilder(initSize);
31343134
for (int i = 0; i < initSize; i++) {
31353135
TimeValuePair timeValuePair = cachedLastValueAndPathList.get(i).left;
3136-
LastQueryUtil.appendLastValue(
3136+
LastQueryUtil.appendLastValueRespectBlob(
31373137
builder,
31383138
timeValuePair.getTimestamp(),
31393139
cachedLastValueAndPathList.get(i).right,
3140-
timeValuePair.getValue().getStringValue(),
3140+
timeValuePair.getValue(),
31413141
timeValuePair.getValue().getDataType().name());
31423142
}
31433143

0 commit comments

Comments
 (0)