flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [flink] twalthr commented on a change in pull request #8062: [FLINK-11884][table] Implement expression resolution on top of new Expressions
Date Mon, 15 Apr 2019 11:32:12 GMT
twalthr commented on a change in pull request #8062:  [FLINK-11884][table] Implement expression
resolution on top of new Expressions
URL: https://github.com/apache/flink/pull/8062#discussion_r275315193
 
 

 ##########
 File path: flink-table/flink-table-planner/src/main/java/org/apache/flink/table/operations/JoinOperationFactory.java
 ##########
 @@ -0,0 +1,153 @@
+/*
+ * 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.flink.table.operations;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.api.java.operators.join.JoinType;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.expressions.ApiExpressionDefaultVisitor;
+import org.apache.flink.table.expressions.ApiExpressionUtils;
+import org.apache.flink.table.expressions.BuiltInFunctionDefinitions;
+import org.apache.flink.table.expressions.CallExpression;
+import org.apache.flink.table.expressions.Expression;
+import org.apache.flink.table.expressions.ExpressionBridge;
+import org.apache.flink.table.expressions.FieldReferenceExpression;
+import org.apache.flink.table.expressions.PlannerExpression;
+import org.apache.flink.table.plan.logical.CalculatedTable;
+import org.apache.flink.table.plan.logical.Join;
+import org.apache.flink.table.plan.logical.LogicalNode;
+
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.Set;
+
+import static java.util.Arrays.asList;
+
+/**
+ * Utility class for creating a valid {@link Join} operation.
+ */
+@Internal
+public class JoinOperationFactory {
+
+	private final ExpressionBridge<PlannerExpression> expressionBridge;
+	private final EquiJoinExistsChecker equiJoinExistsChecker = new EquiJoinExistsChecker();
+
+	public JoinOperationFactory(ExpressionBridge<PlannerExpression> expressionBridge)
{
+		this.expressionBridge = expressionBridge;
+	}
+
+	/**
+	 * Creates a valid {@link Join} operation.
+	 *
+	 * <p>It performs validations such as:
+	 * <ul>
+	 * <li>condition returns boolean</li>
+	 * <li>the condition is either always true or contains equi join</li>
+	 * <li>left and right side of the join do not contain ambiguous column names</li>
+	 * <li>that correlated join is an INNER join</li>
+	 * </ul>
+	 *
+	 * @param left left side of the relational operation
+	 * @param right right side of the relational operation
+	 * @param joinType what sort of join to create
+	 * @param condition join condition to apply
+	 * @param correlated if the join should be a correlated join
+	 * @return valid join operation
+	 */
+	public LogicalNode create(
+			TableOperation left,
+			TableOperation right,
+			JoinType joinType,
+			Expression condition,
+			boolean correlated) {
+		verifyConditionType(condition);
+		validateNamesAmbiguity(left, right);
+		validateCondition(right, joinType, condition, correlated);
+
+		PlannerExpression plannerExpression = expressionBridge.bridge(condition);
+		return new Join((LogicalNode) left, (LogicalNode) right, joinType, Optional.of(plannerExpression),
correlated);
+	}
+
+	private void validateCondition(TableOperation right, JoinType joinType, Expression condition,
boolean correlated) {
+		boolean alwaysTrue = ApiExpressionUtils.extractValue(condition, Types.BOOLEAN).orElse(false);
+
+		if (alwaysTrue) {
+			return;
+		}
+
+		Boolean equiJoinExists = condition.accept(equiJoinExistsChecker);
+		if (correlated && right instanceof CalculatedTable && joinType != JoinType.INNER)
{
 
 Review comment:
   Introduce our own join types enum. We should not use enums of other APIs.

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


With regards,
Apache Git Services

Mime
View raw message