Skip to content

Commit a692f74

Browse files
Added support for being able to bind a data frame to
cursor.executemany().
1 parent 96fa122 commit a692f74

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1217
-320
lines changed

doc/src/api_manual/async_connection.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ AsyncConnection Methods
137137
.. method:: AsyncConnection.fetch_df_all(statement, parameters=None, \
138138
arraysize=None)
139139

140-
Fetches all rows of the SQL query ``statement``, returning them in an
141-
:ref:`OracleDataFrame <oracledataframeobj>` object. An empty
142-
OracleDataFrame is returned if there are no rows available.
140+
Fetches all rows of the SQL query ``statement``, returning them in a
141+
:ref:`DataFrame <oracledataframeobj>` object. An empty DataFrame is
142+
returned if there are no rows available.
143143

144144
The ``parameters`` parameter can be a list of tuples, where each tuple item
145145
maps to one :ref:`bind variable placeholder <bind>` in ``statement``. It
@@ -165,9 +165,8 @@ AsyncConnection Methods
165165
size=None)
166166

167167
This returns an iterator yielding the next ``size`` rows of the SQL query
168-
``statement`` in each iteration as an :ref:`OracleDataFrame
169-
<oracledataframeobj>` object. An empty OracleDataFrame is returned if there
170-
are no rows available.
168+
``statement`` in each iteration as a :ref:`DataFrame <oracledataframeobj>`
169+
object. An empty DataFrame is returned if there are no rows available.
171170

172171
The ``parameters`` parameter can be a list of tuples, where each tuple item
173172
maps to one :ref:`bind variable placeholder <bind>` in ``statement``. It

doc/src/api_manual/async_cursor.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ AsyncCursor Methods
170170
list of dictionaries, where the keys match the bind variable placeholder
171171
names in ``statement``. If there are no bind values, or values have
172172
previously been bound, the ``parameters`` value can be an integer
173-
specifying the number of iterations.
173+
specifying the number of iterations. The ``parameters`` parameter can also
174+
be a :ref:`DataFrame <oracledataframeobj>`, or a third-party data frame
175+
that supports the `Apache Arrow PyCapsule <https://arrow.apache.org/docs/
176+
format/CDataInterface/PyCapsuleInterface.html>`__ Interface.
174177

175178
In python-oracledb Thick mode, if the size of the buffers allocated for any
176179
of the parameters exceeds 2 GB, you will receive the error ``DPI-1015:
@@ -196,6 +199,10 @@ AsyncCursor Methods
196199
string of length 1 so any values that are later bound as numbers or dates
197200
will raise a TypeError exception.
198201

202+
.. versionchanged:: 3.3.0
203+
204+
Added support for passing data frames in the ``parameters`` parameter.
205+
199206
.. method:: AsyncCursor.fetchall()
200207

201208
Fetches all (remaining) rows of a query result, returning them as a list of

doc/src/api_manual/connection.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ Connection Methods
119119
.. method:: Connection.fetch_df_all(statement, parameters=None, \
120120
arraysize=None)
121121

122-
Fetches all rows of the SQL query ``statement``, returning them in an
123-
:ref:`OracleDataFrame <oracledataframeobj>` object. An empty
124-
OracleDataFrame is returned if there are no rows available.
122+
Fetches all rows of the SQL query ``statement``, returning them in a
123+
:ref:`DataFrame <oracledataframeobj>` object. An empty DataFrame is
124+
returned if there are no rows available.
125125

126126
The ``parameters`` parameter can be a list of tuples, where each tuple item
127127
maps to one :ref:`bind variable placeholder <bind>` in ``statement``. It
@@ -151,9 +151,8 @@ Connection Methods
151151
size=None)
152152

153153
This returns an iterator yielding the next ``size`` rows of the SQL query
154-
``statement`` in each iteration as an :ref:`OracleDataFrame
155-
<oracledataframeobj>` object. An empty OracleDataFrame is returned if there
156-
are no rows available.
154+
``statement`` in each iteration as a :ref:`DataFrame <oracledataframeobj>`
155+
object. An empty DataFrame is returned if there are no rows available.
157156

158157
The ``parameters`` parameter can be a list of tuples, where each tuple item
159158
maps to one :ref:`bind variable placeholder <bind>` in ``statement``. It

