From 8b92263867ffff09b3332ee266644fd04ce1819a Mon Sep 17 00:00:00 2001 From: jackylee-ch Date: Thu, 28 Jul 2022 16:43:57 +0800 Subject: [PATCH 1/2] support function in substring --- .../ColumnarExpressionConverter.scala | 2 ++ .../expression/ColumnarTernaryOperator.scala | 24 ++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarExpressionConverter.scala b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarExpressionConverter.scala index 29d5e6d40..340d0518b 100644 --- a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarExpressionConverter.scala +++ b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarExpressionConverter.scala @@ -287,9 +287,11 @@ object ColumnarExpressionConverter extends Logging { convertBoundRefToAttrRef = convertBoundRefToAttrRef), replaceWithColumnarExpression( ss.pos, + attributeSeq, convertBoundRefToAttrRef = convertBoundRefToAttrRef), replaceWithColumnarExpression( ss.len, + attributeSeq, convertBoundRefToAttrRef = convertBoundRefToAttrRef), expr) case st: StringTranslate => 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 af5ab4329..fb9f30de5 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 @@ -56,14 +56,22 @@ class ColumnarSubString(str: Expression, pos: Expression, len: Expression, origi val (len_node, lenType): (TreeNode, ArrowType) = len.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args) - //FIXME(): gandiva only support pos and len with int64 type - val lit_pos :ColumnarLiteral= pos.asInstanceOf[ColumnarLiteral] - val lit_pos_val = lit_pos.value - val long_pos_node = TreeBuilder.makeLiteral(lit_pos_val.asInstanceOf[Integer].longValue() :java.lang.Long) - - val lit_len :ColumnarLiteral= len.asInstanceOf[ColumnarLiteral] - val lit_len_val = lit_len.value - val long_len_node = TreeBuilder.makeLiteral(lit_len_val.asInstanceOf[Integer].longValue() :java.lang.Long) + // FIXME(): gandiva only support pos and len with int64 type + val long_pos_node = pos match { + case literal: ColumnarLiteral => + TreeBuilder.makeLiteral(literal.value.asInstanceOf[Integer].longValue() : java.lang.Long) + case _ => + TreeBuilder.makeFunction( + "castBIGINT", Lists.newArrayList(pos_node), new ArrowType.Int(64, true)) + } + + val long_len_node = len match { + case literal: ColumnarLiteral => + TreeBuilder.makeLiteral(literal.value.asInstanceOf[Integer].longValue() : java.lang.Long) + case _ => + TreeBuilder.makeFunction( + "castBIGINT", Lists.newArrayList(len_node), new ArrowType.Int(64, true)) + } val resultType = new ArrowType.Utf8() val funcNode = From 02995a0b953109fc04c9f002727e8a58b0691247 Mon Sep 17 00:00:00 2001 From: jackylee-ch Date: Fri, 29 Jul 2022 13:41:11 +0800 Subject: [PATCH 2/2] remove extra match --- .../expression/ColumnarTernaryOperator.scala | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) 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 fb9f30de5..2bb88571e 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 @@ -57,25 +57,15 @@ class ColumnarSubString(str: Expression, pos: Expression, len: Expression, origi len.asInstanceOf[ColumnarExpression].doColumnarCodeGen(args) // FIXME(): gandiva only support pos and len with int64 type - val long_pos_node = pos match { - case literal: ColumnarLiteral => - TreeBuilder.makeLiteral(literal.value.asInstanceOf[Integer].longValue() : java.lang.Long) - case _ => - TreeBuilder.makeFunction( - "castBIGINT", Lists.newArrayList(pos_node), new ArrowType.Int(64, true)) - } + val long_pos_node = TreeBuilder.makeFunction( + "castBIGINT", Lists.newArrayList(pos_node), new ArrowType.Int(64, true)) - val long_len_node = len match { - case literal: ColumnarLiteral => - TreeBuilder.makeLiteral(literal.value.asInstanceOf[Integer].longValue() : java.lang.Long) - case _ => - TreeBuilder.makeFunction( - "castBIGINT", Lists.newArrayList(len_node), new ArrowType.Int(64, true)) - } + val long_len_node = TreeBuilder.makeFunction( + "castBIGINT", Lists.newArrayList(len_node), new ArrowType.Int(64, true)) val resultType = new ArrowType.Utf8() - val funcNode = - TreeBuilder.makeFunction("substr", Lists.newArrayList(str_node, long_pos_node, long_len_node), resultType) + val funcNode = TreeBuilder.makeFunction( + "substr", Lists.newArrayList(str_node, long_pos_node, long_len_node), resultType) (funcNode, resultType) } }