yuqi1129 commented on code in PR #8963: URL: https://github.com/apache/gravitino/pull/8963#discussion_r2476319692
########## lance/lance-common/src/test/java/org/apache/gravitino/lance/common/TestArrowIPC.java: ########## @@ -1,83 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.gravitino.lance.common; - -import java.io.File; -import java.io.FileOutputStream; -import java.util.Arrays; -import org.apache.arrow.memory.BufferAllocator; -import org.apache.arrow.memory.RootAllocator; -import org.apache.arrow.vector.IntVector; -import org.apache.arrow.vector.VarCharVector; -import org.apache.arrow.vector.VectorSchemaRoot; -import org.apache.arrow.vector.ipc.ArrowStreamWriter; -import org.apache.arrow.vector.types.pojo.ArrowType; -import org.apache.arrow.vector.types.pojo.Field; -import org.apache.arrow.vector.types.pojo.Schema; -import org.apache.arrow.vector.util.Text; -import org.junit.jupiter.api.Test; - -public class TestArrowIPC { - - private static final String FILENAME = "/tmp/initial_data.arrow"; - private static final int RECORD_COUNT = 3; - - @Test - void testIPC() throws Exception { Review Comment: There is no need to remove this test; you can just add a test to verify `parseArrowIpcStream` based on it. ########## lance/lance-common/src/test/java/org/apache/gravitino/lance/common/ops/gravitino/TestLanceDataTypeConverter.java: ########## @@ -270,10 +275,11 @@ void testUnsupportedTypeThrowsException() { assertThrows(UnsupportedOperationException.class, () -> CONVERTER.fromGravitino(unparsedType)); } - @Test - void testToGravitinoNotImplemented() { - assertThrows( - UnsupportedOperationException.class, () -> CONVERTER.toGravitino(ArrowType.Utf8.INSTANCE)); + @ParameterizedTest(name = "[{index}] {0}") + @MethodSource("toGravitinoArguments") + void testToGravitino(String testName, Field arrowField, Type expectedGravitinoType) { + Type convertedType = CONVERTER.toGravitino(arrowField); + assertEquals(expectedGravitinoType, convertedType); Review Comment: Can you verify `arrowFileld == CONVERTER.fromGravitino(CONVERTER.toGravitino(arrowField))`? ########## lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/gravitino/GravitinoLanceNamespaceWrapper.java: ########## @@ -646,157 +608,44 @@ public CreateTableResponse createTable( return response; } - private ArrowRecordBatchList parseArrowIpcStream(byte[] stream) { + private JsonArrowSchema toJsonArrowSchema(Column[] columns) { + List<Field> fields = + Arrays.stream(columns) + .map(col -> CONVERTER.toArrowField(col.name(), col.dataType(), col.nullable())) + .collect(Collectors.toList()); + + return JsonArrowSchemaConverter.convertToJsonArrowSchema( + new org.apache.arrow.vector.types.pojo.Schema(fields)); + } + + private org.apache.arrow.vector.types.pojo.Schema parseArrowIpcStream(byte[] stream) { + org.apache.arrow.vector.types.pojo.Schema schema; + try (BufferAllocator allocator = new RootAllocator(); ByteArrayInputStream bais = new ByteArrayInputStream(stream); ArrowStreamReader reader = new ArrowStreamReader(bais, allocator)) { - - org.apache.arrow.vector.types.pojo.Schema schema = reader.getVectorSchemaRoot().getSchema(); - List<VectorSchemaRoot> batches = new ArrayList<>(); - - while (reader.loadNextBatch()) { - VectorSchemaRoot root = reader.getVectorSchemaRoot(); Review Comment: Why do we abandon the data part? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
