Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Java bindings to use default decimal precisions when writing columns #10276

Merged
merged 2 commits into from
Feb 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions java/src/main/java/ai/rapids/cudf/ColumnWriterOptions.java
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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;
}
Expand Down
13 changes: 8 additions & 5 deletions java/src/main/native/src/TableJni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,10 @@ 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_decimal_precision(precisions[read_index])
.set_nullability(nullability[read_index]);
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()) {
child.set_int96_timestamps(is_int96[read_index]);
}
Expand Down Expand Up @@ -717,8 +718,10 @@ 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]);
}
Expand Down