-
Notifications
You must be signed in to change notification settings - Fork 3k
Spark: Fix IllegarlArgumentException when filtering on BinaryType column #3460
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
Changes from 5 commits
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 |
|---|---|---|
|
|
@@ -19,7 +19,6 @@ | |
|
|
||
| package org.apache.iceberg.spark; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
|
|
@@ -636,17 +635,17 @@ public <T> String predicate(UnboundPredicate<T> pred) { | |
| case NOT_NAN: | ||
| return "not_nan(" + pred.ref().name() + ")"; | ||
| case LT: | ||
| return pred.ref().name() + " < " + sqlString(pred.literal()); | ||
| return pred.ref().name() + " < " + pred.literal(); | ||
| case LT_EQ: | ||
| return pred.ref().name() + " <= " + sqlString(pred.literal()); | ||
| return pred.ref().name() + " <= " + pred.literal(); | ||
| case GT: | ||
| return pred.ref().name() + " > " + sqlString(pred.literal()); | ||
| return pred.ref().name() + " > " + pred.literal(); | ||
| case GT_EQ: | ||
| return pred.ref().name() + " >= " + sqlString(pred.literal()); | ||
| return pred.ref().name() + " >= " + pred.literal(); | ||
| case EQ: | ||
| return pred.ref().name() + " = " + sqlString(pred.literal()); | ||
| return pred.ref().name() + " = " + pred.literal(); | ||
| case NOT_EQ: | ||
| return pred.ref().name() + " != " + sqlString(pred.literal()); | ||
| return pred.ref().name() + " != " + pred.literal(); | ||
|
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 did we get rid of the Also, since the representation of This would allow other engines to handle it themselves (e.g. if Flink doesn't use leading
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. @kbendick is right. This should not remove the
Contributor
Author
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.
I think this class is just for generating description information, and the description will be displayed in the log and Spark UI for debugging. So in my opinion, it is an acceptable way to use In fact, except for the difference between StringLiteral's single and double quotes, the current But if you think that keeping sqlString is a better way, I can also modify the code. |
||
| case STARTS_WITH: | ||
| return pred.ref().name() + " LIKE '" + pred.literal() + "%'"; | ||
| case IN: | ||
|
|
@@ -659,17 +658,7 @@ public <T> String predicate(UnboundPredicate<T> pred) { | |
| } | ||
|
|
||
| private static <T> String sqlString(List<org.apache.iceberg.expressions.Literal<T>> literals) { | ||
| return literals.stream().map(DescribeExpressionVisitor::sqlString).collect(Collectors.joining(", ")); | ||
| } | ||
|
|
||
| private static String sqlString(org.apache.iceberg.expressions.Literal<?> lit) { | ||
| if (lit.value() instanceof String) { | ||
| return "'" + lit.value() + "'"; | ||
| } else if (lit.value() instanceof ByteBuffer) { | ||
| throw new IllegalArgumentException("Cannot convert bytes to SQL literal: " + lit); | ||
| } else { | ||
| return lit.value().toString(); | ||
| } | ||
| return literals.stream().map(Object::toString).collect(Collectors.joining(", ")); | ||
|
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. This seems possibly incorrect or a deviation from the behavior before. It looks like this code is calling Object.toString on
Contributor
Author
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. Thanks for your review. After testing, I think this is correct |
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ | |
|
|
||
| package org.apache.iceberg.spark; | ||
|
|
||
| import java.lang.reflect.Array; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
|
|
@@ -118,6 +119,8 @@ private Object[] toJava(Row row) { | |
| return row.getList(pos); | ||
| } else if (value instanceof scala.collection.Map) { | ||
| return row.getJavaMap(pos); | ||
| } else if (value.getClass().isArray() && value.getClass().getComponentType().isPrimitive()) { | ||
| return IntStream.range(0, Array.getLength(value)).mapToObj(i -> Array.get(value, i)).toArray(); | ||
|
Contributor
Author
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. I think this is correct. The |
||
| } else { | ||
| return value; | ||
| } | ||
|
|
||
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.
No need for
duplicatehere becausetoByteArraywon't modify the buffer.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.
Thanks for your review, I have modified the code