Skip to content

Releases v0.12.3b3 #270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions docs/source/db-dbapi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ PyODPS 支持使用 `Python DBAPI <https://peps.python.org/pep-0249/>`_

创建连接
-----------
可以通过指定 ``access_id``、``access_key``、``project````endpoint``
可以通过指定 ``access_id``、\ ``access_key``、\ ``project``\ 和\ ``endpoint``
来建立连接:

.. code-block:: python
Expand All @@ -25,9 +25,15 @@ PyODPS 支持使用 `Python DBAPI <https://peps.python.org/pep-0249/>`_
>>> import odps.dbapi
>>> conn = odps.dbapi.connect(o) # type(o) is ODPS

如果要使用 MaxQA(MCQA 2.0)查询加速,可以指定 ``use_sqa='v2'`` 并指定 ``quota_name`` 参数:

.. code-block:: python

>>> conn = odps.dbapi.connect(o, use_sqa='v2', quota_name='my_quota')

执行 SQL
----------
创建游标并在游标上执行 SQL:
你可以创建游标并在游标上执行 SQL:

.. code-block:: python

Expand All @@ -40,9 +46,23 @@ PyODPS 支持使用 `Python DBAPI <https://peps.python.org/pep-0249/>`_
('petal_width', 'double', None, None, None, None, True),
('category', 'string', None, None, None, None, True)]

PyODPS 使用与标准库 ``sqlite3`` 一样的参数指定方式指定查询参数。你可以使用 ``?`` 指定非命名参数,
使用 ``:name`` 指定命名参数,并使用 tuple 替换非命名参数,使用 dict 替换命名参数。

.. code-block:: python

>>> # 使用非命名参数
>>> cursor.execute("SELECT * FROM pyodps_iris WHERE petal_length > ?", (1.5,))
>>> print(cursor.fetchone())
[5.4, 3.9, 1.7, 0.4, 'Iris-setosa']
>>> # 使用命名参数
>>> cursor.execute("SELECT * FROM pyodps_iris WHERE petal_length > :length", {'length': 1.5})
>>> print(cursor.fetchone())
[5.4, 3.9, 1.7, 0.4, 'Iris-setosa']

读取结果
----------
使用和标准的 DBAPI 一样使用迭代的方式读取结果:
你可以使用和标准的 DBAPI 一样使用迭代的方式读取结果:

.. code-block:: python

Expand Down
4 changes: 2 additions & 2 deletions docs/source/interactive.rst
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,9 @@ PyODPS 还提供了 SQL 插件,来执行 ODPS SQL。下面是单行 SQL:

In [1]: %load_ext odps

In [2]: mytable = 'dual'
In [2]: var = '0'

In [3]: %sql select * from :mytable
In [3]: %sql select * from table_name where c_string_a = :var
|==========================================| 1 / 1 (100.00%) 2s
Out[3]:
c_int_a c_int_b c_double_a c_double_b c_string_a c_string_b c_bool_a \
Expand Down
76 changes: 56 additions & 20 deletions docs/source/locale/en/LC_MESSAGES/db-dbapi.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PyODPS 0.11.2\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-07-31 22:03+0800\n"
"POT-Creation-Date: 2025-04-15 10:45+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -22,17 +22,15 @@ msgid "DBAPI 接口"
msgstr "DBAPI Interface"

#: ../../source/db-dbapi.rst:6
msgid ""
"在 PyODPS 0.10.0 中开始支持。事务操作不被 MaxCompute 支持,因而未实现相关"
"接口。"
msgid "在 PyODPS 0.10.0 中开始支持。事务操作不被 MaxCompute 支持,因而未实现相关接口。"
msgstr ""
"Supported since PyODPS 0.10.0. As transaction operations are not "
"supported in MaxCompute, related interfaces are not implemented."

#: ../../source/db-dbapi.rst:8
msgid ""
"PyODPS 支持使用 `Python DBAPI <https://peps.python.org/pep-0249/>`_ 兼容"
"的数据库访问接口访问 MaxCompute。"
"PyODPS 支持使用 `Python DBAPI <https://peps.python.org/pep-0249/>`_ "
"兼容的数据库访问接口访问 MaxCompute。"
msgstr ""
"PyODPS supports accessing MaxCompute data via `Python DBAPI "
"<https://peps.python.org/pep-0249/>`_ compatible interfaces."
Expand All @@ -43,8 +41,8 @@ msgstr "Create connections"

#: ../../source/db-dbapi.rst:13
msgid ""
"可以通过指定 ``access_id``、``access_key``、``project````endpoint`` "
"建立连接:"
"可以通过指定 ``access_id``、\\ ``access_key``、\\ ``project``\\ 和\\ ``endpoint`` "
"来建立连接:"
msgstr ""
"Connections can be established via ``access_id``, ``access_key``, "
"`project`` and ``endpoint``."
Expand All @@ -66,15 +64,23 @@ msgid ""
">>> conn = odps.dbapi.connect(o) # type(o) is ODPS"
msgstr ""

#: ../../source/db-dbapi.rst:29
#: ../../source/db-dbapi.rst:28
msgid "如果要使用 MaxQA(MCQA 2.0)查询加速,可以指定 ``use_sqa='v2'`` 并指定 ``quota_name`` 参数:"
msgstr ""

