Skip to content

Commit

Permalink
add docs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TCeason committed Jan 7, 2025
1 parent 4d0d5aa commit 1409121
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
29 changes: 15 additions & 14 deletions bindings/python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 8 additions & 1 deletion bindings/python/tests/asyncio/steps/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() == (
Expand Down
9 changes: 8 additions & 1 deletion bindings/python/tests/blocking/steps/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() == (
Expand Down
9 changes: 8 additions & 1 deletion bindings/python/tests/cursor/steps/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 1409121

Please sign in to comment.