Skip to content

Commit

Permalink
RD-10527: Decimal raw data type shows as string in JSON output (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgaidioz authored Jan 26, 2024
1 parent 322c9e6 commit 37d8998
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class TypedPolyglotCsvWriter(os: OutputStream, lineSeparator: String) {
case _: RawLongType => gen.writeNumber(v.asLong())
case _: RawFloatType => gen.writeNumber(v.asFloat())
case _: RawDoubleType => gen.writeNumber(v.asDouble())
case _: RawDecimalType => gen.writeString(v.asHostObject[java.math.BigDecimal]().toString())
case _: RawDecimalType => gen.writeNumber(v.asHostObject[java.math.BigDecimal]())
case _: RawStringType => gen.writeString(v.asString())
case _: RawDateType =>
val date = v.asDate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class TypedPolyglotJsonWriter(os: OutputStream) {
case _: RawLongType => gen.writeNumber(v.asLong())
case _: RawFloatType => gen.writeNumber(v.asFloat())
case _: RawDoubleType => gen.writeNumber(v.asDouble())
case _: RawDecimalType => gen.writeString(v.asHostObject[java.math.BigDecimal]().toString)
case _: RawDecimalType => gen.writeNumber(v.asHostObject[java.math.BigDecimal]())
case _: RawStringType => gen.writeString(v.asString())
case _: RawDateType =>
val date = v.asDate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class Rql2CsvWriter(os: OutputStream, lineSeparator: String) {
case _: Rql2LongType => gen.writeNumber(v.asLong())
case _: Rql2FloatType => gen.writeNumber(v.asFloat())
case _: Rql2DoubleType => gen.writeNumber(v.asDouble())
case _: Rql2DecimalType => gen.writeString(v.asString())
case _: Rql2DecimalType => gen.writeNumber(v.asString())
case _: Rql2StringType => gen.writeString(v.asString())
case _: Rql2DateType =>
val date = v.asDate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Rql2JsonWriter(os: OutputStream) {
case _: Rql2LongType => gen.writeNumber(v.asLong())
case _: Rql2FloatType => gen.writeNumber(v.asFloat())
case _: Rql2DoubleType => gen.writeNumber(v.asDouble())
case _: Rql2DecimalType => gen.writeString(v.asString())
case _: Rql2DecimalType => gen.writeNumber(v.asString())
case _: Rql2StringType => gen.writeString(v.asString())
case _: Rql2DateType =>
val date = v.asDate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,23 @@ trait CsvOutputTest extends CompilerTestContext {

test("""[
|{byteCol: Int.From("1"), shortCol:Int.From("10"), intCol: Int.From("100"), longCol: Int.From("1000"),
| floatCol: Double.From("3.14"), doubleCol: Double.From("6.28"), decimalCol: Double.From("9.42"), boolCol: true,
| floatCol: Double.From("3.14"), doubleCol: Double.From("6.28"), decimalCol: Decimal.From("9.42"), boolCol: true,
| dateCol: Date.Parse("12/25/2023", "M/d/yyyy"), timeCol: Time.Parse("01:02:03", "H:m:s"),
| timestampCol: Timestamp.Parse("12/25/2023 01:02:03", "M/d/yyyy H:m:s"), binaryCol: Binary.FromString("Hello World!")},
| timestampCol: Timestamp.Parse("12/25/2023 01:02:03", "M/d/yyyy H:m:s"), binaryCol: Binary.FromString("Hello World!"),
| stringCol:"Hello,World!"},
|{byteCol: Int.From("120"), shortCol:Int.From("2500"), intCol: Int.From("25000"), longCol: Long.From("9223372036854775807"),
| floatCol: Double.From("30.14"), doubleCol: Double.From("60.28"), decimalCol: Double.From("90.42"), boolCol: false,
| floatCol: Double.From("30.14"), doubleCol: Double.From("60.28"), decimalCol: Decimal.From("90.42"), boolCol: false,
| dateCol: Date.Parse("2/5/2023", "M/d/yyyy"), timeCol: Time.Parse("11:12:13", "H:m:s"),
| timestampCol: Timestamp.Parse("2/5/2023 11:12:13", "M/d/yyyy H:m:s"), binaryCol: Binary.FromString("Olala!")}
| timestampCol: Timestamp.Parse("2/5/2023 11:12:13", "M/d/yyyy H:m:s"), binaryCol: Binary.FromString("Olala!"),
| stringCol:"Ciao World!"}
|]""".stripMargin) { it =>
val path = Files.createTempFile("", "")
try {
it should saveToInFormat(path, "csv")
path should contain(
"""byteCol,shortCol,intCol,longCol,floatCol,doubleCol,decimalCol,boolCol,dateCol,timeCol,timestampCol,binaryCol
|1,10,100,1000,3.14,6.28,9.42,true,2023-12-25,01:02:03,2023-12-25T01:02:03,SGVsbG8gV29ybGQh
|120,2500,25000,9223372036854775807,30.14,60.28,90.42,false,2023-02-05,11:12:13,2023-02-05T11:12:13,T2xhbGEh
"""byteCol,shortCol,intCol,longCol,floatCol,doubleCol,decimalCol,boolCol,dateCol,timeCol,timestampCol,binaryCol,stringCol
|1,10,100,1000,3.14,6.28,9.42,true,2023-12-25,01:02:03,2023-12-25T01:02:03,SGVsbG8gV29ybGQh,"Hello,World!"
|120,2500,25000,9223372036854775807,30.14,60.28,90.42,false,2023-02-05,11:12:13,2023-02-05T11:12:13,T2xhbGEh,Ciao World!
|""".stripMargin
)
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ trait JsonOutputTest extends CompilerTestContext {

test("""[
|{byteCol: Int.From("1"), shortCol:Int.From("10"), intCol: Int.From("100"), longCol: Int.From("1000"),
| floatCol: Double.From("3.14"), doubleCol: Double.From("6.28"), decimalCol: Double.From("9.42"), boolCol: true,
| floatCol: Double.From("3.14"), doubleCol: Double.From("6.28"), decimalCol: Decimal.From("9.42"), boolCol: true,
| dateCol: Date.Parse("12/25/2023", "M/d/yyyy"), timeCol: Time.Parse("01:02:03", "H:m:s"),
| timestampCol: Timestamp.Parse("12/25/2023 01:02:03", "M/d/yyyy H:m:s"), binaryCol: Binary.FromString("Hello World!")},
|{byteCol: Int.From("120"), shortCol:Int.From("2500"), intCol: Int.From("25000"), longCol: Int.From("250000"),
| floatCol: Double.From("30.14"), doubleCol: Double.From("60.28"), decimalCol: Double.From("90.42"), boolCol: false,
| floatCol: Double.From("30.14"), doubleCol: Double.From("60.28"), decimalCol: Decimal.From("90.42"), boolCol: false,
| dateCol: Date.Parse("2/5/2023", "M/d/yyyy"), timeCol: Time.Parse("11:12:13", "H:m:s"),
| timestampCol: Timestamp.Parse("2/5/2023 11:12:13", "M/d/yyyy H:m:s"), binaryCol: Binary.FromString("Olala!")}
|]""".stripMargin) { it =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class TypedResultSetCsvWriter(os: OutputStream, lineSeparator: String) {
case _: RawLongType => gen.writeNumber(v.getLong(i))
case _: RawFloatType => gen.writeNumber(v.getFloat(i))
case _: RawDoubleType => gen.writeNumber(v.getDouble(i))
case _: RawDecimalType => gen.writeString(v.getBigDecimal(i).toString)
case _: RawDecimalType => gen.writeNumber(v.getBigDecimal(i))
case _: RawStringType => gen.writeString(v.getString(i))
case _: RawAnyType => v.getMetaData.getColumnTypeName(i) match {
case "jsonb" | "json" =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class TypedResultSetJsonWriter(os: OutputStream) {
case _: RawLongType => gen.writeNumber(v.getLong(i))
case _: RawFloatType => gen.writeNumber(v.getFloat(i))
case _: RawDoubleType => gen.writeNumber(v.getDouble(i))
case _: RawDecimalType => gen.writeString(v.getBigDecimal(i).toString)
case _: RawDecimalType => gen.writeNumber(v.getBigDecimal(i))
case _: RawStringType => gen.writeString(v.getString(i))
case _: RawAnyType => v.getMetaData.getColumnTypeName(i) match {
case "jsonb" | "json" =>
Expand Down

0 comments on commit 37d8998

Please sign in to comment.