Skip to content

Commit f6c1132

Browse files
natashasehgalfacebook-github-bot
authored andcommitted
Fix varchar cast for json
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
1 parent dfc6304 commit f6c1132

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

presto-native-execution/presto_cpp/main/types/PrestoToVeloxExpr.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,15 @@ std::optional<TypedExprPtr> convertCastToVarcharWithMaxLength(
181181
VELOX_DCHECK(end == returnType.data() + returnType.size() - 1);
182182

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

185+
auto arg = args[0];
186+
// If the argument is of JSON type, convert it to VARCHAR before applying substr.
187+
if (velox::isJsonType(arg->type())) {
188+
arg = std::make_shared<CallTypedExpr>(
189+
velox::VARCHAR(),
190+
std::vector<TypedExprPtr>{arg},
191+
"presto.default.json_format");
192+
}
186193
return std::make_shared<CallTypedExpr>(
187194
arg->type(),
188195
std::vector<TypedExprPtr>{

0 commit comments

Comments
 (0)