deniskuzZ commented on code in PR #6793:
URL: https://github.com/apache/hive/pull/6793#discussion_r4157224923


##########
llap-server/src/java/org/apache/hadoop/hive/llap/io/encoded/ParquetEncodedDataReader.java:
##########
@@ -0,0 +1,654 @@
+/*
+ * 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.hadoop.hive.llap.io.encoded;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.security.PrivilegedExceptionAction;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.Deque;
+import java.util.IdentityHashMap;
+import java.util.Map;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.stream.Collectors;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FSDataInputStream;
+import org.apache.hadoop.fs.FileRange;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hive.common.io.Allocator;
+import org.apache.hadoop.hive.common.io.Allocator.BufferObjectFactory;
+import org.apache.hadoop.hive.common.io.CacheTag;
+import org.apache.hadoop.hive.common.io.DataCache.BooleanRef;
+import org.apache.hadoop.hive.common.io.DiskRange;
+import org.apache.hadoop.hive.common.io.DiskRangeList;
+import org.apache.hadoop.hive.common.io.encoded.MemoryBuffer;
+import org.apache.hadoop.hive.common.io.encoded.MemoryBufferOrBuffers;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
+import org.apache.hadoop.hive.llap.ConsumerFeedback;
+import org.apache.hadoop.hive.llap.ParquetCacheLayout;
+import org.apache.hadoop.hive.llap.ParquetRangeBuffers;
+import org.apache.hadoop.hive.llap.LlapHiveUtils;
+import org.apache.hadoop.hive.llap.cache.BufferUsageManager;
+import org.apache.hadoop.hive.llap.cache.LlapDataBuffer;
+import org.apache.hadoop.hive.llap.cache.LowLevelCache;
+import org.apache.hadoop.hive.llap.cache.LowLevelCache.Priority;
+import org.apache.hadoop.hive.llap.counters.LlapIOCounters;
+import org.apache.hadoop.hive.llap.counters.QueryFragmentCounters;
+import org.apache.hadoop.hive.llap.io.api.LlapProxy;
+import org.apache.hadoop.hive.llap.io.decode.ParquetEncodedDataConsumer;
+import org.apache.hadoop.hive.ql.io.IOConstants;
+import org.apache.hadoop.hive.ql.io.SyntheticFileId;
+import org.apache.hadoop.hive.ql.io.orc.encoded.CacheChunk;
+import org.apache.hadoop.hive.ql.io.parquet.read.DataWritableReadSupport;
+import org.apache.hadoop.hive.ql.io.parquet.vector.ParquetFooterInputFromCache;
+import org.apache.hadoop.hive.ql.io.orc.encoded.StoppableAllocator;
+import org.apache.hadoop.hive.ql.io.parquet.ParquetRecordReaderBase;
+import 
org.apache.hadoop.hive.ql.io.parquet.vector.VectorizedParquetRecordReader;
+import org.apache.hadoop.hive.ql.exec.Utilities;
+import org.apache.hadoop.hive.ql.exec.vector.VectorizedRowBatchCtx;
+import org.apache.hadoop.hive.ql.metadata.RowLineageUtils;
+import org.apache.hadoop.hive.ql.metadata.VirtualColumn;
+import org.apache.hadoop.mapred.FileSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.hadoop.util.functional.FutureIO;
+import org.apache.parquet.format.converter.ParquetMetadataConverter;
+import org.apache.parquet.filter2.compat.FilterCompat;
+import org.apache.parquet.filter2.compat.RowGroupFilter;
+import org.apache.parquet.filter2.predicate.FilterPredicate;
+import org.apache.parquet.hadoop.ParquetFileReader;
+import org.apache.parquet.hadoop.metadata.BlockMetaData;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.hadoop.metadata.ParquetMetadata;
+import org.apache.parquet.hadoop.util.HadoopStreams;
+import org.apache.parquet.io.InputFile;
+import org.apache.parquet.io.SeekableInputStream;
+import org.apache.parquet.column.ColumnDescriptor;
+import org.apache.parquet.schema.MessageType;
+import org.apache.parquet.schema.Type;
+import org.apache.tez.common.CallableWithNdc;
+
+/**
+ * Reads one Parquet split through the LLAP cache on an IO thread. Row groups 
whose first data
+ * page falls in the split are selected and filtered by their statistics; for 
each one the
+ * projected column chunks are looked up in the cache, the missing ranges are 
requested in one
+ * vectored read, and the chunks are handed to the consumer to decode. The 
next row group's
+ * request is issued before the current one is decoded so its transfer 
overlaps the decode, as
+ * long as the two together stay within this thread's share of the cache. 
Every buffer in a
+ * consumed batch carries exactly one ref, owned by the batch until returnData.
+ */
+public class ParquetEncodedDataReader extends CallableWithNdc<Void>
+    implements ConsumerFeedback<ParquetEncodedColumnBatch> {
+
+  private static final BufferObjectFactory DATA_BUFFER_FACTORY = 
LlapDataBuffer::new;
+
+  private final LowLevelCache lowLevelCache;
+  private final BufferUsageManager bufferManager;
+  private final Configuration daemonConf;
+  private final ParquetCacheLayout layout;
+  private final JobConf jobConf;
+  private final FileSplit split;
+  private final ParquetEncodedDataConsumer consumer;
+  private final QueryFragmentCounters counters;
+  private final UserGroupInformation ugi;
+  private final Path path;
+  private final boolean cacheOnly;
+  /** Bytes of column chunks one IO thread may hold across the row group in 
decode and the next. */
+  private final long lookaheadBudget;
+
+  private Object fileKey;
+  private CacheTag cacheTag;
+  private ParquetMetadata footer;
+  private MessageType requestedSchema;
+  private final AtomicBoolean isStopped = new AtomicBoolean(false);
+
+  public ParquetEncodedDataReader(LowLevelCache lowLevelCache, 
BufferUsageManager bufferManager,
+      Configuration daemonConf, Configuration jobConf, FileSplit split,
+      ParquetEncodedDataConsumer consumer, QueryFragmentCounters counters) 
throws IOException {
+    this.lowLevelCache = lowLevelCache;
+    this.bufferManager = bufferManager;
+    this.daemonConf = daemonConf;
+    this.layout = new ParquetCacheLayout(bufferManager.getAllocator(), 
daemonConf);
+    this.jobConf = (JobConf) jobConf;
+    this.split = split;
+    this.consumer = consumer;
+    this.counters = counters;
+    this.path = split.getPath();
+    this.ugi = UserGroupInformation.getCurrentUser();
+    this.cacheOnly = HiveConf.getBoolVar(jobConf, ConfVars.LLAP_IO_CACHE_ONLY);
+    this.lookaheadBudget = HiveConf.getSizeVar(daemonConf, 
ConfVars.LLAP_IO_MEMORY_MAX_SIZE)
+        / Math.max(1, HiveConf.getIntVar(daemonConf, 
ConfVars.LLAP_IO_THREADPOOL_SIZE));
+  }
+
+  /** Reads the footer once (through the LLAP footer cache when the file has a 
usable key). */
+  public ParquetMetadata loadFooter() throws IOException {

Review Comment:
   Follow-up improvement:
   
   Today the stock reader and the native reader each derive the same six 
per-file facts from the same inputs, in different places, and could drift
   
   ````
     
┌────────────────────────────────────────────┬──────────────────────────────────────────┬───────────────────────────────────────────────┐
                                                             
     │                  Decision                  │                  Stock      
             │                    Native                     │                  
                                           
     
├────────────────────────────────────────────┼──────────────────────────────────────────┼───────────────────────────────────────────────┤
                                                             
     │ requested schema                           │ 
VectorizedParquetRecordReader.initialize │ ParquetEncodedDataReader.loadFooter  
         │                                                             
     
├────────────────────────────────────────────┼──────────────────────────────────────────┼───────────────────────────────────────────────┤
                                                             
     │ timestamp, proleptic, legacy-zone flags    │ 
ParquetRecordReaderBase.getSplit:160-170 │ 
ParquetEncodedDataConsumer.initSchema:120-144 │                                 
                            
     
├────────────────────────────────────────────┼──────────────────────────────────────────┼───────────────────────────────────────────────┤
                                                             
     │ writer timezone                            │ 
VectorizedParquetRecordReader:255        │ consumer :129                        
         │                                                             
     
├────────────────────────────────────────────┼──────────────────────────────────────────┼───────────────────────────────────────────────┤
                                                             
     │ row groups in split (first-data-page rule) │ 
ParquetRecordReaderBase:132-138          │ reader :262-268                      
         │                                                             
     
├────────────────────────────────────────────┼──────────────────────────────────────────┼───────────────────────────────────────────────┤
                                                             
     │ SARG to predicate, statistics filter       │ 
ParquetRecordReaderBase:144-146          │ reader :276-284                      
         │                                                             
     
├────────────────────────────────────────────┼──────────────────────────────────────────┼───────────────────────────────────────────────┤
                                                             
     │ decimal64                                  │ plan ctx                    
             │ conf string (F4)                              │                  
                                           
     
└────────────────────────────────────────────┴──────────────────────────────────────────┴───────────────────────────────────────────────┘
     
   ````
   The proposal is one class in ql, built once per split from the things both 
readers already have, whose fields are those decisions:  
   ````
   /** Everything a Parquet split read decides once from the footer and the job 
conf, shared by both readers. */                                                
                                         
     public final class ParquetSplitPlan {                                      
                                                                                
                                           
       public final MessageType requestedSchema;                                
                                                                                
                                           
       public final List<BlockMetaData> rowGroups;        // in-split, 
statistics-filtered                                                             
                                                    
       public final TimestampConversionOptions conversions;                     
                                                                                
                                           
       public final FilterPredicate predicate;             // may be null       
                                                                                
                                           
                                                                                
                                                                                
                                           
       public static ParquetSplitPlan of(JobConf conf, ParquetMetadata footer, 
long splitStart, long splitLength) { … }                                        
                                            
     }    
   ````
   VectorizedParquetRecordReader.initialize and 
ParquetEncodedDataReader.loadFooter both become "footer, then 
ParquetSplitPlan.of(...)", and ParquetEncodedDataConsumer.initSchema disappears 
because the consumer receives the plan. toFilterPredicate and the five 
DataWritableReadSupport statics go back behind it, so the public surface 
between ql and llap-server is one type instead of six methods.
   



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to