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

[NSE-576] implement columnar from_unixtime #577

Merged
merged 1 commit into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import scala.collection.mutable.ListBuffer

import com.intel.oap.expression.ColumnarDateTimeExpressions.ColumnarDateDiff
import com.intel.oap.expression.ColumnarDateTimeExpressions.ColumnarUnixTimestamp
import com.intel.oap.expression.ColumnarDateTimeExpressions.ColumnarFromUnixTime

/**
* A version of add that supports columnar processing for longs.
Expand Down Expand Up @@ -83,6 +84,8 @@ object ColumnarBinaryExpression {
new ColumnarDateDiff(left, right)
case a: UnixTimestamp =>
new ColumnarUnixTimestamp(left, right)
case a: FromUnixTime =>
new ColumnarFromUnixTime(left, right)
case other =>
throw new UnsupportedOperationException(s"not currently supported: $other.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import org.apache.spark.sql.catalyst.expressions.UnixMicros
import org.apache.spark.sql.catalyst.expressions.UnixMillis
import org.apache.spark.sql.catalyst.expressions.UnixSeconds
import org.apache.spark.sql.catalyst.expressions.UnixTimestamp
import org.apache.spark.sql.catalyst.expressions.FromUnixTime
import org.apache.spark.sql.catalyst.expressions.Year
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types.{DateType, IntegerType, LongType, StringType, TimestampType}
Expand Down Expand Up @@ -493,6 +494,43 @@ object ColumnarDateTimeExpressions {
}
}

class ColumnarFromUnixTime(left: Expression, right: Expression)
extends FromUnixTime(left, right) with
ColumnarExpression {

buildCheck()

def buildCheck(): Unit = {
val supportedTypes = List(TimestampType)
if (supportedTypes.indexOf(left.dataType) == -1) {
throw new UnsupportedOperationException(
s"${left.dataType} is not supported in ColumnarFromUnixTime.")
}
if (left.dataType == StringType) {
right match {
case literal: ColumnarLiteral =>
val format = literal.value.toString
if (format.length > 10) {
throw new UnsupportedOperationException(
s"$format is not supported in ColumnarFromUnixTime.")
}
case _ =>
}
}
}

override def doColumnarCodeGen(args: Object): (TreeNode, ArrowType) = {
val (leftNode, leftType) = left.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args)
//val (rightNode, rightType) = right.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args)
val outType = CodeGeneration.getResultType(dataType)

val dateNode = TreeBuilder.makeFunction(
"castVARCHAR", Lists.newArrayList(leftNode, TreeBuilder.makeLiteral(java.lang.Long.valueOf(10L))), outType)

(dateNode, outType)
}
}

class ColumnarDateDiff(left: Expression, right: Expression)
extends DateDiff(left, right) with ColumnarExpression {

Expand Down