You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2021/07/26 22:30:34 UTC

[GitHub] [beam] apilloud commented on a change in pull request #15216: [BEAM-12609] Enable projection pushdown in SchemaIO.

apilloud commented on a change in pull request #15216:
URL: https://github.com/apache/beam/pull/15216#discussion_r676983861



##########
File path: sdks/java/core/src/main/java/org/apache/beam/sdk/schemas/io/PushdownProjector.java
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.sdk.schemas.io;
+
+import org.apache.beam.sdk.annotations.Experimental;
+import org.apache.beam.sdk.schemas.FieldAccessDescriptor;
+import org.apache.beam.sdk.transforms.PTransform;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.PInput;
+import org.apache.beam.sdk.values.Row;
+
+/**
+ * Factory for creating a {@link PTransform} that can execute a projection.
+ *
+ * <p>Typically this interface will be implemented by a reader {@link PTransform} that is capable of
+ * pushing down projection to an external source. For example, {@link SchemaIO#buildReader()} may
+ * return a {@link PushdownProjector} to which a projection may be applied later.
+ */
+@Experimental
+public interface PushdownProjector {
+  /**
+   * Returns a {@link PTransform} that will execute the projection specified by the {@link
+   * FieldAccessDescriptor}.
+   */
+  PTransform<? extends PInput, PCollection<Row>> withProjectionPushdown(

Review comment:
       Awesome.

##########
File path: sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/meta/provider/SchemaIOTableProviderWrapper.java
##########
@@ -118,6 +123,34 @@ public Schema getSchema() {
       return begin.apply(readerTransform);
     }
 
+    @Override
+    public PCollection<Row> buildIOReader(
+        PBegin begin, BeamSqlTableFilter filters, List<String> fieldNames) {
+      PTransform<PBegin, PCollection<Row>> readerTransform = schemaIO.buildReader();
+      if (readerTransform instanceof PushdownProjector) {
+        PushdownProjector pushdownProjector = (PushdownProjector) readerTransform;
+        FieldAccessDescriptor fieldAccessDescriptor =
+            FieldAccessDescriptor.withFieldNames(fieldNames);
+        // The pushdown must return a PTransform that can be applied to a PBegin, or this cast will
+        // fail.
+        readerTransform =
+            (PTransform<PBegin, PCollection<Row>>)
+                pushdownProjector.withProjectionPushdown(fieldAccessDescriptor);
+      }

Review comment:
       Shouldn't this have an `else` that looks something like `BaseBeamTable` and reject attempts to push down if it isn't supported? You should probably also reject filter pushdown (the `if (!(filters instanceof DefaultTableFilter)) {` block).
   
   https://github.com/apache/beam/blob/243128a8fc52798e1b58b0cf1a271d95ee7aa241/sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/meta/BaseBeamTable.java#L30




-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org