2.3 Manipulate database tables and views using familiar Python functions and syntax
With the transparency layer classes, you can manipulate database tables and views using familiar Python functions and syntax, For example, using DataFrame proxy objects that map to database data, users can invoke overloaded Pandas functions that transparently generate SQL that runs in the database, using the database as a high-performance compute engine.
The OML4Py transparency layer does the following:
-
Enables creating tables and views from
pandas.DataFrame
and getting proxy objects to tables and views. -
Overloads specific Python functions that transparently translate functionality to SQL
-
Leverages proxy objects for database data
-
Uses familiar Python syntax to manipulate database data
The following table lists the transparency layer functions for getting and creating proxy objects and tables/views.
Table 2-1 Transparency Layer Functions for getting and creating proxy objects and tables/views
Function | Description |
---|---|
oml.create |
Creates a table in a the database schema from a Python data set. |
oml_object.pull |
Creates a local Python object that contains a copy of data fetched from database object referenced by the |
oml.push |
Pushes data from a Python session into an object in a database schema. |
oml.sync |
Creates a |
oml.dir |
Return the names of |
oml.drop |
Drops a persistent database table, view or in-database model. |
Transparency layer proxy classes map SQL data types or objects to corresponding Python types. The classes provide Python functions and operators that are the same as those on the mapped Python types. The following table lists the transparency layer data type classes.
Table 2-2 Transparency Layer Data Type Classes
Class | Description |
---|---|
oml.Boolean |
A boolean series data class that represents a single column of 0, 1, and NULL values in database data. |
oml.Bytes |
A binary series data class that represents a single column of |
oml.Float |
A numeric series data class that represents a single column of |
oml.String |
A character series data class that represents a single column of |
oml.DataFrame |
A tabular |
oml.Integer |
A data class that represents a single column of NUMBER(*,0) data in the database.
|
oml.Datetime |
A series date class that represents a single column of |
oml.Timezone |
A time class that is used with oml.Datetime to support TIME STAMP WITH TIME ZONE .
|
oml.Timedelta |
A time class that represents a single column series of differences between two dates or times, or INTERVAL DAY TO SECOND in Oracle Database.
|
oml.Vector |
A vector series data class that represents a single
column of VECTOR data in Oracle Database.
|
The following table lists the mappings of Python data types for both the reading and writing of data between Python and the database.
Table 2-3 Python and SQL Data Type Equivalencies
Database Read | Python Data Types | Database Write |
---|---|---|
N/A |
Bool |
If |
|
bytes |
|
|
float |
If |
|
str |
|
NUMBER(*,0) |
int |
NUMBER(*,0) |
TIMESTAMP or TIMESTAMP WITH TIME ZONE |
datetime.datetime |
TIMESTAMP or TIMESTAMP WITH TIME ZONE |
TIMESTAMP WITH TIME ZONE |
datetime.timezone |
TIMESTAMP WITH TIME ZONE |
INTERVAL DAY TO SECOND |
datetime.timedelta |
INTERVAL DAY TO SECOND |
Parent topic: About Oracle Machine Learning for Python