doc/src/api_manual/cursor.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,10 @@ Cursor Methods
176176
list of dictionaries, where the keys match the bind variable placeholder
177177
names in ``statement``. If there are no bind values, or values have
178178
previously been bound, the ``parameters`` value can be an integer
179-
specifying the number of iterations.
179+
specifying the number of iterations. The ``parameters`` parameter can also
180+
be a :ref:`DataFrame <oracledataframeobj>`, or a third-party data frame
181+
that supports the `Apache Arrow PyCapsule <https://arrow.apache.org/docs/
182+
format/CDataInterface/PyCapsuleInterface.html>`__ Interface.
180183

181184
In python-oracledb Thick mode, if the size of the buffers allocated for any
182185
of the parameters exceeds 2 GB, you will receive the error ``DPI-1015:
@@ -202,6 +205,10 @@ Cursor Methods
202205
*None* is assumed to be a string of length 1 so any values that are later
203206
bound as numbers or dates will raise a TypeError exception.
204207

208+
.. versionchanged:: 3.3.0
209+
210+
Added support for passing data frames in the ``parameters`` parameter.
211+
205212
.. method:: Cursor.fetchall()
206213

207214
Fetches all (remaining) rows of a query result, returning them as a list of

doc/src/api_manual/dataframe.rst

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,58 +18,62 @@ from Oracle Database types to Arrow data types.
1818

1919
.. _oracledataframeobj:
2020

21-
OracleDataFrame Objects
22-
=======================
21+
DataFrame Objects
22+
=================
2323

24-
OracleDataFrame objects are returned from the methods
24+
DataFrame objects are returned from the methods
2525
:meth:`Connection.fetch_df_all()` and :meth:`Connection.fetch_df_batches()`.
2626

27-
Each column in OracleDataFrame exposes an `Apache Arrow PyCapsule
27+
Each column in a DataFrame exposes an `Apache Arrow PyCapsule
2828
<https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html>`__
2929
interface, giving access to the underlying Arrow array.
3030

3131
.. dbapiobjectextension::
3232

33+
.. versionchanged:: 3.3.0
34+
35+
Removed the prefix "Oracle" from the class name.
36+
3337
.. versionadded:: 3.0.0
3438

3539
.. _oracledataframemeth:
3640

37-
OracleDataFrame Methods
38-
-----------------------
41+
DataFrame Methods
42+
-----------------
3943

40-
.. method:: OracleDataFrame.column_arrays()
44+
.. method:: DataFrame.column_arrays()
4145

42-
Returns a list of :ref:`OracleArrowArray <oraclearrowarrayobj>` objects,
46+
Returns a list of :ref:`ArrowArray <oraclearrowarrayobj>` objects,
4347
each containing a select list column.
4448

45-
.. method:: OracleDataFrame.column_names()
49+
.. method:: DataFrame.column_names()
4650

4751
Returns a list of the column names in the data frame.
4852

49-
.. method:: OracleDataFrame.get_column(i)
53+
.. method:: DataFrame.get_column(i)
5054

51-
Returns an :ref:`OracleArrowArray <oraclearrowarrayobj>` object for the column
55+
Returns an :ref:`ArrowArray <oraclearrowarrayobj>` object for the column
5256
at the given index ``i``.
5357

54-
.. method:: OracleDataFrame.get_column_by_name(name)
58+
.. method:: DataFrame.get_column_by_name(name)
5559

56-
Returns an :ref:`OracleArrowArray <oraclearrowarrayobj>` object for the column
60+
Returns an :ref:`ArrowArray <oraclearrowarrayobj>` object for the column
5761
with the given name ``name``.
5862

59-
.. method:: OracleDataFrame.num_columns()
63+
.. method:: DataFrame.num_columns()
6064

6165
Returns the number of columns in the data frame.
6266

63-
.. method:: OracleDataFrame.num_rows()
67+
.. method:: DataFrame.num_rows()
6468

6569
Returns the number of rows in the data frame.
6670

6771
.. _oracledataframeattr:
6872

69-
OracleDataFrame Attributes
70-
--------------------------
73+
DataFrame Attributes
74+
--------------------
7175

72-
.. attribute:: OracleDataFrame.metadata
76+
.. attribute:: DataFrame.metadata
7377

7478
This read-only attribute returns the metadata for the data frame as a
7579
dictionary with keys ``num_columns``, ``num_rows``, and ``num_chunks``,
@@ -78,14 +82,17 @@ OracleDataFrame Attributes
7882

7983
.. _oraclearrowarrayobj:
8084

81-
OracleArrowArray Objects
82-
========================
85+
ArrowArray Objects
86+
==================
8387

84-
OracleArrowArray objects are returned by
85-
:meth:`OracleDataFrame.column_arrays()`.
88+
ArrowArray objects are returned by :meth:`DataFrame.column_arrays()`.
8689

8790
These are used for conversion to `PyArrow Tables
8891
<https://arrow.apache.org/docs/python/generated/pyarrow.Table.html>`__, see
8992
:ref:`dataframeformat`.
9093

