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_r384986198
########## File path: flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/Expressions.java ########## @@ -0,0 +1,562 @@ +/* + * 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.annotation.PublicEvolving; +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.table.catalog.DataTypeFactory; +import org.apache.flink.table.expressions.ApiExpressionUtils; +import org.apache.flink.table.expressions.Expression; +import org.apache.flink.table.expressions.ResolvedExpression; +import org.apache.flink.table.expressions.TimePointUnit; +import org.apache.flink.table.functions.BuiltInFunctionDefinitions; +import org.apache.flink.table.functions.FunctionDefinition; +import org.apache.flink.table.functions.UserDefinedFunction; +import org.apache.flink.table.types.DataType; +import org.apache.flink.table.types.utils.TypeConversions; +import org.apache.flink.table.types.utils.ValueDataTypeConverter; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.apache.flink.table.expressions.ApiExpressionUtils.objectToExpression; +import static org.apache.flink.table.expressions.ApiExpressionUtils.unresolvedCall; +import static org.apache.flink.table.expressions.ApiExpressionUtils.unresolvedRef; +import static org.apache.flink.table.expressions.ApiExpressionUtils.valueLiteral; + +/** + * Entry point of the Table API Expression DSL such as: {@code $("myField").plus(10).abs()} + * + * <p>This class contains static methods for referencing table columns, creating literals, + * and building more complex {@link Expression} chains. {@link ApiExpression ApiExpressions} are + * pure API entities that are further translated into {@link ResolvedExpression ResolvedExpressions} + * under the hood. + * + * <p>For fluent definition of expressions and easier readability, we recommend to add a + * star import to the methods of this class: + * + * <pre> + * import static org.apache.flink.table.api.Expressions.*; + * </pre> + * + * <p>Check the documentation for more programming language specific APIs, for example, by using + * Scala implicits. + */ +@PublicEvolving +public final class Expressions { + /** + * Creates an unresolved reference to a table's field. + * + * <p>Example + * <pre>{@code + * tab.select($("key"), $("value")) + * } + * </pre> + */ + //CHECKSTYLE.OFF: MethodName + public static ApiExpression $(String name) { + return new ApiExpression(unresolvedRef(name)); + } + //CHECKSTYLE.ON: MethodName + + /** + * Creates a SQL literal. + * + * <p>The data type is derived from the object's class and its value. + * + * <p>For example: + * <ul> + * <li>{@code lit(12)} leads to {@code INT}</li> + * <li>{@code lit("abc")} leads to {@code CHAR(3)}</li> + * <li>{@code lit(new BigDecimal("123.45"))} leads to {@code DECIMAL(5, 2)}</li> + * </ul> + * + * <p>See {@link ValueDataTypeConverter} for a list of supported literal values. + */ + public static ApiExpression lit(Object v) { + return new ApiExpression(valueLiteral(v)); + } + + /** + * Creates a SQL literal of a given {@link DataType}. + * + * <p>The method {@link #lit(Object)} is preferred as it extracts the {@link DataType} automatically. + * Use this method only when necessary. The class of {@code v} must be supported according to the + * {@link org.apache.flink.table.types.logical.LogicalType#supportsInputConversion(Class)}. + */ + public static ApiExpression lit(Object v, DataType dataType) { + return new ApiExpression(valueLiteral(v, dataType)); + } + + /** + * Indicates a range from 'start' to 'end', which can be used in columns + * selection. + * + * <p>Example: + * <pre>{@code + * Table table = ... + * table.withColumns(range(b, c)) Review comment: Should be within a `select()`. ---------------------------------------------------------------- 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
