[ https://issues.apache.org/jira/browse/FLINK-6847?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16575048#comment-16575048 ]
ASF GitHub Bot commented on FLINK-6847: --------------------------------------- xueyumusic commented on a change in pull request #6282: [FLINK-6847][FLINK-6813] [table] TimestampDiff table api and sql support URL: https://github.com/apache/flink/pull/6282#discussion_r208985576 ########## File path: flink-libraries/flink-table/src/main/scala/org/apache/flink/table/expressions/time.scala ########## @@ -340,3 +343,66 @@ case class DateFormat(timestamp: Expression, format: Expression) extends Express override private[flink] def resultType = STRING_TYPE_INFO } + +case class TimestampDiff( + timeIntervalUnit: Expression, + timestamp1: Expression, + timestamp2: Expression) + extends Expression { + + override private[flink] def children: Seq[Expression] = + timeIntervalUnit :: timestamp1 :: timestamp2 :: Nil + + override private[flink] def validateInput(): ValidationResult = { + if (!TypeCheckUtils.isTimePoint(timestamp1.resultType)) { + return ValidationFailure(s"TimestampDiff operator requires Temporal input, " + + s"but timestamp1 is of type ${timestamp1.resultType}") + } + + if (!TypeCheckUtils.isTimePoint(timestamp2.resultType)) { + return ValidationFailure(s"TimestampDiff operator requires Temporal input, " + + s"but timestamp2 is of type ${timestamp2.resultType}") + } + + timeIntervalUnit match { + case SymbolExpression(TimeIntervalUnit.YEAR) + | SymbolExpression(TimeIntervalUnit.MONTH) + | SymbolExpression(TimeIntervalUnit.DAY) + | SymbolExpression(TimeIntervalUnit.HOUR) + | SymbolExpression(TimeIntervalUnit.MINUTE) + | SymbolExpression(TimeIntervalUnit.SECOND) + if timestamp1.resultType == SqlTimeTypeInfo.DATE + || timestamp1.resultType == SqlTimeTypeInfo.TIMESTAMP + || timestamp2.resultType == SqlTimeTypeInfo.DATE + || timestamp2.resultType == SqlTimeTypeInfo.TIMESTAMP => + ValidationSuccess + + case _ => + ValidationFailure(s"TimestampDiff operator does not support unit '$timeIntervalUnit'" + + s" for input of type ('${timestamp1.resultType}', '${timestamp2.resultType}').") + } + } + override private[flink] def toRexNode(implicit relBuilder: RelBuilder): RexNode = { + val typeFactory = relBuilder + .asInstanceOf[FlinkRelBuilder] + .getTypeFactory + + val intervalUnit = timeIntervalUnit.asInstanceOf[SymbolExpression].symbol + .enum.asInstanceOf[TimeUnitRange] + val intervalType = typeFactory.createSqlIntervalType( + new SqlIntervalQualifier(intervalUnit.startUnit, intervalUnit.endUnit, SqlParserPos.ZERO)) + + val rexCall = relBuilder + .getRexBuilder + .makeCall(intervalType, SqlStdOperatorTable.MINUS_DATE, Review comment: Thanks @twalthr , it seems that if we call `SqlStdOperatorTable#TIMESTAMP_DIFF` here we need to add new codegen for timestampDiff sqlfunction.. I will look deeply the other feedbacks recently, thank you :) ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add TIMESTAMPDIFF supported in TableAPI > --------------------------------------- > > Key: FLINK-6847 > URL: https://issues.apache.org/jira/browse/FLINK-6847 > Project: Flink > Issue Type: Sub-task > Components: Table API & SQL > Affects Versions: 1.4.0 > Reporter: sunjincheng > Priority: Major > Labels: pull-request-available, starter > > see FLINK-6813 -- This message was sent by Atlassian JIRA (v7.6.3#76005)