Skip to content

Commit

Permalink
feat: Common query models (#1155)
Browse files Browse the repository at this point in the history
* Added join and where models for how tables are joined / filtered with sql

Signed-off-by: Grant Seward <[email protected]>

* removed addl space

Signed-off-by: Grant Seward <[email protected]>

* version bump

Signed-off-by: Grant Seward <[email protected]>
  • Loading branch information
sewardgw authored May 25, 2021
1 parent f4bb1de commit 9bc05f2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 17 deletions.
60 changes: 44 additions & 16 deletions common/amundsen_common/models/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,48 @@ class Meta:
register_as_scheme = True


@attr.s(auto_attribs=True, kw_only=True)
class TableSummary:
database: str = attr.ib()
cluster: str = attr.ib()
schema: str = attr.ib()
name: str = attr.ib()
description: Optional[str] = attr.ib(default=None)
schema_description: Optional[str] = attr.ib(default=None)


class TableSummarySchema(AttrsSchema):
class Meta:
target = TableSummary
register_as_scheme = True


@attr.s(auto_attribs=True, kw_only=True)
class SqlJoin:
column: str
joined_on_table: TableSummary
joined_on_column: str
join_type: str
join_sql: str


class SqlJoinSchema(AttrsSchema):
class Meta:
target = SqlJoin
register_as_scheme = True


@attr.s(auto_attribs=True, kw_only=True)
class SqlWnere:
where_clause: str


class SqlWhereSchema(AttrsSchema):
class Meta:
target = SqlWnere
register_as_scheme = True


@attr.s(auto_attribs=True, kw_only=True)
class Table:
database: str
Expand All @@ -145,25 +187,11 @@ class Table:
source: Optional[Source] = None
is_view: Optional[bool] = attr.ib(default=None, converter=default_if_none)
programmatic_descriptions: List[ProgrammaticDescription] = []
common_joins: Optional[List[SqlJoin]] = None
common_filters: Optional[List[SqlWnere]] = None


class TableSchema(AttrsSchema):
class Meta:
target = Table
register_as_scheme = True


@attr.s(auto_attribs=True, kw_only=True)
class TableSummary:
database: str = attr.ib()
cluster: str = attr.ib()
schema: str = attr.ib()
name: str = attr.ib()
description: Optional[str] = attr.ib(default=None)
schema_description: Optional[str] = attr.ib(default=None)


class TableSummarySchema(AttrsSchema):
class Meta:
target = TableSummary
register_as_scheme = True
2 changes: 1 addition & 1 deletion common/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from setuptools import find_packages, setup

__version__ = '0.11.0'
__version__ = '0.12.0'

setup(
name='amundsen-common',
Expand Down

0 comments on commit 9bc05f2

Please sign in to comment.