You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2018/08/09 15:56:47 UTC
[GitHub] xueyumusic commented on a change in pull request #6282:
[FLINK-6847][FLINK-6813] [table] TimestampDiff table api and sql support
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:
users@infra.apache.org
With regards,
Apache Git Services