Skip to content

Commit a6c522b

Browse files
committed
feat: Add Exasol support for datacontract test (#1335)
Implements ibis Exasol backend for the test engine with comprehensive refinements: - GEOMETRY(srid) parser override: sqlglot's Exasol dialect now parses srid as srid (not subtype) - Extended type-alias normalization: NVARCHAR, CLOB, HASHTYPE(m BIT), and INTERVAL forms match their catalog spellings; physicalType checks accept either spelling - TLS certificate policy moved to DATACONTRACT_EXASOL_FINGERPRINT and DATACONTRACT_EXASOL_VALIDATE_CERTIFICATE env vars; contract host stays ODCS-compliant - Config options for fingerprint and validate_certificate; docs/configuration.md updated - Exasol icon added to card grid (alphabetically between Azure Blob/ADLS and GCS) - Fixed identifier resolution docs: schema follows Exasol quoting rules; table and column names match case-insensitively without quotes - Moved exasol_patch import to top of _connect_exasol Live verification on Exasol 2026.1.2: physicalType matching, row checks, custom SQL quality rules, --filter, --metadata-only, TLS strict/fingerprint/nocertcheck, all check types on logicalType-only contracts.
1 parent 8234bbd commit a6c522b

36 files changed

Lines changed: 594 additions & 29 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212

1313
### Added
1414
- `datacontract test` supports SAP HANA Cloud and SAP Datasphere through the optional `hana` extra (#1332)
15+
- `datacontract test` supports Exasol through the `exasol` extra (#1335)
1516
- `datacontract export excel` and `datacontract import excel` now support all versions of the Excel template (ODCS v3.0.2, v3.1.0, v3.2.0)
1617
- `datacontract export great-expectations --checks` restricts the suite to `quality` and/or `properties` expectations (#1617)
1718
- `datacontract import` warns once per import about column types that have no mapping to a `logicalType` (#1629)

‎datacontract/api.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ def _parse_filters_query(filters: str | None) -> dict[str, str] | None:
483483
"oracle": ("host", "oracle_host", ("oracle_password",)),
484484
"impala": ("host", "impala_host", ("impala_password",)),
485485
"trino": ("host", "trino_host", ("trino_password",)),
486+
"exasol": ("host", "exasol_host", ("exasol_password",)),
486487
"redshift": ("host", "redshift_host", ("redshift_password",)),
487488
"sqlserver": ("host", "sqlserver_host", ("sqlserver_password",)),
488489
"snowflake": (

‎datacontract/config/settings.py‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
"databricks_schema": "schema",
4141
"duckdb_database": "database",
4242
"duckdb_schema": "schema",
43+
"exasol_host": "host",
44+
"exasol_port": "port",
45+
"exasol_schema": "schema",
4346
"iceberg_catalog_url": "catalogUrl",
4447
"iceberg_catalog": "catalog",
4548
"iceberg_namespace": "namespace",
@@ -283,6 +286,16 @@ class Config(BaseSettings):
283286
sqlserver_port: int | None = None
284287
sqlserver_database: str | None = None
285288

289+
# exasol
290+
exasol_username: str | None = None
291+
exasol_password: SecretStr | None = None
292+
exasol_fingerprint: str | None = None
293+
exasol_validate_certificate: bool | None = None
294+
# overrides for the contract's servers block
295+
exasol_host: str | None = None
296+
exasol_port: int | None = None
297+
exasol_schema: str | None = None
298+
286299
# trino
287300
trino_authentication: str | None = None
288301
trino_username: str | None = None
@@ -900,6 +913,28 @@ def get_sqlserver_port(self) -> int | None:
900913
def get_sqlserver_database(self, required: bool = False) -> str | None:
901914
return self._str_option("sqlserver_database", required)
902915

916+
# --- exasol ---
917+
def get_exasol_username(self, required: bool = False) -> str | None:
918+
return self._str_option("exasol_username", required)
919+
920+
def get_exasol_password(self, required: bool = False) -> str | None:
921+
return self._str_option("exasol_password", required)
922+
923+
def get_exasol_fingerprint(self, required: bool = False) -> str | None:
924+
return self._str_option("exasol_fingerprint", required)
925+
926+
def get_exasol_validate_certificate(self, default: bool = True) -> bool:
927+
return self._bool_option("exasol_validate_certificate", default)
928+
929+
def get_exasol_host(self, required: bool = False) -> str | None:
930+
return self._str_option("exasol_host", required)
931+
932+
def get_exasol_port(self) -> int | None:
933+
return self._int_option("exasol_port")
934+
935+
def get_exasol_schema(self, required: bool = False) -> str | None:
936+
return self._str_option("exasol_schema", required)
937+
903938
# --- trino ---
904939
def get_trino_authentication(self, required: bool = False) -> str | None:
905940
return self._str_option("trino_authentication", required)

‎datacontract/engines/checks/physical_type_match.py‎

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import sqlglot
2626
from sqlglot import exp
2727

28+
from datacontract.engines.ibis.native_type import strip_exasol_charset
29+
2830
# Tokens that mean "sqlglot parsed something, but not a type it understands".
2931
_UNRESOLVED = {exp.DataType.Type.UNKNOWN, exp.DataType.Type.USERDEFINED, exp.DataType.Type.NULL}
3032

@@ -79,6 +81,43 @@ def _is_snowflake(dialect) -> bool:
7981
_TRINO_DIALECTS = {"athena", "trino", "presto"}
8082
_TRINO_TEXT_FAMILY = {exp.DataType.Type.VARCHAR, exp.DataType.Type.TEXT}
8183

84+
# Exasol's catalog reports these aliases as the type on the right
85+
# (https://docs.exasol.com/db/latest/sql_references/data_types/datatypealiases.htm);
86+
# sqlglot's Exasol generator does not know them yet, drop this once it does.
87+
_EXASOL_ALIASES = {
88+
"int": "decimal(18,0)",
89+
"integer": "decimal(18,0)",
90+
"bigint": "decimal(36,0)",
91+
"smallint": "decimal(9,0)",
92+
"shortint": "decimal(9,0)",
93+
"tinyint": "decimal(3,0)",
94+
"float": "double",
95+
"real": "double",
96+
"number": "double",
97+
"nchar": "char(1)",
98+
"clob": "varchar(2000000)",
99+
"long varchar": "varchar(2000000)",
100+
"character large object": "varchar(2000000)",
101+
}
102+
_EXASOL_ALIAS_PATTERNS = [
103+
(r"^nchar(\(.+\))$", r"char\1"),
104+
(r"^(?:nvarchar2?|clob|character large object)(\(.+\))$", r"varchar\1"),
105+
(r"^hashtype\((\d+) bit\)$", lambda m: f"hashtype({int(m.group(1)) // 8} byte)"),
106+
# the catalog spells INTERVAL with its default precisions
107+
(r"^interval year to month$", "interval year(2) to month"),
108+
(r"^interval day to second$", "interval day(2) to second(3)"),
109+
(r"^interval day to second(\(\d+\))$", r"interval day(2) to second\1"),
110+
(r"^interval day(\(\d+\)) to second$", r"interval day\1 to second(3)"),
111+
]
112+
113+
114+
def _normalize_exasol_declared(expected: str) -> str:
115+
expected = _normalize_raw(strip_exasol_charset(expected))
116+
expected = _EXASOL_ALIASES.get(expected, expected)
117+
for pattern, replacement in _EXASOL_ALIAS_PATTERNS:
118+
expected = re.sub(pattern, replacement, expected)
119+
return expected
120+
82121

83122
def _parse(type_str: str, dialect) -> Optional[exp.DataType]:
84123
"""Parse a type string into an ``exp.DataType`` for ``dialect``, or ``None``."""
@@ -226,8 +265,9 @@ def physical_type_matches(
226265
"""
227266
if not expected or not expected.strip() or not actual or not actual.strip():
228267
return None, "no physical type to compare; skipping the physical type check"
229-
230-
exp_dt = _parse(expected, dialect)
268+
# The declared type as parsed; `expected` itself stays the author's spelling for messages.
269+
declared = _normalize_exasol_declared(expected) if _dialect_name(dialect) == "exasol" else expected
270+
exp_dt = _parse(declared, dialect)
231271
act_dt = _parse(actual, dialect)
232272

233273
# When both sides are types sqlglot cannot model (e.g. Oracle ROWID / RAW /
@@ -236,7 +276,7 @@ def physical_type_matches(
236276
# is an ordinary type, the physicalType is foreign to this server's dialect
237277
# (e.g. a SQL Server 'uniqueidentifier' declared against Snowflake): skip.
238278
if exp_dt is None and act_dt is None:
239-
if _raw_match(expected, actual):
279+
if _raw_match(declared, actual):
240280
return True, ""
241281
return False, f"expected physical type '{expected}' but the column is '{actual}'"
242282
if exp_dt is None or act_dt is None:
@@ -258,7 +298,7 @@ def physical_type_matches(
258298

259299
# sqlglot fills in a dialect's default precision (a bare NUMBER parses as
260300
# DECIMAL(38,0)), so what the contract declares is read off the raw string.
261-
if _split_base(_normalize_raw(expected))[1] and not _scalar_params_equal(exp_dt, act_dt):
301+
if _split_base(_normalize_raw(declared))[1] and not _scalar_params_equal(exp_dt, act_dt):
262302
return False, f"expected physical type '{expected}' but the column is '{actual}'"
263303

264304
return True, ""

‎datacontract/engines/checks/sql_guard.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"athena": "athena",
4444
"bigquery": "bigquery",
4545
"databricks": "databricks",
46+
"exasol": "exasol",
4647
"mysql": "mysql",
4748
"oracle": "oracle",
4849
"postgres": "postgres",
@@ -70,6 +71,10 @@ def is_read_only_query(query: str, dialect: Optional[str] = None) -> bool:
7071
through, and so is one that holds a second statement -- a trailing
7172
`; DROP TABLE orders` must never reach the data source.
7273
"""
74+
if dialect == "exasol":
75+
# ibis registers its own Postgres-based `exasol` dialect over sqlglot's, so by
76+
# name the parser would depend on whether ibis has been imported yet.
77+
from sqlglot.dialects.exasol import Exasol as dialect
7378
try:
7479
statements = sqlglot.parse(query, dialect=dialect)
7580
except sqlglot.errors.ParseError:

‎datacontract/engines/ibis/connections/connect.py‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ def connect_ibis(
196196
if server_type == "impala":
197197
return _connect_impala(ibis, server, config)
198198

199+
if server_type == "exasol":
200+
return _connect_exasol(ibis, server, config)
201+
199202
if server_type in LINT_ONLY_SERVER_TYPES:
200203
_unsupported(
201204
run,
@@ -870,6 +873,44 @@ def _connect_trino(ibis, server: Server, config: Config):
870873
)
871874

872875

876+
def _connect_exasol(ibis, server: Server, config: Config):
877+
import ssl
878+
879+
from datacontract.engines.ibis.connections.exasol_patch import apply_exasol_compatibility_patch
880+
881+
host = config.get_exasol_host() or server.host
882+
# pyexasol takes the certificate policy as a host suffix: `host/<sha256>` pins the
883+
# certificate, `host/nocertcheck` skips verification.
884+
if fingerprint := config.get_exasol_fingerprint():
885+
host = f"{host}/{fingerprint}"
886+
elif not config.get_exasol_validate_certificate():
887+
host = f"{host}/nocertcheck"
888+
# ibis defaults to CERT_NONE; restore pyexasol's own default of verifying the
889+
# certificate unless a suffix replaces that check.
890+
cert_reqs = ssl.CERT_NONE if host and "/" in host else ssl.CERT_REQUIRED
891+
kwargs = dict(
892+
host=host,
893+
port=config.get_exasol_port() or (int(server.port) if server.port else 8563),
894+
user=config.get_exasol_username(required=True),
895+
password=config.get_exasol_password(required=True),
896+
websocket_sslopt={"cert_reqs": cert_reqs},
897+
)
898+
schema = config.get_exasol_schema() or server.schema_
899+
if schema:
900+
kwargs["schema"] = schema
901+
902+
try:
903+
con = ibis.exasol.connect(**kwargs)
904+
except Exception as e:
905+
# pyexasol renders its errors as a multi-line block; the run reports only the first line.
906+
message = getattr(e, "message", None)
907+
if isinstance(message, str):
908+
raise ConnectionError(message) from e
909+
raise
910+
apply_exasol_compatibility_patch(con)
911+
return con
912+
913+
873914
def _get_custom_property(server: Server, name: str):
874915
if server.customProperties:
875916
for prop in server.customProperties:
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from __future__ import annotations
2+
3+
import types
4+
5+
6+
def _raw_sql(self, query):
7+
return self.con.execute(query)
8+
9+
10+
def _from_sqlglot_GEOMETRY(cls, arg=None, srid=None, nullable=None):
11+
from ibis.backends.sql.datatypes import ExasolType
12+
13+
# Exasol spells it GEOMETRY(srid); ibis expects GEOMETRY(POINT, srid)
14+
if arg is not None and srid is None and str(arg.this.this).isdigit():
15+
srid, arg = arg, None
16+
return super(ExasolType, cls)._from_sqlglot_GEOMETRY(arg, srid, nullable=nullable)
17+
18+
19+
def apply_exasol_compatibility_patch(con) -> None:
20+
from ibis.backends.sql.datatypes import ExasolType
21+
22+
if not hasattr(con, "raw_sql"):
23+
con.raw_sql = types.MethodType(_raw_sql, con)
24+
ExasolType._from_sqlglot_GEOMETRY = classmethod(_from_sqlglot_GEOMETRY)

‎datacontract/engines/ibis/ibis_check_execute.py‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,15 +627,29 @@ def patindex(pattern: str, expression: str) -> int: # -> PATINDEX(pattern, expr
627627
return patindex(like, column) > 0
628628

629629

630+
def _exasol_regex_search(column, pattern: str):
631+
"""``REGEXP_INSTR(column, pattern) > 0``: Exasol's regex match is the
632+
``REGEXP_LIKE`` predicate, which ibis cannot compile ``re_search`` to."""
633+
import ibis
634+
635+
@ibis.udf.scalar.builtin
636+
def regexp_instr(expression: str, pattern: str) -> int: ...
637+
638+
return regexp_instr(column, pattern) > 0
639+
640+
630641
def _regex_search_expr(t, column, pattern: str):
631642
"""Unanchored regex/pattern match, portable across backends.
632643
633644
Most ibis backends compile ``re_search`` to a native regex operator. SQL
634645
Server has none, so fall back to a PATINDEX-based LIKE match for the mssql
635-
backend.
646+
backend; Exasol has one, but only as a predicate ibis does not know.
636647
"""
637-
if _backend_name(t) == "mssql":
648+
backend = _backend_name(t)
649+
if backend == "mssql":
638650
return _mssql_pattern_search(column, pattern)
651+
if backend == "exasol":
652+
return _exasol_regex_search(column, pattern)
639653
return column.re_search(pattern)
640654

641655

@@ -1395,6 +1409,9 @@ def _apply_row_filter(t, model: str, predicate: str):
13951409
WHERE clause included and the recorded per-check SQL shows it.
13961410
"""
13971411
alias = f"{model}_filtered" if _SIMPLE_IDENTIFIER.match(model) else "filtered_rows"
1412+
# ibis quotes the alias it defines, Exasol upper-cases the unquoted reference to it.
1413+
if _backend_name(t) == "exasol":
1414+
alias = alias.upper()
13981415
return t.alias(alias).sql(f"SELECT * FROM {alias} WHERE {predicate}")
13991416

14001417

‎datacontract/engines/ibis/native_type.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from __future__ import annotations
2525

2626
import logging
27+
import re
2728
from typing import Optional
2829

2930
from open_data_contract_standard.model import Server
@@ -48,6 +49,7 @@
4849
"athena": "full_type",
4950
"trino": "full_type",
5051
"bigquery": "bigquery",
52+
"exasol": "exasol",
5153
}
5254

5355

@@ -335,12 +337,31 @@ def _read_bigquery(con, server: Server, model: str) -> Optional[dict[str, str]]:
335337
return _map_full_type(con, query)
336338

337339

340+
def _read_exasol(con, server: Server, model: str) -> Optional[dict[str, str]]:
341+
"""Exasol reports a complete type string in ``SYS.EXA_ALL_COLUMNS.column_type``,
342+
with the character set appended to string types (``VARCHAR(100) UTF8``)."""
343+
schema_filter = _schema_filter(server, column="column_schema")
344+
query = (
345+
"SELECT column_name, column_type FROM SYS.EXA_ALL_COLUMNS "
346+
f"WHERE upper(column_table) = upper('{_quote(model)}'){schema_filter}"
347+
)
348+
native_types = _map_full_type(con, query)
349+
if not native_types:
350+
return None
351+
return {column: strip_exasol_charset(native) for column, native in native_types.items()}
352+
353+
354+
def strip_exasol_charset(native_type: str) -> str:
355+
return re.sub(r"\s+(UTF8|ASCII)$", "", native_type, flags=re.IGNORECASE)
356+
357+
338358
_READERS = {
339359
"information_schema": _read_information_schema,
340360
"oracle": _read_oracle,
341361
"databricks": _read_databricks,
342362
"full_type": _read_full_type_information_schema,
343363
"bigquery": _read_bigquery,
364+
"exasol": _read_exasol,
344365
}
345366

346367

‎datacontract/model/server.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"db2",
3232
"denodo",
3333
"dremio",
34-
"exasol",
3534
"hana",
3635
"hive",
3736
"informix",

0 commit comments

Comments
 (0)