Skip to content

Commit

Permalink
[NSE-1024] Support ShortType in ColumnarLiteral (oap-project#1025)
Browse files Browse the repository at this point in the history
* Initial commit

* Cast short type to int32
  • Loading branch information
PHILO-HE authored Jul 22, 2022
1 parent 8437145 commit 50ef3d1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,19 @@ object CodeGeneration {

def getResultType(left: ArrowType, right: ArrowType): ArrowType = {
//TODO(): remove this API
left
// Use left type except that left is int16. If both right & left are int16,
// int32 will be used.
left match {
case intLeft: ArrowType.Int if (intLeft.getBitWidth == 16) =>
right match {
case intRight: ArrowType.Int if (intRight.getBitWidth == 16) =>
new ArrowType.Int(32, true)
case _ =>
right
}
case _ =>
left
}
}

def getResultType(dataType: DataType): ArrowType = {
Expand Down Expand Up @@ -81,6 +93,8 @@ object CodeGeneration {
dataType match {
case t: ArrowType.FloatingPoint =>
s"castFLOAT${4 * dataType.asInstanceOf[ArrowType.FloatingPoint].getPrecision().getFlatbufID()}"
case i: ArrowType.Int if i.getBitWidth == 32 =>
"castINT"
case _ =>
throw new UnsupportedOperationException(s"getCastFuncName(${dataType}) is not supported.")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ColumnarLiteral(lit: Literal)

def buildCheck(): ArrowType = {
val supportedTypes =
List(StringType, IntegerType, LongType, DoubleType, FloatType, DateType,
List(StringType, ShortType, IntegerType, LongType, DoubleType, FloatType, DateType,
BooleanType, CalendarIntervalType, BinaryType, TimestampType)
if (supportedTypes.indexOf(dataType) == -1 && !dataType.isInstanceOf[DecimalType]) {
// Decimal is supported in ColumnarLiteral
Expand Down Expand Up @@ -75,6 +75,8 @@ class ColumnarLiteral(lit: Literal)
throw new UnsupportedOperationException(
s"can't support CalendarIntervalType with microseconds yet")
}
case ShortType =>
new ArrowType.Int(32, true)
case _ =>
CodeGeneration.getResultType(dataType)
}
Expand All @@ -97,12 +99,13 @@ class ColumnarLiteral(lit: Literal)
case _ =>
(TreeBuilder.makeLiteral(value.asInstanceOf[Integer]), resultType)
}
case t: ShortType =>
case _: ShortType =>
value match {
case null =>
(TreeBuilder.makeNull(resultType), resultType)
case _ =>
(TreeBuilder.makeLiteral(value.asInstanceOf[Integer]), resultType)
(TreeBuilder.makeLiteral(new Integer(
value.asInstanceOf[java.lang.Short].toInt)), resultType)
}
case t: LongType =>
value match {
Expand Down

0 comments on commit 50ef3d1

Please sign in to comment.