Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(exasol): port to sqlglot #8032

Merged
merged 28 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
10f4d12
chore: start the port of exasol to sqlglot
cpcloud Jan 18, 2024
e517a15
chore(exasol): remove bogus kwargs in docstring
cpcloud Jan 18, 2024
0e2206a
test(exasol): test_aggregation working
cpcloud Jan 19, 2024
7b9a456
test(exasol): test_api
cpcloud Jan 19, 2024
2386655
test(exasol): test_asof_join
cpcloud Jan 19, 2024
4d107f8
test(exasol): test_client
cpcloud Jan 19, 2024
455bda7
test(exasol): test_dot_sql
cpcloud Jan 19, 2024
fa35ae0
test(exasol): test_export
cpcloud Jan 19, 2024
3db3793
test(exasol): test_generic
cpcloud Jan 19, 2024
dfac5b8
test(exasol): test_join
cpcloud Jan 19, 2024
fc77022
test(exasol): test_numeric
cpcloud Jan 19, 2024
c357501
test(exasol): test_param
cpcloud Jan 19, 2024
23c8003
test(exasol): test_sql
cpcloud Jan 19, 2024
360ac7a
test(exasol): test_string
cpcloud Jan 19, 2024
05bed54
test(exasol): test_uuid
cpcloud Jan 19, 2024
2250a7e
test(exasol): fix another typo in data loading
cpcloud Jan 19, 2024
df3180e
test(exasol): setup win table
cpcloud Jan 19, 2024
22d1f27
test(exasol): enable xpassing test_export tests
cpcloud Jan 19, 2024
be126de
test(exasol): enable xpassing test_aggregation tests
cpcloud Jan 19, 2024
188ff05
test(exasol): test_temporal
cpcloud Jan 19, 2024
24f5e59
test(exasol): test_window
cpcloud Jan 19, 2024
d8dbc0d
test(exasol): more xpasses
cpcloud Jan 19, 2024
5a14f04
chore: deal with things that are not sql
cpcloud Jan 19, 2024
6102b36
chore: deal with base table naming
cpcloud Jan 19, 2024
de94b21
test(mysql): enable xpassing test
cpcloud Jan 19, 2024
79d80d5
test(druid): enable xpassing test
cpcloud Jan 19, 2024
9820208
ci: add back exasol ci
cpcloud Jan 19, 2024
b5b4a56
chore: remove dead commented sqlalchemy2 lockfile generation step
cpcloud Jan 19, 2024
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
72 changes: 16 additions & 56 deletions .github/workflows/ibis-backends.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,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 @@ -290,15 +290,15 @@ jobs:
# - flink
# services:
# - flink
# - os: windows-latest
# backend:
# name: exasol
# title: Exasol
# serial: true
# extras:
# - exasol
# services:
# - exasol
- 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 @@ -606,46 +606,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 @@
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

Check warning on line 765 in ibis/backends/base/sqlglot/datatypes.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/base/sqlglot/datatypes.py#L765

Added line #L765 was not covered by tests
else:
precision = int(precision.this.this)

if scale is None:
scale = cls.default_decimal_scale

Check warning on line 770 in ibis/backends/base/sqlglot/datatypes.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/base/sqlglot/datatypes.py#L770

Added line #L770 was not covered by tests
else:
scale = int(scale.this.this)

if not scale:
if 0 < precision <= 3:
return dt.Int8(nullable=cls.default_nullable)

Check warning on line 776 in ibis/backends/base/sqlglot/datatypes.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/base/sqlglot/datatypes.py#L776

Added line #L776 was not covered by tests
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(

Check warning on line 784 in ibis/backends/base/sqlglot/datatypes.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/base/sqlglot/datatypes.py#L784

Added line #L784 was not covered by tests
"Decimal precision is too large; Exasol supports precision up to 36."
)
return dt.Decimal(precision, scale, nullable=cls.default_nullable)

Check warning on line 787 in ibis/backends/base/sqlglot/datatypes.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/base/sqlglot/datatypes.py#L787

Added line #L787 was not covered by tests

@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")

Check warning on line 808 in ibis/backends/base/sqlglot/datatypes.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/base/sqlglot/datatypes.py#L808

Added line #L808 was not covered by tests

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

Check warning on line 812 in ibis/backends/base/sqlglot/datatypes.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/base/sqlglot/datatypes.py#L812

Added line #L812 was not covered by tests

@classmethod
def _from_sqlglot_STRUCT(cls, *cols: sge.ColumnDef) -> NoReturn:
raise com.UnsupportedBackendType("Structs not supported in Exasol")

Check warning on line 816 in ibis/backends/base/sqlglot/datatypes.py

View check run for this annotation

Codecov / codecov/patch

ibis/backends/base/sqlglot/datatypes.py#L816

Added line #L816 was not covered by tests
2 changes: 1 addition & 1 deletion ibis/backends/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ def ddl_con(ddl_backend):


@pytest.fixture(
params=_get_backends_to_test(keep=("exasol", "mssql", "oracle", "sqlite")),
params=_get_backends_to_test(keep=("mssql", "oracle", "sqlite")),
scope="session",
)
def alchemy_backend(request, data_dir, tmp_path_factory, worker_id):
Expand Down
Loading
Loading