alexdongli0829 commented on code in PR #4199:
URL: https://github.com/apache/hive/pull/4199#discussion_r1222438852


##########
hbase-handler/src/java/org/apache/hadoop/hive/hbase/HiveHBaseTableInputFormatV2.java:
##########
@@ -0,0 +1,370 @@
+/*
+ * 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.hbase;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.HBaseConfiguration;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.client.Connection;
+import org.apache.hadoop.hbase.client.ConnectionFactory;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.Scan;
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+import org.apache.hadoop.hbase.mapred.TableMapReduceUtil;
+import org.apache.hadoop.hbase.mapreduce.TableSplit;
+import org.apache.hadoop.hive.hbase.ColumnMappings.ColumnMapping;
+import org.apache.hadoop.hive.ql.exec.SerializationUtilities;
+import org.apache.hadoop.hive.ql.index.IndexPredicateAnalyzer;
+import org.apache.hadoop.hive.ql.index.IndexSearchCondition;
+import org.apache.hadoop.hive.ql.plan.ExprNodeDesc;
+import org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc;
+import org.apache.hadoop.hive.ql.plan.TableScanDesc;
+import org.apache.hadoop.hive.serde.serdeConstants;
+import org.apache.hadoop.hive.serde2.SerDeException;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo;
+import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils;
+import org.apache.hadoop.hive.shims.ShimLoader;
+import org.apache.hadoop.mapred.InputFormat;
+import org.apache.hadoop.mapred.InputSplit;
+import org.apache.hadoop.mapred.RecordReader;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.Reporter;
+import org.apache.hadoop.mapreduce.Job;
+import org.apache.hadoop.mapreduce.JobContext;
+import org.apache.hadoop.mapreduce.TaskAttemptContext;
+import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * It`s the pair with {@link HiveHBaseTableInputFormat}, instead of directly 
extending TableInputFormatBase, using delegate
+ * to make the class ONLY inherit from mapred.*, which makes the hierarchy 
more clear and avoid downstream application
+ * like spark issue, ex https://github.com/apache/spark/pull/31302
+ */
+public class HiveHBaseTableInputFormatV2 implements 
InputFormat<ImmutableBytesWritable, ResultWritable> {
+
+  static final Logger LOG = 
LoggerFactory.getLogger(HiveHBaseTableInputFormatV2.class);
+  private static final Object HBASE_TABLE_MONITOR = new Object();
+
+  private HiveHBaseTableInputFormatDelegate delegate = new 
HiveHBaseTableInputFormatDelegate();
+
+  @Override public RecordReader<ImmutableBytesWritable, ResultWritable> 
getRecordReader(InputSplit split,
+                                                                               
         JobConf jobConf, final Reporter reporter) throws IOException {
+
+    HBaseSplit hbaseSplit = (HBaseSplit) split;
+    TableSplit tableSplit = hbaseSplit.getTableSplit();
+
+    final org.apache.hadoop.mapreduce.RecordReader<ImmutableBytesWritable, 
Result> recordReader;
+
+    Job job = new Job(jobConf);
+    TaskAttemptContext tac = 
ShimLoader.getHadoopShims().newTaskAttemptContext(job.getConfiguration(), 
reporter);
+
+    final Connection conn;
+
+    synchronized (HBASE_TABLE_MONITOR) {
+      conn = 
ConnectionFactory.createConnection(HBaseConfiguration.create(jobConf));

Review Comment:
   The connection is used by the RecordReader, so the close will be involved in 
the reader close() which at line 107



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