[ 
https://issues.apache.org/jira/browse/BEAM-12609?focusedWorklogId=628042&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-628042
 ]

ASF GitHub Bot logged work on BEAM-12609:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 26/Jul/21 22:30
            Start Date: 26/Jul/21 22:30
    Worklog Time Spent: 10m 
      Work Description: 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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 628042)
    Time Spent: 0.5h  (was: 20m)

> Projection pushdown in SchemaIO
> -------------------------------
>
>                 Key: BEAM-12609
>                 URL: https://issues.apache.org/jira/browse/BEAM-12609
>             Project: Beam
>          Issue Type: New Feature
>          Components: sdk-java-core
>            Reporter: Kyle Weaver
>            Assignee: Kyle Weaver
>            Priority: P2
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> https://docs.google.com/document/d/1M71LrbjfPZwk5C0IpI13Su63UWSBFKYjSrz9SsyBM_Y/edit



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to