From 5e4b79bc01dc35fa97b098d4a7d673f8ccbc5afe Mon Sep 17 00:00:00 2001 From: Raza Jafri Date: Mon, 22 Nov 2021 16:34:21 -0800 Subject: [PATCH] Allow decimal128 cast and add tests --- java/src/main/native/src/ColumnViewJni.cpp | 25 ++++++++++++++----- .../java/ai/rapids/cudf/ColumnVectorTest.java | 16 ++++++++++++ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/java/src/main/native/src/ColumnViewJni.cpp b/java/src/main/native/src/ColumnViewJni.cpp index 4efac307627..12735b4de5a 100644 --- a/java/src/main/native/src/ColumnViewJni.cpp +++ b/java/src/main/native/src/ColumnViewJni.cpp @@ -904,9 +904,13 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_castTo(JNIEnv *env, jclas } if (n_data_type.id() == cudf::type_id::STRING) { switch (column->type().id()) { - case cudf::type_id::BOOL8: result = cudf::strings::from_booleans(*column); break; + case cudf::type_id::BOOL8: + result = cudf::strings::from_booleans(*column); + break; case cudf::type_id::FLOAT32: - case cudf::type_id::FLOAT64: result = cudf::strings::from_floats(*column); break; + case cudf::type_id::FLOAT64: + result = cudf::strings::from_floats(*column); + break; case cudf::type_id::INT8: case cudf::type_id::UINT8: case cudf::type_id::INT16: @@ -914,16 +918,25 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_castTo(JNIEnv *env, jclas case cudf::type_id::INT32: case cudf::type_id::UINT32: case cudf::type_id::INT64: - case cudf::type_id::UINT64: result = cudf::strings::from_integers(*column); break; + case cudf::type_id::UINT64: + result = cudf::strings::from_integers(*column); + break; case cudf::type_id::DECIMAL32: - case cudf::type_id::DECIMAL64: result = cudf::strings::from_fixed_point(*column); break; + case cudf::type_id::DECIMAL64: + case cudf::type_id::DECIMAL128: + result = cudf::strings::from_fixed_point(*column); + break; default: JNI_THROW_NEW(env, "java/lang/IllegalArgumentException", "Invalid data type", 0); } } else if (column->type().id() == cudf::type_id::STRING) { switch (n_data_type.id()) { - case cudf::type_id::BOOL8: result = cudf::strings::to_booleans(*column); break; + case cudf::type_id::BOOL8: + result = cudf::strings::to_booleans(*column); + break; case cudf::type_id::FLOAT32: - case cudf::type_id::FLOAT64: result = cudf::strings::to_floats(*column, n_data_type); break; + case cudf::type_id::FLOAT64: + result = cudf::strings::to_floats(*column, n_data_type); + break; case cudf::type_id::INT8: case cudf::type_id::UINT8: case cudf::type_id::INT16: diff --git a/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java b/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java index a582541a0d4..a2832184b5b 100644 --- a/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java +++ b/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java @@ -3370,6 +3370,22 @@ void testFixedWidthCast() { } } + @Test + void testCastBigDecimalToString() { + BigDecimal[] bigValues = {new BigDecimal("923121331938210123.321"), + new BigDecimal("9223372036854775808.191"), + new BigDecimal("9328323982309091029831.002") + }; + + try (ColumnVector cv = ColumnVector.fromDecimals(bigValues); + ColumnVector values = cv.castTo(DType.STRING); + ColumnVector expected = ColumnVector.fromStrings("923121331938210123.321", + "9223372036854775808.191", + "9328323982309091029831.002")) { + assertColumnsAreEqual(expected, values); + } + } + @Test void testCastStringToBigDecimal() { String[] bigValues = {"923121331938210123.321",