-
Notifications
You must be signed in to change notification settings - Fork 176
feat: restrict the usage of any in return types #798
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
base: main
Are you sure you want to change the base?
Conversation
Was having a discussion with some folks about any type restrictions, and we realized that we probably shouldn't allow function signatures like |
I think These are cases we have internally (actually the first one isn't correct since I guess it means "a struct of any one child field" while in reality there can be 1 or more, so maybe it should just be
|
We do want the type to be known so that optimization can be performed on the plan (and that the final types can be computed) so this makes sense. I suppose if you want to use functionality like get_struct_field you either need some better computation from the type system (being able to extract or construct types from the input types) or have a variant type that is handled externally (like the geo opaque type or variants in Snowflake). |
For For
technically returns a We don't have a way to write a function that takes X arguments, and outputs a struct of those X arguments. We could possibly finagle the type-system to figure out how to encode that, but that seems quite painful. Another approach would be to be to declare a new Expression that captures "make_struct". |
It turns there's already an expression construct for this in the protobuf spec. substrait/proto/substrait/algebra.proto Lines 1128 to 1167 in 4a47244
|
any must not be used as the return type of a function
7ebcb1c
to
31a9a37
Compare
Interesting, I don't think either substrait-spark or DF uses that, but maybe someday they will 😅 Another case where we found ourselves using |
Interesting. Is the function defined with an
parameter, as seen in as seen in from_avro, to set the concrete return type in the invocation? |
Yes:
|
I did notice there's an substrait/proto/substrait/algebra.proto Line 1196 in d01089b
Which means that on any actual Substrait plan, the output type of the function is explicitly and uniquely defined. What'd then be the benefit of restricting the function's return type? I think that means things like:
are already doable. |
I brought this up in the sync today and filed #820 related to it. The general consensus was that we should avoid unbound
Part of this is that we want the function definitions themselves to be self-contained outside of a plan context.
That would be one way to approach the issue. |
any must not be used as the return type of a function