|
| 1 | +package io.cloudquery.scalar; |
| 2 | + |
| 3 | +import io.cloudquery.types.UUIDType; |
| 4 | +import org.apache.arrow.vector.types.DateUnit; |
| 5 | +import org.apache.arrow.vector.types.FloatingPointPrecision; |
| 6 | +import org.apache.arrow.vector.types.TimeUnit; |
| 7 | +import org.apache.arrow.vector.types.pojo.ArrowType; |
| 8 | +import org.apache.arrow.vector.types.pojo.ExtensionTypeRegistry; |
| 9 | +import org.junit.jupiter.params.ParameterizedTest; |
| 10 | +import org.junit.jupiter.params.provider.Arguments; |
| 11 | +import org.junit.jupiter.params.provider.MethodSource; |
| 12 | + |
| 13 | +import java.time.ZoneOffset; |
| 14 | +import java.util.stream.Stream; |
| 15 | + |
| 16 | +import static org.junit.jupiter.api.Assertions.assertInstanceOf; |
| 17 | + |
| 18 | +public class ScalarTest { |
| 19 | + @ParameterizedTest |
| 20 | + @MethodSource("testDataSource") |
| 21 | + public void shouldCreateScalarFromArrowType(ArrowType arrowType, Class<? extends Scalar<?>> scalarClazz) { |
| 22 | + ExtensionTypeRegistry.register(new UUIDType()); |
| 23 | + |
| 24 | + assertInstanceOf(scalarClazz, Scalar.fromArrowType(arrowType)); |
| 25 | + } |
| 26 | + |
| 27 | + public static Stream<Arguments> testDataSource() { |
| 28 | + return Stream.of( |
| 29 | + // Timestamp |
| 30 | + Arguments.of(new ArrowType.Timestamp(TimeUnit.MILLISECOND, ZoneOffset.UTC.toString()), Timestamp.class), |
| 31 | + |
| 32 | + // String |
| 33 | + Arguments.of(new ArrowType.Utf8(), String.class), |
| 34 | + Arguments.of(new ArrowType.LargeUtf8(), String.class), |
| 35 | + |
| 36 | + // Binary |
| 37 | + Arguments.of(new ArrowType.Binary(), Binary.class), |
| 38 | + Arguments.of(new ArrowType.LargeBinary(), Binary.LargeBinary.class), |
| 39 | + |
| 40 | + // Boolean |
| 41 | + Arguments.of(new ArrowType.Bool(), Bool.class), |
| 42 | + |
| 43 | + // Signed Integers |
| 44 | + Arguments.of(new ArrowType.Int(8, true), Number.Int8.class), |
| 45 | + Arguments.of(new ArrowType.Int(16, true), Number.Int16.class), |
| 46 | + Arguments.of(new ArrowType.Int(32, true), Number.Int32.class), |
| 47 | + Arguments.of(new ArrowType.Int(64, true), Number.Int64.class), |
| 48 | + |
| 49 | + // Unsigned Integers |
| 50 | + Arguments.of(new ArrowType.Int(8, false), Number.UInt8.class), |
| 51 | + Arguments.of(new ArrowType.Int(16, false), Number.UInt16.class), |
| 52 | + Arguments.of(new ArrowType.Int(32, false), Number.UInt32.class), |
| 53 | + Arguments.of(new ArrowType.Int(64, false), Number.UInt64.class), |
| 54 | + |
| 55 | + // Float |
| 56 | + // Arguments.of( new ArrowType.FloatingPoint(FloatingPointPrecision.HALF), Number.Float16.class), |
| 57 | + Arguments.of(new ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE), Number.Float32.class), |
| 58 | + Arguments.of(new ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE), Number.Float64.class), |
| 59 | + |
| 60 | + // Extension |
| 61 | + Arguments.of(new UUIDType(), UUID.class), |
| 62 | + |
| 63 | + // Date |
| 64 | + Arguments.of(new ArrowType.Date(DateUnit.DAY), DateDay.class), |
| 65 | + Arguments.of(new ArrowType.Date(DateUnit.MILLISECOND), DateMilli.class), |
| 66 | + |
| 67 | + // Duration |
| 68 | + Arguments.of(new ArrowType.Duration(TimeUnit.MILLISECOND), Duration.class) |
| 69 | + ); |
| 70 | + } |
| 71 | +} |
0 commit comments