Skip to content

Commit

Permalink
Correct the Blob data cast error msg
Browse files Browse the repository at this point in the history
  • Loading branch information
JackieTien97 authored Jan 21, 2025
1 parent 0f799c6 commit 3491493
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
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

0 comments on commit 3491493

Please sign in to comment.