JingsongLi commented on a change in pull request #12025:
URL: https://github.com/apache/flink/pull/12025#discussion_r425536040



##########
File path: 
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/connectors/hive/ConsumeOrder.java
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.connectors.hive;
+
+/**
+ * {@link ConsumeOrder} defines the orders to continuously consume stream 
source.
+ */
+public enum ConsumeOrder {
+
+       /**
+        * create-time compare partition/file creation time,
+        * this is not the partition create time in Hive metaStore,
+        * but the folder/file create time in filesystem.
+        */
+       CREATE_TIME_ORDER("create-time"),
+
+       /**
+        * partition-time compare time represented by partition name.
+        */
+       PARTITION_TIME_ORDER("partition-time");
+
+       private final String order;
+       ConsumeOrder(String order) {
+               this.order = order;
+       }
+
+       @Override
+       public String toString() {
+               return order;
+       }
+
+       /**
+        * Get {@link ConsumeOrder} from consume order string.
+        */
+       public static ConsumeOrder getConsumeOrder(String consumeOrderStr) {
+               for (ConsumeOrder consumeOrder : ConsumeOrder.values()) {

Review comment:
       `ConsumeOrder.values()` -> `values()`

##########
File path: 
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/connectors/hive/ConsumeOrder.java
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.connectors.hive;
+
+/**
+ * {@link ConsumeOrder} defines the orders to continuously consume stream 
source.
+ */
+public enum ConsumeOrder {
+
+       /**
+        * create-time compare partition/file creation time,
+        * this is not the partition create time in Hive metaStore,
+        * but the folder/file create time in filesystem.
+        */
+       CREATE_TIME_ORDER("create-time"),
+
+       /**
+        * partition-time compare time represented by partition name.
+        */
+       PARTITION_TIME_ORDER("partition-time");
+
+       private final String order;
+       ConsumeOrder(String order) {

Review comment:
       Above should have a blank line.

##########
File path: 
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/connectors/hive/read/HiveTableFileInputFormat.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.connectors.hive.read;
+
+import org.apache.flink.api.common.functions.RuntimeContext;
+import org.apache.flink.api.common.io.FileInputFormat;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.connectors.hive.HiveTablePartition;
+import org.apache.flink.core.fs.FileInputSplit;
+import org.apache.flink.table.data.RowData;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+
+import java.io.IOException;
+import java.net.URI;
+
+/**
+ * A {@link FileInputFormat} that wraps a {@link HiveTableInputFormat}.
+ */
+public class HiveTableFileInputFormat extends FileInputFormat<RowData> {
+
+       private HiveTableInputFormat inputFormat;
+       private HiveTablePartition hiveTablePartition;
+
+       public HiveTableFileInputFormat(
+                       HiveTableInputFormat inputFormat,
+                       HiveTablePartition hiveTablePartition) {
+               this.inputFormat = inputFormat;
+               this.hiveTablePartition = hiveTablePartition;
+       }
+
+       @Override
+       public void open(FileInputSplit fileSplit) throws IOException {
+               URI uri = fileSplit.getPath().toUri();
+               HiveTableInputSplit split = new HiveTableInputSplit(
+                               fileSplit.getSplitNumber(),
+                               new FileSplit(new Path(uri), 
fileSplit.getStart(), fileSplit.getLength(), (String[]) null),
+                               inputFormat.getJobConf(),
+                               hiveTablePartition
+               );
+               inputFormat.open(split);
+       }
+
+       @Override
+       public boolean reachedEnd() throws IOException {
+               return inputFormat.reachedEnd();
+       }
+
+       @Override
+       public RowData nextRecord(RowData reuse) throws IOException {
+               return inputFormat.nextRecord(reuse);
+       }
+
+       @Override
+       public void configure(Configuration parameters) {
+               inputFormat.configure(parameters);

Review comment:
       A better way is first `super.`, second do own works.
   same below.

##########
File path: 
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/connectors/hive/HiveTableSource.java
##########
@@ -261,6 +267,57 @@ private boolean isStreamingSource() {
                return new DataStreamSource<>(source);
        }
 
+       private DataStream<RowData> createStreamSourceForNonPartitionTable(
+                       StreamExecutionEnvironment execEnv,
+                       TypeInformation<RowData> typeInfo,
+                       HiveTableInputFormat inputFormat,
+                       HiveTablePartition hiveTable) {
+               HiveTableFileInputFormat fileInputFormat = new 
HiveTableFileInputFormat(
+                               inputFormat,
+                               hiveTable);
+               fileInputFormat.setFilePath(getFilePath());
+
+               final Map<String, String> properties = 
catalogTable.getOptions();
+
+               String consumeOrderStr = properties.getOrDefault(
+                               STREAMING_SOURCE_CONSUME_ORDER.key(),
+                               STREAMING_SOURCE_CONSUME_ORDER.defaultValue());
+               ConsumeOrder consumeOrder = 
ConsumeOrder.getConsumeOrder(consumeOrderStr);
+               if (consumeOrder != ConsumeOrder.CREATE_TIME_ORDER) {
+                       throw new UnsupportedOperationException("Unsupported 
consumer order: " + consumeOrder);
+               }
+
+               String consumeOffset = properties.getOrDefault(
+                               STREAMING_SOURCE_CONSUME_START_OFFSET.key(),
+                               
STREAMING_SOURCE_CONSUME_START_OFFSET.defaultValue());
+               long currentReadTime = Long.MIN_VALUE;
+               if (consumeOffset != null) {

Review comment:
       never null.

##########
File path: 
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/connectors/hive/HiveTableSource.java
##########
@@ -261,6 +267,57 @@ private boolean isStreamingSource() {
                return new DataStreamSource<>(source);
        }
 
+       private DataStream<RowData> createStreamSourceForNonPartitionTable(
+                       StreamExecutionEnvironment execEnv,
+                       TypeInformation<RowData> typeInfo,
+                       HiveTableInputFormat inputFormat,
+                       HiveTablePartition hiveTable) {
+               HiveTableFileInputFormat fileInputFormat = new 
HiveTableFileInputFormat(
+                               inputFormat,
+                               hiveTable);
+               fileInputFormat.setFilePath(getFilePath());

Review comment:
       Remove `getFilePath`, we can get path from `allHivePartitions`(should be 
a single object when no partitions.).

##########
File path: 
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/connectors/hive/read/HiveTableFileInputFormat.java
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.connectors.hive.read;
+
+import org.apache.flink.api.common.functions.RuntimeContext;
+import org.apache.flink.api.common.io.FileInputFormat;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.connectors.hive.HiveTablePartition;
+import org.apache.flink.core.fs.FileInputSplit;
+import org.apache.flink.table.data.RowData;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.mapred.FileSplit;
+
+import java.io.IOException;
+import java.net.URI;
+
+/**
+ * A {@link FileInputFormat} that wraps a {@link HiveTableInputFormat}.

Review comment:
       Please add comments:
   - Only support FileInputSplit
   - Only support renaming inserting 
   - getSplit use flinks instead format.

##########
File path: 
flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableSourceTest.java
##########
@@ -531,6 +534,76 @@ public void testStreamPartitionRead() throws Exception {
                job.cancel();
        }
 
+       @Test(timeout = 30000)
+       public void testNonPartitionStreamingSourceWithMapredReader() throws 
Exception {
+               testNonPartitionStreamingSource(true, "test_mapred_reader");
+       }
+
+       @Test(timeout = 30000)
+       public void testNonPartitionStreamingSourceWithVectorizedReader() 
throws Exception {
+               testNonPartitionStreamingSource(false, 
"test_vectorized_reader");
+       }
+
+       private void testNonPartitionStreamingSource(Boolean useMapredReader, 
String tblName) throws Exception {
+               final String catalogName = "hive";
+               final String dbName = "source_db";
+               hiveShell.execute("CREATE TABLE source_db." + tblName + " (" +
+                               "  a INT," +
+                               "  b CHAR(1) " +
+                               ") TBLPROPERTIES (" +
+                               "  'streaming-source.enable'='true'," +

Review comment:
       `useMapredReader` only works in parquet and orc, you should use them.

##########
File path: 
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/connectors/hive/HiveTableSource.java
##########
@@ -261,6 +267,57 @@ private boolean isStreamingSource() {
                return new DataStreamSource<>(source);
        }
 
+       private DataStream<RowData> createStreamSourceForNonPartitionTable(
+                       StreamExecutionEnvironment execEnv,
+                       TypeInformation<RowData> typeInfo,
+                       HiveTableInputFormat inputFormat,
+                       HiveTablePartition hiveTable) {
+               HiveTableFileInputFormat fileInputFormat = new 
HiveTableFileInputFormat(
+                               inputFormat,
+                               hiveTable);
+               fileInputFormat.setFilePath(getFilePath());
+
+               final Map<String, String> properties = 
catalogTable.getOptions();

Review comment:
       ```
   Configuration configuration = new Configuration();
   options.forEach(configuration::setString)
   ```
   We can use `Configuration` to get option.

##########
File path: 
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/connectors/hive/ConsumeOrder.java
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.connectors.hive;
+
+/**
+ * {@link ConsumeOrder} defines the orders to continuously consume stream 
source.
+ */
+public enum ConsumeOrder {
+
+       /**
+        * create-time compare partition/file creation time,
+        * this is not the partition create time in Hive metaStore,
+        * but the folder/file create time in filesystem.
+        */
+       CREATE_TIME_ORDER("create-time"),
+
+       /**
+        * partition-time compare time represented by partition name.
+        */
+       PARTITION_TIME_ORDER("partition-time");
+
+       private final String order;
+       ConsumeOrder(String order) {
+               this.order = order;
+       }
+
+       @Override
+       public String toString() {
+               return order;
+       }
+
+       /**
+        * Get {@link ConsumeOrder} from consume order string.
+        */
+       public static ConsumeOrder getConsumeOrder(String consumeOrderStr) {
+               for (ConsumeOrder consumeOrder : ConsumeOrder.values()) {
+                       if (consumeOrder.order.equals(consumeOrderStr)) {

Review comment:
       `equalsIgnoreCase`

##########
File path: 
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/connectors/hive/ConsumeOrder.java
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.connectors.hive;
+
+/**
+ * {@link ConsumeOrder} defines the orders to continuously consume stream 
source.
+ */
+public enum ConsumeOrder {
+
+       /**
+        * create-time compare partition/file creation time,
+        * this is not the partition create time in Hive metaStore,
+        * but the folder/file create time in filesystem.
+        */
+       CREATE_TIME_ORDER("create-time"),
+
+       /**
+        * partition-time compare time represented by partition name.
+        */
+       PARTITION_TIME_ORDER("partition-time");
+
+       private final String order;
+       ConsumeOrder(String order) {
+               this.order = order;
+       }
+
+       @Override
+       public String toString() {
+               return order;
+       }
+
+       /**
+        * Get {@link ConsumeOrder} from consume order string.
+        */
+       public static ConsumeOrder getConsumeOrder(String consumeOrderStr) {
+               for (ConsumeOrder consumeOrder : ConsumeOrder.values()) {
+                       if (consumeOrder.order.equals(consumeOrderStr)) {
+                               return consumeOrder;
+                       }
+               }
+               return null;

Review comment:
       throw exception, we should not pass a null to operators.




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to