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 2 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
4 changes: 2 additions & 2 deletions cpp/src/io/orc/orc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,16 +548,16 @@ std::vector<int> metadata::select_columns(std::vector<std::string> use_names,
}
}
}
CUDF_EXPECTS(selection.size() > 0, "Filtered out all columns");
} 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 @@ -425,6 +425,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 @@ -738,3 +738,19 @@ def test_nanoseconds_overflow():

pyarrow_got = pa.orc.ORCFile(buffer).read()
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)