Skip to content

Commit

Permalink
feat(bindings/python): support nested types Array,Map,Tuple (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
everpcpc authored Apr 17, 2024
1 parent 7c7fa94 commit 9e8de91
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 22 deletions.
4 changes: 2 additions & 2 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ runs:
targets: ${{ inputs.target }}

- name: Setup sccache
uses: mozilla-actions/sccache-action@v0.0.3
uses: mozilla-actions/sccache-action@v0.0.4

- name: Cache Cargo
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.cargo/registry/
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/bindings.nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Setup Rust toolchain
uses: ./.github/actions/setup
with:
cache-key: bindings-nodejs
cache-key: bindings-nodejs-integration
- name: Setup node
uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
- name: Setup Rust toolchain
uses: ./.github/actions/setup
with:
cache-key: bindings-nodejs
cache-key: bindings-nodejs-${{ matrix.os }}-${{ matrix.arch }}
target: ${{ matrix.target }}
- name: Setup node
uses: actions/setup-node@v4
Expand Down Expand Up @@ -103,9 +103,9 @@ jobs:
working-directory: bindings/nodejs
run: |
strip -x *.node
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: bindings-nodejs
name: bindings-nodejs-${{ matrix.os }}-${{ matrix.arch }}
path: bindings/nodejs/*.node

publish:
Expand All @@ -131,9 +131,11 @@ jobs:
working-directory: bindings/nodejs
run: yarn install --immutable
- name: Download all artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
path: bindings/nodejs/artifacts
pattern: bindings-nodejs-*
merge-multiple: true
- name: Move artifacts
shell: bash
working-directory: bindings/nodejs
Expand Down
18 changes: 14 additions & 4 deletions .github/workflows/bindings.python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Setup Rust toolchain
uses: ./.github/actions/setup
with:
cache-key: bindings-python
cache-key: bindings-python-integration
- name: Setup Python
uses: actions/setup-python@v4
with:
Expand Down Expand Up @@ -69,6 +69,11 @@ jobs:
else
echo "BUILD_ARGS=--release --strip --out dist" >> $GITHUB_OUTPUT
fi
- name: Setup Rust toolchain
uses: ./.github/actions/setup
with:
cache-key: bindings-python-${{ matrix.os }}-${{ matrix.arch }}
target: ${{ matrix.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
Expand All @@ -77,9 +82,9 @@ jobs:
sccache: 'true'
args: ${{ steps.opts.outputs.BUILD_ARGS }}
- name: Upload artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: dist
name: bindings-python-${{ matrix.os }}-${{ matrix.arch }}
path: bindings/python/dist/*.whl

publish:
Expand All @@ -94,7 +99,12 @@ jobs:
url: https://pypi.org/p/databend-driver/
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
path: bindings/python/artifacts
pattern: bindings-python-*
merge-multiple: true
- uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
packages-dir: bindings/python/artifacts
12 changes: 7 additions & 5 deletions bindings/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[build-system]
build-backend = "maturin"
requires = ["maturin>=1.0,<2.0"]

[project]
classifiers = [
"Programming Language :: Rust",
Expand All @@ -8,7 +12,9 @@ description = "Databend Driver Python Binding"
license = { text = "Apache-2.0" }
name = "databend-driver"
readme = "README.md"
requires-python = ">=3.7"
# PyO3 doesn't support python 3.13 yet.
# ref: https://github.com/apache/opendal/issues/4268
requires-python = ">=3.7, < 3.13"

[project.optional-dependencies]
docs = ["pdoc"]
Expand All @@ -22,7 +28,3 @@ Repository = "https://github.com/datafuselabs/bendsql"
features = ["pyo3/extension-module"]
module-name = "databend_driver._databend_driver"
python-source = "package"

[build-system]
build-backend = "maturin"
requires = ["maturin>=1.0,<2.0"]
18 changes: 15 additions & 3 deletions bindings/python/tests/asyncio/steps/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,21 @@ async def _(context, input, output):
async def _(context):
# NumberValue::Decimal
row = await context.conn.query_row("SELECT 15.7563::Decimal(8,4), 2.0+3.0")
expected = (Decimal("15.7563"), Decimal("5.0"))
assert row.values() == expected
assert row.values() == (Decimal("15.7563"), Decimal("5.0"))

# Array
row = await context.conn.query_row("select [10::Decimal(15,2), 1.1+2.3]")
assert row.values() == ([Decimal("10.00"), Decimal("3.40")],)

# Map
row = await context.conn.query_row("select {'xx':to_date('2020-01-01')}")
assert row.values() == ({"xx": "2020-01-01"},)

# Tuple
row = await context.conn.query_row(
"select (10, '20', to_datetime('2024-04-16 12:34:56.789'))"
)
assert row.values() == ((10, "20", "2024-04-16 12:34:56.789"),)


@then("Select numbers should iterate all rows")
Expand Down Expand Up @@ -121,5 +134,4 @@ async def _(context):
(-2, 2, 2.0, "2", "2", "2012-05-31", "2012-05-31 11:20:00"),
(-3, 3, 3.0, "3", "2", "2016-04-04", "2016-04-04 11:30:00"),
]
print("==>", ret)
assert ret == expected
18 changes: 15 additions & 3 deletions bindings/python/tests/blocking/steps/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,21 @@ def _(context, input, output):
async def _(context):
# NumberValue::Decimal
row = context.conn.query_row("SELECT 15.7563::Decimal(8,4), 2.0+3.0")
expected = (Decimal("15.7563"), Decimal("5.0"))
assert row.values() == expected
assert row.values() == (Decimal("15.7563"), Decimal("5.0"))

# Array
row = context.conn.query_row("select [10::Decimal(15,2), 1.1+2.3]")
assert row.values() == ([Decimal("10.00"), Decimal("3.40")],)

# Map
row = context.conn.query_row("select {'xx':to_date('2020-01-01')}")
assert row.values() == ({"xx": "2020-01-01"},)

# Tuple
row = context.conn.query_row(
"select (10, '20', to_datetime('2024-04-16 12:34:56.789'))"
)
assert row.values() == ((10, "20", "2024-04-16 12:34:56.789"),)


@then("Select numbers should iterate all rows")
Expand Down Expand Up @@ -113,5 +126,4 @@ def _(context):
(-2, 2, 2.0, "2", "2", "2012-05-31", "2012-05-31 11:20:00"),
(-3, 3, 3.0, "3", "2", "2016-04-04", "2016-04-04 11:30:00"),
]
print("==>", ret)
assert ret == expected

0 comments on commit 9e8de91

Please sign in to comment.