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

Correct the Blob data cast error msg #14749

Merged
merged 1 commit into from
Jan 21, 2025
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 @@ -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()) {
Expand Down Expand Up @@ -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()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading