Skip to content

Commit

Permalink
refactor(oracle): port to sqlglot (ibis-project#8020)
Browse files Browse the repository at this point in the history
  • Loading branch information
gforsyth authored and kszucs committed Feb 1, 2024
1 parent 0972b71 commit 6b5a354
Show file tree
Hide file tree
Showing 32 changed files with 1,261 additions and 531 deletions.
32 changes: 16 additions & 16 deletions .github/workflows/ibis-backends.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,20 @@ jobs:
- druid
services:
- druid
# - name: oracle
# title: Oracle
# serial: true
# extras:
# - oracle
# services:
# - oracle
- name: exasol
title: Exasol
serial: true
extras:
- exasol
services:
- exasol
- name: oracle
title: Oracle
serial: true
extras:
- oracle
services:
- oracle
# - name: flink
# title: Flink
# serial: true
Expand Down Expand Up @@ -272,15 +272,15 @@ jobs:
- druid
services:
- druid
# - os: windows-latest
# backend:
# name: oracle
# title: Oracle
# serial: true
# extras:
# - oracle
# services:
# - oracle
- os: windows-latest
backend:
name: oracle
title: Oracle
serial: true
extras:
- oracle
services:
- oracle
# - os: windows-latest
# backend:
# name: flink
Expand Down
23 changes: 23 additions & 0 deletions ibis/backends/base/sqlglot/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,29 @@ class DruidType(SqlglotType):
class OracleType(SqlglotType):
dialect = "oracle"

default_decimal_precision = 38
default_decimal_scale = 9

default_temporal_scale = 9

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

@classmethod
def _from_sqlglot_FLOAT(cls) -> dt.Float64:
return dt.Float64(nullable=cls.default_nullable)

@classmethod
def _from_sqlglot_DECIMAL(cls, precision=None, scale=None) -> dt.Decimal:
if scale is None or int(scale.this.this) == 0:
return dt.Int64(nullable=cls.default_nullable)
else:
return super()._from_sqlglot_DECIMAL(precision, scale)

@classmethod
def _from_ibis_String(cls, dtype: dt.String) -> sge.DataType:
nullable = " NOT NULL" if not dtype.nullable else ""
return "VARCHAR2(4000)" + nullable


class SnowflakeType(SqlglotType):
dialect = "snowflake"
Expand Down
17 changes: 15 additions & 2 deletions ibis/backends/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from ibis import util
from ibis.backends.base import CanCreateDatabase, CanCreateSchema, _get_backend_names
from ibis.conftest import WINDOWS
from ibis.util import promote_tuple

if TYPE_CHECKING:
from collections.abc import Iterable
Expand Down Expand Up @@ -413,6 +414,13 @@ def pytest_runtest_call(item):

backend = next(iter(backend))

def _filter_none_from_raises(kwargs):
# Filter out any None values from kwargs['raises']
# to cover any missing backend error types as defined in ibis/backends/tests/errors.py
if (raises := kwargs.get("raises")) is not None:
kwargs["raises"] = tuple(filter(None, promote_tuple(raises)))
return kwargs

# Ibis hasn't exposed existing functionality
# This xfails so that you know when it starts to pass
for marker in item.iter_markers(name="notimpl"):
Expand All @@ -424,6 +432,7 @@ def pytest_runtest_call(item):
raise ValueError("notimpl requires a raises")
kwargs = marker.kwargs.copy()
kwargs.setdefault("reason", f"Feature not yet exposed in {backend}")
kwargs = _filter_none_from_raises(kwargs)
item.add_marker(pytest.mark.xfail(**kwargs))

# Functionality is unavailable upstream (but could be)
Expand All @@ -438,13 +447,16 @@ def pytest_runtest_call(item):

kwargs = marker.kwargs.copy()
kwargs.setdefault("reason", f"Feature not available upstream for {backend}")
kwargs = _filter_none_from_raises(kwargs)
item.add_marker(pytest.mark.xfail(**kwargs))

for marker in item.iter_markers(name="never"):
if backend in marker.args[0]:
if "reason" not in marker.kwargs.keys():
raise ValueError("never requires a reason")
item.add_marker(pytest.mark.xfail(**marker.kwargs))
kwargs = marker.kwargs.copy()
kwargs = _filter_none_from_raises(kwargs)
item.add_marker(pytest.mark.xfail(**kwargs))

# Something has been exposed as broken by a new test and it shouldn't be
# imperative for a contributor to fix it just because they happened to
Expand All @@ -459,10 +471,12 @@ def pytest_runtest_call(item):

kwargs = marker.kwargs.copy()
kwargs.setdefault("reason", f"Feature is failing on {backend}")
kwargs = _filter_none_from_raises(kwargs)
item.add_marker(pytest.mark.xfail(**kwargs))

for marker in item.iter_markers(name="xfail_version"):
kwargs = marker.kwargs.copy()
kwargs = _filter_none_from_raises(kwargs)
if backend not in kwargs:
continue

Expand Down Expand Up @@ -548,7 +562,6 @@ def ddl_con(ddl_backend):
params=_get_backends_to_test(
keep=(
"mssql",
"oracle",
"risingwave",
"sqlite",
)
Expand Down
Loading

0 comments on commit 6b5a354

Please sign in to comment.