From f5f5aab93229de9de03c103354efccbcd6a95ec0 Mon Sep 17 00:00:00 2001 From: Yuan Zhou Date: Mon, 5 Sep 2022 14:42:29 +0800 Subject: [PATCH] allow to use differnent case in SQL Signed-off-by: Yuan Zhou --- .../oap/expression/ColumnarExpressionConverter.scala | 2 +- .../intel/oap/expression/ColumnarHashAggregation.scala | 10 +++------- .../com/intel/oap/expression/ConverterUtils.scala | 7 +++---- 3 files changed, 7 insertions(+), 12 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 f79afab7f..8187d8f13 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 @@ -58,7 +58,7 @@ object ColumnarExpressionConverter extends Logging { val b = bindReference.asInstanceOf[BoundReference] new ColumnarBoundReference(b.ordinal, b.dataType, b.nullable) } else { - return new ColumnarAttributeReference(a.name, a.dataType, a.nullable, a.metadata)( + return new ColumnarAttributeReference(a.name.toLowerCase, a.dataType, a.nullable, a.metadata)( a.exprId, a.qualifier) } diff --git a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarHashAggregation.scala b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarHashAggregation.scala index 70868ee3f..b863b7dbc 100644 --- a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarHashAggregation.scala +++ b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ColumnarHashAggregation.scala @@ -455,8 +455,7 @@ class ColumnarHashAggregation( } val originalInputFieldList = originalInputAttributes.toList.map(attr => { - Field - .nullable(s"${attr.name}#${attr.exprId.id}", CodeGeneration.getResultType(attr.dataType)) + ConverterUtils.createArrowField(attr) }) //////////////// Project original input to aggregateExpression input ////////////////// @@ -501,7 +500,7 @@ class ColumnarHashAggregation( val inputAttrs = originalInputAttributes.zipWithIndex .filter { case (attr, i) => - !groupingAttributes.contains(attr) && !partialProjectOrdinalList.toList.contains(i) + !groupingAttributes.contains(attr.withName(attr.name.toLowerCase)) && !partialProjectOrdinalList.toList.contains(i) } .map(_._1) inputAttrQueue = scala.collection.mutable.Queue(inputAttrs: _*) @@ -516,10 +515,7 @@ class ColumnarHashAggregation( val aggregateAttributeFieldList = allAggregateResultAttributes.map(attr => { - Field - .nullable( - s"${attr.name}#${attr.exprId.id}", - CodeGeneration.getResultType(attr.dataType)) + ConverterUtils.createArrowField(attr) }) val nativeFuncNodes = groupingNativeFuncNodes ::: aggrNativeFuncNodes diff --git a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ConverterUtils.scala b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ConverterUtils.scala index 65531681a..06dcec518 100644 --- a/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ConverterUtils.scala +++ b/native-sql-engine/core/src/main/scala/com/intel/oap/expression/ConverterUtils.scala @@ -325,7 +325,7 @@ object ConverterUtils extends Logging { case a: AggregateExpression => getAttrFromExpr(a.aggregateFunction.children(0)) case a: AttributeReference => - a + a.withName(a.name.toLowerCase) case a: Alias => if (skipAlias) { if (a.child.isInstanceOf[AttributeReference] || a.child.isInstanceOf[Coalesce]) { @@ -483,8 +483,7 @@ object ConverterUtils extends Logging { def toArrowSchema(attributes: Seq[Attribute]): Schema = { val fields = attributes.map(attr => { - Field - .nullable(s"${attr.name}#${attr.exprId.id}", CodeGeneration.getResultType(attr.dataType)) + createArrowField(attr) }) new Schema(fields.toList.asJava) } @@ -618,7 +617,7 @@ object ConverterUtils extends Logging { } def createArrowField(attr: Attribute): Field = - createArrowField(s"${attr.name}#${attr.exprId.id}", attr.dataType) + createArrowField(s"${attr.name.toLowerCase}#${attr.exprId.id}", attr.dataType) private def asTimestampType(inType: ArrowType): ArrowType.Timestamp = { if (inType.getTypeID != ArrowTypeID.Timestamp) {