[ 
https://issues.apache.org/jira/browse/FLINK-26945?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17703649#comment-17703649
 ] 

jackylau commented on FLINK-26945:
----------------------------------

I tried what you said, but it also didn't work . it will throws exception 
ValidationException: Invalid argument type at position 0. Data type DATE 
expected but STRING passed.

The reason is the implicit cast need supportsImplicitCast and StringToDate 
should explicit

 

 
{code:java}
// code placeholder
class DateTimeArgumentTypeStrategy implements InputTypeStrategy {

    @Override
    public Optional<List<DataType>> inferInputTypes(
            CallContext callContext, boolean throwOnFailure) {
        List<DataType> argumentDataTypes = callContext.getArgumentDataTypes();
        List<LogicalType> argumentTypes =
                argumentDataTypes.stream()
                        .map(DataType::getLogicalType)
                        .collect(Collectors.toList());

        LogicalType dateType = argumentTypes.get(0);
        if (dateType.isAnyOf(LogicalTypeFamily.CHARACTER_STRING)
                || dateType.isAnyOf(
                        LogicalTypeRoot.TIMESTAMP_WITHOUT_TIME_ZONE,
                        LogicalTypeRoot.TIMESTAMP_WITH_LOCAL_TIME_ZONE)) {
            argumentTypes.set(0, new DateType());
        }

        if (dateType.isAnyOf(LogicalTypeFamily.CHARACTER_STRING)
                || dateType.isAnyOf(
                        LogicalTypeRoot.TINYINT,
                        LogicalTypeRoot.SMALLINT,
                        LogicalTypeRoot.INTEGER)) {
            argumentTypes.set(1, new IntType());
        }

        // TODO fail other types.
        return Optional.of(
                argumentTypes.stream()
                        .map(TypeConversions::fromLogicalToDataType)
                        .collect(Collectors.toList()));
    }
}



{code}
 

 

> Add DATE_SUB supported in SQL & Table API
> -----------------------------------------
>
>                 Key: FLINK-26945
>                 URL: https://issues.apache.org/jira/browse/FLINK-26945
>             Project: Flink
>          Issue Type: Sub-task
>          Components: Table SQL / API
>            Reporter: dalongliu
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 1.17.0
>
>
> Returns the date {{numDays}} before {{{}startDate{}}}.
> Syntax:
> {code:java}
> date_sub(startDate, numDays) {code}
> Arguments:
>  * {{{}startDate{}}}: A DATE expression.
>  * {{{}numDays{}}}: An INTEGER expression.
> Returns:
> A DATE.
> If {{numDays}} is negative abs(num_days) are added to {{{}startDate{}}}.
> If the result date overflows the date range the function raises an error.
> Examples:
> {code:java}
> > SELECT date_sub('2016-07-30', 1);
>  2016-07-29 {code}
> See more:
>  * 
> [Spark|https://spark.apache.org/docs/latest/sql-ref-functions-builtin.html#date-and-timestamp-functions]
>  * [Hive|https://cwiki.apache.org/confluence/display/hive/languagemanual+udf]



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to