Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions data/src/test/java/org/apache/iceberg/data/DataGenerators.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,6 @@ public Schema schema() {
}

// Generator for reader default-value tests across primitive types.
// FIXED is excluded: Spark's InternalRowConverter expects a ByteBuffer but the generator produces
// byte[] (ClassCastException).
// TODO: include FIXED once Spark's converter handles it.
static class PrimitiveDefaults implements DataGenerator {
static final Schema READ_SCHEMA =
new Schema(
Expand Down Expand Up @@ -302,7 +299,18 @@ static class PrimitiveDefaults implements DataGenerator {
14,
"time_with_default",
Types.TimeType.get(),
Literal.of(DateTimeUtil.isoTimeToMicros("23:59:59.999999"))));
Literal.of(DateTimeUtil.isoTimeToMicros("23:59:59.999999"))),
optionalWithDefault(
15,
"fixed_with_default",
Types.FixedType.ofLength(16),
Literal.of(
ByteBuffer.wrap(
new byte[] {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
}))
.to(Types.FixedType.ofLength(16))));

static final Schema WRITE_SCHEMA = new Schema(required(1, "id", Types.LongType.get()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.iceberg.Schema;
import org.apache.iceberg.data.Record;
import org.apache.iceberg.types.Type;
import org.apache.iceberg.types.Types;
import org.apache.iceberg.util.ByteBuffers;
import org.apache.spark.sql.catalyst.InternalRow;
import org.apache.spark.sql.catalyst.expressions.GenericInternalRow;
import org.apache.spark.sql.catalyst.util.ArrayBasedMapData;
Expand Down Expand Up @@ -79,13 +79,7 @@ private static Object convert(Type type, Object value) {
: ChronoUnit.MICROS.between(EPOCH, ((LocalDateTime) value).atZone(ZoneId.of("UTC")));
case STRING -> UTF8String.fromString((String) value);
case UUID -> UTF8String.fromString(value.toString());
case FIXED, BINARY -> {
ByteBuffer buffer = (ByteBuffer) value;
yield Arrays.copyOfRange(
buffer.array(),
buffer.arrayOffset() + buffer.position(),
buffer.arrayOffset() + buffer.remaining());
}
case FIXED, BINARY -> toByteArray(value);
case DECIMAL -> Decimal.apply((BigDecimal) value);
case STRUCT -> convert((Types.StructType) type, (Record) value);
case LIST ->
Expand All @@ -112,4 +106,15 @@ private static Object convert(Type type, Object value) {
"Unsupported type for conversion to InternalRow: " + type);
};
}

private static byte[] toByteArray(Object value) {
if (value instanceof byte[] bytes) {
return bytes;
} else if (value instanceof ByteBuffer buffer) {
return ByteBuffers.toByteArray(buffer);
}

throw new UnsupportedOperationException(
"Unsupported binary value class: " + value.getClass().getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@
public class TestSparkFormatModel extends BaseFormatModelTests<InternalRow> {

private static final Set<Type.TypeID> UNSUPPORTED_TYPE_IDS =
Set.of(
Type.TypeID.TIME,
Type.TypeID.TIMESTAMP_NANO,
// TODO: Remove once FIXED is working on TCK
Type.TypeID.FIXED);
Set.of(Type.TypeID.TIME, Type.TypeID.TIMESTAMP_NANO);

@Override
protected Collection<Type.TypeID> unsupportedTypeIds() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.iceberg.Schema;
import org.apache.iceberg.data.Record;
import org.apache.iceberg.types.Type;
import org.apache.iceberg.types.Types;
import org.apache.iceberg.util.ByteBuffers;
import org.apache.spark.sql.catalyst.InternalRow;
import org.apache.spark.sql.catalyst.expressions.GenericInternalRow;
import org.apache.spark.sql.catalyst.util.ArrayBasedMapData;
Expand Down Expand Up @@ -79,13 +79,7 @@ private static Object convert(Type type, Object value) {
: ChronoUnit.MICROS.between(EPOCH, ((LocalDateTime) value).atZone(ZoneId.of("UTC")));
case STRING -> UTF8String.fromString((String) value);
case UUID -> UTF8String.fromString(value.toString());
case FIXED, BINARY -> {
ByteBuffer buffer = (ByteBuffer) value;
yield Arrays.copyOfRange(
buffer.array(),
buffer.arrayOffset() + buffer.position(),
buffer.arrayOffset() + buffer.remaining());
}
case FIXED, BINARY -> toByteArray(value);
case DECIMAL -> Decimal.apply((BigDecimal) value);
case STRUCT -> convert((Types.StructType) type, (Record) value);
case LIST ->
Expand All @@ -112,4 +106,15 @@ private static Object convert(Type type, Object value) {
"Unsupported type for conversion to InternalRow: " + type);
};
}

private static byte[] toByteArray(Object value) {
if (value instanceof byte[] bytes) {
return bytes;
} else if (value instanceof ByteBuffer buffer) {
return ByteBuffers.toByteArray(buffer);
}

throw new UnsupportedOperationException(
"Unsupported binary value class: " + value.getClass().getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@
public class TestSparkFormatModel extends BaseFormatModelTests<InternalRow> {

private static final Set<Type.TypeID> UNSUPPORTED_TYPE_IDS =
Set.of(
Type.TypeID.TIME,
Type.TypeID.TIMESTAMP_NANO,
// TODO: Remove once FIXED is working on TCK
Type.TypeID.FIXED);
Set.of(Type.TypeID.TIME, Type.TypeID.TIMESTAMP_NANO);

@Override
protected Collection<Type.TypeID> unsupportedTypeIds() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.apache.iceberg.Schema;
import org.apache.iceberg.data.Record;
import org.apache.iceberg.types.Type;
import org.apache.iceberg.types.Types;
import org.apache.iceberg.util.ByteBuffers;
import org.apache.spark.sql.catalyst.InternalRow;
import org.apache.spark.sql.catalyst.expressions.GenericInternalRow;
import org.apache.spark.sql.catalyst.util.ArrayBasedMapData;
Expand Down Expand Up @@ -79,13 +79,7 @@ private static Object convert(Type type, Object value) {
: ChronoUnit.MICROS.between(EPOCH, ((LocalDateTime) value).atZone(ZoneId.of("UTC")));
case STRING -> UTF8String.fromString((String) value);
case UUID -> UTF8String.fromString(value.toString());
case FIXED, BINARY -> {
ByteBuffer buffer = (ByteBuffer) value;
yield Arrays.copyOfRange(
buffer.array(),
buffer.arrayOffset() + buffer.position(),
buffer.arrayOffset() + buffer.remaining());
}
case FIXED, BINARY -> toByteArray(value);
case DECIMAL -> Decimal.apply((BigDecimal) value);
case STRUCT -> convert((Types.StructType) type, (Record) value);
case LIST ->
Expand All @@ -112,4 +106,15 @@ private static Object convert(Type type, Object value) {
"Unsupported type for conversion to InternalRow: " + type);
};
}

private static byte[] toByteArray(Object value) {
if (value instanceof byte[] bytes) {
return bytes;
} else if (value instanceof ByteBuffer buffer) {
return ByteBuffers.toByteArray(buffer);
}

throw new UnsupportedOperationException(
"Unsupported binary value class: " + value.getClass().getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@
public class TestSparkFormatModel extends BaseFormatModelTests<InternalRow> {

private static final Set<Type.TypeID> UNSUPPORTED_TYPE_IDS =
Set.of(
Type.TypeID.TIME,
Type.TypeID.TIMESTAMP_NANO,
// TODO: Remove once FIXED is working on TCK
Type.TypeID.FIXED);
Set.of(Type.TypeID.TIME, Type.TypeID.TIMESTAMP_NANO);

@Override
protected Collection<Type.TypeID> unsupportedTypeIds() {
Expand Down
Loading