You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"Cannot infer common argument type for comparison operation Union..." #10180
I took a look a bit, and I found that your return_type is Union, but If I understand correctly, you should compute the return type based on args. For example, in your test json_get(json_data, 'foo'), if you compute the return_type based on foo, you return Int, then you will not meet the error.
The error is because Union is not yet supported in comparison_coercion
@jayzhan211 that doesn't work since the argument types don't tell you what type will be returned.
e.g.:
if the value in column foo is {"x": "abc"}, then json_get(foo, 'x') will return a string
but if the value in column foo is {"x": 123}, then json_get(foo, 'x') will return an integer
However I think I have a work around, I'm requiring a cast, so you have to do json_get(foo, 'x')::string or json_get(foo, 'x')::int, then I'm using a FunctionRewrite to rewrite the function from json_get to json_get_str or json_get_int.
With that the only remaining issue is making the error less ugly and more informative.
@samuelcolvin Did you also consider return_type_from_exprs, if it does not work, I think we can either support Union in comparison_coercion or better design ScalarUDFImpl to do more customize about the return type.
Activity
jayzhan211 commentedon Apr 23, 2024
I took a look a bit, and I found that your
return_typeisUnion, but If I understand correctly, you should compute the return type based on args. For example, in your testjson_get(json_data, 'foo'), if you compute the return_type based onfoo, you returnInt, then you will not meet the error.The error is because Union is not yet supported in
comparison_coercionsamuelcolvin commentedon Apr 23, 2024
@jayzhan211 that doesn't work since the argument types don't tell you what type will be returned.
e.g.:
foois{"x": "abc"}, thenjson_get(foo, 'x')will return a stringfoois{"x": 123}, thenjson_get(foo, 'x')will return an integerHowever I think I have a work around, I'm requiring a cast, so you have to do
json_get(foo, 'x')::stringorjson_get(foo, 'x')::int, then I'm using aFunctionRewriteto rewrite the function fromjson_gettojson_get_strorjson_get_int.With that the only remaining issue is making the error less ugly and more informative.
jayzhan211 commentedon Apr 24, 2024
@samuelcolvin Did you also consider
return_type_from_exprs, if it does not work, I think we can either support Union incomparison_coercionor better design ScalarUDFImpl to do more customize about the return type.samuelcolvin commentedon Apr 24, 2024
ye,
return_type_from_exprsdoesn't help.I got around it mostly, with I think good performance by rewriting the query when there's a cast, so:
Will be rewritten to:
The main requirement I have now is that the error when you do try to compare a union is more helpful and less ugly.
jayzhan211 commentedon Apr 24, 2024
Do you mean the error message in
comparision_coerion?samuelcolvin commentedon Aug 8, 2024
sorry for the slow reply, yes exactly.
samuelcolvin commentedon Aug 9, 2024
I'm working on this, initially in arrow-rs.