#: ../../source/db-dbapi.rst:30
msgid ">>> conn = odps.dbapi.connect(o, use_sqa='v2', quota_name='my_quota')"
msgstr ""

#: ../../source/db-dbapi.rst:35
msgid "执行 SQL"
msgstr "Execute SQL statements"

#: ../../source/db-dbapi.rst:30
msgid "创建游标并在游标上执行 SQL:"
msgstr "Create a cursor and execute SQL statement on it."
#: ../../source/db-dbapi.rst:36
msgid "你可以创建游标并在游标上执行 SQL:"
msgstr "You can create a cursor and execute SQL statement on it."

#: ../../source/db-dbapi.rst:32
#: ../../source/db-dbapi.rst:38
msgid ""
">>> cursor = conn.cursor()\n"
">>> cursor.execute(\"SELECT * FROM pyodps_iris\")\n"
Expand All @@ -86,25 +92,55 @@ msgid ""
" ('category', 'string', None, None, None, None, True)]"
msgstr ""

#: ../../source/db-dbapi.rst:44
#: ../../source/db-dbapi.rst:49
msgid ""
"PyODPS 使用与标准库 ``sqlite3`` 一样的参数指定方式指定查询参数。你可以使用 ``?`` 指定非命名参数, 使用 "
"``:name`` 指定命名参数,并使用 tuple 替换非命名参数,使用 dict 替换命名参数。"
msgstr ""

#: ../../source/db-dbapi.rst:52
msgid ""
">>> # 使用非命名参数\n"
">>> cursor.execute(\"SELECT * FROM pyodps_iris WHERE petal_length > ?\", "
"(1.5,))\n"
">>> print(cursor.fetchone())\n"
"[5.4, 3.9, 1.7, 0.4, 'Iris-setosa']\n"
">>> # 使用命名参数\n"
">>> cursor.execute(\"SELECT * FROM pyodps_iris WHERE petal_length > "
":length\", {'length': 1.5})\n"
">>> print(cursor.fetchone())\n"
"[5.4, 3.9, 1.7, 0.4, 'Iris-setosa']"
msgstr ""
">>> # use anonymous parameters\n"
">>> cursor.execute(\"SELECT * FROM pyodps_iris WHERE petal_length > ?\", "
"(1.5,))\n"
">>> print(cursor.fetchone())\n"
"[5.4, 3.9, 1.7, 0.4, 'Iris-setosa']\n"
">>> # use named parameters\n"
">>> cursor.execute(\"SELECT * FROM pyodps_iris WHERE petal_length > "
":length\", {'length': 1.5})\n"
">>> print(cursor.fetchone())\n"
"[5.4, 3.9, 1.7, 0.4, 'Iris-setosa']"

#: ../../source/db-dbapi.rst:64
msgid "读取结果"
msgstr "Read results"

#: ../../source/db-dbapi.rst:45
msgid "使用和标准的 DBAPI 一样使用迭代的方式读取结果:"
msgstr "Use iterations to read results just like standard DBAPI."
#: ../../source/db-dbapi.rst:65
msgid "你可以使用和标准的 DBAPI 一样使用迭代的方式读取结果:"
msgstr "You can use iterations to read results just like standard DBAPI."

#: ../../source/db-dbapi.rst:47
#: ../../source/db-dbapi.rst:67
msgid ""
">>> for rec in cursor:\n"
">>> print(rec)"
msgstr ""

#: ../../source/db-dbapi.rst:52
#: ../../source/db-dbapi.rst:72
msgid "也可以一次性读取所有结果:"
msgstr "You can also fetch all results at once."

#: ../../source/db-dbapi.rst:54
#: ../../source/db-dbapi.rst:74
msgid ">>> print(cursor.fetchall())"
msgstr ""

8 changes: 4 additions & 4 deletions docs/source/locale/en/LC_MESSAGES/interactive.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ msgid ""
msgstr ""
"Project-Id-Version: PyODPS 0.7.16\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-07-19 13:45+0800\n"
"POT-Creation-Date: 2025-04-15 10:45+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.12.1\n"
"Generated-By: Babel 2.16.0\n"

#: ../../source/interactive.rst:5
msgid "交互体验增强"
Expand Down Expand Up @@ -522,9 +522,9 @@ msgstr ""
msgid ""
"In [1]: %load_ext odps\n"
"\n"
"In [2]: mytable = 'dual'\n"
"In [2]: var = '0'\n"
"\n"
"In [3]: %sql select * from :mytable\n"
"In [3]: %sql select * from table_name where c_string_a = :var\n"
"|==========================================| 1 / 1 (100.00%) "
"2s\n"
"Out[3]:\n"
Expand Down
2 changes: 1 addition & 1 deletion odps/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

version_info = (0, 12, 3, "b2")
version_info = (0, 12, 3, "b3")
_num_index = max(idx if isinstance(v, int) else 0 for idx, v in enumerate(version_info))
__version__ = ".".join(map(str, version_info[: _num_index + 1])) + "".join(
version_info[_num_index + 1 :]
Expand Down
Loading