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

Fix ORC reader for empty DataFrame/Table #7624

Merged
merged 4 commits into from
Mar 22, 2021
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
6 changes: 4 additions & 2 deletions cpp/src/io/orc/orc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,26 +538,28 @@ std::vector<int> metadata::select_columns(std::vector<std::string> use_names,
if (not use_names.empty()) {
int index = 0;
for (const auto &use_name : use_names) {
bool name_found = false;
for (int i = 0; i < get_num_columns(); ++i, ++index) {
if (index >= get_num_columns()) { index = 0; }
if (get_column_name(index) == use_name) {
name_found = true;
selection.emplace_back(index);
if (ff.types[index].kind == orc::TIMESTAMP) { has_timestamp_column = true; }
index++;
break;
}
}
CUDF_EXPECTS(name_found, "Unknown column name : " + std::string(use_name));
}
} else {
// For now, only select all leaf nodes
for (int i = 0; i < get_num_columns(); ++i) {
for (int i = 1; i < get_num_columns(); ++i) {
if (ff.types[i].subtypes.empty()) {
selection.emplace_back(i);
if (ff.types[i].kind == orc::TIMESTAMP) { has_timestamp_column = true; }
}
}
}
CUDF_EXPECTS(selection.size() > 0, "Filtered out all columns");
rgsl888prabhu marked this conversation as resolved.
Show resolved Hide resolved

return selection;
}
Expand Down
3 changes: 3 additions & 0 deletions cpp/src/io/orc/reader_impl.cu
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ table_with_metadata reader::impl::read(size_type skip_rows,
std::vector<std::unique_ptr<column>> out_columns;
table_metadata out_metadata;

// There are no columns in table
if (_selected_columns.size() == 0) return {std::make_unique<table>(), std::move(out_metadata)};

// Select only stripes required (aka row groups)
const auto selected_stripes = _metadata->select_stripes(stripes, skip_rows, num_rows);

Expand Down
16 changes: 16 additions & 0 deletions python/cudf/cudf/tests/test_orc.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,22 @@ def test_nanoseconds_overflow():
assert_eq(expected.to_pandas(), pyarrow_got.to_pandas())


def test_empty_dataframe():
buffer = BytesIO()
expected = cudf.DataFrame()
expected.to_orc(buffer)

# Raise error if column name is mentioned, but it doesn't exist.
rgsl888prabhu marked this conversation as resolved.
Show resolved Hide resolved
with pytest.raises(RuntimeError):
cudf.read_orc(buffer, columns=["a"])

got_df = cudf.read_orc(buffer)
expected_pdf = pd.read_orc(buffer)

assert_eq(expected, got_df)
assert_eq(expected_pdf, got_df)


@pytest.mark.parametrize(
"data", [[None, ""], ["", None], [None, None], ["", ""]]
)
Expand Down