twalthr commented on code in PR #25582:
URL: https://github.com/apache/flink/pull/25582#discussion_r1824689298
##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/Expressions.java:
##########
@@ -947,6 +947,120 @@ public static ApiExpression jsonArrayAgg(JsonOnNull
onNull, Object itemExpr) {
return apiCall(functionDefinition, itemExpr);
}
+ /**
+ * A window function that provides access to a row at a specified physical
offset which comes
Review Comment:
there is no specified offset
##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/Expressions.java:
##########
@@ -947,6 +947,120 @@ public static ApiExpression jsonArrayAgg(JsonOnNull
onNull, Object itemExpr) {
return apiCall(functionDefinition, itemExpr);
}
+ /**
+ * A window function that provides access to a row at a specified physical
offset which comes
+ * after the current row.
+ *
+ * <p>Example:
+ *
+ * <pre>{@code
+ * org.window(Over.orderBy($("ts")).partitionBy("organisation").as("w"))
+ * .select(
+ * $("organisation"),
+ * $("revenue"),
+ * lag($("revenue")).over($("w").as("next_revenue")
+ * )
+ * }</pre>
+ */
+ public static ApiExpression lead(Object value) {
+ return apiCall(BuiltInFunctionDefinitions.LEAD, value);
+ }
+
+ /**
+ * A window function that provides access to a row at a specified physical
offset which comes
+ * after the current row.
+ *
+ * <p>Example:
+ *
+ * <pre>{@code
+ * org.window(Over.orderBy($("ts")).partitionBy("organisation").as("w"))
+ * .select(
+ * $("organisation"),
+ * $("revenue"),
+ * lag($("revenue"), 1).over($("w").as("next_revenue")
+ * )
+ * }</pre>
+ */
+ public static ApiExpression lead(Object value, Object offset) {
+ return apiCall(BuiltInFunctionDefinitions.LEAD, value, offset);
+ }
+
+ /**
+ * A window function that provides access to a row at a specified physical
offset which comes
+ * after the current row.
+ *
+ * <p>Example:
+ *
+ * <pre>{@code
+ * org.window(Over.orderBy($("ts")).partitionBy("organisation").as("w"))
+ * .select(
+ * $("organisation"),
+ * $("revenue"),
+ * lag($("revenue"), 1, lit(0)).over($("w").as("next_revenue")
+ * )
+ * }</pre>
+ */
+ public static ApiExpression lead(Object value, Object offset, Object
defaultValue) {
+ return apiCall(BuiltInFunctionDefinitions.LEAD, value, offset,
defaultValue);
+ }
+
+ /**
+ * A window function that provides access to a row at a specified physical
offset which comes
Review Comment:
there is no specified offset
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/strategies/LeadLagInputTypeStrategy.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * 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.types.inference.strategies;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.table.functions.BuiltInFunctionDefinitions;
+import org.apache.flink.table.functions.FunctionDefinition;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.inference.ArgumentCount;
+import org.apache.flink.table.types.inference.ArgumentTypeStrategy;
+import org.apache.flink.table.types.inference.CallContext;
+import org.apache.flink.table.types.inference.ConstantArgumentCount;
+import org.apache.flink.table.types.inference.InputTypeStrategies;
+import org.apache.flink.table.types.inference.InputTypeStrategy;
+import org.apache.flink.table.types.inference.Signature;
+import org.apache.flink.table.types.inference.Signature.Argument;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.LogicalTypeFamily;
+import org.apache.flink.table.types.logical.utils.LogicalTypeMerging;
+import org.apache.flink.table.types.utils.TypeConversions;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Type strategy for {@link BuiltInFunctionDefinitions#LAG} & { @link
Review Comment:
```suggestion
* Type strategy for {@link BuiltInFunctionDefinitions#LAG} and { @link
```
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/functions/BuiltInFunctionDefinitions.java:
##########
@@ -780,6 +780,22 @@ ANY, and(logical(LogicalTypeRoot.BOOLEAN), LITERAL)
.outputTypeStrategy(TypeStrategies.aggArg0(t -> t, true))
.build();
+ public static final BuiltInFunctionDefinition LEAD =
+ BuiltInFunctionDefinition.newBuilder()
+ .name("lead")
+ .kind(AGGREGATE)
+ .inputTypeStrategy(SpecificInputTypeStrategies.LEAD_LAG)
+ .outputTypeStrategy(SpecificTypeStrategies.LEAD_LAG)
Review Comment:
for our book keeping add:
```
.runtimeProvided()
```
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/strategies/SpecificInputTypeStrategies.java:
##########
@@ -167,6 +167,12 @@ public static ArgumentTypeStrategy percentageArray(boolean
expectedNullability)
/** Type strategy specific for {@link BuiltInFunctionDefinitions#IN}. */
public static final InputTypeStrategy IN = new SubQueryInputTypeStrategy();
+ /**
+ * Type strategy for {@link BuiltInFunctionDefinitions#LAG} & { @link
Review Comment:
```suggestion
* Type strategy for {@link BuiltInFunctionDefinitions#LAG} and { @link
```
##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/Expressions.java:
##########
@@ -947,6 +947,120 @@ public static ApiExpression jsonArrayAgg(JsonOnNull
onNull, Object itemExpr) {
return apiCall(functionDefinition, itemExpr);
}
+ /**
+ * A window function that provides access to a row at a specified physical
offset which comes
+ * after the current row.
+ *
+ * <p>Example:
+ *
+ * <pre>{@code
+ * org.window(Over.orderBy($("ts")).partitionBy("organisation").as("w"))
+ * .select(
+ * $("organisation"),
+ * $("revenue"),
+ * lag($("revenue")).over($("w").as("next_revenue")
+ * )
+ * }</pre>
+ */
+ public static ApiExpression lead(Object value) {
+ return apiCall(BuiltInFunctionDefinitions.LEAD, value);
+ }
+
+ /**
+ * A window function that provides access to a row at a specified physical
offset which comes
+ * after the current row.
+ *
+ * <p>Example:
+ *
+ * <pre>{@code
+ * org.window(Over.orderBy($("ts")).partitionBy("organisation").as("w"))
+ * .select(
+ * $("organisation"),
+ * $("revenue"),
+ * lag($("revenue"), 1).over($("w").as("next_revenue")
+ * )
+ * }</pre>
+ */
+ public static ApiExpression lead(Object value, Object offset) {
+ return apiCall(BuiltInFunctionDefinitions.LEAD, value, offset);
+ }
+
+ /**
+ * A window function that provides access to a row at a specified physical
offset which comes
+ * after the current row.
Review Comment:
explain the default
##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/strategies/OverTypeStrategy.java:
##########
@@ -182,18 +204,16 @@ private Optional<String> validateFollowingPreceding(
public List<Signature> getExpectedSignatures(FunctionDefinition
definition) {
return Arrays.asList(
Signature.of(
Review Comment:
Does the signature still make sense?
##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/Expressions.java:
##########
@@ -947,6 +947,120 @@ public static ApiExpression jsonArrayAgg(JsonOnNull
onNull, Object itemExpr) {
return apiCall(functionDefinition, itemExpr);
}
+ /**
+ * A window function that provides access to a row at a specified physical
offset which comes
+ * after the current row.
+ *
+ * <p>Example:
+ *
+ * <pre>{@code
+ * org.window(Over.orderBy($("ts")).partitionBy("organisation").as("w"))
+ * .select(
+ * $("organisation"),
+ * $("revenue"),
+ * lag($("revenue")).over($("w").as("next_revenue")
+ * )
+ * }</pre>
+ */
+ public static ApiExpression lead(Object value) {
+ return apiCall(BuiltInFunctionDefinitions.LEAD, value);
+ }
+
+ /**
+ * A window function that provides access to a row at a specified physical
offset which comes
+ * after the current row.
+ *
+ * <p>Example:
+ *
+ * <pre>{@code
+ * org.window(Over.orderBy($("ts")).partitionBy("organisation").as("w"))
+ * .select(
+ * $("organisation"),
+ * $("revenue"),
+ * lag($("revenue"), 1).over($("w").as("next_revenue")
+ * )
+ * }</pre>
+ */
+ public static ApiExpression lead(Object value, Object offset) {
+ return apiCall(BuiltInFunctionDefinitions.LEAD, value, offset);
+ }
+
+ /**
+ * A window function that provides access to a row at a specified physical
offset which comes
+ * after the current row.
+ *
+ * <p>Example:
+ *
+ * <pre>{@code
+ * org.window(Over.orderBy($("ts")).partitionBy("organisation").as("w"))
+ * .select(
+ * $("organisation"),
+ * $("revenue"),
+ * lag($("revenue"), 1, lit(0)).over($("w").as("next_revenue")
+ * )
+ * }</pre>
+ */
+ public static ApiExpression lead(Object value, Object offset, Object
defaultValue) {
+ return apiCall(BuiltInFunctionDefinitions.LEAD, value, offset,
defaultValue);
+ }
+
+ /**
+ * A window function that provides access to a row at a specified physical
offset which comes
+ * before the current row.
+ *
+ * <p>Example:
+ *
+ * <pre>{@code
+ * org.window(Over.orderBy($("ts")).partitionBy("organisation").as("w"))
+ * .select(
+ * $("organisation"),
+ * $("revenue"),
+ * lag($("revenue")).over($("w").as("prev_revenue")
+ * )
+ * }</pre>
+ */
+ public static ApiExpression lag(Object value) {
+ return apiCall(BuiltInFunctionDefinitions.LAG, value);
+ }
+
+ /**
+ * A window function that provides access to a row at a specified physical
offset which comes
+ * before the current row.
+ *
+ * <p>Example:
+ *
+ * <pre>{@code
+ * org.window(Over.orderBy($("ts")).partitionBy("organisation").as("w"))
+ * .select(
+ * $("organisation"),
+ * $("revenue"),
+ * lag($("revenue"), 1).over($("w").as("prev_revenue")
+ * )
+ * }</pre>
+ */
+ public static ApiExpression lag(Object value, Object offset) {
+ return apiCall(BuiltInFunctionDefinitions.LAG, value, offset);
+ }
+
+ /**
+ * A window function that provides access to a row at a specified physical
offset which comes
Review Comment:
explain the default
##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/Expressions.java:
##########
@@ -947,6 +947,120 @@ public static ApiExpression jsonArrayAgg(JsonOnNull
onNull, Object itemExpr) {
return apiCall(functionDefinition, itemExpr);
}
+ /**
+ * A window function that provides access to a row at a specified physical
offset which comes
+ * after the current row.
+ *
+ * <p>Example:
+ *
+ * <pre>{@code
+ * org.window(Over.orderBy($("ts")).partitionBy("organisation").as("w"))
Review Comment:
```suggestion
*
table.window(Over.orderBy($("ts")).partitionBy("organisation").as("w"))
```
--
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]