Skip to content

Commit

Permalink
Allow cast decimal128 to string and add tests (#9756)
Browse files Browse the repository at this point in the history
Small PR that enables Decimal128 cast

Authors:
  - Raza Jafri (https://github.com/razajafri)

Approvers:
  - Jason Lowe (https://github.com/jlowe)

URL: #9756
  • Loading branch information
razajafri authored Dec 1, 2021
1 parent 677e632 commit 7d8a8e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion java/src/main/native/src/ColumnViewJni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,8 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_castTo(JNIEnv *env, jclas
case cudf::type_id::INT64:
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) {
Expand Down
16 changes: 16 additions & 0 deletions java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3372,6 +3372,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",
Expand Down

0 comments on commit 7d8a8e5

Please sign in to comment.