From f5dfe4fb70e707e322e82cef2f681fbdbfb9eff5 Mon Sep 17 00:00:00 2001 From: sperlingxx Date: Mon, 14 Feb 2022 16:35:40 +0800 Subject: [PATCH 1/2] only set precision for decimal columns Signed-off-by: sperlingxx --- .../main/java/ai/rapids/cudf/ColumnWriterOptions.java | 9 ++++++--- java/src/main/native/src/TableJni.cpp | 11 ++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/java/src/main/java/ai/rapids/cudf/ColumnWriterOptions.java b/java/src/main/java/ai/rapids/cudf/ColumnWriterOptions.java index 0e49636fae6..78b3d5d52ec 100644 --- a/java/src/main/java/ai/rapids/cudf/ColumnWriterOptions.java +++ b/java/src/main/java/ai/rapids/cudf/ColumnWriterOptions.java @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2021, NVIDIA CORPORATION. + * Copyright (c) 2021-2022, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,6 +40,9 @@ private ColumnWriterOptions(AbstractStructBuilder builder) { (ColumnWriterOptions[]) builder.children.toArray(new ColumnWriterOptions[0]); } + // The sentinel value of unknown precision (default value) + public static int UNKNOWN_PRECISION = -1; + /** * Constructor used for list */ @@ -103,7 +106,7 @@ protected ColumnWriterOptions withDecimal(String name, int precision, protected ColumnWriterOptions withTimestamp(String name, boolean isInt96, boolean isNullable) { - return new ColumnWriterOptions(name, isInt96, 0, isNullable); + return new ColumnWriterOptions(name, isInt96, UNKNOWN_PRECISION, isNullable); } /** @@ -243,7 +246,7 @@ public ColumnWriterOptions(String columnName, boolean isTimestampTypeInt96, public ColumnWriterOptions(String columnName, boolean isNullable) { this.isTimestampTypeInt96 = false; - this.precision = 0; + this.precision = UNKNOWN_PRECISION; this.isNullable = isNullable; this.columnName = columnName; } diff --git a/java/src/main/native/src/TableJni.cpp b/java/src/main/native/src/TableJni.cpp index eac76222475..6412bd65c48 100644 --- a/java/src/main/native/src/TableJni.cpp +++ b/java/src/main/native/src/TableJni.cpp @@ -677,8 +677,10 @@ int set_column_metadata(cudf::io::column_in_metadata &column_metadata, for (int i = 0; i < num_children; i++, write_index++) { cudf::io::column_in_metadata child; child.set_name(col_names[read_index]) - .set_decimal_precision(precisions[read_index]) .set_nullability(nullability[read_index]); + if (precisions[read_index] > - 1) { + child.set_decimal_precision(precisions[read_index]); + } if (!is_int96.is_null()) { child.set_int96_timestamps(is_int96[read_index]); } @@ -717,8 +719,11 @@ void createTableMetaData(JNIEnv *env, jint num_children, jobjectArray &j_col_nam for (int i = read_index, write_index = 0; i < top_level_children; i++, write_index++) { metadata.column_metadata[write_index] .set_name(cpp_names[read_index]) - .set_nullability(col_nullability[read_index]) - .set_decimal_precision(precisions[read_index]); + .set_nullability(col_nullability[read_index]); + if (precisions[read_index] > - 1) { + metadata.column_metadata[write_index] + .set_decimal_precision(precisions[read_index]); + } if (!is_int96.is_null()) { metadata.column_metadata[write_index].set_int96_timestamps(is_int96[read_index]); } From fd2aa6d15fc1d188bd471d60bd29c39b4e908bd6 Mon Sep 17 00:00:00 2001 From: sperlingxx Date: Mon, 14 Feb 2022 18:13:59 +0800 Subject: [PATCH 2/2] fix Signed-off-by: sperlingxx --- java/src/main/native/src/TableJni.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/java/src/main/native/src/TableJni.cpp b/java/src/main/native/src/TableJni.cpp index 6412bd65c48..1cf56da35da 100644 --- a/java/src/main/native/src/TableJni.cpp +++ b/java/src/main/native/src/TableJni.cpp @@ -676,9 +676,8 @@ int set_column_metadata(cudf::io::column_in_metadata &column_metadata, int write_index = 0; for (int i = 0; i < num_children; i++, write_index++) { cudf::io::column_in_metadata child; - child.set_name(col_names[read_index]) - .set_nullability(nullability[read_index]); - if (precisions[read_index] > - 1) { + child.set_name(col_names[read_index]).set_nullability(nullability[read_index]); + if (precisions[read_index] > -1) { child.set_decimal_precision(precisions[read_index]); } if (!is_int96.is_null()) { @@ -720,9 +719,8 @@ void createTableMetaData(JNIEnv *env, jint num_children, jobjectArray &j_col_nam metadata.column_metadata[write_index] .set_name(cpp_names[read_index]) .set_nullability(col_nullability[read_index]); - if (precisions[read_index] > - 1) { - metadata.column_metadata[write_index] - .set_decimal_precision(precisions[read_index]); + if (precisions[read_index] > -1) { + metadata.column_metadata[write_index].set_decimal_precision(precisions[read_index]); } if (!is_int96.is_null()) { metadata.column_metadata[write_index].set_int96_timestamps(is_int96[read_index]);