You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2024/01/17 12:09:50 UTC
[PR] Fix datafusion-cli print output [arrow-datafusion]
alamb opened a new pull request, #8895:
URL: https://github.com/apache/arrow-datafusion/pull/8895
## Which issue does this PR close?
Resolves https://github.com/apache/arrow-datafusion/issues/8702
## Rationale for this change
This is a regression introduced in https://github.com/apache/arrow-datafusion/pull/8651 where if the first record batch happens to be empty data in non empty batches will not be printed.
## What changes are included in this PR?
1. Fix bug
2. Add test
## Are these changes tested?
Yes, new tests
## Are there any user-facing changes?
Fix but
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix `datafusion-cli` print output [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #8895:
URL: https://github.com/apache/arrow-datafusion/pull/8895#discussion_r1457315634
##########
datafusion-cli/src/print_format.rs:
##########
@@ -161,23 +161,29 @@ impl PrintFormat {
maxrows: MaxRows,
with_header: bool,
) -> Result<()> {
- if batches.is_empty() || batches[0].num_rows() == 0 {
+ // filter out any empty batches
+ let batches: Vec<_> = batches
+ .iter()
+ .filter(|b| b.num_rows() > 0)
+ .cloned()
+ .collect();
+ if batches.is_empty() {
Review Comment:
Filed https://github.com/apache/arrow-datafusion/issues/8904 to track (and I confirmed the "print nothing if no data" behavior was present in versions 33 and 25).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix `datafusion-cli` print output [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #8895:
URL: https://github.com/apache/arrow-datafusion/pull/8895#discussion_r1455792157
##########
datafusion-cli/src/print_format.rs:
##########
@@ -161,7 +161,7 @@ impl PrintFormat {
maxrows: MaxRows,
with_header: bool,
) -> Result<()> {
- if batches.is_empty() || batches[0].num_rows() == 0 {
+ if batches.is_empty() {
Review Comment:
fixed in 2ef1f9dcd
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix `datafusion-cli` print output [arrow-datafusion]
Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on code in PR #8895:
URL: https://github.com/apache/arrow-datafusion/pull/8895#discussion_r1457211730
##########
datafusion-cli/src/print_format.rs:
##########
@@ -161,23 +161,29 @@ impl PrintFormat {
maxrows: MaxRows,
with_header: bool,
) -> Result<()> {
- if batches.is_empty() || batches[0].num_rows() == 0 {
+ // filter out any empty batches
+ let batches: Vec<_> = batches
+ .iter()
+ .filter(|b| b.num_rows() > 0)
+ .cloned()
+ .collect();
+ if batches.is_empty() {
Review Comment:
Ah ok, I didn't realize the "print nothing if no data" was a previous issue before that streaming PR
Then yeah I agree can fix that separately if it wasn't technically a regression
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix `datafusion-cli` print output [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #8895:
URL: https://github.com/apache/arrow-datafusion/pull/8895#discussion_r1455399428
##########
datafusion-cli/src/print_format.rs:
##########
@@ -161,7 +161,7 @@ impl PrintFormat {
maxrows: MaxRows,
with_header: bool,
) -> Result<()> {
- if batches.is_empty() || batches[0].num_rows() == 0 {
+ if batches.is_empty() {
Review Comment:
This is the fix (thanks @Jefffrey for finding this). The rest of the PR is tests
##########
datafusion-cli/src/print_format.rs:
##########
@@ -351,4 +351,82 @@ mod tests {
Ok(())
}
+
+
+ #[test]
+ fn test_print_batches_empty_batches() -> Result<()> {
+ let batch = RecordBatch::try_from_iter(
+ vec![
+ ("a", Arc::new(Int32Array::from(vec![1, 2, 3])) as ArrayRef),
+ ],
+ )?;
+ let empty_batch = RecordBatch::new_empty(batch.schema());
+
+ PrintBatchesTest::new()
+ .with_format(PrintFormat::Table)
+ .with_batches(vec![
+ empty_batch.clone(),
+ batch,
+ empty_batch,
+ ])
+ .with_expected(
+ &[
+ "+---+",
+ "| a |",
+ "+---+",
+ "| 1 |",
+ "| 2 |",
+ "| 3 |",
+ "+---+\n",
+ ])
+ .run();
+ Ok(())
+ }
+
+ struct PrintBatchesTest {
Review Comment:
I plan to rework the rest of the tests in this module as a follow on PR using this struct
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix `datafusion-cli` print output [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8895:
URL: https://github.com/apache/arrow-datafusion/pull/8895#issuecomment-1896635246
I plan to merge this tomorrow morning US Eastern time unless anyone else would like more time to review
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix `datafusion-cli` print output [arrow-datafusion]
Posted by "crepererum (via GitHub)" <gi...@apache.org>.
crepererum commented on code in PR #8895:
URL: https://github.com/apache/arrow-datafusion/pull/8895#discussion_r1455440663
##########
datafusion-cli/src/print_format.rs:
##########
@@ -161,7 +161,7 @@ impl PrintFormat {
maxrows: MaxRows,
with_header: bool,
) -> Result<()> {
- if batches.is_empty() || batches[0].num_rows() == 0 {
+ if batches.is_empty() {
Review Comment:
To keep the intended behavior, I think this should probably be:
```suggestion
if batches.is_empty() || batches.iter().all(|b| b.num_rows() == 0) {
```
However, I think the intention is wrong. We should totally print the header even if there's no data. This entire "don't print anything if the result is empty" is super confusing, at least in my opinion.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix `datafusion-cli` print output [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8895:
URL: https://github.com/apache/arrow-datafusion/pull/8895#issuecomment-1898309616
Thanks everyone for the reviews
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix `datafusion-cli` print output [arrow-datafusion]
Posted by "Jefffrey (via GitHub)" <gi...@apache.org>.
Jefffrey commented on code in PR #8895:
URL: https://github.com/apache/arrow-datafusion/pull/8895#discussion_r1456993754
##########
datafusion-cli/src/print_format.rs:
##########
@@ -161,23 +161,29 @@ impl PrintFormat {
maxrows: MaxRows,
with_header: bool,
) -> Result<()> {
- if batches.is_empty() || batches[0].num_rows() == 0 {
+ // filter out any empty batches
+ let batches: Vec<_> = batches
+ .iter()
+ .filter(|b| b.num_rows() > 0)
+ .cloned()
+ .collect();
+ if batches.is_empty() {
Review Comment:
What will happen for queries that return empty results?
e.g.
```sql
select * from table where 1=0
```
Will this print nothing at all, not even the table outline?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix `datafusion-cli` print output [arrow-datafusion]
Posted by "crepererum (via GitHub)" <gi...@apache.org>.
crepererum commented on code in PR #8895:
URL: https://github.com/apache/arrow-datafusion/pull/8895#discussion_r1457179034
##########
datafusion-cli/src/print_format.rs:
##########
@@ -161,23 +161,29 @@ impl PrintFormat {
maxrows: MaxRows,
with_header: bool,
) -> Result<()> {
- if batches.is_empty() || batches[0].num_rows() == 0 {
+ // filter out any empty batches
+ let batches: Vec<_> = batches
+ .iter()
+ .filter(|b| b.num_rows() > 0)
+ .cloned()
+ .collect();
+ if batches.is_empty() {
Review Comment:
> Will this print nothing at all, not even the table outline?
Right, it will NOT print the outline / header. Also see https://github.com/apache/arrow-datafusion/pull/8895#discussion_r1455440663 , i.e. I also find this rather confusing. However this PR here just fixes the status quo to not swallow the output for aggregates. I personally think we should change the behavior in a follow-up to at least print the table outline / header even for empty results.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix `datafusion-cli` print output [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #8895:
URL: https://github.com/apache/arrow-datafusion/pull/8895#issuecomment-1898531044
I added better test coverage in https://github.com/apache/arrow-datafusion/pull/8896 as promised
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix `datafusion-cli` print output [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #8895:
URL: https://github.com/apache/arrow-datafusion/pull/8895#discussion_r1455723399
##########
datafusion-cli/src/print_format.rs:
##########
@@ -161,7 +161,7 @@ impl PrintFormat {
maxrows: MaxRows,
with_header: bool,
) -> Result<()> {
- if batches.is_empty() || batches[0].num_rows() == 0 {
+ if batches.is_empty() {
Review Comment:
> However, I think the intention is wrong. We should totally print the header even if there's no data. This entire "don't print anything if the result is empty" is super confusing, at least in my opinion.
This is a good call -- I will update and add a test
I believe the logic is to support generating output incrementally ("Streaming") rather than waiting for the entire output to be generated as `Vec<RecordBatch>`.
However, that logic is sort of split between this module and `print_format.rs` which I agree is confusing
cc @berkaysynnada
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix `datafusion-cli` print output [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #8895:
URL: https://github.com/apache/arrow-datafusion/pull/8895#discussion_r1455804945
##########
datafusion-cli/src/print_format.rs:
##########
@@ -351,4 +351,82 @@ mod tests {
Ok(())
}
+
+
+ #[test]
+ fn test_print_batches_empty_batches() -> Result<()> {
+ let batch = RecordBatch::try_from_iter(
+ vec![
+ ("a", Arc::new(Int32Array::from(vec![1, 2, 3])) as ArrayRef),
+ ],
+ )?;
+ let empty_batch = RecordBatch::new_empty(batch.schema());
+
+ PrintBatchesTest::new()
+ .with_format(PrintFormat::Table)
+ .with_batches(vec![
+ empty_batch.clone(),
+ batch,
+ empty_batch,
+ ])
+ .with_expected(
+ &[
+ "+---+",
+ "| a |",
+ "+---+",
+ "| 1 |",
+ "| 2 |",
+ "| 3 |",
+ "+---+\n",
+ ])
+ .run();
+ Ok(())
+ }
+
+ struct PrintBatchesTest {
Review Comment:
https://github.com/apache/arrow-datafusion/pull/8896
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix `datafusion-cli` print output [arrow-datafusion]
Posted by "berkaysynnada (via GitHub)" <gi...@apache.org>.
berkaysynnada commented on code in PR #8895:
URL: https://github.com/apache/arrow-datafusion/pull/8895#discussion_r1457015913
##########
datafusion-cli/src/print_format.rs:
##########
@@ -161,23 +161,29 @@ impl PrintFormat {
maxrows: MaxRows,
with_header: bool,
) -> Result<()> {
- if batches.is_empty() || batches[0].num_rows() == 0 {
+ // filter out any empty batches
+ let batches: Vec<_> = batches
+ .iter()
+ .filter(|b| b.num_rows() > 0)
+ .cloned()
+ .collect();
+ if batches.is_empty() {
Review Comment:
I would also like to mention that a similar behavior exists for streaming results. If the first batch of the stream is empty, the header will not be printed, even if it was set to true (this issue existed prior to this PR). Perhaps we should print an empty record batch for the header before these checks if the flag is set.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix `datafusion-cli` print output [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #8895:
URL: https://github.com/apache/arrow-datafusion/pull/8895
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org