2323import org .apache .iotdb .db .protocol .session .SessionManager ;
2424import org .apache .iotdb .db .queryengine .common .ExplainType ;
2525import org .apache .iotdb .db .queryengine .common .MPPQueryContext ;
26+ import org .apache .iotdb .db .queryengine .common .header .DatasetHeader ;
2627import org .apache .iotdb .db .queryengine .plan .Coordinator ;
2728import org .apache .iotdb .db .queryengine .plan .execution .ExecutionResult ;
2829import org .apache .iotdb .db .queryengine .plan .planner .LocalExecutionPlanner ;
3637import org .apache .iotdb .db .queryengine .plan .relational .sql .ast .LogicalExpression ;
3738import org .apache .iotdb .db .queryengine .plan .relational .sql .ast .LongLiteral ;
3839import org .apache .iotdb .db .queryengine .plan .relational .sql .ast .NotExpression ;
40+ import org .apache .iotdb .db .queryengine .plan .relational .sql .ast .StringLiteral ;
3941import org .apache .iotdb .db .queryengine .plan .relational .sql .ast .SubqueryExpression ;
4042import org .apache .iotdb .db .queryengine .plan .relational .sql .parser .SqlParser ;
4143import org .apache .iotdb .rpc .TSStatusCode ;
4244
4345import org .apache .tsfile .block .column .Column ;
46+ import org .apache .tsfile .enums .TSDataType ;
4447import org .apache .tsfile .read .common .block .TsBlock ;
4548
49+ import java .util .List ;
4650import java .util .Optional ;
4751
4852import static com .google .common .base .Preconditions .checkArgument ;
@@ -140,7 +144,13 @@ private static Optional<Literal> fetchUncorrelatedSubqueryResultForPredicate(
140144 checkArgument (
141145 tsBlock .get ().getPositionCount () == 1 && !tsBlock .get ().getColumn (0 ).isNull (0 ),
142146 "Scalar Subquery result should only have one row." );
143- switch (columns [0 ].getDataType ()) {
147+
148+ // column type
149+ DatasetHeader datasetHeader = coordinator .getQueryExecution (queryId ).getDatasetHeader ();
150+ List <TSDataType > dataTypes = datasetHeader .getRespDataTypes ();
151+ checkArgument (dataTypes .size () == 1 , "Scalar Subquery result should only have one column." );
152+
153+ switch (dataTypes .get (0 )) {
144154 case INT32 :
145155 case DATE :
146156 return Optional .of (new LongLiteral (Long .toString (columns [0 ].getInt (0 ))));
@@ -154,9 +164,10 @@ private static Optional<Literal> fetchUncorrelatedSubqueryResultForPredicate(
154164 case BOOLEAN :
155165 return Optional .of (new BooleanLiteral (Boolean .toString (columns [0 ].getBoolean (0 ))));
156166 case BLOB :
167+ return Optional .of (new BinaryLiteral (columns [0 ].getBinary (0 ).toString ()));
157168 case TEXT :
158169 case STRING :
159- return Optional .of (new BinaryLiteral (columns [0 ].getBinary (0 ).toString ()));
170+ return Optional .of (new StringLiteral (columns [0 ].getBinary (0 ).toString ()));
160171 default :
161172 throw new IllegalArgumentException (
162173 String .format (
0 commit comments