Skip to content

Commit

Permalink
refactor(oracle): more test fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
gforsyth committed Jan 18, 2024
1 parent 9d0ad1b commit c9b34ba
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 43 deletions.
6 changes: 1 addition & 5 deletions ibis/backends/base/sqlglot/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,7 @@ class OracleType(SqlglotType):

default_temporal_scale = 9

unknown_type_strings = FrozenDict(
{
"raw": dt.binary,
}
)
unknown_type_strings = FrozenDict({"raw": dt.binary})

@classmethod
def _from_sqlglot_FLOAT(cls) -> dt.Float64:
Expand Down
55 changes: 55 additions & 0 deletions ibis/backends/oracle/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ def visit_Literal(self, op, *, value, dtype):
)
elif dtype.is_uuid():
return sge.convert(str(value))

Check warning on line 160 in ibis/backends/oracle/compiler.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/oracle/compiler.py#L160

Added line #L160 was not covered by tests
elif dtype.is_interval():
if dtype.unit.short in ("Y", "M"):
return self.f.numtoyminterval(value, dtype.unit.name)

Check warning on line 163 in ibis/backends/oracle/compiler.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/oracle/compiler.py#L163

Added line #L163 was not covered by tests
elif dtype.unit.short in ("D", "h", "m", "s"):
return self.f.numtodsinterval(value, dtype.unit.name)

Check warning on line 165 in ibis/backends/oracle/compiler.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/oracle/compiler.py#L165

Added line #L165 was not covered by tests
else:
raise com.UnsupportedOperationError(

Check warning on line 167 in ibis/backends/oracle/compiler.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/oracle/compiler.py#L167

Added line #L167 was not covered by tests
f"Intervals with precision {dtype.unit.name} not supported in Oracle."
)

return super().visit_Literal(op, value=value, dtype=dtype)

Check warning on line 171 in ibis/backends/oracle/compiler.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/oracle/compiler.py#L171

Added line #L171 was not covered by tests

Expand Down Expand Up @@ -224,6 +233,50 @@ def visit_Limit(self, op, *, parent, n, offset):
def visit_Date(self, op, *, arg):
return sg.cast(arg, to="date")

Check warning on line 234 in ibis/backends/oracle/compiler.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/oracle/compiler.py#L234

Added line #L234 was not covered by tests

# @visit_node.register(ops.TimestampFromYMDHMS)
# def visit_TimestampFromYMDHMS(
# self, op, *, year, month, day, hours, minutes, seconds
# ):
# date_str = self.f.concat(
# self.f.lpad(self.cast(year, dt.string), 4, "0"),
# self.f.concat(
# "-",
# self.f.concat(
# self.f.lpad(self.cast(month, dt.string), 2, "0"),
# self.f.concat(
# "-",
# self.f.concat(
# self.f.lpad(self.cast(day, dt.string), 2, "0"),
# self.f.concat(
# "T",
# self.f.concat(
# self.f.lpad(self.cast(hours, dt.string), 2, "0"),
# self.f.concat(
# ":",
# self.f.concat(
# self.f.lpad(
# self.cast(minutes, dt.string), 2, "0"
# ),
# self.f.concat(
# ":",
# self.f.lpad(
# self.cast(seconds, dt.string),
# 2,
# "0",
# ),
# ),
# ),
# ),
# ),
# ),
# ),
# ),
# ),
# ),
# )
# expr = self.f.to_timestamp(date_str, 'YYYY-MM-DD"T"HH24:MI:SS')
# return expr

@visit_node.register(ops.IsNan)

Check warning on line 280 in ibis/backends/oracle/compiler.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/oracle/compiler.py#L280

Added line #L280 was not covered by tests
def visit_IsNan(self, op, *, arg):
return arg.eq(self.NAN)

Check warning on line 282 in ibis/backends/oracle/compiler.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/oracle/compiler.py#L282

