|
| 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, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package org.apache.flink.table.data.columnar; |
| 20 | + |
| 21 | +import org.apache.flink.table.data.columnar.vector.heap.HeapBytesVector; |
| 22 | + |
| 23 | +import org.junit.jupiter.api.DisplayName; |
| 24 | +import org.junit.jupiter.api.Test; |
| 25 | + |
| 26 | +import static org.assertj.core.api.Assertions.assertThat; |
| 27 | + |
| 28 | +class ColumnarArrayDataTest { |
| 29 | + |
| 30 | + @Test |
| 31 | + @DisplayName("getBinary() should work correctly for slices with position 0") |
| 32 | + void testGetBinaryWhenOffsetIsZero() { |
| 33 | + HeapBytesVector vector = new HeapBytesVector(2); |
| 34 | + byte[] sourceData = new byte[] {10, 20, 30, 40, 50}; |
| 35 | + |
| 36 | + vector.appendBytes(0, sourceData, 0, 3); |
| 37 | + |
| 38 | + ColumnarArrayData arrayData = new ColumnarArrayData(vector, 0, 1); |
| 39 | + |
| 40 | + byte[] actual = arrayData.getBinary(0); |
| 41 | + |
| 42 | + byte[] expected = new byte[] {10, 20, 30}; |
| 43 | + assertThat(actual).isEqualTo(expected); |
| 44 | + } |
| 45 | + |
| 46 | + @Test |
| 47 | + @DisplayName("getBinary() should return correct sub-array when slice position is non-zero") |
| 48 | + void testGetBinaryWhenPositionNonZero() { |
| 49 | + HeapBytesVector vector = new HeapBytesVector(3); |
| 50 | + |
| 51 | + // Append a DUMMY element first |
| 52 | + byte[] dummyData = new byte[] {99, 99, 99, 99}; |
| 53 | + vector.appendBytes(0, dummyData, 0, 4); |
| 54 | + |
| 55 | + // Append the REAL data |
| 56 | + byte[] sourceData1 = new byte[] {30, 40, 50, 60}; |
| 57 | + vector.appendBytes(1, sourceData1, 0, 4); |
| 58 | + |
| 59 | + byte[] sourceData2 = new byte[] {70, 80, 90, 100}; |
| 60 | + vector.appendBytes(2, sourceData2, 0, 4); |
| 61 | + |
| 62 | + // Create a ColumnarArrayData that wraps the entire vector |
| 63 | + ColumnarArrayData arrayData = new ColumnarArrayData(vector, 0, 1); |
| 64 | + assertThat(arrayData.getBinary(0)).isEqualTo(dummyData); |
| 65 | + assertThat(arrayData.getBinary(1)).isEqualTo(sourceData1); |
| 66 | + assertThat(arrayData.getBinary(2)).isEqualTo(sourceData2); |
| 67 | + } |
| 68 | +} |
0 commit comments