twalthr commented on a change in pull request #11081: [FLINK-16033][table-api] Introduced Java Table API Expression DSL URL: https://github.com/apache/flink/pull/11081#discussion_r385008937
########## File path: flink-table/flink-table-api-scala/src/test/scala/org/apache/flink/table/api/ExpressionsConsistencyCheckTest.scala ########## @@ -0,0 +1,294 @@ +/* + * 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.api + +import org.apache.flink.table.api.Expressions._ +import org.apache.flink.table.expressions.ApiExpressionUtils._ +import org.apache.flink.table.expressions.Expression +import org.apache.flink.table.functions.BuiltInFunctionDefinitions.{EQUALS, PLUS, TRIM} + +import org.hamcrest.CoreMatchers +import org.hamcrest.collection.IsEmptyIterable +import org.junit.Assert._ +import org.junit.Test + +import java.lang.reflect.Modifier + +import scala.collection.JavaConverters._ + +/** + * We test that all methods are either available or have equivalents in both Scala and Java + * expression DSL's + * + * If there are methods that do not map exactly in both APIs but have equivalent + * methods add those to `explicitScalaToJavaStaticMethodsMapping`(for static methods + * [[ImplicitExpressionConversions]]/[[Expressions]]) or `explicitScalaToJavaMapping` + * (for infix methods [[ApiExpression]]/[[ImplicitExpressionOperations]]). + * If equally named methods are not found the test will check if a mapping exists. + * This is a bidirectional mapping. + * + * If there are methods that should not have an equivalent in the other API add those to a + * corresponding list of exclude (`excludedStaticScalaMethods`, `excludedScalaMethods`, + * `excludedStaticJavaMethods`, `excludedJavaMethods`). + */ +class ExpressionsConsistencyCheckTest { + + // we cannot get class of package object + class Conversions extends ImplicitExpressionConversions {} + + // static methods from ImplicitExpressionConversions + val explicitScalaToJavaStaticMethodsMapping = Map( + "FieldExpression" -> "$", + "UnresolvedFieldExpression" -> "$", + "UserDefinedAggregateFunctionCall" -> "call", + "ScalarFunctionCall" -> "call", + "TableFunctionCall" -> "call", + "concat_ws" -> "concatWs" + ) + + // methods from WithOperations + val explicitScalaToJavaMapping = Map( + "$bang$eq$eq" -> "isNotEqual", // !== + "$eq$eq$eq" -> "isEqual", // === + "$less$eq" -> "isLessOrEqual", // <= + "$greater$eq" -> "isGreaterOrEqual", // >= + "$less" -> "isLess", // < + "$greater" -> "isGreater", // > + "$amp$amp" -> "and", // && + "$bar$bar" -> "or", // || + "$times" -> "multipliedBy", // * Review comment: should we also call it `times`? It would be shorter but not in sync with `dividedBy` anymore. ---------------------------------------------------------------- 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: [email protected] With regards, Apache Git Services
