Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
chenhao-db committed May 13, 2024
1 parent b558422 commit e8e4263
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ case object VariantGet {
case Type.DOUBLE => Literal(v.getDouble, DoubleType)
case Type.DECIMAL =>
val d = Decimal(v.getDecimal)
Literal(Decimal(v.getDecimal), DecimalType(d.precision, d.scale))
Literal(d, DecimalType(d.precision, d.scale))
case Type.DATE => Literal(v.getLong.toInt, DateType)
case Type.TIMESTAMP => Literal(v.getLong, TimestampType)
case Type.TIMESTAMP_NTZ => Literal(v.getLong, TimestampNTZType)
Expand Down Expand Up @@ -682,9 +682,8 @@ object SchemaOfVariant {
case Type.STRING => SQLConf.get.defaultStringType
case Type.DOUBLE => DoubleType
case Type.DECIMAL =>
val d = v.getDecimal
// Spark doesn't allow `DecimalType` to have `precision < scale`.
DecimalType(d.precision().max(d.scale()), d.scale())
val d = Decimal(v.getDecimal)
DecimalType(d.precision, d.scale)
case Type.DATE => DateType
case Type.TIMESTAMP => TimestampType
case Type.TIMESTAMP_NTZ => TimestampNTZType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,16 @@ class VariantEndToEndSuite extends QueryTest with SharedSparkSession {
check("1", "BIGINT")
check("1.0", "DECIMAL(1,0)")
check("0.01", "DECIMAL(2,2)")
check("1.00", "DECIMAL(1,0)")
check("10.00", "DECIMAL(2,0)")
check("10.10", "DECIMAL(3,1)")
check("0.0", "DECIMAL(1,0)")
check("-0.0", "DECIMAL(1,0)")
check("2147483647.999", "DECIMAL(13,3)")
check("9223372036854775808", "DECIMAL(19,0)")
check("-9223372036854775808.0", "DECIMAL(19,0)")
check("9999999999999999999.9999999999999999999", "DECIMAL(38,19)")
check("9999999999999999999.99999999999999999999", "DOUBLE")
check("1E0", "DOUBLE")
check("true", "BOOLEAN")
check("\"2000-01-01\"", "STRING")
Expand Down

0 comments on commit e8e4263

Please sign in to comment.