-
Notifications
You must be signed in to change notification settings - Fork 603
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(formats): turn TypeParser
into a TypeMapper
implementation for sqlglot
#6876
Conversation
from collections.abc import Mapping | ||
|
||
|
||
class PostgresTypeParser(TypeParser): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to base/sql/glot/datatypes.py
for centralization, probably I should move it back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small naming nit, otherwise LGTM!
This PR is not complete yet, I'd like to add more roundtrip tests for certain backends using hypothesis. |
ee66638
to
f74e8fd
Compare
81e2f6e
to
28349ff
Compare
@cpcloud could you please give it a preliminary review? I still need to update the cloud backends and somewhat improve the testing. |
4874821
to
a712d34
Compare
@cpcloud the cloud backends are passing too, please take a look! Feel free to update the PR as needed, I won't be touching it for a couple of days. |
@@ -278,6 +277,7 @@ def test_rename_table(con, temp_table, temp_table_orig, new_schema): | |||
@mark.notyet( | |||
["trino"], reason="trino doesn't support NOT NULL in its in-memory catalog" | |||
) | |||
@mark.broken(["snowflake"], reason="snowflake shows not nullable column as nullable") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this broken upstream or is there a bug in the implementation of type parsing for snowflake?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is due to a weird behaviour of snowflake
>create temporary table _ibis_test_nullability (a number not null);
+----------------------------------------------------+
| status |
|----------------------------------------------------|
| Table _IBIS_TEST_NULLABILITY successfully created. |
+----------------------------------------------------+
1 Row(s) produced. Time Elapsed: 0.470s
>desc _ibis_test_nullability;
+------+--------------+--------+-------+---------+-------------+------------+-------+------------+---------+-------------+
| name | type | kind | null? | default | primary key | unique key | check | expression | comment | policy name |
|------+--------------+--------+-------+---------+-------------+------------+-------+------------+---------+-------------|
| A | NUMBER(38,0) | COLUMN | N | NULL | N | N | NULL | NULL | NULL | NULL |
+------+--------------+--------+-------+---------+-------------+------------+-------+------------+---------+-------------+
1 Row(s) produced. Time Elapsed: 0.212s
>select * from _ibis_test_nullability;
+---+
| A |
|---|
+---+
0 Row(s) produced. Time Elapsed: 0.224s
>DESC RESULT last_query_id();
+------+--------------+--------+-------+---------+-------------+------------+-------+------------+---------+-------------+
| name | type | kind | null? | default | primary key | unique key | check | expression | comment | policy name |
|------+--------------+--------+-------+---------+-------------+------------+-------+------------+---------+-------------|
| A | NUMBER(38,0) | COLUMN | Y | NULL | N | N | NULL | NULL | NULL | NULL |
+------+--------------+--------+-------+---------+-------------+------------+-------+------------+---------+-------------+
1 Row(s) produced. Time Elapsed: 0.222s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the null?
values.
f"CREATE PRIVATE TEMPORARY TABLE {table} AS {query.strip(';')}" | ||
) | ||
result = con.exec_driver_sql(f"DESCRIBE {table}").mappings().all() | ||
con.exec_driver_sql(f"DROP TABLE {table}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why there are a bunch of uncovered lines here.
"ipv6": dt.INET(nullable=default_nullable), | ||
"object('json')": dt.JSON(nullable=default_nullable), | ||
"array(null)": dt.Array(dt.null, nullable=default_nullable), | ||
"array(nothing)": dt.Array(dt.null, nullable=default_nullable), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These types are case sensitive, why did you alter their case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From_string converts the input string to lowercase before looking up the types unknown to sqlglot
6a81a51
to
98f0f6a
Compare
@cpcloud could you please take another look? |
0dc48e0
to
e17ac89
Compare
4694739
to
76d4a84
Compare
Cloud backends look good:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweeeeeeet!
76d4a84
to
7abda66
Compare
Extend the
TypeMapper
interface withto_string()
andfrom_string()
classmethods, then implement theTypeParser
to rather be an implementation ofTypeMapper
forsqlglot
. This means that the mappers are able to convert between ibis types and sqlglot datatype expressions back and forth. Hopefully this will turn useful once we are going to depend on sqlglot more heavily.Additionally support for parsing typestrings and compiling to typestrings (this was the original functionality of the previous type parser), the latter functionality is offloaded to sqlglot (with a couple of exceptions already handled in the original type parse).