Added line #L282 was not covered by tests
Expand Down Expand Up @@ -503,6 +556,8 @@ def visit_Window(self, op, *, how, func, start, end, group_by, order_by):
@visit_node.register(ops.DateDelta)
@visit_node.register(ops.TimestampDelta)
@visit_node.register(ops.TimestampNow)
@visit_node.register(ops.TimestampFromYMDHMS)
@visit_node.register(ops.TimeFromHMS)
@visit_node.register(ops.IntervalFromInteger)
@visit_node.register(ops.DayOfWeekIndex)
@visit_node.register(ops.DayOfWeekName)
Expand Down
5 changes: 5 additions & 0 deletions ibis/backends/tests/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,8 @@
from pydruid.db.exceptions import ProgrammingError as PyDruidProgrammingError
except ImportError:
PyDruidProgrammingError = None

try:
from oracledb.exceptions import DatabaseError as OracleDatabaseError
except ImportError:
OracleDatabaseError = None
5 changes: 5 additions & 0 deletions ibis/backends/tests/test_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,11 @@ def test_median(alltypes, df):
raises=ClickHouseDatabaseError,
reason="doesn't support median of strings",
)
@pytest.mark.notyet(
["oracle"],
raises=OracleDatabaseError,
reason="doesn't support median of strings",
)
@pytest.mark.broken(
["pyspark"], raises=AssertionError, reason="pyspark returns null for string median"
)
Expand Down
2 changes: 2 additions & 0 deletions ibis/backends/tests/test_asof_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def time_keyed_right(time_keyed_df2):
"druid",
"impala",
"bigquery",
"oracle",
]
)
def test_asof_join(con, time_left, time_right, time_df1, time_df2, direction, op):
Expand Down Expand Up @@ -127,6 +128,7 @@ def test_asof_join(con, time_left, time_right, time_df1, time_df2, direction, op
"druid",
"impala",
"bigquery",
"oracle",
]
)
def test_keyed_asof_join_with_tolerance(
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/tests/test_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


@pytest.mark.notimpl(
["clickhouse", "impala", "druid"],
["clickhouse", "impala", "druid", "oracle"],
"Unsupported type: Binary(nullable=True)",
raises=NotImplementedError,
)
Expand Down
8 changes: 2 additions & 6 deletions ibis/backends/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
GoogleBadRequest,
ImpalaHiveServer2Error,
MySQLProgrammingError,
OracleDatabaseError,
PyDruidProgrammingError,
SnowflakeProgrammingError,
TrinoUserError,
Expand Down Expand Up @@ -415,11 +416,7 @@ def test_table_fillna_invalid(alltypes):
"replacements",
[
param({"int_col": 20}, id="int"),
param(
{"double_col": -1, "string_col": "missing"},
id="double-int-str",
marks=[pytest.mark.notimpl(["oracle"])],
),
param({"double_col": -1, "string_col": "missing"}, id="double-int-str"),
param({"double_col": -1.5, "string_col": "missing"}, id="double-str"),
],
)
Expand All @@ -437,7 +434,6 @@ def test_table_fillna_mapping(backend, alltypes, replacements):
backend.assert_frame_equal(result, expected, check_dtype=False)


