Skip to content

Commit f336aca

Browse files
Address amoghs feedback
1 parent d95d9f0 commit f336aca

3 files changed

Lines changed: 54 additions & 9 deletions

File tree

api/src/main/java/org/apache/iceberg/expressions/Literals.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.time.format.DateTimeFormatter;
3131
import java.time.temporal.ChronoUnit;
3232
import java.util.Comparator;
33+
import java.util.Locale;
3334
import java.util.Objects;
3435
import java.util.UUID;
3536
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
@@ -587,6 +588,32 @@ public <T> Literal<T> to(Type type) {
587588
BigDecimal decimal = new BigDecimal(value().toString());
588589
return (Literal<T>) new DecimalLiteral(decimal);
589590

591+
case FIXED:
592+
try {
593+
ByteBuffer b =
594+
ByteBuffer.wrap(
595+
BaseEncoding.base16().decode(value().toString().toUpperCase(Locale.ROOT)));
596+
Types.FixedType fixed = (Types.FixedType) type;
597+
if (b.remaining() == fixed.length()) {
598+
return (Literal<T>) new FixedLiteral(b);
599+
}
600+
return null;
601+
} catch (IllegalArgumentException e) {
602+
// Invalid hex string
603+
return null;
604+
}
605+
606+
case BINARY:
607+
try {
608+
return (Literal<T>)
609+
new BinaryLiteral(
610+
ByteBuffer.wrap(
611+
BaseEncoding.base16().decode(value().toString().toUpperCase(Locale.ROOT))));
612+
} catch (IllegalArgumentException e) {
613+
// Invalid hex string
614+
return null;
615+
}
616+
590617
default:
591618
return null;
592619
}

spark/v4.1/spark-extensions/src/test/java/org/apache/iceberg/spark/extensions/TestRemoteScanPlanning.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import org.apache.iceberg.rest.RESTCatalogProperties;
2626
import org.apache.iceberg.spark.SparkCatalogConfig;
2727
import org.apache.iceberg.spark.sql.TestSelect;
28-
import org.junit.jupiter.api.Disabled;
29-
import org.junit.jupiter.api.TestTemplate;
3028
import org.junit.jupiter.api.extension.ExtendWith;
3129

3230
@ExtendWith(ParameterizedTestExtension.class)
@@ -48,11 +46,4 @@ protected static Object[][] parameters() {
4846
}
4947
};
5048
}
51-
52-
@TestTemplate
53-
@Disabled(
54-
"binary filter that is used by Spark is not working because ExpressionParser.fromJSON doesn't have the Schema to properly parse the filter expression")
55-
public void testBinaryInFilter() {
56-
super.testBinaryInFilter();
57-
}
5849
}

spark/v4.1/spark/src/test/java/org/apache/iceberg/spark/sql/TestSelect.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
import org.apache.iceberg.Parameter;
3333
import org.apache.iceberg.ParameterizedTestExtension;
3434
import org.apache.iceberg.Parameters;
35+
import org.apache.iceberg.PartitionSpec;
36+
import org.apache.iceberg.Schema;
3537
import org.apache.iceberg.Table;
38+
import org.apache.iceberg.catalog.TableIdentifier;
3639
import org.apache.iceberg.events.Listeners;
3740
import org.apache.iceberg.events.ScanEvent;
3841
import org.apache.iceberg.exceptions.ValidationException;
@@ -43,6 +46,7 @@
4346
import org.apache.iceberg.spark.Spark3Util;
4447
import org.apache.iceberg.spark.SparkCatalogConfig;
4548
import org.apache.iceberg.spark.SparkReadOptions;
49+
import org.apache.iceberg.types.Types;
4650
import org.apache.spark.sql.Dataset;
4751
import org.apache.spark.sql.Row;
4852
import org.junit.jupiter.api.AfterEach;
@@ -637,6 +641,29 @@ public void testBinaryInFilter() {
637641
sql("SELECT id, binary FROM %s where binary > X'11'", binaryTableName));
638642
}
639643

644+
@TestTemplate
645+
public void testFixedInFilter() {
646+
// Create table programmatically with fixed type since Spark SQL DDL doesn't support it
647+
Schema schema =
648+
new Schema(
649+
Types.NestedField.required(1, "id", Types.LongType.get()),
650+
Types.NestedField.required(2, "fixed", Types.FixedType.ofLength(2)));
651+
652+
TableIdentifier fixedTableIdent = TableIdentifier.of(tableIdent.namespace(), "fixed_table");
653+
validationCatalog.createTable(fixedTableIdent, schema, PartitionSpec.unpartitioned());
654+
655+
String fixedTableName = tableName("fixed_table");
656+
sql("INSERT INTO %s VALUES (1, X'0000'), (2, X'1111'), (3, X'0011')", fixedTableName);
657+
List<Object[]> expected = ImmutableList.of(row(2L, new byte[] {0x11, 0x11}));
658+
659+
assertEquals(
660+
"Should return all expected rows",
661+
expected,
662+
sql("SELECT id, fixed FROM %s WHERE fixed > X'0011'", fixedTableName));
663+
664+
sql("DROP TABLE IF EXISTS %s", fixedTableName);
665+
}
666+
640667
@TestTemplate
641668
public void testComplexTypeFilter() {
642669
String complexTypeTableName = tableName("complex_table");

0 commit comments

Comments
 (0)