94+
.. versionchanged:: 3.3.0
95+
96+
Removed the prefix "Oracle" from the class name.
97+
9198
.. versionadded:: 3.0.0

doc/src/api_manual/module.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,6 +2163,19 @@ Oracledb Methods
21632163

21642164
.. versionadded:: 2.5.0
21652165

2166+
.. function:: from_arrow(obj)
2167+
2168+
This method converts a data frame to a :ref:`DataFrame <oracledataframeobj>`
2169+
or :ref:`ArrowArray <oraclearrowarrayobj>` instance.
2170+
2171+
If ``obj`` supports the Arrow PyCapsule interface ``__arrow_c_stream__``
2172+
method, then ``from_arrow()`` returns the instance as a :ref:`DataFrame
2173+
<oracledataframeobj>`. If ``obj`` does not support that method, but does
2174+
support ``__arrow_c_array__``, then an :ref:`ArrowArray
2175+
<oraclearrowarrayobj>` is returned.
2176+
2177+
.. versionadded:: 3.3.0
2178+
21662179
.. function:: get_pool(pool_alias)
21672180

21682181
Returns a :ref:`ConnectionPool object <connpool>` from the python-oracledb

doc/src/release_notes.rst

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,25 @@ Common Changes
4242

4343
#) Changes to :ref:`data frame <dataframeformat>` support:
4444

45+
- Added support for binding data frames to :meth:`Cursor.executemany()` and
46+
:meth:`AsyncCursor.executemany()` for fast data ingestion. See
47+
:ref:`dfinsert`.
4548
- Added internal support for the ArrowArrayStream PyCapsule interface to
46-
simplify :ref:`OracleDataFrame <oracledataframeobj>` use.
47-
- Remove use of the DataFrame Interchange Protocol in
48-
:ref:`OracleDataFrames <oracledataframeobj>`.
49-
- Documentation on methods and attributes on the ``DataFrame`` and
50-
``ArrowArray`` objects are now available in Python plugins such as those
51-
found in VS Code
52-
- Upgraded Arrow C Data (nanoarrow) API version to 0.7.0
53-
- Ensure that the GIL is held when releasing references to ``ArrowArray``
54-
objects when exported Arrow buffers are released by the consumer. In
55-
some circumstances this could cause a segfault.
49+
simplify :ref:`DataFrame <oracledataframeobj>` use.
50+
- Remove use of the DataFrame Interchange Protocol in python-oracledb
51+
:ref:`DataFrame <oracledataframeobj>` objects.
52+
- Documentation on methods and attributes of the :ref:`DataFrame
53+
<oracledataframeobj>` and :ref:`ArrowArray <oraclearrowarrayobj>` objects
54+
is now available when using IDE introspection.
55+
- Upgraded Arrow C Data (nanoarrow) API version to 0.7.0.
56+
- Ensure that the GIL is held when releasing references to :ref:`ArrowArray
57+
<oraclearrowarrayobj>` objects when exported Arrow buffers are released
58+
by the consumer. This avoids a segfault seen in some circumstances.
5659
- Fixed bug when deciding Arrow datatype for numeric expressions
5760
(`issue 510 <https://github.com/oracle/python-oracledb/issues/510>`__)
5861

5962
Note the data frame support in python-oracledb 3.3 is a pre-release, and
60-
may change in a future version
63+
may change in a future version.
6164

6265
oracledb `3.2.0 <https://github.com/oracle/python-oracledb/compare/v3.1.1...v3.2.0>`__ (June 2025)
6366
--------------------------------------------------------------------------------------------------

doc/src/user_guide/batch_statement.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ the bind variable placeholder names:
102102
cursor.executemany("insert into ParentTable values :pid, :pdesc)", data)
103103
104104
105+
A data frame can alternatively be passed to :meth:`Cursor.executemany()`, see
106+
:ref:`dfinsert`.
107+
105108
.. _predefmemory:
106109

107110
Predefining Memory Areas

0 commit comments

Comments
 (0)