Skip to content

Commit

Permalink
add config hash for caches
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronsteers committed Sep 12, 2024
1 parent 759e530 commit 30038fe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
7 changes: 5 additions & 2 deletions airbyte/caches/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ def __init__(self, **data: Any) -> None: # noqa: ANN401

@property
def config_hash(self) -> str | None:
"""Return a hash of the cache configuration."""
pass
"""Return a hash of the cache configuration.
This is the same as the SQLConfig hash from the superclass.
"""
return super(SqlConfig, self).config_hash

@final
@property
Expand Down
23 changes: 23 additions & 0 deletions airbyte/shared/sql_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
)

from airbyte import exceptions as exc
from airbyte._util.hashing import one_way_hash
from airbyte._util.name_normalizers import LowerCaseNormalizer
from airbyte.constants import (
AB_EXTRACTED_AT_COLUMN,
Expand Down Expand Up @@ -101,6 +102,28 @@ def get_database_name(self) -> str:
"""Return the name of the database."""
...

@property
def config_hash(self) -> str | None:
"""Return a unique one-way hash of the configuration.
The generic implementation uses the SQL Alchemy URL, schema name, and table prefix. Some
inputs may be redundant with the SQL Alchemy URL, but this does not hurt the hash
uniqueness.
In most cases, subclasses do not need to override this method.
"""
return one_way_hash(
SecretString(
":".join(
[
str(self.get_sql_alchemy_url()),
self.schema_name or "",
self.table_prefix or "",
]
)
)
)

def get_sql_engine(self) -> Engine:
"""Return a new SQL engine to use."""
return create_engine(
Expand Down

0 comments on commit 30038fe

Please sign in to comment.