-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for hybrid tables and indexes (#533)
* Add support for hybrid tables * Update DESCRIPTION.md and add support for indexes
- Loading branch information
1 parent
b5af4e3
commit 43c6b56
Showing
26 changed files
with
679 additions
and
33 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
13 changes: 13 additions & 0 deletions
13
src/snowflake/sqlalchemy/sql/custom_schema/custom_table_prefix.py
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,13 @@ | ||
# | ||
# Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved. | ||
|
||
from enum import Enum | ||
|
||
|
||
class CustomTablePrefix(Enum): | ||
DEFAULT = 0 | ||
EXTERNAL = 1 | ||
EVENT = 2 | ||
HYBRID = 3 | ||
ICEBERG = 4 | ||
DYNAMIC = 5 |
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
67 changes: 67 additions & 0 deletions
67
src/snowflake/sqlalchemy/sql/custom_schema/hybrid_table.py
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,67 @@ | ||
# | ||
# Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved. | ||
# | ||
|
||
from typing import Any | ||
|
||
from sqlalchemy.exc import ArgumentError | ||
from sqlalchemy.sql.schema import MetaData, SchemaItem | ||
|
||
from snowflake.sqlalchemy.custom_commands import NoneType | ||
|
||
from .custom_table_base import CustomTableBase | ||
from .custom_table_prefix import CustomTablePrefix | ||
|
||
|
||
class HybridTable(CustomTableBase): | ||
""" | ||
A class representing a hybrid table with configurable options and settings. | ||
The `HybridTable` class allows for the creation and querying of OLTP Snowflake Tables . | ||
While it does not support reflection at this time, it provides a flexible | ||
interface for creating dynamic tables and management. | ||
""" | ||
|
||
__table_prefixes__ = [CustomTablePrefix.HYBRID] | ||
|
||
_support_primary_and_foreign_keys = True | ||
|
||
def __init__( | ||
self, | ||
name: str, | ||
metadata: MetaData, | ||
*args: SchemaItem, | ||
**kw: Any, | ||
) -> None: | ||
if kw.get("_no_init", True): | ||
return | ||
super().__init__(name, metadata, *args, **kw) | ||
|
||
def _init( | ||
self, | ||
name: str, | ||
metadata: MetaData, | ||
*args: SchemaItem, | ||
**kw: Any, | ||
) -> None: | ||
super().__init__(name, metadata, *args, **kw) | ||
|
||
def _validate_table(self): | ||
missing_attributes = [] | ||
if self.key is NoneType: | ||
missing_attributes.append("Primary Key") | ||
if missing_attributes: | ||
raise ArgumentError( | ||
"HYBRID TABLE must have the following arguments: %s" | ||
% ", ".join(missing_attributes) | ||
) | ||
super()._validate_table() | ||
|
||
def __repr__(self) -> str: | ||
return "HybridTable(%s)" % ", ".join( | ||
[repr(self.name)] | ||
+ [repr(self.metadata)] | ||
+ [repr(x) for x in self.columns] | ||
+ [f"{k}={repr(getattr(self, k))}" for k in ["schema"]] | ||
) |
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,4 @@ | ||
# serializer version: 1 | ||
# name: test_orm_one_to_many_relationship_with_hybrid_table | ||
ProgrammingError('(snowflake.connector.errors.ProgrammingError) 200009 (22000): Foreign key constraint "SYS_INDEX_HB_TBL_ADDRESS_FOREIGN_KEY_USER_ID_HB_TBL_USER_ID" was violated.') | ||
# --- |
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,2 @@ | ||
# | ||
# Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved. |
Oops, something went wrong.