Skip to content

Commit

Permalink
feat(bindings/python): support nested types Array,Map,Tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
everpcpc committed Apr 17, 2024
1 parent 7c7fa94 commit ffe8bdb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
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 ffe8bdb

Please sign in to comment.