diff --git a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarArithmetic.scala b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarArithmetic.scala index 6331c2014..049641ab0 100644 --- a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarArithmetic.scala +++ b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarArithmetic.scala @@ -39,6 +39,13 @@ class ColumnarAdd(left: Expression, right: Expression, original: Expression) extends Add(left: Expression, right: Expression) with ColumnarExpression with Logging { + val gName = "add" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + left.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + right.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } // If casting between DecimalType, unnecessary cast is skipped to avoid data loss, // because actually res type of "cast" is the res type in "add/subtract", @@ -103,6 +110,14 @@ class ColumnarSubtract(left: Expression, right: Expression, original: Expression with ColumnarExpression with Logging { + val gName = "subtract" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + left.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + right.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } + val left_val: Any = left match { case c: ColumnarCast => if (c.child.dataType.isInstanceOf[DecimalType] && @@ -163,6 +178,14 @@ class ColumnarMultiply(left: Expression, right: Expression, original: Expression with ColumnarExpression with Logging { + val gName = "multiply" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + left.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + right.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } + val left_val: Any = left match { case c: ColumnarCast => if (c.child.dataType.isInstanceOf[DecimalType] && @@ -247,9 +270,6 @@ class ColumnarMultiply(left: Expression, right: Expression, original: Expression } } - override def supportColumnarCodegen(args: java.lang.Object): Boolean = { - return left_val.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && right_val.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) - } } class ColumnarDivide(left: Expression, right: Expression, @@ -257,6 +277,13 @@ class ColumnarDivide(left: Expression, right: Expression, extends Divide(left: Expression, right: Expression) with ColumnarExpression with Logging { + val gName = "divide" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + left.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + right.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } val left_val: Any = left match { case c: ColumnarCast => @@ -349,6 +376,15 @@ class ColumnarBitwiseAnd(left: Expression, right: Expression, original: Expressi extends BitwiseAnd(left: Expression, right: Expression) with ColumnarExpression with Logging { + + val gName = "bitwise_and" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + left.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + right.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } + override def doColumnarCodeGen(args: Object): (TreeNode, ArrowType) = { val (left_node, left_type): (TreeNode, ArrowType) = left.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args) @@ -370,6 +406,15 @@ class ColumnarBitwiseOr(left: Expression, right: Expression, original: Expressio extends BitwiseOr(left: Expression, right: Expression) with ColumnarExpression with Logging { + + val gName = "bitwise_or" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + left.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + right.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } + override def doColumnarCodeGen(args: Object): (TreeNode, ArrowType) = { val (left_node, left_type): (TreeNode, ArrowType) = left.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args) diff --git a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarBinaryExpression.scala b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarBinaryExpression.scala index eff1cfda9..4c9ff216a 100644 --- a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarBinaryExpression.scala +++ b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarBinaryExpression.scala @@ -119,6 +119,14 @@ class ColumnarGetJsonObject(left: Expression, right: Expression, original: GetJs class ColumnarStringInstr(left: Expression, right: Expression, original: StringInstr) extends StringInstr(original.str, original.substr) with ColumnarExpression with Logging { + val gName = "locate" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + left.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + right.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } + override def doColumnarCodeGen(args: Object): (TreeNode, ArrowType) = { val (left_node, _): (TreeNode, ArrowType) = left.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args) diff --git a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarBinaryOperator.scala b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarBinaryOperator.scala index d0adf8fa1..88d8d197b 100644 --- a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarBinaryOperator.scala +++ b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarBinaryOperator.scala @@ -103,6 +103,14 @@ class ColumnarStartsWith(left: Expression, right: Expression, original: Expressi extends StartsWith(left: Expression, right: Expression) with ColumnarExpression with Logging { + val gName = "starts_with" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + left.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + right.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } + override def doColumnarCodeGen(args: java.lang.Object): (TreeNode, ArrowType) = { val (left_node, left_type): (TreeNode, ArrowType) = left.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args) @@ -121,6 +129,14 @@ class ColumnarLike(left: Expression, right: Expression, original: Expression) with ColumnarExpression with Logging { + val gName = "like" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + left.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + right.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } + buildCheck() def buildCheck(): Unit = { @@ -156,7 +172,14 @@ class ColumnarRLike(left: Expression, right: Expression, original: Expression) extends RLike(left: Expression, right: Expression) with ColumnarExpression with Logging { + val gName = "equal" + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + left.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + right.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } + buildCheck() def buildCheck(): Unit = { @@ -166,10 +189,6 @@ class ColumnarRLike(left: Expression, right: Expression, original: Expression) } } - override def supportColumnarCodegen(args: java.lang.Object): Boolean = { - false - } - override def doColumnarCodeGen(args: java.lang.Object): (TreeNode, ArrowType) = { val (left_node, left_type): (TreeNode, ArrowType) = left.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args) @@ -208,6 +227,14 @@ class ColumnarEqualTo(left: Expression, right: Expression, original: Expression) extends EqualTo(left: Expression, right: Expression) with ColumnarExpression with Logging { + val gName = "equal" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + left.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + right.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } + override def doColumnarCodeGen(args: java.lang.Object): (TreeNode, ArrowType) = { var (left_node, left_type): (TreeNode, ArrowType) = left.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args) @@ -307,8 +334,11 @@ class ColumnarLessThan(left: Expression, right: Expression, original: Expression with ColumnarExpression with Logging { + val gName = "less_than" + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { - true && left.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + codegenFuncList.contains(gName) && + left.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && right.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) } @@ -354,6 +384,14 @@ class ColumnarLessThanOrEqual(left: Expression, right: Expression, original: Exp extends LessThanOrEqual(left: Expression, right: Expression) with ColumnarExpression with Logging { + val gName = "less_than_or_equal_to" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + left.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + right.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } + override def doColumnarCodeGen(args: java.lang.Object): (TreeNode, ArrowType) = { var (left_node, left_type): (TreeNode, ArrowType) = left.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args) @@ -398,6 +436,15 @@ class ColumnarGreaterThan(left: Expression, right: Expression, original: Express extends GreaterThan(left: Expression, right: Expression) with ColumnarExpression with Logging { + + val gName = "greater_than" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + left.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + right.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } + override def doColumnarCodeGen(args: java.lang.Object): (TreeNode, ArrowType) = { var (left_node, left_type): (TreeNode, ArrowType) = left.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args) @@ -442,6 +489,14 @@ class ColumnarGreaterThanOrEqual(left: Expression, right: Expression, original: extends GreaterThanOrEqual(left: Expression, right: Expression) with ColumnarExpression with Logging { + val gName = "greater_than_or_equal_to" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + left.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + right.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } + override def doColumnarCodeGen(args: java.lang.Object): (TreeNode, ArrowType) = { var (left_node, left_type): (TreeNode, ArrowType) = left.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args) @@ -486,6 +541,15 @@ class ColumnarShiftLeft(left: Expression, right: Expression, original: Expressio extends ShiftLeft(left: Expression, right: Expression) with ColumnarExpression with Logging { + + val gName = "shift_left" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + left.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + right.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } + override def doColumnarCodeGen(args: Object): (TreeNode, ArrowType) = { var (left_node, left_type): (TreeNode, ArrowType) = left.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args) @@ -508,6 +572,15 @@ class ColumnarShiftRight(left: Expression, right: Expression, original: Expressi extends ShiftRight(left: Expression, right: Expression) with ColumnarExpression with Logging { + + val gName = "shift_right" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + left.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + right.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } + override def doColumnarCodeGen(args: Object): (TreeNode, ArrowType) = { val (left_node, left_type): (TreeNode, ArrowType) = left.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args) diff --git a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarCaseWhenOperator.scala b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarCaseWhenOperator.scala index dcc097af4..5606c9544 100644 --- a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarCaseWhenOperator.scala +++ b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarCaseWhenOperator.scala @@ -33,7 +33,7 @@ import org.apache.spark.sql.types._ import scala.collection.mutable.ListBuffer /** - * A version of substring that supports columnar processing for utf8. + * Columnar impl for Case When base on Gandiva if/else */ class ColumnarCaseWhen( branches: Seq[(Expression, Expression)], @@ -64,9 +64,6 @@ class ColumnarCaseWhen( } override def doColumnarCodeGen(args: java.lang.Object): (TreeNode, ArrowType) = { - logInfo(s"children: ${branches.flatMap(b => b._1 :: b._2 :: Nil) ++ elseValue}") - logInfo(s"branches: $branches") - logInfo(s"else: $elseValue") val i = 0 val exprs = branches.flatMap(b => b._1 :: b._2 :: Nil) ++ elseValue val exprList = { exprs.filter(expr => !expr.isInstanceOf[Literal]) } diff --git a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarCoalesceOperator.scala b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarCoalesceOperator.scala index 00b422364..43c2d934c 100644 --- a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarCoalesceOperator.scala +++ b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarCoalesceOperator.scala @@ -46,6 +46,16 @@ class ColumnarCoalesce(exps: Seq[Expression], original: Expression) with ColumnarExpression with Logging { + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + for (expr <- exps) { + val colExpr = ColumnarExpressionConverter.replaceWithColumnarExpression(expr) + if (!colExpr.asInstanceOf[ColumnarExpression].supportColumnarCodegen(Lists.newArrayList())) { + return false + } + } + return true + } + buildCheck() def buildCheck(): Unit = { diff --git a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarDateTimeExpressions.scala b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarDateTimeExpressions.scala index dd0b77a50..aaf90c92c 100644 --- a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarDateTimeExpressions.scala +++ b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarDateTimeExpressions.scala @@ -255,6 +255,12 @@ object ColumnarDateTimeExpressions { class ColumnarYear(child: Expression) extends Year(child) with ColumnarExpression { + val gName = "extractYear" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + child.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } buildCheck() @@ -420,6 +426,12 @@ object ColumnarDateTimeExpressions { class ColumnarMicrosToTimestamp(child: Expression) extends MicrosToTimestamp(child) with ColumnarExpression { + val gName = "micros_to_timestamp" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + child.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } buildCheck() @@ -453,6 +465,8 @@ object ColumnarDateTimeExpressions { extends UnixTimestamp(left, right, timeZoneId, failOnError) with ColumnarExpression { + val gName = "unix_seconds" + val yearMonthDayFormat = "yyyy-MM-dd" val yearMonthDayTimeFormat = "yyyy-MM-dd HH:mm:ss" val yearMonthDayTimeNoSepFormat = "yyyyMMddHHmmss" @@ -488,7 +502,8 @@ object ColumnarDateTimeExpressions { } override def supportColumnarCodegen(args: Object): Boolean = { - false && left.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + codegenFuncList.contains(gName) && + left.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && right.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) } diff --git a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarExpression.scala b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarExpression.scala index 967271768..b7b911767 100644 --- a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarExpression.scala +++ b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarExpression.scala @@ -27,9 +27,57 @@ import scala.collection.mutable.ListBuffer trait ColumnarExpression { + val codegenFuncList: List[String] = List( + "less_than", + "less_than_with_nan", + "greater_than", + "greater_than_with_nan", + "less_than_or_equal_to", + "less_than_or_equal_to_with_nan", + "greater_than_or_equal_to", + "greater_than_or_equal_to_with_nan", + "equal", + "equal_with_nan", + "not", + "isnotnull", + "isnull", + "starts_with", + "like", + "get_json_object", + "translate", + "substr", + "locate", + "btrim", + "ltrim", + "rtrim", + "upper", + "lower", + "castDATE", + "castDECIMAL", + "castDECIMALNullOnOverflow", + "castINTOrNull", + "castBIGINTOrNull", + "castFLOAT4OrNull", + "castFLOAT8OrNull", + "rescaleDECIMAL", + "extractYear", + "round", + "abs", + "add", + "subtract", + "multiply", + "divide", + "shift_left", + "shift_right", + "bitwise_and", + "bitwise_or", + "normalize", + "convertTimestampUnit", + "micros_to_timestamp" + ) + def supportColumnarCodegen(args: java.lang.Object): (Boolean) = { - // TODO: disable all codegen unless manuall enabled - true + false } def doColumnarCodeGen(args: java.lang.Object): (TreeNode, ArrowType) = { diff --git a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarLiterals.scala b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarLiterals.scala index 5e5070823..4c025a636 100644 --- a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarLiterals.scala +++ b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarLiterals.scala @@ -38,6 +38,10 @@ class ColumnarLiteral(lit: Literal) extends Literal(lit.value, lit.dataType) with ColumnarExpression { + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + true + } + val resultType: ArrowType = buildCheck() def buildCheck(): ArrowType = { diff --git a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarNamedExpressions.scala b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarNamedExpressions.scala index 0032d59b2..3d50a011d 100644 --- a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarNamedExpressions.scala +++ b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarNamedExpressions.scala @@ -55,6 +55,10 @@ class ColumnarAttributeReference( extends AttributeReference(name, dataType, nullable, metadata)(exprId, qualifier) with ColumnarExpression { + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + true + } + override def doColumnarCodeGen(args: java.lang.Object): (TreeNode, ArrowType) = { val resultType = CodeGeneration.getResultType(dataType) val field = Field.nullable(s"${name}#${exprId.id}", resultType) diff --git a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarRoundOperator.scala b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarRoundOperator.scala index ec7808a68..1cb733a6e 100644 --- a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarRoundOperator.scala +++ b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarRoundOperator.scala @@ -38,6 +38,13 @@ class ColumnarRound(child: Expression, scale: Expression, original: Expression) extends Round(child: Expression, scale: Expression) with ColumnarExpression with Logging { + val gName = "round" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + child.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + scale.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } buildCheck() diff --git a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarString2TrimOperator.scala b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarString2TrimOperator.scala index 5e2c18c20..55e244374 100644 --- a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarString2TrimOperator.scala +++ b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarString2TrimOperator.scala @@ -32,6 +32,18 @@ class ColumnarStringTrim(srcStr: Expression, trimStr: Option[Expression], origin extends StringTrim(srcStr: Expression, trimStr: Option[Expression]) with ColumnarExpression with Logging { + val gName = "btrim" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + if (trimStr.isEmpty) { + codegenFuncList.contains(gName) && + srcStr.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } else { + codegenFuncList.contains(gName) && + srcStr.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + trimStr.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } + } buildCheck() @@ -63,7 +75,18 @@ class ColumnarStringTrimLeft(srcStr: Expression, trimStr: Option[Expression], or extends StringTrimLeft(srcStr: Expression, trimStr: Option[Expression]) with ColumnarExpression with Logging { - + val gName = "ltrim" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + if (trimStr.isEmpty) { + codegenFuncList.contains(gName) && + srcStr.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } else { + codegenFuncList.contains(gName) && + srcStr.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + trimStr.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } + } buildCheck() def buildCheck(): Unit = { @@ -93,7 +116,18 @@ class ColumnarStringTrimRight(child: Expression, trimStr: Option[Expression], or extends StringTrimRight(child: Expression, trimStr: Option[Expression]) with ColumnarExpression with Logging { - + val gName = "rtrim" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + if (trimStr.isEmpty) { + codegenFuncList.contains(gName) && + srcStr.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } else { + codegenFuncList.contains(gName) && + srcStr.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + trimStr.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } + } buildCheck() def buildCheck(): Unit = { diff --git a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarTernaryOperator.scala b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarTernaryOperator.scala index 8779c1e33..fd1249a44 100644 --- a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarTernaryOperator.scala +++ b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarTernaryOperator.scala @@ -39,6 +39,16 @@ class ColumnarSubString(str: Expression, pos: Expression, len: Expression, origi with ColumnarExpression with Logging { + + val gName = "substr" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + str.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + pos.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + len.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } + buildCheck() def buildCheck(): Unit = { @@ -117,6 +127,15 @@ class ColumnarStringTranslate(src: Expression, matchingExpr: Expression, replaceExpr: Expression, original: Expression) extends StringTranslate(src, matchingExpr, replaceExpr) with ColumnarExpression { + val gName = "translate" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + src.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + matchingExpr.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) && + replaceExpr.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } + buildCheck def buildCheck: Unit = { diff --git a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarUnaryOperator.scala b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarUnaryOperator.scala index 80e59f2db..02f99365c 100644 --- a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarUnaryOperator.scala +++ b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarUnaryOperator.scala @@ -58,6 +58,12 @@ class ColumnarIsNotNull(child: Expression, original: Expression) extends IsNotNull(child: Expression) with ColumnarExpression with Logging { + val gName = "isnotnull" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + child.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } buildCheck() @@ -92,10 +98,17 @@ class ColumnarIsNotNull(child: Expression, original: Expression) } class ColumnarIsNull(child: Expression, original: Expression) - extends IsNotNull(child: Expression) + extends IsNull(child: Expression) with ColumnarExpression with Logging { + val gName = "isnull" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + child.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } + buildCheck() def buildCheck(): Unit = { @@ -282,6 +295,12 @@ class ColumnarAbs(child: Expression, original: Expression) extends Abs(child: Expression) with ColumnarExpression with Logging { + val gName = "abs" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + child.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } buildCheck() @@ -369,6 +388,12 @@ class ColumnarUpper(child: Expression, original: Expression) extends Upper(child: Expression) with ColumnarExpression with Logging { + val gName = "upper" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + child.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } buildCheck() @@ -395,6 +420,12 @@ class ColumnarLower(child: Expression, original: Expression) extends Lower(child: Expression) with ColumnarExpression with Logging { + val gName = "lower" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + child.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } buildCheck() @@ -415,10 +446,6 @@ class ColumnarLower(child: Expression, original: Expression) TreeBuilder.makeFunction("lower", Lists.newArrayList(child_node), resultType) (funcNode, resultType) } - - override def supportColumnarCodegen(args: java.lang.Object): Boolean = { - false - } } class ColumnarBitwiseNot(child: Expression, original: Expression) @@ -453,7 +480,12 @@ class ColumnarCheckOverflow(child: Expression, original: CheckOverflow) original.nullOnOverflow: Boolean) with ColumnarExpression with Logging { + val gName = "castDECIMAL" + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + child.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } buildCheck() def buildCheck(): Unit = { @@ -492,6 +524,12 @@ class ColumnarCast( extends Cast(child: Expression, datatype: DataType, timeZoneId: Option[String]) with ColumnarExpression with Logging { + val gName = "Cast" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + true && + child.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } buildCheck() @@ -815,6 +853,13 @@ class ColumnarUnscaledValue(child: Expression, original: Expression) with ColumnarExpression with Logging { + val gName = "multiply" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + child.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } + buildCheck() def buildCheck(): Unit = { @@ -890,6 +935,12 @@ class ColumnarNormalizeNaNAndZero(child: Expression, original: NormalizeNaNAndZe extends NormalizeNaNAndZero(child: Expression) with ColumnarExpression with Logging { + val gName = "normalize" + + override def supportColumnarCodegen(args: java.lang.Object): Boolean = { + codegenFuncList.contains(gName) && + child.asInstanceOf[ColumnarExpression].supportColumnarCodegen(args) + } buildCheck() diff --git a/native-sql-engine/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc b/native-sql-engine/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc index b60aaa624..265dba5e1 100644 --- a/native-sql-engine/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc +++ b/native-sql-engine/cpp/src/codegen/arrow_compute/ext/expression_codegen_visitor.cc @@ -324,7 +324,7 @@ arrow::Status ExpressionCodegenVisitor::Visit(const gandiva::FunctionNode& node) prepare_ss << "if (" << check_str_ << ")" << std::endl; prepare_ss << codes_str_ << " = " << ss.str() << ";" << std::endl; prepare_str_ += prepare_ss.str(); - } else if (func_name.compare("instr") == 0) { + } else if (func_name.compare("locate") == 0) { codes_str_ = func_name + "_" + std::to_string(cur_func_id); auto validity = codes_str_ + "_validity"; real_codes_str_ = codes_str_;