Github user walterddr commented on a diff in the pull request:

    https://github.com/apache/flink/pull/6188#discussion_r197622239
  
    --- Diff: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/expressions/time.scala
 ---
    @@ -328,6 +330,42 @@ case class TemporalOverlaps(
       }
     }
     
    +  /**
    +    * Standard conversion of the TIMESTAMPADD operator.
    +    * Source: 
[[org.apache.calcite.sql2rel.StandardConvertletTable#TimestampAddConvertlet]]
    +    */
    +case class TimestampAdd(
    +    unit: Expression,
    +    count: Expression,
    +    timestamp: Expression)
    +  extends Expression {
    +
    +  override private[flink] def children = unit :: count :: timestamp :: Nil
    +
    +  override private[flink] def toRexNode(implicit relBuilder: RelBuilder) = 
{
    +    var timeUnit : Option[TimeUnit] = None
    +    if (unit.isInstanceOf[Literal]) {
    +        var unitValue= unit.asInstanceOf[Literal].value.toString()
    +        val sqlTsiArray = Array("SQL_TSI_YEAR", "SQL_TSI_QUARTER", 
"SQL_TSI_MONTH", "SQL_TSI_WEEK",
    +            "SQL_TSI_DAY", "SQL_TSI_HOUR", "SQL_TSI_MINUTE", 
"SQL_TSI_SECOND")
    +        if (sqlTsiArray.contains(unitValue)) {
    +          unitValue = unitValue.split("_").last
    +        }
    +        timeUnit = Some(TimeUnit.valueOf(unitValue))
    +    }
    +
    +    relBuilder.call(SqlStdOperatorTable.DATETIME_PLUS, timestamp.toRexNode,
    +        relBuilder.call(SqlStdOperatorTable.MULTIPLY,
    +          
relBuilder.getRexBuilder.makeIntervalLiteral(timeUnit.get.multiplier,
    --- End diff --
    
    no. what I mean is something like:
    ```
    count match {
          case literal: Literal => //...generate a new IntervalSqlType based on 
unit and count
          case other: _ => //... Use your current approach using SQL 
SqlStdOperatorTable.MULTIPLY
       }
    ```
    You can move the logic to validate `unit` as a `Literal` to `validateInput` 
function like @hequn8128 mentioned.


---

Reply via email to