-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Various cleanups and improvements in TypeParameter #27574
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: master
Are you sure you want to change the base?
Conversation
core/trino-spi/src/main/java/io/trino/spi/type/TypeParameter.java
Outdated
Show resolved
Hide resolved
9ae3f14 to
1ed4023
Compare
e62a20a to
6fa0b0c
Compare
84e65fc to
c0b738d
Compare
findepi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Get type arguments directly from the type LGTM
core/trino-main/src/main/java/io/trino/operator/scalar/Re2JCastToRegexpFunction.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/operator/scalar/Re2JCastToRegexpFunction.java
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/operator/scalar/Re2JCastToRegexpFunction.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/operator/scalar/Re2JCastToRegexpFunction.java
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaHiveTypeTranslator.java
Outdated
Show resolved
Hide resolved
plugin/trino-hive/src/main/java/io/trino/plugin/hive/util/HiveTypeTranslator.java
Outdated
Show resolved
Hide resolved
findepi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove TypeParameter LGTM
core/trino-main/src/main/java/io/trino/type/RowParametricType.java
Outdated
Show resolved
Hide resolved
findepi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename TypeSignatureParameter -> TypeParameter LGTM assuming it's mechanical rename
findepi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix incorrect type declaration LGTM
core/trino-main/src/test/java/io/trino/operator/scalar/CustomFunctions.java
Show resolved
Hide resolved
core/trino-main/src/test/java/io/trino/operator/scalar/CustomFunctions.java
Show resolved
Hide resolved
c0b738d to
aa9d352
Compare
findepi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove NamedType and friends LGTM
client/trino-jdbc/src/main/java/io/trino/jdbc/AbstractTrinoResultSet.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/server/protocol/ProtocolUtil.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/type/RowParametricType.java
Outdated
Show resolved
Hide resolved
core/trino-spi/src/main/java/io/trino/spi/type/TypeParameter.java
Outdated
Show resolved
Hide resolved
|
|
||
| if (kind == ParameterKind.VARIABLE) { | ||
| prefix = "@"; | ||
| prefix += "@"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aren't name.isPresent() and kind == ParameterKind.VARIABLE exclusive conditions?
if so, better to have a check then lenient +=
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory, it would be possible to have a named field with an unbound type.
plugin/trino-hive/src/test/java/io/trino/plugin/hive/HiveTestUtils.java
Outdated
Show resolved
Hide resolved
plugin/trino-hive/src/test/java/io/trino/plugin/hive/HiveTestUtils.java
Outdated
Show resolved
Hide resolved
findepi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecate Type.getTypeParameters()
TL;DR
many of these refactors looks good on their own, but it's hard to review all of them at once
| // Until we support HASH_SWITCH strategy for code generation here, we treat structural type as an unsupported case | ||
| // and fall back to existing expression evaluator for small lists | ||
| if (!type.getTypeParameters().isEmpty()) { | ||
| if (type instanceof ArrayType || type instanceof MapType || type instanceof RowType) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ParametricTypeis in SPI so one could imagine a plugin adding a structural type. The new check doesn't reject this.- in fact,
ClassifierTypeis an example for which the new check returns different result
- in fact,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. However, that's only a theoretical concern right now. There's also a difference from a structural type (i.e., a container such as map/array/row) and a specialized type for type-safety and static type validations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in fact, i don't know why we throw for some types, and return false for some other types.
it's looks like throwing isn't necessary in this method at all, because the final type validation/rejection needs to be done somewhere later ... and therefore it doesn't matter much what we do here. the new validation is weaker (more persmissive), and therefore likely incorrect, but it's whatever
findepi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Improve type safety for TypeParameter
this change is least mechanical of all the commits in this PR.
i'd suggest separate PR.
Happy to do that. However, since all these commits affect the SPI, I wanted to get them all in the same timeframe to avoid thrash across multiple releases. |
aa9d352 to
3ad5d93
Compare
They are meant to be reviewed individually. They are all logically independent from each other, although they build on/touch the same areas the previous commit touched. |
3ad5d93 to
ca6668b
Compare
fair & my understanding as well. just the diff is longish |
findepi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecate Type.getTypeParameters()
i don't like this single long diff of manual & interesting changes to be forced upon me within this PR.
but ok, looked thru and LGTM % comments
lib/trino-hive-formats/src/main/java/io/trino/hive/formats/avro/AvroPageDataReader.java
Outdated
Show resolved
Hide resolved
| Type elementType = switch (type) { | ||
| case RowType rowType -> rowType.getFields().getFirst().getType(); | ||
| case ArrayType arrayType -> arrayType.getElementType(); | ||
| default -> throw new IllegalArgumentException("Unexpected type: " + type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- it's weird to take just a first field of a row. worth code comment
- the code also worked for map type which is now unhandled. i understand map never lands in this (test) code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was confusing to me, too. But I think this method is designed to handle the case of decoding a list of uniform values and either pivot it into a row or map it to a Trino array. I actually have no idea why this method would be called with a row type where only the first field type matters. It seems like a I'm not sure what the semantics would be for a Map (maybe key-value pairs?), either, but it doesn't matter since it doesn't happen in practice. We can always add that whenever the use case comes up.
BTW, getting the first field the row is not a new behavior -- that's implicitly how it it was done before. I just ported the behavior.
...test/java/io/trino/hive/formats/avro/TestAvroPageDataReaderWithAvroNativeTypeManagement.java
Outdated
Show resolved
Hide resolved
...rmats/src/test/java/io/trino/hive/formats/avro/TestAvroPageDataWriterWithoutTypeManager.java
Outdated
Show resolved
Hide resolved
...rmats/src/test/java/io/trino/hive/formats/avro/TestAvroPageDataWriterWithoutTypeManager.java
Outdated
Show resolved
Hide resolved
lib/trino-parquet/src/main/java/io/trino/parquet/reader/ParquetReader.java
Outdated
Show resolved
Hide resolved
I don't think it's a really big problem. |
ca6668b to
7cd92ab
Compare
TypeSignature should not be used in contexts where the Type is available. It's purpose is mainly for doing type inference and generic manipulation of types.
It's only used during instantiation of parametric types, as a mirror of TypeSignatureParameter. The translation is not needed.
The type parameter must match the argument it corresponds to.
It's not an ideal abstraction. Naming of fields is orthogonal to what type the argument is, so we don't need a dedicated class for it.
For general use, it's preferable to call the type-specific methods (e.g., ArrayType.getElementType(), MapType.getKeyType, MapType.getValueType())
Use a sum type instead of a tag + value. It makes it possible to use deconstruction patterns and switch statements/expressions to manipulate the values of the type.
7cd92ab to
a4c9055
Compare
|
@findepi , updated |
Description
See individual commit details.
Release notes
(x) Release notes are required, with the following suggested text: