Repository navigation
Fix Row equality/hashing, RowUtils validation and ByteBuffer handling, and LogicalTypeCoder DATETIME conversion #40789
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
441fb29
b6af710
340f9ca
57941fa
9c373a7
d542376
2a4a062
33b4bdd
ad142a8
03bb446
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 |
|---|---|---|
|
|
@@ -486,7 +486,10 @@ public static int deepHashCode(Object a, Schema.FieldType fieldType) { | |
| if (a == null) { | ||
| return 0; | ||
| } else if (fieldType.getTypeName() == TypeName.LOGICAL_TYPE) { | ||
| return deepHashCode(a, fieldType.getLogicalType().getBaseType()); | ||
| Schema.LogicalType<Object, Object> logicalType = | ||
| (Schema.LogicalType<Object, Object>) fieldType.getLogicalType(); | ||
| return deepHashCode( | ||
| SchemaUtils.toLogicalBaseType(logicalType, a), logicalType.getBaseType()); | ||
|
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. why not just logicalType.toBaseType(a) instead of the SchemaUtils call? |
||
| } else if (fieldType.getTypeName() == Schema.TypeName.BYTES) { | ||
| return Arrays.hashCode((byte[]) a); | ||
| } else if (fieldType.getTypeName().isCollectionType()) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -173,11 +173,7 @@ public Object match( | |
| processedValue = cases.processByte(rowPosition, (Byte) value, this); | ||
| break; | ||
| case BYTES: | ||
| processedValue = | ||
| cases.processBytes( | ||
| rowPosition, | ||
| (byte[]) (value instanceof ByteBuffer ? ((ByteBuffer) value).array() : value), | ||
| this); | ||
| processedValue = cases.processBytes(rowPosition, toByteArray(value), this); | ||
| break; | ||
| case INT16: | ||
| processedValue = cases.processInt16(rowPosition, (Short) value, this); | ||
|
|
@@ -423,6 +419,12 @@ public Row processRow( | |
| } | ||
| retValue = new RowWithStorage(schema, values); | ||
| } | ||
| if (retValue != null && !schema.equals(retValue.getSchema())) { | ||
|
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. Was this added for a reason? It will add extra cost here. |
||
| throw new IllegalArgumentException( | ||
| String.format( | ||
| "Expected schema %s for field %s, but got %s", | ||
| schema, rowPosition.descriptor, retValue.getSchema())); | ||
| } | ||
| return retValue; | ||
| } | ||
|
|
||
|
|
@@ -605,7 +607,26 @@ public Boolean processBoolean(RowPosition rowPosition, Boolean value, RowFieldMa | |
| @Override | ||
| public byte[] processBytes(RowPosition rowPosition, byte[] value, RowFieldMatcher matcher) { | ||
| Object retValue = overrideOrReturn(rowPosition, value); | ||
| return (retValue instanceof ByteBuffer) ? ((ByteBuffer) retValue).array() : (byte[]) retValue; | ||
| return toByteArray(retValue); | ||
| } | ||
| } | ||
|
|
||
| static byte @Nullable [] toByteArray(@Nullable Object value) { | ||
| if (value == null) { | ||
| return null; | ||
| } | ||
| if (value instanceof ByteBuffer) { | ||
| ByteBuffer buf = (ByteBuffer) value; | ||
| if (buf.hasArray() | ||
| && buf.arrayOffset() == 0 | ||
| && buf.position() == 0 | ||
| && buf.limit() == buf.capacity()) { | ||
| return buf.array(); | ||
| } | ||
| byte[] bytes = new byte[buf.remaining()]; | ||
| buf.duplicate().get(bytes); | ||
| return bytes; | ||
| } | ||
| return (byte[]) value; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -140,16 +140,19 @@ public boolean equals(@Nullable Object o) { | |
| } | ||
| if (o instanceof RowWithGetters) { | ||
| RowWithGetters other = (RowWithGetters) o; | ||
| return Objects.equals(getSchema(), other.getSchema()) | ||
| && Objects.equals(getterTarget, other.getterTarget); | ||
| } else if (o instanceof Row) { | ||
| if (Objects.equals(getSchema(), other.getSchema()) | ||
| && Objects.equals(getterTarget, other.getterTarget)) { | ||
| return true; | ||
| } | ||
| } | ||
| if (o instanceof Row) { | ||
| return super.equals(o); | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(getSchema(), getterTarget); | ||
| return super.hashCode(); | ||
|
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. What's the reason for this change here? |
||
| } | ||
| } | ||
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.
Looking at the code it looks like we usually store input values in the row, meaning that this code is correct. However I'm not sure if we are consistent - the comment on attachValues says that base values should be passed. We should investigate this a bit more.