This is an automated email from the ASF dual-hosted git repository.
haonan pushed a commit to branch refector_py_table_session
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/refector_py_table_session by
this push:
new 255a6b181f3 tableSession python
255a6b181f3 is described below
commit 255a6b181f338028d972272fe0b8574c544ad70e
Author: HTHou <[email protected]>
AuthorDate: Thu Nov 28 15:13:37 2024 +0800
tableSession python
---
.github/workflows/multi-language-client.yml | 1 -
iotdb-client/client-py/iotdb/SessionPool.py | 6 ++-
iotdb-client/client-py/iotdb/table_session.py | 63 ++++++++++++++++++++++
iotdb-client/client-py/iotdb/table_session_pool.py | 47 ++++++++++++++++
4 files changed, 114 insertions(+), 3 deletions(-)
diff --git a/.github/workflows/multi-language-client.yml
b/.github/workflows/multi-language-client.yml
index f4c24188e38..5b66391a408 100644
--- a/.github/workflows/multi-language-client.yml
+++ b/.github/workflows/multi-language-client.yml
@@ -4,7 +4,6 @@ on:
branches:
- master
- "rc/*"
- - refector_py_table_session
paths:
- 'pom.xml'
- 'iotdb-client/pom.xml'
diff --git a/iotdb-client/client-py/iotdb/SessionPool.py
b/iotdb-client/client-py/iotdb/SessionPool.py
index 7d4b310bdcc..9fd6e5d0542 100644
--- a/iotdb-client/client-py/iotdb/SessionPool.py
+++ b/iotdb-client/client-py/iotdb/SessionPool.py
@@ -43,6 +43,7 @@ class PoolConfig(object):
time_zone: str = DEFAULT_TIME_ZONE,
max_retry: int = DEFAULT_MAX_RETRY,
enable_compression: bool = False,
+ enable_redirection: bool = True,
):
self.host = host
self.port = port
@@ -59,6 +60,7 @@ class PoolConfig(object):
self.time_zone = time_zone
self.max_retry = max_retry
self.enable_compression = enable_compression
+ self.enable_redirection = enable_redirection
class SessionPool(object):
@@ -83,7 +85,7 @@ class SessionPool(object):
self.__pool_config.password,
self.__pool_config.fetch_size,
self.__pool_config.time_zone,
- enable_redirection=True,
+ enable_redirection=self.__pool_config.enable_redirection,
)
session.sql_dialect = self.sql_dialect
session.database = self.database
@@ -96,7 +98,7 @@ class SessionPool(object):
self.__pool_config.password,
self.__pool_config.fetch_size,
self.__pool_config.time_zone,
- enable_redirection=True,
+ enable_redirection=self.__pool_config.enable_redirection,
)
session.sql_dialect = self.sql_dialect
session.database = self.database
diff --git a/iotdb-client/client-py/iotdb/table_session.py
b/iotdb-client/client-py/iotdb/table_session.py
index 747712125d3..5008f342e56 100644
--- a/iotdb-client/client-py/iotdb/table_session.py
+++ b/iotdb-client/client-py/iotdb/table_session.py
@@ -33,8 +33,29 @@ class TableSessionConfig(object):
database: str = None,
fetch_size: int = 5000,
time_zone: str = Session.DEFAULT_ZONE_ID,
+ enable_redirection: bool = True,
enable_compression: bool = False,
):
+ """
+ Initialize a TableSessionConfig object with the provided parameters.
+
+ Parameters:
+ node_urls (list, optional): A list of node URLs for the database
connection.
+ Defaults to ["localhost:6667"].
+ username (str, optional): The username for the database connection.
+ Defaults to "root".
+ password (str, optional): The password for the database connection.
+ Defaults to "root".
+ database (str, optional): The target database to connect to.
Defaults to None.
+ fetch_size (int, optional): The number of rows to fetch per query.
Defaults to 5000.
+ time_zone (str, optional): The default time zone for the session.
+ Defaults to Session.DEFAULT_ZONE_ID.
+ enable_redirection (bool, optional): Whether to enable redirection.
+ Defaults to False.
+ enable_compression (bool, optional): Whether to enable data
compression.
+ Defaults to False.
+
+ """
if node_urls is None:
node_urls = ["localhost:6667"]
self.node_urls = node_urls
@@ -43,6 +64,7 @@ class TableSessionConfig(object):
self.database = database
self.fetch_size = fetch_size
self.time_zone = time_zone
+ self.enable_redirection = enable_redirection
self.enable_compression = enable_compression
@@ -59,6 +81,7 @@ class TableSession(object):
table_session_config.password,
table_session_config.fetch_size,
table_session_config.time_zone,
+ table_session_config.enable_redirection,
)
self.__session.sql_dialect = "table"
self.__session.database = table_session_config.database
@@ -67,17 +90,57 @@ class TableSession(object):
self.__session = self.__session_pool.get_session()
def insert(self, tablet: Union[Tablet, NumpyTablet]):
+ """
+ Insert data into the database.
+
+ Parameters:
+ tablet (Tablet | NumpyTablet): The tablet containing the data to
be inserted.
+ Accepts either a `Tablet` or
`NumpyTablet`.
+
+ Raises:
+ IoTDBConnectionException: If there is an issue with the database
connection.
+ """
self.__session.insert_relational_tablet(tablet)
def execute_non_query_statement(self, sql: str):
+ """
+ Execute a non-query SQL statement.
+
+ Parameters:
+ sql (str): The SQL statement to execute. Typically used for
commands
+ such as INSERT, DELETE, or UPDATE.
+
+ Raises:
+ IoTDBConnectionException: If there is an issue with the database
connection.
+ """
self.__session.execute_non_query_statement(sql)
def execute_query_statement(
self, sql: str, timeout_in_ms: int = 0
) -> SessionDataSet:
+ """
+ Execute a query SQL statement and return the result set.
+
+ Parameters:
+ sql (str): The SQL query to execute.
+ timeout_in_ms (int, optional): Timeout for the query in
milliseconds. Defaults to 0,
+ which means no timeout.
+
+ Returns:
+ SessionDataSet: The result set of the query.
+
+ Raises:
+ IoTDBConnectionException: If there is an issue with the database
connection.
+ """
return self.__session.execute_query_statement(sql, timeout_in_ms)
def close(self):
+ """
+ Close the session and release resources.
+
+ Raises:
+ IoTDBConnectionException: If there is an issue closing the
connection.
+ """
if self.__session_pool is None:
self.__session.close()
else:
diff --git a/iotdb-client/client-py/iotdb/table_session_pool.py
b/iotdb-client/client-py/iotdb/table_session_pool.py
index a39628e5f42..8e3275a86e5 100644
--- a/iotdb-client/client-py/iotdb/table_session_pool.py
+++ b/iotdb-client/client-py/iotdb/table_session_pool.py
@@ -30,10 +30,36 @@ class TableSessionPoolConfig(object):
database: str = None,
fetch_size: int = 5000,
time_zone: str = Session.DEFAULT_ZONE_ID,
+ enable_redirection: bool = False,
enable_compression: bool = False,
wait_timeout_in_ms: int = 10000,
max_retry: int = 3,
):
+ """
+ Initialize a TableSessionPoolConfig object with the provided
parameters.
+
+ Parameters:
+ node_urls (list, optional): A list of node URLs for the database
connection.
+ Defaults to None.
+ max_pool_size (int, optional): The maximum number of sessions in
the pool.
+ Defaults to 5.
+ username (str, optional): The username for the database connection.
+ Defaults to Session.DEFAULT_USER.
+ password (str, optional): The password for the database connection.
+ Defaults to Session.DEFAULT_PASSWORD.
+ database (str, optional): The target database to connect to.
Defaults to None.
+ fetch_size (int, optional): The number of rows to fetch per query.
Defaults to 5000.
+ time_zone (str, optional): The default time zone for the session
pool.
+ Defaults to Session.DEFAULT_ZONE_ID.
+ enable_redirection (bool, optional): Whether to enable redirection.
+ Defaults to False.
+ enable_compression (bool, optional): Whether to enable data
compression.
+ Defaults to False.
+ wait_timeout_in_ms (int, optional): The maximum time (in
milliseconds) to wait for a session
+ to become available. Defaults
to 10000.
+ max_retry (int, optional): The maximum number of retry attempts
for operations. Defaults to 3.
+
+ """
if node_urls is None:
node_urls = ["localhost:6667"]
self.pool_config = PoolConfig(
@@ -43,6 +69,7 @@ class TableSessionPoolConfig(object):
fetch_size=fetch_size,
time_zone=time_zone,
max_retry=max_retry,
+ enable_redirection=enable_redirection,
enable_compression=enable_compression,
)
self.max_pool_size = max_pool_size
@@ -63,7 +90,27 @@ class TableSessionPool(object):
self.__session_pool.database = table_session_pool_config.database
def get_session(self) -> TableSession:
+ """
+ Retrieve a new TableSession instance.
+
+ Returns:
+ TableSession: A new session object configured with the session
pool.
+
+ Notes:
+ The session is initialized with the underlying session pool for
managing
+ connections. Ensure proper usage of the session's lifecycle.
+ """
return TableSession(None, session_pool=self.__session_pool)
def close(self):
+ """
+ Close the session pool and release all resources.
+
+ This method closes the underlying session pool, ensuring that all
+ resources associated with it are properly released.
+
+ Notes:
+ After calling this method, the session pool cannot be used to
retrieve
+ new sessions, and any attempt to do so may raise an exception.
+ """
self.__session_pool.close()