Skip to content

Commit

Permalink
Fix varchar cast for json
Browse files Browse the repository at this point in the history
Summary:
https://www.internalfb.com/tasks/?t=211442303

There was an error in running query on Prestissimo not Presto - "Scalar function presto.default.substr not registered with arguments: (JSON, BIGINT, BIGINT)".

This is not due to missing function, as the function signature does not exist in Presto. It occurs when attempting to cast JSON as varchar of capped length.
Related Diff: https://www.internalfb.com/diff/D59531026
Note: Exception is still raised for try_cast() behavior. Alignment is out of scope for this PR

Differential Revision: D68353517
  • Loading branch information
natashasehgal authored and facebook-github-bot committed Jan 17, 2025
1 parent dfc6304 commit f6c1132
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,15 @@ std::optional<TypedExprPtr> convertCastToVarcharWithMaxLength(
VELOX_DCHECK(end == returnType.data() + returnType.size() - 1);

VELOX_DCHECK_EQ(args.size(), 1);
const auto arg = args[0];

auto arg = args[0];
// If the argument is of JSON type, convert it to VARCHAR before applying substr.
if (velox::isJsonType(arg->type())) {
arg = std::make_shared<CallTypedExpr>(
velox::VARCHAR(),
std::vector<TypedExprPtr>{arg},
"presto.default.json_format");
}
return std::make_shared<CallTypedExpr>(
arg->type(),
std::vector<TypedExprPtr>{
Expand Down

0 comments on commit f6c1132

Please sign in to comment.