Repository navigation
GH-3877: Add FINITE_VECTOR logical type support #3876
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?
Changes from all commits
9ee42ed
1c8d398
d7d8da6
8a44a99
4f95e9c
5e5daec
1b31654
36e534d
99ef065
4b1e872
5bdd8f1
0b4bba9
5565d64
974f3fb
869eb6c
362317e
c42087c
a7d8129
6493ae2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -62,6 +62,13 @@ protected LogicalTypeAnnotation fromString(List<String> params) { | |||||
| return listType(); | ||||||
| } | ||||||
| }, | ||||||
| FINITE_VECTOR { | ||||||
| @Override | ||||||
| protected LogicalTypeAnnotation fromString(List<String> params) { | ||||||
| Preconditions.checkArgument(params.size() == 1, "Expecting 1 parameter for FINITE_VECTOR: %s", params); | ||||||
| return finiteVectorType(Integer.parseInt(params.get(0))); | ||||||
| } | ||||||
| }, | ||||||
| VARIANT { | ||||||
| @Override | ||||||
| protected LogicalTypeAnnotation fromString(List<String> params) { | ||||||
|
|
@@ -314,6 +321,10 @@ public static ListLogicalTypeAnnotation listType() { | |||||
| return ListLogicalTypeAnnotation.INSTANCE; | ||||||
| } | ||||||
|
|
||||||
| public static FiniteVectorLogicalTypeAnnotation finiteVectorType(int numElements) { | ||||||
| return new FiniteVectorLogicalTypeAnnotation(numElements); | ||||||
| } | ||||||
|
|
||||||
| public static VariantLogicalTypeAnnotation variantType(byte specVersion) { | ||||||
| return new VariantLogicalTypeAnnotation(specVersion); | ||||||
| } | ||||||
|
|
@@ -503,7 +514,7 @@ LogicalTypeToken getType() { | |||||
|
|
||||||
| @Override | ||||||
| public boolean equals(Object obj) { | ||||||
| return obj instanceof ListLogicalTypeAnnotation; | ||||||
| return obj instanceof ListLogicalTypeAnnotation && !(obj instanceof FiniteVectorLogicalTypeAnnotation); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: this way the parent needs to know about its subclass. How about:
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
|
|
@@ -513,6 +524,45 @@ public int hashCode() { | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| public static class FiniteVectorLogicalTypeAnnotation extends ListLogicalTypeAnnotation { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The spec says every non-null vector MUST have exactly |
||||||
| private final int numElements; | ||||||
|
|
||||||
| private FiniteVectorLogicalTypeAnnotation(int numElements) { | ||||||
| Preconditions.checkArgument(numElements > 0, "Invalid FINITE_VECTOR length: %s", numElements); | ||||||
| this.numElements = numElements; | ||||||
| } | ||||||
|
|
||||||
| public int getNumElements() { | ||||||
| return numElements; | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public <T> Optional<T> accept(LogicalTypeAnnotationVisitor<T> visitor) { | ||||||
| return visitor.visit(this); | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| LogicalTypeToken getType() { | ||||||
| return LogicalTypeToken.FINITE_VECTOR; | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| protected String typeParametersAsString() { | ||||||
| return "(" + numElements + ")"; | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public boolean equals(Object obj) { | ||||||
| return obj instanceof FiniteVectorLogicalTypeAnnotation | ||||||
| && numElements == ((FiniteVectorLogicalTypeAnnotation) obj).numElements; | ||||||
| } | ||||||
|
|
||||||
| @Override | ||||||
| public int hashCode() { | ||||||
| return 31 * getClass().hashCode() + numElements; | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| public static class EnumLogicalTypeAnnotation extends LogicalTypeAnnotation { | ||||||
| private static final EnumLogicalTypeAnnotation INSTANCE = new EnumLogicalTypeAnnotation(); | ||||||
|
|
||||||
|
|
@@ -1536,6 +1586,10 @@ default Optional<T> visit(ListLogicalTypeAnnotation listLogicalType) { | |||||
| return empty(); | ||||||
| } | ||||||
|
|
||||||
| default Optional<T> visit(FiniteVectorLogicalTypeAnnotation vectorLogicalType) { | ||||||
| return visit((ListLogicalTypeAnnotation) vectorLogicalType); | ||||||
| } | ||||||
|
divjotarora marked this conversation as resolved.
Resolved
|
||||||
|
|
||||||
| default Optional<T> visit(VariantLogicalTypeAnnotation variantLogicalType) { | ||||||
| return empty(); | ||||||
| } | ||||||
|
|
||||||
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.
Nice, this maps to
FixedSizeListnow 👍 The other direction still loses the length:fromArrowmapsArrowType.FixedSizeListto a plainLIST(createListTypeMapping()), soFINITE_VECTOR→ Arrow → Parquet gives aLIST. Should we map it back toFINITE_VECTOR(listSize)when the child is a non-nullable supported primitive, or do we keep that for a follow-up?