Skip to content
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
45 changes: 28 additions & 17 deletions bindings/python/tests/asyncio/steps/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
from decimal import Decimal

from behave import given, when, then
import unittest

tc = unittest.TestCase()

os.environ["DATABEND_DRIVER_HEARTBEAT_INTERVAL_SECONDS"] = "1"
os.environ["RUST_LOG"] = "warn,databend_driver=debug,databend_client=debug"
Expand Down Expand Up @@ -123,23 +126,28 @@ async def _(context):
Decimal("5.0"),
), f"Decimal: {row.values()}"

# 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")],), (
f"Array: {row.values()}"
)
if DRIVER_VERSION >= (0, 33, 1): # quote change to `"`
# 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")],), (
f"Array: {row.values()}"
)

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

# Tuple
row = await context.conn.query_row(
"select (10, '20', to_datetime('2024-04-16 12:34:56.789'))"
)
assert row.values() == (
(10, "20", datetime(2024, 4, 16, 12, 34, 56, 789000, tzinfo=default_tzinfo)),
), f"Tuple: {row.values()}"
# Tuple
row = await context.conn.query_row(
"select (10, '20', to_datetime('2024-04-16 12:34:56.789'))"
)
assert row.values() == (
(
10,
"20",
datetime(2024, 4, 16, 12, 34, 56, 789000, tzinfo=default_tzinfo),
),
), f"Tuple: {row.values()}"


@then("Select numbers should iterate all rows")
Expand Down Expand Up @@ -267,6 +275,9 @@ async def test_load_file(context, load_method):

rows = await context.conn.query_iter("SELECT * FROM test1")
ret = [row.values() for row in rows]

quoted_empty = "" if DB_VERSION >= (1, 2, 866) else None

expected = [
(
-1,
Expand All @@ -282,7 +293,7 @@ async def test_load_file(context, load_method):
2,
2.0,
'"',
None,
quoted_empty,
date(2012, 5, 31),
datetime(2012, 5, 31, 11, 20, tzinfo=default_tzinfo),
),
Expand All @@ -296,7 +307,7 @@ async def test_load_file(context, load_method):
datetime(2016, 4, 4, 11, 30, tzinfo=default_tzinfo),
),
]
assert ret == expected, f"{load_method} ret: {ret}"
tc.assertEqual(ret, expected, load_method)


@then("Load file with Stage and Select should be equal")
Expand Down
39 changes: 25 additions & 14 deletions bindings/python/tests/blocking/steps/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
from decimal import Decimal
import time
from time import sleep
import unittest

tc = unittest.TestCase()

from behave import given, when, then

Expand Down Expand Up @@ -125,18 +128,6 @@ def _(context):
f"Array: {row.values()}"
)

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

# Tuple
row = context.conn.query_row(
"select (10, '20', to_datetime('2024-04-16 12:34:56.789'))"
)
assert row.values() == (
(10, "20", datetime(2024, 4, 16, 12, 34, 56, 789000, tzinfo=default_tzinfo)),
), f"Tuple: {row.values()}"

import sys

if (
Expand Down Expand Up @@ -198,6 +189,23 @@ def _(context):
)
assert row.values()[0] == "POINT(60 37)", f"geography: {row.values()}"

if DRIVER_VERSION >= (0, 33, 1): # quote change to `"`
# Map
row = context.conn.query_row("select {'xx':to_date('2020-01-01')}")
assert row.values() == ({"xx": date(2020, 1, 1)},), f"Map: {row.values()}"

# Tuple
row = context.conn.query_row(
"select (10, '20', to_datetime('2024-04-16 12:34:56.789'))"
)
assert row.values() == (
(
10,
"20",
datetime(2024, 4, 16, 12, 34, 56, 789000, tzinfo=default_tzinfo),
),
), f"Tuple: {row.values()}"


@then("Select numbers should iterate all rows")
def _(context):
Expand Down Expand Up @@ -322,6 +330,9 @@ def test_load_file(context, load_method):

rows = context.conn.query_iter("SELECT * FROM test1")
ret = [row.values() for row in rows]

quoted_empty = "" if DB_VERSION >= (1, 2, 866) else None

expected = [
(
-1,
Expand All @@ -337,7 +348,7 @@ def test_load_file(context, load_method):
2,
2.0,
'"',
None,
quoted_empty,
date(2012, 5, 31),
datetime(2012, 5, 31, 11, 20, tzinfo=default_tzinfo),
),
Expand All @@ -351,7 +362,7 @@ def test_load_file(context, load_method):
datetime(2016, 4, 4, 11, 30, tzinfo=default_tzinfo),
),
]
assert ret == expected, f"{load_method} ret: {ret}"
tc.assertEqual(ret, expected, load_method)


@then("Load file with Stage and Select should be equal")
Expand Down
37 changes: 20 additions & 17 deletions bindings/python/tests/cursor/steps/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,26 @@ def _(context):
expected = ([Decimal("10.00"), Decimal("3.40")],)
assert row.values() == expected, f"Array: {row.values()}"

# Map
context.cursor.execute("select {'xx':to_date('2020-01-01')}")
row = context.cursor.fetchone()
expected = ({"xx": date(2020, 1, 1)},)
assert row.values() == expected, f"Map: {row.values()}"

# Tuple
context.cursor.execute("select (10, '20', to_datetime('2024-04-16 12:34:56.789'))")
row = context.cursor.fetchone()
expected = (
(
10,
"20",
datetime(2024, 4, 16, 12, 34, 56, 789000, tzinfo=default_tzinfo),
),
)
assert row.values() == expected, f"Tuple: {row.values()}"
if DRIVER_VERSION >= (0, 33, 1): # quote change to `"`
# Map
context.cursor.execute("select {'xx':to_date('2020-01-01')}")
row = context.cursor.fetchone()
expected = ({"xx": date(2020, 1, 1)},)
assert row.values() == expected, f"Map: {row.values()}"

# Tuple
context.cursor.execute(
"select (10, '20', to_datetime('2024-04-16 12:34:56.789'))"
)
row = context.cursor.fetchone()
expected = (
(
10,
"20",
datetime(2024, 4, 16, 12, 34, 56, 789000, tzinfo=default_tzinfo),
),
)
assert row.values() == expected, f"Tuple: {row.values()}"


@then("Select numbers should iterate all rows")
Expand Down
Loading