rdblue commented on a change in pull request #3460:
URL: https://github.com/apache/iceberg/pull/3460#discussion_r742282785
##########
File path: api/src/main/java/org/apache/iceberg/expressions/Literals.java
##########
@@ -639,5 +647,12 @@ Object writeReplace() throws ObjectStreamException {
protected Type.TypeID typeId() {
return Type.TypeID.BINARY;
}
+
+ @Override
+ public String toString() {
+ byte[] binary = new byte[value().remaining()];
+ value().duplicate().get(binary);
+ return "0x" + BaseEncoding.base16().encode(binary);
Review comment:
This should just be for debugging. If we are converting a literal to a
string and back, then that's a problem.
##########
File path:
spark/v3.2/spark/src/main/java/org/apache/iceberg/spark/Spark3Util.java
##########
@@ -636,17 +635,17 @@ public String or(String leftResult, String rightResult) {
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();
Review comment:
@kbendick is right. This should not remove the `sqlString` function.
That converts a literal into a form that is usable by Spark. Instead, you
should update that function to produce Spark's binary literal format.
##########
File path:
spark/v3.2/spark/src/test/java/org/apache/iceberg/spark/SparkTestBase.java
##########
@@ -157,7 +158,11 @@ private void assertEquals(String context, Object[]
expectedRow, Object[] actualR
Object actualValue = actualRow[col];
if (expectedValue != null && expectedValue.getClass().isArray()) {
String newContext = String.format("%s (nested col %d)", context, col +
1);
- assertEquals(newContext, (Object[]) expectedValue, (Object[])
actualValue);
+ if (expectedValue.getClass().getComponentType().isPrimitive()) {
+ new ExactComparisonCriteria().arrayEquals(newContext, expectedValue,
actualValue);
+ } else {
+ assertEquals(newContext, (Object[]) expectedValue, (Object[])
actualValue);
+ }
Review comment:
Why was this needed?
##########
File path:
spark/v3.2/spark/src/test/java/org/apache/iceberg/spark/sql/TestSelect.java
##########
@@ -49,8 +49,8 @@ public TestSelect(String catalogName, String implementation,
Map<String, String>
@Before
public void createTables() {
- sql("CREATE TABLE %s (id bigint, data string, float float) USING iceberg",
tableName);
- sql("INSERT INTO %s VALUES (1, 'a', 1.0), (2, 'b', 2.0), (3, 'c',
float('NaN'))", tableName);
+ sql("CREATE TABLE %s (id bigint, data string, float float, binary binary)
USING iceberg", tableName);
+ sql("INSERT INTO %s VALUES (1, 'a', 1.0, X''), (2, 'b', 2.0, X'11'), (3,
'c', float('NaN'), X'1111')", tableName);
Review comment:
Rather than repurposing old test cases, can you create new ones? We want
to avoid mixing tests together in confusing ways that look like other failures.
##########
File path: api/src/main/java/org/apache/iceberg/expressions/Literals.java
##########
@@ -639,5 +647,12 @@ Object writeReplace() throws ObjectStreamException {
protected Type.TypeID typeId() {
return Type.TypeID.BINARY;
}
+
+ @Override
+ public String toString() {
+ byte[] binary = new byte[value().remaining()];
+ value().duplicate().get(binary);
+ return "0x" + BaseEncoding.base16().encode(binary);
Review comment:
This should just be for debugging. If we are converting a literal to a
string and back, then that's a problem.
##########
File path:
spark/v3.2/spark/src/main/java/org/apache/iceberg/spark/Spark3Util.java
##########
@@ -636,17 +635,17 @@ public String or(String leftResult, String rightResult) {
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();
Review comment:
@kbendick is right. This should not remove the `sqlString` function.
That converts a literal into a form that is usable by Spark. Instead, you
should update that function to produce Spark's binary literal format.
##########
File path:
spark/v3.2/spark/src/test/java/org/apache/iceberg/spark/SparkTestBase.java
##########
@@ -157,7 +158,11 @@ private void assertEquals(String context, Object[]
expectedRow, Object[] actualR
Object actualValue = actualRow[col];
if (expectedValue != null && expectedValue.getClass().isArray()) {
String newContext = String.format("%s (nested col %d)", context, col +
1);
- assertEquals(newContext, (Object[]) expectedValue, (Object[])
actualValue);
+ if (expectedValue.getClass().getComponentType().isPrimitive()) {
+ new ExactComparisonCriteria().arrayEquals(newContext, expectedValue,
actualValue);
+ } else {
+ assertEquals(newContext, (Object[]) expectedValue, (Object[])
actualValue);
+ }
Review comment:
Why was this needed?
##########
File path:
spark/v3.2/spark/src/test/java/org/apache/iceberg/spark/sql/TestSelect.java
##########
@@ -49,8 +49,8 @@ public TestSelect(String catalogName, String implementation,
Map<String, String>
@Before
public void createTables() {
- sql("CREATE TABLE %s (id bigint, data string, float float) USING iceberg",
tableName);
- sql("INSERT INTO %s VALUES (1, 'a', 1.0), (2, 'b', 2.0), (3, 'c',
float('NaN'))", tableName);
+ sql("CREATE TABLE %s (id bigint, data string, float float, binary binary)
USING iceberg", tableName);
+ sql("INSERT INTO %s VALUES (1, 'a', 1.0, X''), (2, 'b', 2.0, X'11'), (3,
'c', float('NaN'), X'1111')", tableName);
Review comment:
Rather than repurposing old test cases, can you create new ones? We want
to avoid mixing tests together in confusing ways that look like other failures.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]