diff --git a/client/src/main/scala/raw/client/writers/TypedPolyglotCsvWriter.scala b/client/src/main/scala/raw/client/writers/TypedPolyglotCsvWriter.scala index 56dbaf357..61f4187f4 100644 --- a/client/src/main/scala/raw/client/writers/TypedPolyglotCsvWriter.scala +++ b/client/src/main/scala/raw/client/writers/TypedPolyglotCsvWriter.scala @@ -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() diff --git a/client/src/main/scala/raw/client/writers/TypedPolyglotJsonWriter.scala b/client/src/main/scala/raw/client/writers/TypedPolyglotJsonWriter.scala index 671d2193a..9384219c3 100644 --- a/client/src/main/scala/raw/client/writers/TypedPolyglotJsonWriter.scala +++ b/client/src/main/scala/raw/client/writers/TypedPolyglotJsonWriter.scala @@ -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() diff --git a/snapi-client/src/main/scala/raw/client/rql2/truffle/Rql2CsvWriter.scala b/snapi-client/src/main/scala/raw/client/rql2/truffle/Rql2CsvWriter.scala index 600178b77..2881ec625 100644 --- a/snapi-client/src/main/scala/raw/client/rql2/truffle/Rql2CsvWriter.scala +++ b/snapi-client/src/main/scala/raw/client/rql2/truffle/Rql2CsvWriter.scala @@ -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() diff --git a/snapi-client/src/main/scala/raw/client/rql2/truffle/Rql2JsonWriter.scala b/snapi-client/src/main/scala/raw/client/rql2/truffle/Rql2JsonWriter.scala index 86ae07d3f..e7a8714a3 100644 --- a/snapi-client/src/main/scala/raw/client/rql2/truffle/Rql2JsonWriter.scala +++ b/snapi-client/src/main/scala/raw/client/rql2/truffle/Rql2JsonWriter.scala @@ -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() diff --git a/snapi-client/src/test/scala/raw/compiler/rql2/tests/output/CsvOutputTest.scala b/snapi-client/src/test/scala/raw/compiler/rql2/tests/output/CsvOutputTest.scala index 878e41188..5f791240f 100644 --- a/snapi-client/src/test/scala/raw/compiler/rql2/tests/output/CsvOutputTest.scala +++ b/snapi-client/src/test/scala/raw/compiler/rql2/tests/output/CsvOutputTest.scala @@ -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 { diff --git a/snapi-client/src/test/scala/raw/compiler/rql2/tests/output/JsonOutputTest.scala b/snapi-client/src/test/scala/raw/compiler/rql2/tests/output/JsonOutputTest.scala index f8ee9252a..67c666d4c 100644 --- a/snapi-client/src/test/scala/raw/compiler/rql2/tests/output/JsonOutputTest.scala +++ b/snapi-client/src/test/scala/raw/compiler/rql2/tests/output/JsonOutputTest.scala @@ -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 => diff --git a/sql-client/src/main/scala/raw/client/sql/writers/TypedResultSetCsvWriter.scala b/sql-client/src/main/scala/raw/client/sql/writers/TypedResultSetCsvWriter.scala index 8ce248089..da4d6054e 100644 --- a/sql-client/src/main/scala/raw/client/sql/writers/TypedResultSetCsvWriter.scala +++ b/sql-client/src/main/scala/raw/client/sql/writers/TypedResultSetCsvWriter.scala @@ -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" => diff --git a/sql-client/src/main/scala/raw/client/sql/writers/TypedResultSetJsonWriter.scala b/sql-client/src/main/scala/raw/client/sql/writers/TypedResultSetJsonWriter.scala index ca95d2178..745fb1f5a 100644 --- a/sql-client/src/main/scala/raw/client/sql/writers/TypedResultSetJsonWriter.scala +++ b/sql-client/src/main/scala/raw/client/sql/writers/TypedResultSetJsonWriter.scala @@ -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" =>