Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
joocer committed Nov 9, 2023
1 parent ac0ac7f commit 3097cc7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
7 changes: 4 additions & 3 deletions opteryx/components/logical_planner_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ def cast(branch, alias=None, key=None):
data_type = branch["data_type"]["Custom"][0][0]["value"].upper()
if data_type == "Timestamp":
data_type = "TIMESTAMP"
elif data_type == "Date":
data_type = "DATE"
elif "Varchar" in data_type:
data_type = "VARCHAR"
elif "Decimal" in data_type:
Expand Down Expand Up @@ -291,6 +293,8 @@ def try_cast(branch, alias=None, key="TryCast"):
data_type = branch["data_type"]["Custom"][0][0]["value"].upper()
if data_type == "Timestamp":
data_type = "TIMESTAMP"
elif data_type == "Date":
data_type = "DATE"
elif "Varchar" in data_type:
data_type = "VARCHAR"
elif "Decimal" in data_type:
Expand All @@ -306,9 +310,6 @@ def try_cast(branch, alias=None, key="TryCast"):
else:
raise SqlError(f"Unsupported type for `{function_name}` - '{data_type}'")

# alias.append(f"{function_name}({args[0].value} AS {data_type})")
# alias.append(f"{data_type.upper} {args[0].value}")

return Node(
NodeType.FUNCTION,
value=f"TRY_{data_type.upper()}",
Expand Down
2 changes: 2 additions & 0 deletions opteryx/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ def execute_to_arrow(
Returns:
The query results in Arrow table format.
"""
if hasattr(operation, "decode"):
operation = operation.decode()
results = self._execute_statements(operation, params)
if results is not None:
result_data, self._result_type = next(results, (ResultType._UNDEFINED, None))
Expand Down
20 changes: 20 additions & 0 deletions tests/misc/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,26 @@ def test_execute():
assert isinstance(planets, pandas.DataFrame)


def test_byte_strings():
import opteryx

cur = opteryx.query(b"SELECT * FROM $planets")
assert cur.rowcount == 9
assert cur.shape == (9, 20)

conn = opteryx.connect()
cur = conn.cursor()
cur.execute(b"SELECT * FROM $planets")
assert cur.rowcount == 9
assert cur.shape == (9, 20)

conn = opteryx.connect()
cur = conn.cursor()
arrow = cur.execute_to_arrow(b"SELECT * FROM $planets")
assert arrow.num_rows == 9, cur.rowcount
assert arrow.shape == (9, 20)


if __name__ == "__main__": # pragma: no cover
from tests.tools import run_tests

Expand Down
6 changes: 3 additions & 3 deletions tests/sql_battery/test_battery_sql92.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
("SELECT DATE '2016-03-26' <> DATE '2016-03-26'", "F051-04"),
("SELECT DATE '2016-03-26' = DATE '2016-03-26'", "F051-04"),
("SELECT DATE '2016-03-26' > DATE '2016-03-26'", "F051-04"),
# ("SELECT DATE '2016-03-26' >= DATE '2016-03-26'", "F051-04"),
("SELECT DATE '2016-03-26' >= DATE '2016-03-26'", "F051-04"),
# ("SELECT TIME '01:02:03' < TIME '01:02:03'", "F051-04"),
# ("SELECT TIME '01:02:03' <= TIME '01:02:03'", "F051-04"),
# ("SELECT TIME '01:02:03' <> TIME '01:02:03'", "F051-04"),
Expand All @@ -174,10 +174,10 @@
("SELECT TIMESTAMP '2016-03-26 01:02:03' = TIMESTAMP '2016-03-26 01:02:03'", "F051-04"),
("SELECT TIMESTAMP '2016-03-26 01:02:03' > TIMESTAMP '2016-03-26 01:02:03'", "F051-04"),
("SELECT TIMESTAMP '2016-03-26 01:02:03' >= TIMESTAMP '2016-03-26 01:02:03'", "F051-04"),
# ("SELECT CAST ( '2016-03-26' AS DATE )", "F051-05"),
("SELECT CAST ( '2016-03-26' AS DATE )", "F051-05"),
# ("SELECT CAST ( '01:02:03' AS TIME )", "F051-05"),
("SELECT CAST ( '2016-03-26 01:02:03' AS TIMESTAMP WITHOUT TIME ZONE )", "F051-05"),
# ("SELECT CAST ( CAST ( '2016-03-26' AS DATE ) AS VARCHAR )", "F051-05"),
("SELECT CAST ( CAST ( '2016-03-26' AS DATE ) AS VARCHAR )", "F051-05"),
# ("SELECT CAST ( CAST ( '01:02:03' AS TIME ) AS VARCHAR )", "F051-05"),
("SELECT CAST ( CAST ( '2016-03-26 01:02:03' AS TIMESTAMP WITHOUT TIME ZONE ) AS VARCHAR )", "F051-05"),
# ("SELECT CAST ( CAST ( '01:02:03' AS TIME ) AS TIME )", "F051-05"),
Expand Down

0 comments on commit 3097cc7

Please sign in to comment.