kennknowles commented on code in PR #40695: URL: https://github.com/apache/beam/pull/40695#discussion_r4339925723
########## sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rel/BeamCrossJoinRel.java: ########## @@ -0,0 +1,175 @@ +/* + * 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.impl.rel; + +import java.util.Collections; +import java.util.List; +import java.util.Set; +import org.apache.beam.sdk.extensions.sql.impl.utils.CalciteUtils; +import org.apache.beam.sdk.schemas.Schema; +import org.apache.beam.sdk.transforms.DoFn; +import org.apache.beam.sdk.transforms.PTransform; +import org.apache.beam.sdk.transforms.ParDo; +import org.apache.beam.sdk.transforms.View; +import org.apache.beam.sdk.transforms.windowing.TimestampCombiner; +import org.apache.beam.sdk.transforms.windowing.Window; +import org.apache.beam.sdk.values.PCollection; +import org.apache.beam.sdk.values.PCollectionList; +import org.apache.beam.sdk.values.PCollectionView; +import org.apache.beam.sdk.values.Row; +import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.plan.RelOptCluster; +import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.plan.RelTraitSet; +import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.rel.RelNode; +import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.rel.core.CorrelationId; +import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.rel.core.Join; +import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.rel.core.JoinRelType; +import org.apache.beam.vendor.calcite.v1_40_0.org.apache.calcite.rex.RexNode; + +/** + * A {@code BeamJoinRel} that implements a BOUNDED cartesian (CROSS) join, used for the literal-TRUE + * join conditions that Calcite emits when it decorrelates uncorrelated scalar / IN / EXISTS + * subqueries and lateral joins. + * + * <p>Only supported when BOTH inputs are bounded. The right side is broadcast as a side input and + * the left side is iterated; every (left, right) pair is emitted as one combined row (left values + * followed by right values). + * + * <p>First increment: INNER join with an always-true condition. A non-trivial (residual) condition + * is not yet evaluated here. + */ +@SuppressWarnings({ Review Comment: Can we leave this out of new files ########## sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rel/BeamSortRel.java: ########## @@ -378,9 +378,16 @@ public int compare(Row row1, Row row2) { if (isValue1Null && isValue2Null) { continue; } else if (isValue1Null && !isValue2Null) { - fieldRet = -1 * (nullsFirst.get(i) ? -1 : 1); + // NULL placement is absolute: NULLS FIRST means the null row always sorts before the Review Comment: This comment is excessively verbose for the little fix. ########## sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rel/BeamWindowRel.java: ########## @@ -208,8 +261,12 @@ public FieldAggregation( @Override public NodeStats estimateNodeStats(BeamRelMetadataQuery mq) { - NodeStats inputStat = BeamSqlRelUtils.getNodeStats(this.input, mq); - return inputStat; + // Derive from the planner's row-count for the input, which stays finite even when the input is Review Comment: This comment is complex and refers to all sorts of things elsewhere, and is just a comment on why the change was made, not explaining the current code. ########## sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rel/BeamSortRel.java: ########## @@ -389,9 +396,17 @@ public int compare(Row row1, Row row2) { case BIGINT: case FLOAT: case DOUBLE: + case DECIMAL: + case BOOLEAN: case VARCHAR: + case CHAR: case DATE: + case TIME: case TIMESTAMP: + // All of the above map to Java types that implement Comparable (Boolean, BigDecimal, Review Comment: This comment is redundant with the code ########## sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rel/BeamWindowRel.java: ########## @@ -142,9 +143,37 @@ public PTransform<PCollectionList<Row>, PCollection<Row>> buildPTransform() { List<Integer> argList = anAggCall.getArgList(); Schema.Field field = CalciteUtils.toField(anAggCall.getName(), anAggCall.getType()); - Combine.CombineFn combineFn = - AggregationCombineFnAdapter.createCombineFnAnalyticsFunctions( - anAggCall, field, anAggCall.getAggregation().getName()); + String aggName = anAggCall.getAggregation().getName(); + Combine.CombineFn combineFn; + if (anAggCall.ignoreNulls() + && ("FIRST_VALUE".equals(aggName) || "LAST_VALUE".equals(aggName))) { + // Spark's first(col, ignoreNulls=true) / last(col, ignoreNulls=true) Review Comment: This is more general than spark, as it is for TCP-DS ########## sdks/java/extensions/sql/src/main/java/org/apache/beam/sdk/extensions/sql/impl/rel/BeamWindowRel.java: ########## @@ -220,10 +277,12 @@ public NodeStats estimateNodeStats(BeamRelMetadataQuery mq) { */ @Override public BeamCostModel beamComputeSelfCost(RelOptPlanner planner, BeamRelMetadataQuery mq) { - NodeStats inputStat = BeamSqlRelUtils.getNodeStats(this.input, mq); + // Use the planner's row-count (RelSubset-safe) rather than BeamSqlRelUtils.getNodeStats, which Review Comment: I wonder if `BeamSqlrelUtils.getNodeStats` should be changed, if we are replacing it with all these trivial inlines. FWIW this comment is actually an OK explanation for the code. -- 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]
