Skip to content

Commit

Permalink
overflow check at expression encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
mickjermsurawong-stripe committed Jun 30, 2019
1 parent 414e48f commit b3740ba
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@

package org.apache.spark.sql.catalyst

import org.apache.spark.sql.catalyst.expressions.{CreateNamedStruct, Expression, IsNull, UnsafeArrayData}
import org.apache.spark.sql.catalyst.expressions.{CheckOverflow, CreateNamedStruct, Expression, IsNull, UnsafeArrayData}
import org.apache.spark.sql.catalyst.expressions.objects._
import org.apache.spark.sql.catalyst.util.{DateTimeUtils, GenericArrayData}
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types._
import org.apache.spark.unsafe.types.UTF8String

object SerializerBuildHelper {

private def nullOnOverflow: Boolean = SQLConf.get.decimalOperationsNullOnOverflow

def createSerializerForBoolean(inputObject: Expression): Expression = {
Invoke(inputObject, "booleanValue", BooleanType)
}
Expand Down Expand Up @@ -99,25 +102,25 @@ object SerializerBuildHelper {
}

def createSerializerForJavaBigDecimal(inputObject: Expression): Expression = {
StaticInvoke(
CheckOverflow(StaticInvoke(
Decimal.getClass,
DecimalType.SYSTEM_DEFAULT,
"apply",
inputObject :: Nil,
returnNullable = false)
returnNullable = false), DecimalType.SYSTEM_DEFAULT, nullOnOverflow)
}

def createSerializerForScalaBigDecimal(inputObject: Expression): Expression = {
createSerializerForJavaBigDecimal(inputObject)
}

def createSerializerForJavaBigInteger(inputObject: Expression): Expression = {
StaticInvoke(
CheckOverflow(StaticInvoke(
Decimal.getClass,
DecimalType.BigIntDecimal,
"apply",
inputObject :: Nil,
returnNullable = false)
returnNullable = false), DecimalType.BigIntDecimal, nullOnOverflow)
}

def createSerializerForScalaBigInt(inputObject: Expression): Expression = {
Expand Down

0 comments on commit b3740ba

Please sign in to comment.