Skip to content

Commit

Permalink
refactor(exasol): port to sqlglot (ibis-project#8032)
Browse files Browse the repository at this point in the history
This PR ports exasol to sqlglot instead of sqlalchemy.
  • Loading branch information
cpcloud authored and kszucs committed Feb 2, 2024
1 parent b45ea31 commit 433bb75
Show file tree
Hide file tree
Showing 31 changed files with 986 additions and 655 deletions.
72 changes: 16 additions & 56 deletions .github/workflows/ibis-backends.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ jobs:
# - oracle
# services:
# - oracle
# - name: exasol
# title: Exasol
# serial: true
# extras:
# - exasol
# services:
# - exasol
- name: exasol
title: Exasol
serial: true
extras:
- exasol
services:
- exasol
# - name: flink
# title: Flink
# serial: true
Expand Down Expand Up @@ -299,21 +299,21 @@ jobs:
# - flink
# - os: windows-latest
# backend:
# name: exasol
# title: Exasol
# serial: true
# extras:
# - exasol
# services:
# - exasol
# - os: windows-latest
# backend:
# name: risingwave
# title: Risingwave
# services:
# - risingwave
# extras:
# - risingwave
- os: windows-latest
backend:
name: exasol
title: Exasol
serial: true
extras:
- exasol
services:
- exasol
steps:
- name: update and install system dependencies
if: matrix.os == 'ubuntu-latest' && matrix.backend.sys-deps != null
Expand Down Expand Up @@ -612,46 +612,6 @@ jobs:
with:
flags: backend,pyspark,${{ runner.os }},python-${{ steps.install_python.outputs.python-version }}

# gen_lockfile_sqlalchemy2:
# name: Generate Poetry Lockfile for SQLAlchemy 2
# runs-on: ubuntu-latest
# steps:
# - name: checkout
# uses: actions/checkout@v4
#
# - name: install python
# uses: actions/setup-python@v5
# with:
# python-version: "3.11"
#
# - run: python -m pip install --upgrade pip 'poetry==1.7.1'
#
# - name: remove deps that are not compatible with sqlalchemy 2
# run: poetry remove sqlalchemy-exasol
#
# - name: add sqlalchemy 2
# run: poetry add --lock --optional 'sqlalchemy>=2,<3'
#
# - name: checkout the lock file
# run: git checkout poetry.lock
#
# - name: lock with no updates
# # poetry add is aggressive and will update other dependencies like
# # numpy and pandas so we keep the pyproject.toml edits and then relock
# # without updating anything except the requested versions
# run: poetry lock --no-update
#
# - name: check the sqlalchemy version
# run: poetry show sqlalchemy --no-ansi | grep version | cut -d ':' -f2- | sed 's/ //g' | grep -P '^2\.'
#
# - name: upload deps file
# uses: actions/upload-artifact@v3
# with:
# name: deps
# path: |
# pyproject.toml
# poetry.lock

# test_backends_sqlalchemy2:
# name: SQLAlchemy 2 ${{ matrix.backend.title }} ${{ matrix.os }} python-${{ matrix.python-version }}
# runs-on: ${{ matrix.os }}
Expand Down
40 changes: 27 additions & 13 deletions ci/schema/exasol.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DROP SCHEMA IF EXISTS EXASOL CASCADE;
CREATE SCHEMA EXASOL;

CREATE OR REPLACE TABLE EXASOL.diamonds
CREATE OR REPLACE TABLE EXASOL."diamonds"
(
"carat" DOUBLE,
"cut" VARCHAR(256),
Expand All @@ -15,13 +15,13 @@ CREATE OR REPLACE TABLE EXASOL.diamonds
"z" DOUBLE
);

CREATE OR REPLACE TABLE EXASOL.batting
CREATE OR REPLACE TABLE EXASOL."batting"
(
"playerID" VARCHAR(256),
"yearID" BIGINT,
"stint" BIGINT,
"teamID" VARCHAR(256),
"logID" VARCHAR(256),
"lgID" VARCHAR(256),
"G" BIGINT,
"AB" BIGINT,
"R" BIGINT,
Expand All @@ -41,22 +41,22 @@ CREATE OR REPLACE TABLE EXASOL.batting
"GIDP" BIGINT
);

CREATE OR REPLACE TABLE EXASOL.awards_players
CREATE OR REPLACE TABLE EXASOL."awards_players"
(
"playerId" VARCHAR(256),
"playerID" VARCHAR(256),
"awardID" VARCHAR(256),
"yearID" VARCHAR(256),
"logID" VARCHAR(256),
"yearID" BIGINT,
"lgID" VARCHAR(256),
"tie" VARCHAR(256),
"notest" VARCHAR(256)
);

CREATE OR REPLACE TABLE EXASOL.functional_alltypes
CREATE OR REPLACE TABLE EXASOL."functional_alltypes"
(
"id" INTEGER,
"bool_col" BOOLEAN,
"tinyint_col" SHORTINT,
"small_int" SMALLINT,
"smallint_col" SMALLINT,
"int_col" INTEGER,
"bigint_col" BIGINT,
"float_col" FLOAT,
Expand All @@ -69,7 +69,21 @@ CREATE OR REPLACE TABLE EXASOL.functional_alltypes
);


IMPORT INTO EXASOL.diamonds FROM LOCAL CSV FILE '/data/diamonds.csv' COLUMN SEPARATOR = ',' SKIP = 1;
IMPORT INTO EXASOL.batting FROM LOCAL CSV FILE '/data/batting.csv' COLUMN SEPARATOR = ',' SKIP = 1;
IMPORT INTO EXASOL.awards_players FROM LOCAL CSV FILE '/data/awards_players.csv' COLUMN SEPARATOR = ',' SKIP = 1;
IMPORT INTO EXASOL.functional_alltypes FROM LOCAL CSV FILE '/data/functional_alltypes.csv' COLUMN SEPARATOR = ',' SKIP = 1;
IMPORT INTO EXASOL."diamonds" FROM LOCAL CSV FILE '/data/diamonds.csv' COLUMN SEPARATOR = ',' SKIP = 1;
IMPORT INTO EXASOL."batting" FROM LOCAL CSV FILE '/data/batting.csv' COLUMN SEPARATOR = ',' SKIP = 1;
IMPORT INTO EXASOL."awards_players" FROM LOCAL CSV FILE '/data/awards_players.csv' COLUMN SEPARATOR = ',' SKIP = 1;
IMPORT INTO EXASOL."functional_alltypes" FROM LOCAL CSV FILE '/data/functional_alltypes.csv' COLUMN SEPARATOR = ',' SKIP = 1;

CREATE OR REPLACE TABLE EXASOL."win"
(
"g" VARCHAR(1),
"x" BIGINT,
"y" BIGINT
);

INSERT INTO "win" VALUES
('a', 0, 3),
('a', 1, 2),
('a', 2, 0),
('a', 3, 1),
('a', 4, 1);
76 changes: 76 additions & 0 deletions ibis/backends/base/sqlglot/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,3 +738,79 @@ def _from_ibis_Int64(cls, dtype: dt.Int64) -> NoReturn:
raise com.UnsupportedBackendType(
"int64 is not a supported input or output type in BigQuery UDFs; use float64 instead"
)


class ExasolType(SqlglotType):
dialect = "exasol"

default_temporal_scale = 3

default_decimal_precision = 18
default_decimal_scale = 0

@classmethod
def _from_ibis_String(cls, dtype: dt.String) -> sge.DataType:
return sge.DataType(
this=sge.DataType.Type.VARCHAR,
expressions=[sge.DataTypeParam(this=sge.convert(2_000_000))],
)

@classmethod
def _from_sqlglot_DECIMAL(
cls,
precision: sge.DataTypeParam | None = None,
scale: sge.DataTypeParam | None = None,
) -> dt.Decimal:
if precision is None:
precision = cls.default_decimal_precision
else:
precision = int(precision.this.this)

if scale is None:
scale = cls.default_decimal_scale
else:
scale = int(scale.this.this)

if not scale:
if 0 < precision <= 3:
return dt.Int8(nullable=cls.default_nullable)
elif 3 < precision <= 9:
return dt.Int16(nullable=cls.default_nullable)
elif 9 < precision <= 18:
return dt.Int32(nullable=cls.default_nullable)
elif 18 < precision <= 36:
return dt.Int64(nullable=cls.default_nullable)
else:
raise com.UnsupportedBackendType(
"Decimal precision is too large; Exasol supports precision up to 36."
)
return dt.Decimal(precision, scale, nullable=cls.default_nullable)

@classmethod
def _from_ibis_Array(cls, dtype: dt.Array) -> NoReturn:
raise com.UnsupportedBackendType("Arrays not supported in Exasol")

@classmethod
def _from_ibis_Map(cls, dtype: dt.Map) -> NoReturn:
raise com.UnsupportedBackendType("Maps not supported in Exasol")

@classmethod
def _from_ibis_Struct(cls, dtype: dt.Struct) -> NoReturn:
raise com.UnsupportedBackendType("Structs not supported in Exasol")

@classmethod
def _from_ibis_Timestamp(cls, dtype: dt.Timestamp) -> sge.DataType:
code = typecode.TIMESTAMP if dtype.timezone is None else typecode.TIMESTAMPTZ
return sge.DataType(this=code)

@classmethod
def _from_sqlglot_ARRAY(cls, value_type: sge.DataType) -> NoReturn:
raise com.UnsupportedBackendType("Arrays not supported in Exasol")

@classmethod
def _from_sqlglot_MAP(cls, key: sge.DataType, value: sge.DataType) -> NoReturn:
raise com.UnsupportedBackendType("Maps not supported in Exasol")

@classmethod
def _from_sqlglot_STRUCT(cls, *cols: sge.ColumnDef) -> NoReturn:
raise com.UnsupportedBackendType("Structs not supported in Exasol")
1 change: 0 additions & 1 deletion ibis/backends/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,6 @@ def ddl_con(ddl_backend):
@pytest.fixture(
params=_get_backends_to_test(
keep=(
"exasol",
"mssql",
"oracle",
"risingwave",
Expand Down
Loading

0 comments on commit 433bb75

Please sign in to comment.