From cac53c5b7f4845faea935b29a6efb323eff56a19 Mon Sep 17 00:00:00 2001 From: Raza Jafri Date: Mon, 22 Nov 2021 10:42:59 -0800 Subject: [PATCH] Enable string to decimal 128 cast (#9742) A short PR to enable String to Decimal 128 cast Authors: - Raza Jafri (https://github.com/razajafri) Approvers: - Robert (Bobby) Evans (https://github.com/revans2) URL: https://github.com/rapidsai/cudf/pull/9742 --- java/src/main/native/src/ColumnViewJni.cpp | 1 + .../java/ai/rapids/cudf/ColumnVectorTest.java | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/java/src/main/native/src/ColumnViewJni.cpp b/java/src/main/native/src/ColumnViewJni.cpp index bce330ea4a3..4efac307627 100644 --- a/java/src/main/native/src/ColumnViewJni.cpp +++ b/java/src/main/native/src/ColumnViewJni.cpp @@ -936,6 +936,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_castTo(JNIEnv *env, jclas break; case cudf::type_id::DECIMAL32: case cudf::type_id::DECIMAL64: + case cudf::type_id::DECIMAL128: result = cudf::strings::to_fixed_point(*column, n_data_type); break; default: JNI_THROW_NEW(env, "java/lang/IllegalArgumentException", "Invalid data type", 0); diff --git a/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java b/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java index f332661dc19..a582541a0d4 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 testCastStringToBigDecimal() { + String[] bigValues = {"923121331938210123.321", + "9223372036854775808.191", + "9328323982309091029831.002" + }; + + try (ColumnVector cv = ColumnVector.fromStrings(bigValues); + ColumnVector values = cv.castTo(DType.create(DType.DTypeEnum.DECIMAL128, -3)); + ColumnVector expected = ColumnVector.fromDecimals(new BigDecimal("923121331938210123.321"), + new BigDecimal("9223372036854775808.191"), + new BigDecimal("9328323982309091029831.002"))) { + assertColumnsAreEqual(expected, values); + } + } + @Test void testCastByteToString() {