Skip to content

Commit

Permalink
Enable string to decimal 128 cast (#9742)
Browse files Browse the repository at this point in the history
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: #9742
  • Loading branch information
razajafri authored Nov 22, 2021
1 parent 7fa15db commit cac53c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions java/src/main/native/src/ColumnViewJni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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 @@ -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() {

Expand Down

0 comments on commit cac53c5

Please sign in to comment.