Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RD-10527: Decimal raw data type shows as string in JSON output #343

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading