zhztheplayer commented on a change in pull request #7030: URL: https://github.com/apache/arrow/pull/7030#discussion_r426395161
########## File path: java/dataset/src/test/java/org/apache/arrow/dataset/file/TestSingleFileDataset.java ########## @@ -0,0 +1,237 @@ +/* + * 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.arrow.dataset.file; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +import org.apache.arrow.dataset.DatasetTypes; +import org.apache.arrow.dataset.filter.Filter; +import org.apache.arrow.dataset.jni.TestNativeDataset; +import org.apache.arrow.dataset.scanner.ScanOptions; +import org.apache.arrow.util.AutoCloseables; +import org.apache.arrow.vector.FieldVector; +import org.apache.arrow.vector.VectorLoader; +import org.apache.arrow.vector.VectorSchemaRoot; +import org.apache.arrow.vector.ipc.message.ArrowRecordBatch; +import org.apache.arrow.vector.types.Types; +import org.apache.arrow.vector.types.pojo.Schema; +import org.apache.avro.generic.GenericData; +import org.apache.avro.generic.GenericRecord; +import org.apache.avro.generic.GenericRecordBuilder; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +import com.google.common.collect.ImmutableList; + +public class TestSingleFileDataset extends TestNativeDataset { + + @ClassRule + public static final TemporaryFolder TMP = new TemporaryFolder(); + + public static final String AVRO_SCHEMA_USER = "user.avsc"; + + @Test + public void testParquetRead() throws Exception { + ParquetWriteSupport writeSupport = new ParquetWriteSupport(AVRO_SCHEMA_USER, TMP.newFolder()); + GenericRecord record = new GenericData.Record(writeSupport.getAvroSchema()); + record.put("id", 1); + record.put("name", "a"); + writeSupport.writeRecord(record); + writeSupport.close(); + + SingleFileDatasetFactory factory = new SingleFileDatasetFactory(rootAllocator(), + FileFormat.PARQUET, FileSystem.LOCAL, writeSupport.getOutputFile()); + ScanOptions options = new ScanOptions(new String[0], Filter.EMPTY, 100); + + Schema schema = inferResultSchemaFromFactory(factory, options); + assertEquals(2, schema.getFields().size()); + assertEquals("id", schema.getFields().get(0).getName()); + assertEquals("name", schema.getFields().get(1).getName()); + assertEquals(Types.MinorType.INT.getType(), schema.getFields().get(0).getType()); + assertEquals(Types.MinorType.VARCHAR.getType(), schema.getFields().get(1).getType()); + + assertSingleTaskProduced(factory, options); + + List<ArrowRecordBatch> datum = collectResultFromFactory(factory, options); + assertEquals(1, datum.size()); + checkParquetReadResult(schema, Collections.singletonList(record), datum); + AutoCloseables.close(datum); + } + + @Test + public void testParquetProjector() throws Exception { + ParquetWriteSupport writeSupport = new ParquetWriteSupport(AVRO_SCHEMA_USER, TMP.newFolder()); Review comment: done. thanks for the suggestion. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org