-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Coral-Trino] Migrate 'CurrentTimestampTransformer' from RelNode to S…
…qlNode layer (#384)
- Loading branch information
Showing
3 changed files
with
41 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
...ain/java/com/linkedin/coral/trino/rel2trino/transformers/CurrentTimestampTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Copyright 2023 LinkedIn Corporation. All rights reserved. | ||
* Licensed under the BSD-2 Clause license. | ||
* See LICENSE in the project root for license information. | ||
*/ | ||
package com.linkedin.coral.trino.rel2trino.transformers; | ||
|
||
import org.apache.calcite.sql.SqlBasicTypeNameSpec; | ||
import org.apache.calcite.sql.SqlCall; | ||
import org.apache.calcite.sql.SqlDataTypeSpec; | ||
import org.apache.calcite.sql.fun.SqlStdOperatorTable; | ||
import org.apache.calcite.sql.parser.SqlParserPos; | ||
import org.apache.calcite.sql.type.SqlTypeName; | ||
|
||
import com.linkedin.coral.common.transformers.SqlCallTransformer; | ||
|
||
|
||
/** | ||
* This class implements the transformation for the CURRENT_TIMESTAMP function. | ||
* For example, "SELECT CURRENT_TIMESTAMP" is transformed into "SELECT CAST(CURRENT_TIMESTAMP AS TIMESTAMP(3))". | ||
* This transformation ensures compatibility with Trino. | ||
*/ | ||
public class CurrentTimestampTransformer extends SqlCallTransformer { | ||
|
||
private static final String CURRENT_TIMESTAMP_FUNCTION_NAME = "CURRENT_TIMESTAMP"; | ||
|
||
@Override | ||
protected boolean condition(SqlCall sqlCall) { | ||
return sqlCall.getOperator().getName().equalsIgnoreCase(CURRENT_TIMESTAMP_FUNCTION_NAME); | ||
} | ||
|
||
@Override | ||
protected SqlCall transform(SqlCall sqlCall) { | ||
SqlDataTypeSpec timestampType = | ||
new SqlDataTypeSpec(new SqlBasicTypeNameSpec(SqlTypeName.TIMESTAMP, 3, SqlParserPos.ZERO), SqlParserPos.ZERO); | ||
return SqlStdOperatorTable.CAST.createCall(SqlParserPos.ZERO, sqlCall, timestampType); | ||
} | ||
} |