-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sqlite): implement
_get_schema_using_query
in SQLite backend
As SQLite does not provide this functionality directly the code here creates a temporal view for the query and then uses `table_info` pragma for retrieving the schema. A convoluted and changing named is used for the view in order to avoid collisions. The lifetime of SQLAlchemy SQLite backend connections is not documented so this seems to be the safest thing to do. The code has been highly inspired by DuckDB backend code.
- Loading branch information
Showing
9 changed files
with
118 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
"""Parse SQLite data types.""" | ||
|
||
from __future__ import annotations | ||
|
||
import ibis.expr.datatypes as dt | ||
|
||
|
||
def parse(text: str) -> dt.DataType: | ||
"""Parse `text` into an ibis data type.""" | ||
text = text.strip().upper() | ||
|
||
# SQLite affinity rules | ||
# (see https://www.sqlite.org/datatype3.html). | ||
|
||
# 1. If the declared type contains the string "INT" then it is | ||
# assigned INTEGER affinity. | ||
if "INT" in text: | ||
return dt.int64 | ||
|
||
# 2. If the declared type of the column contains any of the | ||
# strings "CHAR", "CLOB", or "TEXT" then that column has TEXT | ||
# affinity. Notice that the type VARCHAR contains the string | ||
# "CHAR" and is thus assigned TEXT affinity. | ||
if "CHAR" in text or "CLOB" in text or "TEXT" in text: | ||
return dt.string | ||
|
||
# 3. If the declared type for a column contains the string "BLOB" | ||
# or if no type is specified then the column has affinity BLOB. | ||
if not text or "BLOB" in text: | ||
return dt.binary | ||
|
||
# 4. If the declared type for a column contains any of the strings | ||
# "REAL", "FLOA", or "DOUB" then the column has REAL affinity. | ||
if "REAL" in text or "FLOA" in text or "DOUB" in text: | ||
return dt.float64 | ||
|
||
# 5. Otherwise, the affinity is NUMERIC. | ||
return dt.decimal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters