Skip to content

Fix: CLOB, NCHAR, NVARCHAR, DATETIME and DATE compile to DDL CrateDB cannot parse - #305

Open
bgunebakan wants to merge 3 commits into
mainfrom
bilal/304-types-clob-nchar-nvarchar-datetime-and-date-compile-to-ddl-cratedb-cannot-parse
Open

Fix: CLOB, NCHAR, NVARCHAR, DATETIME and DATE compile to DDL CrateDB cannot parse#305
bgunebakan wants to merge 3 commits into
mainfrom
bilal/304-types-clob-nchar-nvarchar-datetime-and-date-compile-to-ddl-cratedb-cannot-parse

Conversation

@bgunebakan

@bgunebakan bgunebakan commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Summary of the changes / Why this is an improvement

  • Added five visitors on CrateTypeCompiler.
  • Also added tests/test_type_compilation.py tests to cover all CrateDB supported types, it tests all supported types to extend coverage. (it's a bit out of scope of this ticket but I wanted to extend the test coverage)

Discovered while working on #12 and moved changes on this PR.

Checklist

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 18d415ce-97cf-457b-b1ab-71fcbdf02302

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

def visit_DATETIME(self, type_, **kw):
return self.visit_TIMESTAMP(type_, **kw)

def visit_DATE(self, type_, **kw):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an open question how to handle DATE type in CrateDB >=6.5, We can store them as TIMESTAMP but they will cost "not implementing" new type storage. Maybe implementing crate version check?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's also the case of casting as DATE.

sqlalchemy can tell the two apart: when it renders the type of a column, it passes the column as type_expression. So visit_DATE can return TIMESTAMP for columns only, if our get_column_specification passes type_expression=column to it. visit_ARRAY must also pass **kw through, or ARRAY(sa.DATE) columns still come out as ARRAY(DATE). #300 already does that

Before 6.5, we could cast to timestamp midnight UTC or smth, or raise an exception - I think raising is better, since it shows crate doesn't support that at compile time, rather than maybe introducing a new timezone bug. But this ofc means we don't have casts to date before 6.5.

@florinutz florinutz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good work! got some observations

"BOOLEAN": lambda: sa.BOOLEAN,
"CHAR": lambda: sa.CHAR(5),
"CLOB": lambda: sa.CLOB,
"DATE": lambda: sa.DATE,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test can't catch a mistake in the DATE mapping. CI only uses the nightly build (the unreleased 6.5), and 6.5 can store a DATE column. So the DATE row passes even without visit_DATE. I checked it: I removed the compiler change and kept the tests. CLOB, NCHAR, NVARCHAR and DATETIME failed, but DATE passed.

Could we test the five mappings in tests/create_table_test.py instead, next to test_table_time_type? Those tests compare the exact CREATE TABLE text through a fake cursor. They need no server, so the result is the same for every CrateDB version. A cast case there would also cover the DATE/TIMESTAMP split.

"TEXT": lambda: sa.TEXT,
"TIME": lambda: sa.TIME,
"TIMESTAMP": lambda: sa.TIMESTAMP,
"UUID": lambda: sa.UUID,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crate only added uuid in 6.2.0, so this would need a skip for versions < 6.2.0, if we ever move this CI to run against other versions than nightly

@@ -246,6 +255,12 @@ def visit_datetime(self, type_, **kw):
def visit_date(self, type_, **kw):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

visit_date and visit_datetime are now redundant, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Types: CLOB, NCHAR, NVARCHAR, DATETIME and DATE compile to DDL CrateDB cannot parse

2 participants