JingsongLi commented on code in PR #113:
URL: https://github.com/apache/flink-table-store/pull/113#discussion_r869942726


##########
flink-table-store-hive/src/main/java/org/apache/flink/table/store/mapred/TableStoreInputFormat.java:
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.flink.table.store.mapred;
+
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.table.catalog.ObjectIdentifier;
+import org.apache.flink.table.data.binary.BinaryRowData;
+import org.apache.flink.table.store.JobConfWrapper;
+import org.apache.flink.table.store.RowDataContainer;
+import org.apache.flink.table.store.file.FileStore;
+import org.apache.flink.table.store.file.FileStoreImpl;
+import org.apache.flink.table.store.file.FileStoreOptions;
+import org.apache.flink.table.store.file.data.DataFileMeta;
+import 
org.apache.flink.table.store.file.mergetree.compact.DeduplicateMergeFunction;
+import org.apache.flink.table.store.file.mergetree.compact.MergeFunction;
+import 
org.apache.flink.table.store.file.mergetree.compact.ValueCountMergeFunction;
+import org.apache.flink.table.store.file.operation.FileStoreRead;
+import org.apache.flink.table.store.file.operation.FileStoreScan;
+import org.apache.flink.table.types.logical.BigIntType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.util.Preconditions;
+
+import org.apache.hadoop.mapred.InputFormat;
+import org.apache.hadoop.mapred.InputSplit;
+import org.apache.hadoop.mapred.JobConf;
+import org.apache.hadoop.mapred.RecordReader;
+import org.apache.hadoop.mapred.Reporter;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * {@link InputFormat} for table store. It divides all files into {@link 
InputSplit}s (one split per
+ * bucket) and creates {@link RecordReader} for each split.
+ */
+public class TableStoreInputFormat implements InputFormat<Void, 
RowDataContainer> {
+
+    @Override
+    public InputSplit[] getSplits(JobConf jobConf, int numSplits) throws 
IOException {
+        FileStoreImpl store = getFileStore(jobConf);
+        FileStoreScan scan = store.newScan();
+        List<TableStoreInputSplit> result = new ArrayList<>();
+        for (Map.Entry<BinaryRowData, Map<Integer, List<DataFileMeta>>> pe :
+                scan.plan().groupByPartFiles().entrySet()) {
+            for (Map.Entry<Integer, List<DataFileMeta>> be : 
pe.getValue().entrySet()) {
+                BinaryRowData partition = pe.getKey();
+                int bucket = be.getKey();
+                String bucketPath =
+                        store.pathFactory()
+                                .createDataFilePathFactory(partition, bucket)
+                                .toPath("")
+                                .toString();
+                TableStoreInputSplit split =
+                        new TableStoreInputSplit(
+                                store.partitionType(),
+                                store.keyType(),
+                                store.valueType(),
+                                partition,
+                                bucket,
+                                be.getValue(),
+                                bucketPath);
+                result.add(split);
+            }
+        }
+        return result.toArray(new TableStoreInputSplit[0]);
+    }
+
+    @Override
+    public RecordReader<Void, RowDataContainer> getRecordReader(
+            InputSplit inputSplit, JobConf jobConf, Reporter reporter) throws 
IOException {
+        FileStore store = getFileStore(jobConf);
+        FileStoreRead read = store.newRead();
+        TableStoreInputSplit split = (TableStoreInputSplit) inputSplit;
+        org.apache.flink.table.store.file.utils.RecordReader wrapped =
+                read.withDropDelete(true)
+                        .createReader(split.partition(), split.bucket(), 
split.files());
+        long splitLength = split.getLength();
+        return new JobConfWrapper(jobConf).getPrimaryKeyNames().isPresent()
+                ? new TableStorePkRecordReader(wrapped, splitLength)
+                : new TableStoreCountRecordReader(wrapped, splitLength);
+    }
+
+    private FileStoreImpl getFileStore(JobConf jobConf) {
+        JobConfWrapper wrapper = new JobConfWrapper(jobConf);
+
+        String catalogName = wrapper.getCatalogName();
+        String dbName = wrapper.getDbName();
+        String tableName = wrapper.getTableName();
+        ObjectIdentifier identifier = ObjectIdentifier.of(catalogName, dbName, 
tableName);
+
+        Configuration fileStoreOptions = new Configuration();
+        fileStoreOptions.setString(FileStoreOptions.PATH, 
wrapper.getLocation());

Review Comment:
   The location should be table location.
   We can get rid of `catalogName` and `dbName` and `tableName`



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

Reply via email to