Skip to content

Commit

Permalink
[FLINK-36840][table] Add correct call syntax for functions without ()
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavodemorais authored Dec 4, 2024
1 parent 7d95fe8 commit 134a9e6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,11 @@ public static Stream<TestSpec> testData() {
.withField("f0", DataTypes.TIMESTAMP())
.withField("f1", DataTypes.TIMESTAMP())
.expectStr("TIMESTAMPDIFF(DAY, `f0`, `f1`)"),
TestSpec.forExpr(Expressions.currentDate()).expectStr("CURRENT_DATE()"),
TestSpec.forExpr(Expressions.currentTime()).expectStr("CURRENT_TIME()"),
TestSpec.forExpr(Expressions.currentTimestamp()).expectStr("CURRENT_TIMESTAMP()"),
TestSpec.forExpr(Expressions.currentDate()).expectStr("CURRENT_DATE"),
TestSpec.forExpr(Expressions.currentTime()).expectStr("CURRENT_TIME"),
TestSpec.forExpr(Expressions.currentTimestamp()).expectStr("CURRENT_TIMESTAMP"),
TestSpec.forExpr(Expressions.localTimestamp()).expectStr("LOCALTIMESTAMP"),
TestSpec.forExpr(Expressions.localTime()).expectStr("LOCALTIME"),
TestSpec.forExpr(Expressions.dateFormat($("f0"), lit("yyyy-MM-dd")))
.withField("f0", DataTypes.TIMESTAMP(3))
.expectStr("DATE_FORMAT(`f0`, 'yyyy-MM-dd')"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2155,6 +2155,7 @@ ANY, and(logical(LogicalTypeRoot.BOOLEAN), LITERAL)
BuiltInFunctionDefinition.newBuilder()
.name("currentDate")
.sqlName("CURRENT_DATE")
.callSyntax(SqlCallSyntax.NO_PARENTHESIS)
.kind(SCALAR)
.outputTypeStrategy(explicit(DATE().notNull()))
.build();
Expand All @@ -2163,13 +2164,15 @@ ANY, and(logical(LogicalTypeRoot.BOOLEAN), LITERAL)
BuiltInFunctionDefinition.newBuilder()
.name("currentTime")
.sqlName("CURRENT_TIME")
.callSyntax(SqlCallSyntax.NO_PARENTHESIS)
.kind(SCALAR)
.outputTypeStrategy(explicit(TIME().notNull()))
.build();

public static final BuiltInFunctionDefinition LOCAL_TIME =
BuiltInFunctionDefinition.newBuilder()
.name("localTime")
.callSyntax(SqlCallSyntax.NO_PARENTHESIS)
.kind(SCALAR)
.outputTypeStrategy(explicit(TIME().notNull()))
.build();
Expand All @@ -2178,6 +2181,7 @@ ANY, and(logical(LogicalTypeRoot.BOOLEAN), LITERAL)
BuiltInFunctionDefinition.newBuilder()
.name("currentTimestamp")
.sqlName("CURRENT_TIMESTAMP")
.callSyntax(SqlCallSyntax.NO_PARENTHESIS)
.kind(SCALAR)
.outputTypeStrategy(explicit(TIMESTAMP_LTZ(3).notNull()))
.build();
Expand All @@ -2201,6 +2205,7 @@ ANY, and(logical(LogicalTypeRoot.BOOLEAN), LITERAL)
public static final BuiltInFunctionDefinition LOCAL_TIMESTAMP =
BuiltInFunctionDefinition.newBuilder()
.name("localTimestamp")
.callSyntax(SqlCallSyntax.NO_PARENTHESIS)
.kind(SCALAR)
.outputTypeStrategy(explicit(TIMESTAMP(3).notNull()))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ private String doUnParse(
}
};

/**
* Function syntax for functions without parenthesis (e.g., CURRENT_DATE, LOCALTIMESTAMP,
* LOCALTIME, CURRENT_TIMESTAMP, CURRENT_TIME).
*/
SqlCallSyntax NO_PARENTHESIS = (sqlName, operands) -> sqlName;

/**
* Function syntax for handling DISTINCT aggregates. Special case. It does not have a syntax
* itself, but modifies the syntax of the nested call.
Expand Down

0 comments on commit 134a9e6

Please sign in to comment.