From 1409121bed2e4250c34220867bdfe0ea666abc37 Mon Sep 17 00:00:00 2001 From: TCeason Date: Tue, 7 Jan 2025 12:11:13 +0800 Subject: [PATCH] add docs and tests --- bindings/python/README.md | 29 ++++++++++--------- .../python/tests/asyncio/steps/binding.py | 9 +++++- .../python/tests/blocking/steps/binding.py | 9 +++++- bindings/python/tests/cursor/steps/binding.py | 9 +++++- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/bindings/python/README.md b/bindings/python/README.md index 385448f0..e28dc1cb 100644 --- a/bindings/python/README.md +++ b/bindings/python/README.md @@ -97,20 +97,21 @@ asyncio.run(main()) ### General Data Types -| Databend | Python | -| ----------- | ------------------- | -| `BOOLEAN` | `bool` | -| `TINYINT` | `int` | -| `SMALLINT` | `int` | -| `INT` | `int` | -| `BIGINT` | `int` | -| `FLOAT` | `float` | -| `DOUBLE` | `float` | -| `DECIMAL` | `decimal.Decimal` | -| `DATE` | `datetime.date` | -| `TIMESTAMP` | `datetime.datetime` | -| `VARCHAR` | `str` | -| `BINARY` | `bytes` | +| Databend | Python | +|-------------|----------------------| +| `BOOLEAN` | `bool` | +| `TINYINT` | `int` | +| `SMALLINT` | `int` | +| `INT` | `int` | +| `BIGINT` | `int` | +| `FLOAT` | `float` | +| `DOUBLE` | `float` | +| `DECIMAL` | `decimal.Decimal` | +| `DATE` | `datetime.date` | +| `TIMESTAMP` | `datetime.datetime` | +| `Interval` | `datetime.timedelta` | +| `VARCHAR` | `str` | +| `BINARY` | `bytes` | ### Semi-Structured Data Types diff --git a/bindings/python/tests/asyncio/steps/binding.py b/bindings/python/tests/asyncio/steps/binding.py index a2336812..bda0319a 100644 --- a/bindings/python/tests/asyncio/steps/binding.py +++ b/bindings/python/tests/asyncio/steps/binding.py @@ -13,7 +13,7 @@ # limitations under the License. import os -from datetime import datetime, date +from datetime import datetime, date, timedelta from decimal import Decimal from behave import given, when, then @@ -66,6 +66,13 @@ async def _(context): row = await context.conn.query_row("select to_binary('xyz')") assert row.values() == (b"xyz",), f"Binary: {row.values()}" + # Interval + context.cursor.execute("select to_interval('1 hours')") + row = context.cursor.fetch_one() + assert row.values() == ( + timedelta(hours=1), + ), f"Interval: {row.values()}" + # Decimal row = await context.conn.query_row("SELECT 15.7563::Decimal(8,4), 2.0+3.0") assert row.values() == ( diff --git a/bindings/python/tests/blocking/steps/binding.py b/bindings/python/tests/blocking/steps/binding.py index 6ff9e734..bfa8ad00 100644 --- a/bindings/python/tests/blocking/steps/binding.py +++ b/bindings/python/tests/blocking/steps/binding.py @@ -13,7 +13,7 @@ # limitations under the License. import os -from datetime import datetime, date +from datetime import datetime, date, timedelta from decimal import Decimal from behave import given, when, then @@ -61,6 +61,13 @@ async def _(context): row = context.conn.query_row("select to_binary('xyz')") assert row.values() == (b"xyz",), f"Binary: {row.values()}" + # Interval + context.cursor.execute("select to_interval('1 microseconds')") + row = context.cursor.fetch_one() + assert row.values() == ( + timedelta(microseconds=1), + ), f"Interval: {row.values()}" + # Decimal row = context.conn.query_row("SELECT 15.7563::Decimal(8,4), 2.0+3.0") assert row.values() == ( diff --git a/bindings/python/tests/cursor/steps/binding.py b/bindings/python/tests/cursor/steps/binding.py index 4cbabdc1..5c9dfeb1 100644 --- a/bindings/python/tests/cursor/steps/binding.py +++ b/bindings/python/tests/cursor/steps/binding.py @@ -13,7 +13,7 @@ # limitations under the License. import os -from datetime import datetime, date +from datetime import datetime, date, timedelta from decimal import Decimal from behave import given, when, then @@ -62,6 +62,13 @@ async def _(context): row = context.cursor.fetch_one() assert row[0] == b"xyz", f"Binary: {row.values()}" + # Interval + context.cursor.execute("select to_interval('1 days')") + row = context.cursor.fetch_one() + assert row.values() == ( + timedelta(1), + ), f"Interval: {row.values()}" + # Decimal context.cursor.execute("SELECT 15.7563::Decimal(8,4), 2.0+3.0") row = context.cursor.fetch_one()