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 2020/06/18 17:07:43 UTC

[GitHub] [beam] jhnmora000 commented on a change in pull request #11975: [BEAM-9198] BeamSQL aggregation analytics functionality

jhnmora000 commented on a change in pull request #11975:
URL: https://github.com/apache/beam/pull/11975#discussion_r442376683



##########
File path: sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/BeamAnalyticFunctionsExperimentTest.java
##########
@@ -0,0 +1,187 @@
+/*
+ * 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.extensions.sql;
+
+import java.util.Iterator;
+import java.util.List;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.testing.PAssert;
+import org.apache.beam.sdk.transforms.Create;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.Row;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * A simple Analytic Functions experiment for BeamSQL created in order to understand the query
+ * processing workflow of BeamSQL and Calcite.
+ */
+public class BeamAnalyticFunctionsExperimentTest extends BeamSqlDslBase {
+
+  /**
+   * Table schema and data taken from
+   * https://cloud.google.com/bigquery/docs/reference/standard-sql/analytic-function-concepts#produce_table
+   *
+   * <p>Compute a cumulative sum query taken from
+   * https://cloud.google.com/bigquery/docs/reference/standard-sql/analytic-function-concepts#compute_a_cumulative_sum
+   */
+  @Test
+  public void testOverCumulativeSum() throws Exception {
+    pipeline.enableAbandonedNodeEnforcement(false);
+    Schema schema =
+        Schema.builder()
+            .addStringField("item")
+            .addStringField("category")
+            .addInt32Field("purchases")
+            .build();
+    PCollection<Row> inputRows =
+        pipeline
+            .apply(
+                Create.of(
+                    TestUtils.rowsBuilderOf(schema)
+                        .addRows(
+                            "kale",
+                            "vegetable",
+                            23,
+                            "orange",
+                            "fruit",
+                            2,
+                            "cabbage",
+                            "vegetable",
+                            9,
+                            "apple",
+                            "fruit",
+                            8,
+                            "leek",
+                            "vegetable",
+                            2,
+                            "lettuce",
+                            "vegetable",
+                            10)
+                        .getRows()))
+            .setRowSchema(schema);
+    String sql =
+        "SELECT item, purchases, category, sum(purchases) over "
+            + "(PARTITION BY category ORDER BY purchases ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)"
+            + " as total_purchases  FROM PCOLLECTION";

Review comment:
       `LogicalProject(item=[$0], purchases=[$2], category=[$1], total_purchases=[SUM($2) OVER (PARTITION BY $1 ORDER BY $2 ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)])
     BeamIOSourceRel(table=[[beam, PCOLLECTION]])`




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