echauchot commented on a change in pull request #15218:
URL: https://github.com/apache/beam/pull/15218#discussion_r681744306



##########
File path: 
runners/spark/3/src/main/java/org/apache/beam/runners/spark/structuredstreaming/translation/batch/DatasetSourceBatch.java
##########
@@ -0,0 +1,240 @@
+/*
+ * 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.beam.runners.spark.structuredstreaming.translation.batch;
+
+import static 
org.apache.beam.runners.spark.structuredstreaming.Constants.BEAM_SOURCE_OPTION;
+import static 
org.apache.beam.runners.spark.structuredstreaming.Constants.DEFAULT_PARALLELISM;
+import static 
org.apache.beam.runners.spark.structuredstreaming.Constants.PIPELINE_OPTIONS;
+import static 
org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Preconditions.checkArgument;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.beam.runners.core.construction.SerializablePipelineOptions;
+import org.apache.beam.runners.core.serialization.Base64Serializer;
+import 
org.apache.beam.runners.spark.structuredstreaming.translation.helpers.RowHelpers;
+import 
org.apache.beam.runners.spark.structuredstreaming.translation.helpers.SchemaHelpers;
+import org.apache.beam.sdk.io.BoundedSource;
+import org.apache.beam.sdk.options.PipelineOptions;
+import org.apache.beam.sdk.util.WindowedValue;
+import org.apache.parquet.Strings;
+import org.apache.spark.sql.catalyst.InternalRow;
+import org.apache.spark.sql.connector.catalog.SupportsRead;
+import org.apache.spark.sql.connector.catalog.Table;
+import org.apache.spark.sql.connector.catalog.TableCapability;
+import org.apache.spark.sql.connector.catalog.TableProvider;
+import org.apache.spark.sql.connector.expressions.Transform;
+import org.apache.spark.sql.connector.read.Batch;
+import org.apache.spark.sql.connector.read.InputPartition;
+import org.apache.spark.sql.connector.read.PartitionReader;
+import org.apache.spark.sql.connector.read.PartitionReaderFactory;
+import org.apache.spark.sql.connector.read.Scan;
+import org.apache.spark.sql.connector.read.ScanBuilder;
+import org.apache.spark.sql.types.StructType;
+import org.apache.spark.sql.util.CaseInsensitiveStringMap;
+
+/**
+ * Empty impl needed for compilation. Spark DataSourceV2 API was removed in 
Spark3. Need to code a
+ * Beam source using new spark 3 API.
+ */
+public class DatasetSourceBatch implements TableProvider {
+
+  private static final StructType BINARY_SCHEMA = SchemaHelpers.binarySchema();
+
+  public DatasetSourceBatch() {}
+
+  @Override
+  public StructType inferSchema(CaseInsensitiveStringMap options) {
+    return BINARY_SCHEMA;
+  }
+
+  @Override
+  public boolean supportsExternalMetadata() {
+    return true;
+  }
+
+  @Override
+  public Table getTable(
+      StructType schema, Transform[] partitioning, Map<String, String> 
properties) {
+    return new DatasetSourceBatchTable();
+  }
+
+  private static class DatasetSourceBatchTable implements SupportsRead {
+
+    @Override
+    public ScanBuilder newScanBuilder(CaseInsensitiveStringMap options) {
+      return new ScanBuilder() {
+
+        @Override
+        public Scan build() {
+          return new Scan() { // scan for Batch reading
+
+            @Override
+            public StructType readSchema() {
+              return BINARY_SCHEMA;
+            }
+
+            @Override
+            public Batch toBatch() {
+              return new BeamBatch<>(options);
+            }
+          };
+        }
+      };
+    }
+
+    @Override
+    public String name() {
+      return "BeamSource";
+    }
+
+    @Override
+    public StructType schema() {
+      return BINARY_SCHEMA;
+    }
+
+    @Override
+    public Set<TableCapability> capabilities() {
+      final HashSet<TableCapability> capabilities = new HashSet<>();

Review comment:
       I tried to stick to java libs, but sure, we can use guava as it is 
already used everywhere in beam




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