|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.apache.iceberg.arrow.vectorized; |
| 20 | + |
| 21 | +import static org.assertj.core.api.Assertions.assertThat; |
| 22 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 23 | +import static org.mockito.Mockito.mock; |
| 24 | +import static org.mockito.Mockito.when; |
| 25 | + |
| 26 | +import java.math.BigDecimal; |
| 27 | +import java.util.function.Supplier; |
| 28 | +import org.apache.arrow.vector.IntVector; |
| 29 | +import org.apache.iceberg.types.Types; |
| 30 | +import org.apache.parquet.column.ColumnDescriptor; |
| 31 | +import org.apache.parquet.schema.PrimitiveType; |
| 32 | +import org.junit.jupiter.api.BeforeEach; |
| 33 | +import org.junit.jupiter.api.Test; |
| 34 | +import org.mockito.InjectMocks; |
| 35 | +import org.mockito.Mock; |
| 36 | +import org.mockito.MockitoAnnotations; |
| 37 | + |
| 38 | +class GenericArrowVectorAccessorFactoryTest { |
| 39 | + @Mock |
| 40 | + Supplier<GenericArrowVectorAccessorFactory.DecimalFactory<BigDecimal>> decimalFactorySupplier; |
| 41 | + |
| 42 | + @Mock Supplier<GenericArrowVectorAccessorFactory.StringFactory<String>> stringFactorySupplier; |
| 43 | + |
| 44 | + @Mock |
| 45 | + Supplier<GenericArrowVectorAccessorFactory.StructChildFactory<Integer>> |
| 46 | + structChildFactorySupplier; |
| 47 | + |
| 48 | + @Mock |
| 49 | + Supplier<GenericArrowVectorAccessorFactory.ArrayFactory<Integer, Integer[]>> arrayFactorySupplier; |
| 50 | + |
| 51 | + @InjectMocks GenericArrowVectorAccessorFactory genericArrowVectorAccessorFactory; |
| 52 | + |
| 53 | + @BeforeEach |
| 54 | + void before() { |
| 55 | + MockitoAnnotations.openMocks(this); |
| 56 | + } |
| 57 | + |
| 58 | + @Test |
| 59 | + void testGetVectorAccessorWithIntVector() { |
| 60 | + IntVector vector = mock(IntVector.class); |
| 61 | + when(vector.get(0)).thenReturn(88); |
| 62 | + |
| 63 | + Types.NestedField nestedField = Types.NestedField.optional(0, "a1", Types.IntegerType.get()); |
| 64 | + ColumnDescriptor columnDescriptor = |
| 65 | + new ColumnDescriptor( |
| 66 | + new String[] {nestedField.name()}, PrimitiveType.PrimitiveTypeName.INT32, 0, 1); |
| 67 | + NullabilityHolder nullabilityHolder = new NullabilityHolder(10000); |
| 68 | + VectorHolder vectorHolder = |
| 69 | + new VectorHolder(columnDescriptor, vector, false, null, nullabilityHolder, nestedField); |
| 70 | + ArrowVectorAccessor actual = genericArrowVectorAccessorFactory.getVectorAccessor(vectorHolder); |
| 71 | + assertThat(actual).isNotNull(); |
| 72 | + assertThat(actual).isInstanceOf(ArrowVectorAccessor.class); |
| 73 | + int intValue = actual.getInt(0); |
| 74 | + assertThat(intValue).isEqualTo(88); |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + void testGetVectorAccessorWithNullVector() { |
| 79 | + assertThatThrownBy( |
| 80 | + () -> { |
| 81 | + genericArrowVectorAccessorFactory.getVectorAccessor(VectorHolder.dummyHolder(1)); |
| 82 | + }) |
| 83 | + .isInstanceOf(UnsupportedOperationException.class) |
| 84 | + .hasMessage("Unsupported vector: null"); |
| 85 | + } |
| 86 | +} |
0 commit comments