Skip to content

Commit 02d78e8

Browse files
authored
misc: Add lookup cast in standard function resolution (#26657)
## Description cast function is special as it needs to specify both input and output types, hence cannot use the existing lookupBuiltInFunction API. Add the lookupCast API in this PR ## Motivation and Context See description ## Impact See description ## Test Plan Unit test ## Contributor checklist - [ ] Please make sure your submission complies with our [contributing guide](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md), in particular [code style](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#code-style) and [commit standards](https://github.com/prestodb/presto/blob/master/CONTRIBUTING.md#commit-standards). - [ ] PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced. - [ ] Documented new properties (with its default value), SQL syntax, functions, or other functionality. - [ ] If release notes are required, they follow the [release notes guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines). - [ ] Adequate tests were added if applicable. - [ ] CI passed. - [ ] If adding new dependencies, verified they have an [OpenSSF Scorecard](https://securityscorecards.dev/#the-checks) score of 5.0 or higher (or obtained explicit TSC approval for lower scores). ## Release Notes Please follow [release notes guidelines](https://github.com/prestodb/presto/wiki/Release-Notes-Guidelines) and fill in the release notes below. ``` == NO RELEASE NOTE == ```
1 parent 9374cd8 commit 02d78e8

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

presto-main-base/src/main/java/com/facebook/presto/sql/relational/FunctionResolution.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ public boolean isCastFunction(FunctionHandle functionHandle)
148148
return functionAndTypeResolver.getFunctionMetadata(functionHandle).getOperatorType().equals(Optional.of(OperatorType.CAST));
149149
}
150150

151+
@Override
152+
public FunctionHandle lookupCast(String castType, Type fromType, Type toType)
153+
{
154+
return functionAndTypeResolver.lookupCast(castType, fromType, toType);
155+
}
156+
151157
public boolean isTryCastFunction(FunctionHandle functionHandle)
152158
{
153159
return functionAndTypeResolver.getFunctionMetadata(functionHandle).getName().equals(QualifiedObjectName.valueOf(JAVA_BUILTIN_NAMESPACE, "TRY_CAST"));

presto-main-base/src/test/java/com/facebook/presto/sql/relational/TestFunctionResolution.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import static com.facebook.presto.common.type.BooleanType.BOOLEAN;
3838
import static com.facebook.presto.common.type.DoubleType.DOUBLE;
3939
import static com.facebook.presto.common.type.TypeSignature.parseTypeSignature;
40+
import static com.facebook.presto.common.type.VarcharType.VARCHAR;
4041
import static com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager;
4142
import static com.facebook.presto.spi.function.FunctionImplementationType.THRIFT;
4243
import static com.facebook.presto.spi.function.FunctionVersion.notVersioned;
@@ -96,6 +97,9 @@ public void testStandardFunctionResolution()
9697
// full qualified name
9798
assertEquals(standardFunctionResolution.notFunction(), standardFunctionResolution.lookupFunction("presto", "default", "not", ImmutableList.of(BOOLEAN)));
9899
assertEquals(standardFunctionResolution.countFunction(), standardFunctionResolution.lookupFunction("presto", "default", "count", ImmutableList.of()));
100+
101+
// lookup cast
102+
assertTrue(standardFunctionResolution.isCastFunction(standardFunctionResolution.lookupCast("CAST", BIGINT, VARCHAR)));
99103
}
100104

101105
@Test

presto-spi/src/main/java/com/facebook/presto/spi/function/StandardFunctionResolution.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public interface StandardFunctionResolution
6060

6161
boolean isCastFunction(FunctionHandle functionHandle);
6262

63+
FunctionHandle lookupCast(String castType, Type fromType, Type toType);
64+
6365
boolean isCountFunction(FunctionHandle functionHandle);
6466

6567
boolean isCountIfFunction(FunctionHandle functionHandle);

0 commit comments

Comments
 (0)