|
| 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.pinot.plugin.inputformat.parquet; |
| 20 | + |
| 21 | +import java.io.File; |
| 22 | +import java.util.ArrayList; |
| 23 | +import java.util.List; |
| 24 | +import java.util.Map; |
| 25 | +import org.apache.avro.Schema; |
| 26 | +import org.apache.avro.generic.GenericData; |
| 27 | +import org.apache.avro.generic.GenericRecord; |
| 28 | +import org.apache.hadoop.fs.Path; |
| 29 | +import org.apache.parquet.hadoop.ParquetWriter; |
| 30 | +import org.apache.pinot.plugin.inputformat.avro.AvroUtils; |
| 31 | +import org.apache.pinot.spi.data.FieldSpec; |
| 32 | +import org.apache.pinot.spi.data.readers.AbstractRecordReaderTest; |
| 33 | +import org.apache.pinot.spi.data.readers.RecordReader; |
| 34 | + |
| 35 | + |
| 36 | +public class ParquetNativeRecordReaderTest extends AbstractRecordReaderTest { |
| 37 | + private final File _dataFile = new File(_tempDir, "data.parquet"); |
| 38 | + |
| 39 | + @Override |
| 40 | + protected RecordReader createRecordReader() |
| 41 | + throws Exception { |
| 42 | + ParquetNativeRecordReader recordReader = new ParquetNativeRecordReader(); |
| 43 | + recordReader.init(_dataFile, _sourceFields, null); |
| 44 | + return recordReader; |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + protected void writeRecordsToFile(List<Map<String, Object>> recordsToWrite) |
| 49 | + throws Exception { |
| 50 | + Schema schema = AvroUtils.getAvroSchemaFromPinotSchema(getPinotSchema()); |
| 51 | + List<GenericRecord> records = new ArrayList<>(); |
| 52 | + for (Map<String, Object> r : recordsToWrite) { |
| 53 | + GenericRecord record = new GenericData.Record(schema); |
| 54 | + for (FieldSpec fieldSpec : getPinotSchema().getAllFieldSpecs()) { |
| 55 | + record.put(fieldSpec.getName(), r.get(fieldSpec.getName())); |
| 56 | + } |
| 57 | + records.add(record); |
| 58 | + } |
| 59 | + try (ParquetWriter<GenericRecord> writer = ParquetUtils |
| 60 | + .getParquetAvroWriter(new Path(_dataFile.getAbsolutePath()), schema)) { |
| 61 | + for (GenericRecord record : records) { |
| 62 | + writer.write(record); |
| 63 | + } |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments