-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Coral-Trino] use 'TRY_CAST' instead of 'CAST'
- Loading branch information
Showing
8 changed files
with
138 additions
and
88 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
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
45 changes: 45 additions & 0 deletions
45
...rino/src/main/java/com/linkedin/coral/trino/rel2trino/functions/TrinoTryCastFunction.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,45 @@ | ||
/** | ||
* Copyright 2024 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.functions; | ||
|
||
import org.apache.calcite.sql.SqlCall; | ||
import org.apache.calcite.sql.SqlFunction; | ||
import org.apache.calcite.sql.SqlFunctionCategory; | ||
import org.apache.calcite.sql.SqlIntervalQualifier; | ||
import org.apache.calcite.sql.SqlKind; | ||
import org.apache.calcite.sql.SqlWriter; | ||
import org.apache.calcite.sql.fun.SqlStdOperatorTable; | ||
|
||
|
||
/** | ||
* describe: | ||
* | ||
* @author hqbhoho | ||
* @version [v1.0] | ||
* @date 2024/12/18 | ||
*/ | ||
public class TrinoTryCastFunction extends SqlFunction { | ||
public static final TrinoTryCastFunction TRY_CAST = new TrinoTryCastFunction(); | ||
|
||
public TrinoTryCastFunction() { | ||
super("try_cast", SqlKind.CAST, SqlStdOperatorTable.CAST::inferReturnType, null, null, | ||
SqlFunctionCategory.USER_DEFINED_FUNCTION); | ||
} | ||
|
||
public void unparse(SqlWriter writer, SqlCall call, int leftPrec, int rightPrec) { | ||
assert call.operandCount() == 2; | ||
|
||
SqlWriter.Frame frame = writer.startFunCall(this.getName()); | ||
call.operand(0).unparse(writer, 0, 0); | ||
writer.sep("AS"); | ||
if (call.operand(1) instanceof SqlIntervalQualifier) { | ||
writer.sep("INTERVAL"); | ||
} | ||
|
||
call.operand(1).unparse(writer, 0, 0); | ||
writer.endFunCall(frame); | ||
} | ||
} |
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
Oops, something went wrong.