HaoYang670 commented on issue #3819:
URL:
https://github.com/apache/arrow-datafusion/issues/3819#issuecomment-1308371511
Hi @luobei42 . I tested on the datafusion-python 0.6.0 (installed by pip),
but I can't reproduce the bug.
```python
In [1]: import pyarrow as pa
In [2]: import datafusion
In [3]: datafusion.__version__
Out[3]: '0.6.0'
In [4]: batch = pa.RecordBatch.from_arrays(
...: [pa.array(a) for a in [
...: [0, 1, 2, 3],
...: ['Aldous0 Abfalterer0', 'Bob0 Abramovich0', 'Cyril0
Jobstreibitzer0', 'Dmitry0 Laurent0']]
...: ],
...: names=['id', 'name']
...: )
In [5]: batch0 = pa.RecordBatch.from_arrays(
...: [pa.array(a) for a in [
...: [0, 1, 2, 3, 4, 5],
...: [1, 2, 2, 3, 3, 3],
...: ['always a true house', 'always one true banana', 'never the false
tree', 'always the true table',
...: 'never a false house', 'always one green window']]
...: ],
...: names=['id', 'author_id', 'name']
...: )
In [6]: ctx = datafusion.SessionContext()
In [7]: ctx.register_record_batches('author', [[batch]])
In [8]: ctx.register_record_batches('book', [[batch0]])
In [9]: ctx.sql("select count() from author").collect()
---------------------------------------------------------------------------
Exception Traceback (most recent call last)
<ipython-input-10-19463c0b77f0> in <module>
----> 1 ctx.sql("select count() from author").collect()
Exception: DataFusion error: Plan("The function Count expects 1 arguments,
but 0 were provided")
In [10]: ctx.sql("select count(*) from author").collect()
Out[10]:
[pyarrow.RecordBatch
COUNT(UInt8(1)): uint64]
In [11]: ctx.sql("select count(*) from book").collect()
Out[11]:
[pyarrow.RecordBatch
COUNT(UInt8(1)): uint64]
In [14]: ctx.sql("""
...: SELECT a.id, a.name, count(distinct b.id)
...: from author a
...: left join book b on a.id=b.author_id
...: where a.id=0
...: group by a.id, a.name
...: """).show
Out[14]: <function DataFrame.show>
In [15]: ctx.sql("""
...: SELECT a.id, a.name, count(distinct b.id)
...: from author a
...: left join book b on a.id=b.author_id
...: where a.id=0
...: group by a.id, a.name
...: """).show()
+----+---------------------+----------------------+
| id | name | COUNT(DISTINCT b.id) |
+----+---------------------+----------------------+
| 0 | Aldous0 Abfalterer0 | 0 |
+----+---------------------+----------------------+
```
My code is a little different from yours in that I use `show` instead of
`collect`.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]