@@ -16,8 +16,8 @@ as `Apache PyArrow <https://arrow.apache.org/docs/python/index.html>`__,
1616<https://parquet.apache.org/> `__ format.
1717
1818Python-oracledb has a :ref: `DataFrame <oracledataframeobj >` object that exposes
19- an Apache Arrow PyCapsule Interface. This enables zero-copy data interchanges
20- to the data frame objects of other libraries.
19+ an Apache Arrow ArrowArrayStream PyCapsule Interface. This enables zero-copy
20+ data interchanges to the data frame objects of other libraries.
2121
2222.. note ::
2323
@@ -29,28 +29,30 @@ to the data frame objects of other libraries.
2929Fetching Data Frames
3030====================
3131
32- Data frames can be fetched by using a standard SQL query.
32+ Data frames can be fetched by using a standard SQL query with :ref: `Connection
33+ <connobj>` or :ref: `AsyncConnection <asyncconnobj >` methods.
3334
3435Data Frame Queries
3536------------------
3637
37- Python -oracledb has two methods for fetching rows into data frames:
38+ The python -oracledb methods for fetching rows into data frames are :
3839
3940- :meth: `Connection.fetch_df_all() ` fetches all rows from a query
4041- :meth: `Connection.fetch_df_batches() ` implements an iterator for fetching
4142 batches of rows
4243
43- The methods return python-oracledb :ref: `DataFrame <oracledataframeobj >`
44- objects.
44+ These methods can also be called from :ref: `AsyncConnection
45+ <asyncconnobj>`. The methods all return python-oracledb :ref: `DataFrame
46+ <oracledataframeobj>` objects.
4547
4648For example, to fetch all rows from a query and print some information about
4749the results:
4850
4951.. code-block :: python
5052
51- sql = " select * from departments"
53+ sql = " select * from departments where department_id > :1 "
5254 # Adjust arraysize to tune the query fetch performance
53- odf = connection.fetch_df_all(statement = sql, arraysize = 100 )
55+ odf = connection.fetch_df_all(statement = sql, parameters = [ 100 ], arraysize = 100 )
5456
5557 print (odf.column_names())
5658 print (f " { odf.num_columns()} columns " )
@@ -60,20 +62,20 @@ With Oracle Database's standard DEPARTMENTS table, this would display::
6062
6163 ['DEPARTMENT_ID', 'DEPARTMENT_NAME', 'MANAGER_ID', 'LOCATION_ID']
6264 4 columns
63- 27 rows
65+ 17 rows
6466
6567To fetch in batches, use an iterator:
6668
6769.. code-block :: python
6870
6971 import pyarrow
7072
71- sql = " select * from departments where department_id < 80 "
73+ sql = " select * from departments where department_id < :1 "
7274 # Adjust "size" to tune the query fetch performance
7375 # Here it is small to show iteration
74- for odf in connection.fetch_df_batches(statement = sql, size = 4 ):
75- pdf = pyarrow.table(odf).to_pandas()
76- print (pdf )
76+ for odf in connection.fetch_df_batches(statement = sql, parameters = [ 80 ], size = 4 ):
77+ df = pyarrow.table(odf).to_pandas()
78+ print (df )
7779
7880 With Oracle Database's standard DEPARTMENTS table, this would display::
7981
@@ -90,6 +92,24 @@ With Oracle Database's standard DEPARTMENTS table, this would display::
9092Converting to other data frame formats is :ref: `shown later <convertingodf >` in
9193this chapter.
9294
95+ **Asynchronous Data Frame Queries **
96+
97+ With :ref: `asynchronous programming <asyncio >`, use the appropriate syntax. For
98+ example, to fetch all rows at once:
99+
100+ .. code-block :: python
101+
102+ connection = await oracledb.connect_async(... )
103+ odf = await connection.fetch_df_all(sql = " select ..." , parameters = ... , arraysize = ... )
104+
105+ Or to iterate:
106+
107+ .. code-block :: python
108+
109+ connection = await oracledb.connect_async(... )
110+ async for odf in connection.fetch_df_batches(sql = " select ..." , parameters = ... , size = ... ):
111+ do_something(odf)
112+
93113 .. _dftypemapping :
94114
95115Data Frame Type Mapping
0 commit comments