-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31d01ed
commit e6c3591
Showing
8 changed files
with
110 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
from typing import Iterator, Tuple | ||
from typing import Any | ||
|
||
import ibis.expr.datatypes as dt | ||
from ibis.backends.snowflake import Backend as BaseBackend, SnowflakeType | ||
from .._utils import temp_rand_str, normalize_name | ||
import sqlalchemy.types as sat | ||
from ibis.backends.snowflake import Backend as BaseBackend | ||
from ibis.backends.snowflake import ( | ||
SnowflakeCompiler, | ||
SnowflakeExprTranslator, | ||
SnowflakeType, | ||
) | ||
|
||
|
||
class FugueSnowflakeType(SnowflakeType): | ||
@classmethod | ||
def to_ibis(cls, typ: Any, nullable: bool = True): | ||
if isinstance(typ, (sat.BINARY, sat.VARBINARY)): | ||
return dt.Binary(nullable=nullable) | ||
return super().to_ibis(typ, nullable=nullable) | ||
|
||
|
||
class FugueSnowflakeExprTranslator(SnowflakeExprTranslator): | ||
type_mapper = FugueSnowflakeType | ||
|
||
|
||
class FugueSnowflakeCompiler(SnowflakeCompiler): | ||
translator_class = FugueSnowflakeExprTranslator | ||
|
||
|
||
class Backend(BaseBackend): | ||
def _metadata(self, query: str) -> Iterator[Tuple[str, dt.DataType]]: | ||
with self.begin() as con: | ||
database = normalize_name(self.current_database) | ||
schema = normalize_name(self.current_schema) | ||
table = normalize_name("IBIS_" + temp_rand_str()) | ||
full_name = f"{database}.{schema}.{table}" | ||
create_sql = ( | ||
f"CREATE TEMP TABLE {full_name} AS SELECT * FROM ({query}) LIMIT 0" | ||
) | ||
print(create_sql) | ||
con.exec_driver_sql(create_sql) | ||
result = con.exec_driver_sql(f"DESC VIEW {full_name}").mappings().all() | ||
|
||
for field in result: | ||
name = field["name"] | ||
type_string = field["type"] | ||
is_nullable = field["null?"] == "Y" | ||
yield name, SnowflakeType.from_string(type_string, nullable=is_nullable) | ||
|
||
print("schema DONE") | ||
compiler = FugueSnowflakeCompiler |
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