@pytest.mark.notimpl(["oracle"])
def test_table_fillna_scalar(backend, alltypes):
table = alltypes.mutate(
int_col=alltypes.int_col.nullif(1),
Expand Down
23 changes: 21 additions & 2 deletions ibis/backends/tests/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ def test_numeric_literal(con, backend, expr, expected_types):
pytest.mark.notimpl(["exasol"], raises=ExaQueryError),
pytest.mark.notimpl(["mysql"], raises=MySQLOperationalError),
pytest.mark.notyet(["snowflake"], raises=SnowflakeProgrammingError),
pytest.mark.notyet(["oracle"], raises=OracleDatabaseError),
pytest.mark.notyet(["impala"], raises=ImpalaHiveServer2Error),
pytest.mark.broken(
["duckdb"],
Expand Down Expand Up @@ -696,7 +697,7 @@ def test_decimal_literal(con, backend, expr, expected_types, expected_result):
],
)
@pytest.mark.notimpl(
["sqlite", "mssql", "oracle", "flink", "druid"], raises=com.OperationNotDefinedError
["sqlite", "mssql", "flink", "druid"], raises=com.OperationNotDefinedError
)
@pytest.mark.notimpl(["mysql"], raises=(MySQLOperationalError, NotImplementedError))
def test_isnan_isinf(
Expand Down Expand Up @@ -1556,7 +1557,25 @@ def test_bitwise_shift(backend, alltypes, df, op, left_fn, right_fn):

@pytest.mark.parametrize(
"op",
[and_, or_, xor, lshift, rshift],
[
and_,
param(
or_,
marks=pytest.mark.notimpl(["oracle"], raises=OracleDatabaseError),
),
param(
xor,
marks=pytest.mark.notimpl(["oracle"], raises=OracleDatabaseError),
),
param(
lshift,
marks=[pytest.mark.notimpl(["oracle"], raises=OracleDatabaseError)],
),
param(
rshift,
marks=[pytest.mark.notimpl(["oracle"], raises=OracleDatabaseError)],
),
],
)
@pytest.mark.parametrize(
("left", "right"),
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/tests/test_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import ibis
import ibis.expr.datatypes as dt
from ibis import _
from ibis.backends.tests.errors import Py4JJavaError
from ibis.backends.tests.errors import OracleDatabaseError, Py4JJavaError


@pytest.mark.parametrize(
Expand Down
12 changes: 8 additions & 4 deletions ibis/backends/tests/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
import ibis
import ibis.common.exceptions as com
import ibis.expr.datatypes as dt
from ibis.backends.tests.errors import ClickHouseDatabaseError, PyDruidProgrammingError
from ibis.backends.tests.errors import (
ClickHouseDatabaseError,
OracleDatabaseError,
PyDruidProgrammingError,
)
from ibis.common.annotations import ValidationError


Expand Down Expand Up @@ -185,7 +189,7 @@ def uses_java_re(t):
id="rlike",
marks=[
pytest.mark.notimpl(
["mssql", "oracle", "exasol"], raises=com.OperationNotDefinedError
["mssql", "exasol"], raises=com.OperationNotDefinedError
),
],
),
Expand All @@ -195,7 +199,7 @@ def uses_java_re(t):
id="re_search_substring",
marks=[
pytest.mark.notimpl(
["mssql", "oracle", "exasol"], raises=com.OperationNotDefinedError
["mssql", "exasol"], raises=com.OperationNotDefinedError
),
],
),
Expand All @@ -205,7 +209,7 @@ def uses_java_re(t):
id="re_search",
marks=[
pytest.mark.notimpl(
["mssql", "oracle", "exasol"], raises=com.OperationNotDefinedError
["mssql", "exasol"], raises=com.OperationNotDefinedError
),
],
),
Expand Down
38 changes: 14 additions & 24 deletions ibis/backends/tests/test_temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1048,11 +1048,6 @@ def test_temporal_binop(backend, con, alltypes, df, expr_fn, expected_fn):
raises=AssertionError,
reason="DateTime column overflows, should use DateTime64",
),
pytest.mark.broken(
["clickhouse"],
raises=AssertionError,
reason="DateTime column overflows, should use DateTime64",
),
pytest.mark.notimpl(
["flink"],
# Note (mehmet): Following cannot be imported for backends other than Flink.
Expand Down Expand Up @@ -1137,11 +1132,6 @@ def test_temporal_binop(backend, con, alltypes, df, expr_fn, expected_fn):
raises=AssertionError,
reason="DateTime column overflows, should use DateTime64",
),
pytest.mark.broken(
["clickhouse"],
raises=AssertionError,
reason="DateTime column overflows, should use DateTime64",
),
pytest.mark.broken(
["flink"],
# Note (mehmet): Following cannot be imported for backends other than Flink.
Expand Down Expand Up @@ -1843,9 +1833,6 @@ def test_date_literal(con, backend):
["pandas", "dask", "pyspark", "mysql", "oracle"],
raises=com.OperationNotDefinedError,
)
@pytest.mark.notimpl(
["oracle"], raises=sa.exc.DatabaseError, reason="ORA-00904: MAKE TIMESTAMP invalid"
)
@pytest.mark.notyet(["impala"], raises=com.OperationNotDefinedError)
@pytest.mark.notimpl(["exasol"], raises=ExaQueryError)
def test_timestamp_literal(con, backend):
Expand Down Expand Up @@ -1924,11 +1911,10 @@ def test_timestamp_with_timezone_literal(con, timezone, expected):


