diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/AbstractCastFunctionColumnTransformer.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/AbstractCastFunctionColumnTransformer.java index 39d7a91d586e..ee40a3ec6f8e 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/AbstractCastFunctionColumnTransformer.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/AbstractCastFunctionColumnTransformer.java @@ -312,7 +312,7 @@ protected void cast(ColumnBuilder columnBuilder, boolean value) { } } - protected void cast(ColumnBuilder columnBuilder, Binary value) { + protected void castString(ColumnBuilder columnBuilder, Binary value) { String stringValue = value.getStringValue(TSFileConfig.STRING_CHARSET); try { switch (returnType.getTypeEnum()) { @@ -352,4 +352,45 @@ protected void cast(ColumnBuilder columnBuilder, Binary value) { String.format("Cannot cast %s to %s type", stringValue, returnType.getDisplayName())); } } + + protected void castBlob(ColumnBuilder columnBuilder, Binary value) { + String stringValue = BytesUtils.parseBlobByteArrayToString(value.getValues()); + try { + switch (returnType.getTypeEnum()) { + case INT32: + returnType.writeInt(columnBuilder, Integer.parseInt(stringValue)); + break; + case DATE: + returnType.writeInt(columnBuilder, DateUtils.parseDateExpressionToInt(stringValue)); + break; + case INT64: + returnType.writeLong(columnBuilder, Long.parseLong(stringValue)); + break; + case TIMESTAMP: + returnType.writeLong( + columnBuilder, DateTimeUtils.convertDatetimeStrToLong(stringValue, zoneId)); + break; + case FLOAT: + returnType.writeFloat(columnBuilder, CastFunctionHelper.castTextToFloat(stringValue)); + break; + case DOUBLE: + returnType.writeDouble(columnBuilder, CastFunctionHelper.castTextToDouble(stringValue)); + break; + case BOOLEAN: + returnType.writeBoolean(columnBuilder, CastFunctionHelper.castTextToBoolean(stringValue)); + break; + case TEXT: + case STRING: + case BLOB: + returnType.writeBinary(columnBuilder, value); + break; + default: + throw new UnsupportedOperationException( + String.format(ERROR_MSG, returnType.getTypeEnum())); + } + } catch (DateTimeParseException | NumberFormatException e) { + throw new SemanticException( + String.format("Cannot cast %s to %s type", stringValue, returnType.getDisplayName())); + } + } } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/CastFunctionColumnTransformer.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/CastFunctionColumnTransformer.java index 3412246eea0c..b9c8e31b1abb 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/CastFunctionColumnTransformer.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/CastFunctionColumnTransformer.java @@ -62,8 +62,10 @@ protected void transform( break; case TEXT: case STRING: + castString(columnBuilder, childType.getBinary(column, i)); + break; case BLOB: - cast(columnBuilder, childType.getBinary(column, i)); + castBlob(columnBuilder, childType.getBinary(column, i)); break; default: throw new UnsupportedOperationException( diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/TryCastFunctionColumnTransformer.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/TryCastFunctionColumnTransformer.java index 9ff6b649b515..c25fd321c344 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/TryCastFunctionColumnTransformer.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/TryCastFunctionColumnTransformer.java @@ -64,8 +64,10 @@ protected void transform( break; case TEXT: case STRING: + castString(columnBuilder, childType.getBinary(column, i)); + break; case BLOB: - cast(columnBuilder, childType.getBinary(column, i)); + castBlob(columnBuilder, childType.getBinary(column, i)); break; default: throw new UnsupportedOperationException(