paul-rogers commented on a change in pull request #1951: DRILL-7454: Convert 
Avro to EVF
URL: https://github.com/apache/drill/pull/1951#discussion_r363563012
 
 

 ##########
 File path: 
exec/java-exec/src/main/java/org/apache/drill/exec/store/avro/AvroBatchReader.java
 ##########
 @@ -0,0 +1,368 @@
+/*
+ * 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.drill.exec.store.avro;
+
+import org.apache.avro.Schema;
+import org.apache.avro.file.DataFileReader;
+import org.apache.avro.generic.GenericArray;
+import org.apache.avro.generic.GenericContainer;
+import org.apache.avro.generic.GenericDatumReader;
+import org.apache.avro.generic.GenericFixed;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.avro.mapred.FsInput;
+import org.apache.avro.util.Utf8;
+import org.apache.drill.common.exceptions.UserException;
+import org.apache.drill.exec.physical.impl.scan.file.FileScanFramework;
+import org.apache.drill.exec.physical.impl.scan.framework.ManagedReader;
+import org.apache.drill.exec.physical.resultSet.ResultSetLoader;
+import org.apache.drill.exec.physical.resultSet.RowSetLoader;
+import org.apache.drill.exec.record.metadata.ColumnMetadata;
+import org.apache.drill.exec.record.metadata.TupleMetadata;
+import org.apache.drill.exec.util.ImpersonationUtil;
+import org.apache.drill.exec.vector.accessor.ArrayWriter;
+import org.apache.drill.exec.vector.accessor.DictWriter;
+import org.apache.drill.exec.vector.accessor.ObjectWriter;
+import org.apache.drill.exec.vector.accessor.ScalarWriter;
+import org.apache.drill.exec.vector.accessor.TupleWriter;
+import org.apache.drill.shaded.guava.com.google.common.base.Charsets;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.joda.time.DateTimeConstants;
+import org.joda.time.Period;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.IntBuffer;
+import java.security.PrivilegedExceptionAction;
+import java.util.List;
+import java.util.Map;
+
+public class AvroBatchReader implements 
ManagedReader<FileScanFramework.FileSchemaNegotiator> {
+
+  private static final Logger logger = 
LoggerFactory.getLogger(AvroBatchReader.class);
+
+  // currently config is unused but maybe used later
+  private final AvroReaderConfig config;
+
+  private Path filePath;
+  private long endPosition;
+  private DataFileReader<GenericContainer> reader;
+  private ResultSetLoader loader;
+  // re-use container instance
+  private GenericContainer container = null;
+
+  public AvroBatchReader(AvroReaderConfig config) {
+    this.config = config;
+  }
+
+  @Override
+  public boolean open(FileScanFramework.FileSchemaNegotiator negotiator) {
+    FileSplit split = negotiator.split();
+    filePath = split.getPath();
+
+    // Avro files are splittable, define reading start / end positions
+    long startPosition = split.getStart();
+    endPosition = startPosition + split.getLength();
+
+    logger.debug("Processing Avro file: {}, start position: {}, end position: 
{}",
+      filePath, startPosition, endPosition);
+
+    reader = prepareReader(split, negotiator.fileSystem(),
+      negotiator.userName(), 
negotiator.context().getFragmentContext().getQueryUserName());
+
+    logger.debug("Avro file schema: {}", reader.getSchema());
+    TupleMetadata schema = AvroSchemaUtil.convert(reader.getSchema());
 
 Review comment:
   I actually don't have a good example in mind. Planner-side schema planning 
is not really an EVF-specific thing. We used an external schema for CSV files 
using your provisioned schema mechanism. There is the new metadata mechanism 
that was recently added. We do partition and row group pruning for Parquet 
using external metadata.
   
   So, planner-side schema analysis is probably something new we'd want to add. 
I believe that Avro, when used for RPC, defines the schema separate from the 
data. Is something like that available when Avro is used as a file format?
   
   For now, perhaps we can just do the schema planning at open time for each 
file. Then, if that code just does Avro --> ColumnMetadata translation, the 
code can be moved earlier in the process if we find a way to obtain the schema 
earlier.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to