Skip to content

how to get full result of the sql() function #1795

Closed

Description

@l1t1

when the result is larger than 10 rows, it is truncated

>>> from datafusion import SessionContext
>>> import time
>>> ctx = SessionContext()

>>> ctx.sql("create table item as select i%7 i_category, i%11 i_color from (select value i from generate_series(1,10000\
00))")
No data to display

>>> t=time.time();df = ctx.sql("select i_color, count(distinct i_color) from item group by i_color");t=time.time()-t
>>> print(df)
DataFrame()
+---------+------------------------------+
| i_color | count(DISTINCT item.i_color) |
+---------+------------------------------+
| 5       | 1                            |
| 1       | 1                            |
| 10      | 1                            |
| 9       | 1                            |
| 2       | 1                            |
| 4       | 1                            |
| 7       | 1                            |
| 3       | 1                            |
| 8       | 1                            |
| 6       | 1                            |
+---------+------------------------------+
Data truncated.

Activity

  1. mohamd764 commented on Oct 16, 2026

    @mohamd764

    print(df) only shows a preview (the first 10 rows by default), so "Data truncated." doesn't mean the result is incomplete. I checked these options with datafusion 55.0.0 (Python 3.13, Linux) using your table:

    # 1. print more rows (default num=20)
    df.show(num=100)
    
    # 2. raise the limit used by print(df) / repr
    from datafusion.dataframe_formatter import configure_formatter
    configure_formatter(max_rows=50)
    print(df)        # all 11 rows, no "Data truncated."
    
    # 3. get the full result as data instead of a printout
    df.to_pandas()   # needs pandas
    df.to_pylist()   # list of dicts (11 rows here)
    df.collect()     # list of pyarrow RecordBatches
    df.to_arrow_table()

    configure_formatter applies to every DataFrame for the rest of the session. reset_formatter() from the same module restores the defaults.

    One thing to watch for: print(df) and df.show() run the query each time. If you want to look at the result more than once, convert it once (for example pdf = df.to_pandas()), or use df.cache() to keep it in memory.

  2. l1t1 commented on Oct 16, 2026

    @l1t1
    Author

    Thanks @mohamd764

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions