This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-paimon.git
The following commit(s) were added to refs/heads/master by this push:
new cf9827e91 [spark] Extract SparkInputPartitionReader from paimon spark
connector (#658)
cf9827e91 is described below
commit cf9827e9107b0eb50a8be8fe1f53a14cd3340c77
Author: Tyrantlucifer <[email protected]>
AuthorDate: Tue Mar 21 13:45:22 2023 +0800
[spark] Extract SparkInputPartitionReader from paimon spark connector (#658)
---
.../apache/paimon/spark/SparkInputPartition.java | 26 +--------
.../paimon/spark/SparkInputPartitionReader.java | 64 ++++++++++++++++++++++
.../paimon/spark/SparkInputPartitionReader.java | 64 ++++++++++++++++++++++
.../apache/paimon/spark/SparkReaderFactory.java | 26 +--------
4 files changed, 130 insertions(+), 50 deletions(-)
diff --git
a/paimon-spark/paimon-spark-2/src/main/java/org/apache/paimon/spark/SparkInputPartition.java
b/paimon-spark/paimon-spark-2/src/main/java/org/apache/paimon/spark/SparkInputPartition.java
index 5b4b5085a..71bb61b00 100644
---
a/paimon-spark/paimon-spark-2/src/main/java/org/apache/paimon/spark/SparkInputPartition.java
+++
b/paimon-spark/paimon-spark-2/src/main/java/org/apache/paimon/spark/SparkInputPartition.java
@@ -54,31 +54,7 @@ public class SparkInputPartition
}
RecordReaderIterator<InternalRow> iterator = new
RecordReaderIterator<>(recordReader);
SparkInternalRow row = new SparkInternalRow(readBuilder.readType());
- return new
InputPartitionReader<org.apache.spark.sql.catalyst.InternalRow>() {
-
- @Override
- public boolean next() {
- if (iterator.hasNext()) {
- row.replace(iterator.next());
- return true;
- }
- return false;
- }
-
- @Override
- public org.apache.spark.sql.catalyst.InternalRow get() {
- return row;
- }
-
- @Override
- public void close() throws IOException {
- try {
- iterator.close();
- } catch (Exception e) {
- throw new IOException(e);
- }
- }
- };
+ return new SparkInputPartitionReader(iterator, row);
}
@Override
diff --git
a/paimon-spark/paimon-spark-2/src/main/java/org/apache/paimon/spark/SparkInputPartitionReader.java
b/paimon-spark/paimon-spark-2/src/main/java/org/apache/paimon/spark/SparkInputPartitionReader.java
new file mode 100644
index 000000000..c2dc56ea3
--- /dev/null
+++
b/paimon-spark/paimon-spark-2/src/main/java/org/apache/paimon/spark/SparkInputPartitionReader.java
@@ -0,0 +1,64 @@
+/*
+ * 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.paimon.spark;
+
+import org.apache.paimon.reader.RecordReaderIterator;
+
+import org.apache.spark.sql.catalyst.InternalRow;
+import org.apache.spark.sql.sources.v2.reader.InputPartition;
+import org.apache.spark.sql.sources.v2.reader.InputPartitionReader;
+
+import java.io.IOException;
+
+/** A spark 2 {@link InputPartitionReader} for paimon, created by {@link
InputPartition}. */
+public class SparkInputPartitionReader implements
InputPartitionReader<InternalRow> {
+
+ private final RecordReaderIterator<org.apache.paimon.data.InternalRow>
iterator;
+
+ private final SparkInternalRow row;
+
+ public SparkInputPartitionReader(
+ RecordReaderIterator<org.apache.paimon.data.InternalRow> iterator,
+ SparkInternalRow row) {
+ this.iterator = iterator;
+ this.row = row;
+ }
+
+ @Override
+ public boolean next() {
+ if (iterator.hasNext()) {
+ row.replace(iterator.next());
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public InternalRow get() {
+ return row;
+ }
+
+ @Override
+ public void close() throws IOException {
+ try {
+ iterator.close();
+ } catch (Exception e) {
+ throw new IOException(e);
+ }
+ }
+}
diff --git
a/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/SparkInputPartitionReader.java
b/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/SparkInputPartitionReader.java
new file mode 100644
index 000000000..ec6da01f4
--- /dev/null
+++
b/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/SparkInputPartitionReader.java
@@ -0,0 +1,64 @@
+/*
+ * 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.paimon.spark;
+
+import org.apache.paimon.reader.RecordReaderIterator;
+
+import org.apache.spark.sql.catalyst.InternalRow;
+import org.apache.spark.sql.connector.read.PartitionReader;
+import org.apache.spark.sql.connector.read.PartitionReaderFactory;
+
+import java.io.IOException;
+
+/** A spark 3 {@link PartitionReader} for paimon, created by {@link
PartitionReaderFactory}. */
+public class SparkInputPartitionReader implements PartitionReader<InternalRow>
{
+
+ private final RecordReaderIterator<org.apache.paimon.data.InternalRow>
iterator;
+
+ private final SparkInternalRow row;
+
+ public SparkInputPartitionReader(
+ RecordReaderIterator<org.apache.paimon.data.InternalRow> iterator,
+ SparkInternalRow row) {
+ this.iterator = iterator;
+ this.row = row;
+ }
+
+ @Override
+ public boolean next() {
+ if (iterator.hasNext()) {
+ row.replace(iterator.next());
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public InternalRow get() {
+ return row;
+ }
+
+ @Override
+ public void close() throws IOException {
+ try {
+ iterator.close();
+ } catch (Exception e) {
+ throw new IOException(e);
+ }
+ }
+}
diff --git
a/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/SparkReaderFactory.java
b/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/SparkReaderFactory.java
index 0502451a8..abb8c336c 100644
---
a/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/SparkReaderFactory.java
+++
b/paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/SparkReaderFactory.java
@@ -51,30 +51,6 @@ public class SparkReaderFactory implements
PartitionReaderFactory {
}
RecordReaderIterator<InternalRow> iterator = new
RecordReaderIterator<>(reader);
SparkInternalRow row = new SparkInternalRow(readBuilder.readType());
- return new
PartitionReader<org.apache.spark.sql.catalyst.InternalRow>() {
-
- @Override
- public boolean next() {
- if (iterator.hasNext()) {
- row.replace(iterator.next());
- return true;
- }
- return false;
- }
-
- @Override
- public org.apache.spark.sql.catalyst.InternalRow get() {
- return row;
- }
-
- @Override
- public void close() throws IOException {
- try {
- iterator.close();
- } catch (Exception e) {
- throw new IOException(e);
- }
- }
- };
+ return new SparkInputPartitionReader(iterator, row);
}
}