Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
fix from_unixtime (#595)
Browse files Browse the repository at this point in the history
Signed-off-by: Yuan Zhou <yuan.zhou@intel.com>
  • Loading branch information
zhouyuan authored Dec 3, 2021
1 parent 22d5812 commit ed4d133
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -501,16 +501,16 @@ object ColumnarDateTimeExpressions {
buildCheck()

def buildCheck(): Unit = {
val supportedTypes = List(TimestampType)
val supportedTypes = List(LongType)
if (supportedTypes.indexOf(left.dataType) == -1) {
throw new UnsupportedOperationException(
s"${left.dataType} is not supported in ColumnarFromUnixTime.")
}
if (left.dataType == StringType) {
if (left.dataType == LongType) {
right match {
case literal: ColumnarLiteral =>
val format = literal.value.toString
if (format.length > 10) {
if (format.length != 10) {
throw new UnsupportedOperationException(
s"$format is not supported in ColumnarFromUnixTime.")
}
Expand All @@ -523,9 +523,19 @@ object ColumnarDateTimeExpressions {
val (leftNode, leftType) = left.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args)
//val (rightNode, rightType) = right.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args)
val outType = CodeGeneration.getResultType(dataType)

val date32LeftNode = if (left.dataType == LongType) {
// cast unix seconds to date64()
val milliNode = TreeBuilder.makeFunction("multiply", Lists.newArrayList(leftNode,
TreeBuilder.makeLiteral(java.lang.Long.valueOf(1000L))), new ArrowType.Int(8 * 8, true))
val date64Node = TreeBuilder.makeFunction("castDATE",
Lists.newArrayList(milliNode), new ArrowType.Date(DateUnit.MILLISECOND))
TreeBuilder.makeFunction("castDATE", Lists.newArrayList(date64Node), new ArrowType.Date(DateUnit.DAY))
} else {
throw new UnsupportedOperationException(
s"${left.dataType} is not supported in ColumnarFromUnixTime.")
}
val dateNode = TreeBuilder.makeFunction(
"castVARCHAR", Lists.newArrayList(leftNode, TreeBuilder.makeLiteral(java.lang.Long.valueOf(10L))), outType)
"castVARCHAR", Lists.newArrayList(date32LeftNode, TreeBuilder.makeLiteral(java.lang.Long.valueOf(10L))), outType)

(dateNode, outType)
}
Expand Down

0 comments on commit ed4d133

Please sign in to comment.