@pytest.mark.notimpl(
["pandas", "datafusion", "dask", "pyspark", "polars", "mysql"],
["pandas", "datafusion", "dask", "pyspark", "polars", "mysql", "oracle"],
raises=com.OperationNotDefinedError,
)
@pytest.mark.notyet(["clickhouse", "impala"], raises=com.OperationNotDefinedError)
@pytest.mark.notimpl(["oracle"], raises=sa.exc.DatabaseError)
@pytest.mark.notimpl(["druid"], raises=com.OperationNotDefinedError)
@pytest.mark.notimpl(["exasol"], raises=ExaQueryError)
def test_time_literal(con, backend):
Expand Down Expand Up @@ -1957,7 +1943,7 @@ def test_time_literal(con, backend):
["sqlite"], raises=AssertionError, reason="SQLite returns Timedelta from execution"
)
@pytest.mark.notimpl(["dask"], raises=com.OperationNotDefinedError)
@pytest.mark.notyet(["oracle"], raises=sa.exc.DatabaseError)
@pytest.mark.notyet(["oracle"], raises=OracleDatabaseError)
@pytest.mark.parametrize(
"microsecond",
[
Expand Down Expand Up @@ -2108,7 +2094,7 @@ def test_timestamp_column_from_ymdhms(backend, con, alltypes, df):


@pytest.mark.notimpl(
["oracle"], raises=sa.exc.DatabaseError, reason="ORA-01861 literal does not match"
["oracle"], raises=OracleDatabaseError, reason="ORA-01861 literal does not match"
)
def test_date_scalar_from_iso(con):
expr = ibis.literal("2022-02-24")
Expand Down Expand Up @@ -2169,7 +2155,7 @@ def test_integer_cast_to_timestamp_column(backend, alltypes, df):
backend.assert_series_equal(result, expected.astype(result.dtype))


@pytest.mark.notimpl(["oracle"], raises=sa.exc.DatabaseError)
@pytest.mark.notimpl(["oracle"], raises=OracleDatabaseError)
@pytest.mark.notimpl(["exasol"], raises=sa.exc.DBAPIError)
def test_integer_cast_to_timestamp_scalar(alltypes, df):
expr = alltypes.int_col.min().cast("timestamp")
Expand Down Expand Up @@ -2217,7 +2203,7 @@ def build_date_col(t):

@pytest.mark.notimpl(["mssql"], raises=com.OperationNotDefinedError)
@pytest.mark.notimpl(["druid"], raises=PyDruidProgrammingError)
@pytest.mark.notimpl(["oracle"], raises=sa.exc.DatabaseError)
@pytest.mark.notimpl(["oracle"], raises=OracleDatabaseError)
@pytest.mark.parametrize(
("left_fn", "right_fn"),
[
Expand Down Expand Up @@ -2435,7 +2421,6 @@ def test_delta(con, start, end, unit, expected):
"flink",
"impala",
"mysql",
"oracle",
"pandas",
"pyspark",
"sqlite",
Expand Down Expand Up @@ -2470,6 +2455,11 @@ def test_delta(con, start, end, unit, expected):
raises=com.UnsupportedOperationError,
reason="backend doesn't support sub-second interval precision",
),
pytest.mark.notimpl(
["oracle"],
raises=com.UnsupportedOperationError,
reason="backend doesn't support sub-second interval precision",
),
],
id="milliseconds",
),
Expand All @@ -2478,7 +2468,7 @@ def test_delta(con, start, end, unit, expected):
"2s",
marks=[
pytest.mark.notimpl(
["datafusion"],
["datafusion", "oracle"],
raises=com.OperationNotDefinedError,
),
],
Expand All @@ -2489,7 +2479,7 @@ def test_delta(con, start, end, unit, expected):
"300s",
marks=[
pytest.mark.notimpl(
["datafusion"],
["datafusion", "oracle"],
raises=com.OperationNotDefinedError,
),
],
Expand All @@ -2500,7 +2490,7 @@ def test_delta(con, start, end, unit, expected):
"2h",
marks=[
pytest.mark.notimpl(
["datafusion"],
["datafusion", "oracle"],
raises=com.OperationNotDefinedError,
),
],
Expand All @@ -2511,7 +2501,7 @@ def test_delta(con, start, end, unit, expected):
"2D",
marks=[
pytest.mark.notimpl(
["datafusion"],
["datafusion", "oracle"],
raises=com.OperationNotDefinedError,
),
],
Expand Down

0 comments on commit c9b34ba

Please sign in to comment.