Skip to content

Commit

Permalink
Merge pull request #473 from atlanhq/FT-896
Browse files Browse the repository at this point in the history
FT-896: Implemented `creators()` and `updaters()` for `TablePartition`
  • Loading branch information
Aryamanz29 authored Jan 14, 2025
2 parents 67bd4ee + 9c957aa commit e772fa2
Show file tree
Hide file tree
Showing 9 changed files with 649 additions and 10 deletions.
69 changes: 67 additions & 2 deletions pyatlan/generator/templates/methods/asset/column.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@
parent_qualified_name: str,
parent_type: type,
order: int,
) -> Column: ...
) -> Column:
"""
Builds the minimal object necessary to create a Column.

:param name: name of the Column
:param parent_qualified_name: unique name of the table / view / materialized view
/ table partition / snowflake dynamic table in which this Column exists
:param parent_type: type of parent (table, view, materialized view,
table partition, snowflake dynamic table), should be a TYPE_NAME static string
:param order: the order the Column appears within its parent (the Column's position)
:returns: the minimal request necessary to create the Column
"""

@overload
@classmethod
Expand All @@ -27,7 +38,27 @@
table_name: str,
table_qualified_name: str,
connection_qualified_name: str,
) -> Column: ...
) -> Column:
"""
Builds the minimal object necessary to create a Column.

:param name: name of the Column
:param parent_qualified_name: unique name of the table / view / materialized view
/ table partition / snowflake dynamic table in which this Column exist
:param parent_type: type of parent (table, view, materialized view,
table partition, snowflake dynamic table), should be a TYPE_NAME static string
:param order: the order the Column appears within its parent (the Column's position)
:param parent_name: simple name of the table / view / materialized view / table partition
/ snowflake dynamic table in which the Column should be created
:param database_name: simple name of the database in which the Column should be created
:param database_qualified_name: unique name of the database in which the Column should be created
:param schema_name: simple name of the schema in which the Column should be created
:param schema_qualified_name: unique name of the schema in which the Column should be created
:param table_name: (deprecated - unused)
:param table_qualified_name: (deprecated - unused)
:param connection_qualified_name: unique name of the connection in which the Column should be created
:returns: the minimal request necessary to create the Column
"""

@classmethod
@init_guid
Expand All @@ -47,6 +78,40 @@
table_qualified_name: Optional[str] = None,
connection_qualified_name: Optional[str] = None,
) -> Column:
"""
Builds the minimal object necessary to create a Column.

:param name: name of the Column
:param parent_qualified_name: unique name of the table / view / materialized view
/ table partition / snowflake dynamic table in which this Column exists
:param parent_type: type of parent (table, view, materialized view,
table partition, snowflake dynamic table), should be a TYPE_NAME static string
:param order: the order the Column appears within its parent (the Column's position)
:param parent_name: simple name of the table / view / materialized view / table partition
/ snowflake dynamic table in which the Column should be created
:param database_name: simple name of the database in which the Column should be created
:param database_qualified_name: unique name of the database in which the Column should be created
:param schema_name: simple name of the schema in which the Column should be created
:param schema_qualified_name: unique name of the schema in which the Column should be created
:param table_name: (deprecated - unused)
:param table_qualified_name: (deprecated - unused)
:param connection_qualified_name: unique name of the connection in which the Column should be created
:returns: the minimal request necessary to create the Column
"""
if table_name:
warn(
("`table_name` is deprecated, please use `parent_name` instead"),
DeprecationWarning,
stacklevel=2,
)
if table_qualified_name:
warn(
(
"`table_qualified_name` is deprecated, please use `parent_qualified_name` instead"
),
DeprecationWarning,
stacklevel=2,
)
return Column(
attributes=Column.Attributes.create(
name=name,
Expand Down
83 changes: 83 additions & 0 deletions pyatlan/generator/templates/methods/asset/table_partition.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

@overload
@classmethod
def creator(
cls,
*,
name: str,
table_qualified_name: str,
) -> TablePartition:
"""
Builds the minimal object necessary to create a table partition.

:param name: name of the table partition
:param table_qualified_name: unique name of the table in which this table partition exists
:returns: the minimal request necessary to create the table partition
"""

@overload
@classmethod
def creator(
cls,
*,
name: str,
connection_qualified_name: str,
database_name: str,
database_qualified_name: str,
schema_name: str,
schema_qualified_name: str,
table_name: str,
table_qualified_name: str,
) -> TablePartition:
"""
Builds the minimal object necessary to create a table partition.

:param name: name of the TablePartition
:param connection_qualified_name: unique name of the connection in which to create the TablePartition
:param database_name: simple name of the Database in which to create the TablePartition
:param database_qualified_name: unique name of the Database in which to create the TablePartition
:param schema_name: simple name of the Schema in which to create the TablePartition
:param schema_qualified_name: unique name of the Schema in which to create the TablePartition
:param table_name: simple name of the Table in which to create the TablePartition
:param table_qualified_name: unique name of the table in which this table partition exists
:returns: the minimal request necessary to create the table partition
"""

@classmethod
@init_guid
def creator(
cls,
*,
name: str,
connection_qualified_name: Optional[str] = None,
database_name: Optional[str] = None,
database_qualified_name: Optional[str] = None,
schema_name: Optional[str] = None,
schema_qualified_name: Optional[str] = None,
table_name: Optional[str] = None,
table_qualified_name: str,
) -> TablePartition:
"""
Builds the minimal object necessary to create a table partition.

:param name: name of the TablePartition
:param connection_qualified_name: unique name of the connection in which to create the TablePartition
:param database_name: simple name of the Database in which to create the TablePartition
:param database_qualified_name: unique name of the Database in which to create the TablePartition
:param schema_name: simple name of the Schema in which to create the TablePartition
:param schema_qualified_name: unique name of the Schema in which to create the TablePartition
:param table_name: simple name of the Table in which to create the TablePartition
:param table_qualified_name: unique name of the table in which this table partition exists
:returns: the minimal request necessary to create the table partition
"""
attributes = TablePartition.Attributes.creator(
name=name,
connection_qualified_name=connection_qualified_name,
database_name=database_name,
database_qualified_name=database_qualified_name,
schema_name=schema_name,
schema_qualified_name=schema_qualified_name,
table_name=table_name,
table_qualified_name=table_qualified_name,
)
return cls(attributes=attributes)
24 changes: 22 additions & 2 deletions pyatlan/generator/templates/methods/attribute/column.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,26 @@
table_qualified_name: Optional[str] = None,
connection_qualified_name: Optional[str] = None,
) -> Column.Attributes:
"""
Builds the minimal object necessary to create a Column.

:param name: name of the Column
:param parent_qualified_name: unique name of the table / view / materialized view
/ table partition / snowflake dynamic table in which this Column exist
:param parent_type: type of parent (table, view, materialized view,
table partition, snowflake dynamic table), should be a TYPE_NAME static string
:param order: the order the Column appears within its parent (the Column's position)
:param parent_name: simple name of the table / view / materialized view
/ table partition / snowflake dynamic table in which the Column is created
:param database_name: simple name of the database in which the Column should be created
:param database_qualified_name: unique name of the database in which the Column should be created
:param schema_name: simple name of the schema in which the Column should be created
:param schema_qualified_name: unique name of the schema in which the Column should be created
:param table_name: (deprecated - unused)
:param table_qualified_name: (deprecated - unused)
:param connection_qualified_name: unique name of the connection in which the Column should be created
:returns: the minimal request necessary to create the Column
"""
validate_required_fields(
["name", "parent_qualified_name", "parent_type", "order"],
[name, parent_qualified_name, parent_type, order],
Expand Down Expand Up @@ -73,11 +93,11 @@
)
column.view_name = parent_name
elif parent_type == TablePartition:
column.table_qualified_name = table_qualified_name
column.table_qualified_name = parent_qualified_name
column.table_partition = TablePartition.ref_by_qualified_name(
parent_qualified_name
)
column.table_name = table_name
column.table_name = parent_name
elif parent_type == SnowflakeDynamicTable:
column.table_qualified_name = parent_qualified_name
column.snowflake_dynamic_table = (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

@classmethod
@init_guid
def creator(
cls,
*,
name: str,
connection_qualified_name: Optional[str] = None,
database_name: Optional[str] = None,
database_qualified_name: Optional[str] = None,
schema_name: Optional[str] = None,
schema_qualified_name: Optional[str] = None,
table_name: Optional[str] = None,
table_qualified_name: str,
) -> TablePartition.Attributes:
"""
Builds the minimal object necessary to create a table partition.

:param name: name of the TablePartition
:param connection_qualified_name: unique name of the connection in which to create the TablePartition
:param database_name: simple name of the Database in which to create the TablePartition
:param database_qualified_name: unique name of the Database in which to create the TablePartition
:param schema_name: simple name of the Schema in which to create the TablePartition
:param schema_qualified_name: unique name of the Schema in which to create the TablePartition
:param table_name: simple name of the Table in which to create the TablePartition
:param table_qualified_name: unique name of the table in which this table partition exists
:returns: the minimal request necessary to create the table partition
"""
validate_required_fields(
["name", "table_qualified_name"],
[name, table_qualified_name],
)
assert table_qualified_name # noqa: S101
if connection_qualified_name:
connector_name = AtlanConnectorType.get_connector_name(
connection_qualified_name
)
else:
connection_qn, connector_name = AtlanConnectorType.get_connector_name(
table_qualified_name, "table_qualified_name", 6
)

fields = table_qualified_name.split("/")

connection_qualified_name = connection_qualified_name or connection_qn
database_name = database_name or fields[3]
schema_name = schema_name or fields[4]
table_name = table_name or fields[5]
database_qualified_name = (
database_qualified_name
or f"{connection_qualified_name}/{database_name}"
)
schema_qualified_name = (
schema_qualified_name or f"{database_qualified_name}/{schema_name}"
)

qualified_name = f"{schema_qualified_name}/{name}"

return TablePartition.Attributes(
name=name,
qualified_name=qualified_name,
database_name=database_name,
database_qualified_name=database_qualified_name,
schema_name=schema_name,
schema_qualified_name=schema_qualified_name,
connector_name=connector_name,
connection_qualified_name=connection_qualified_name,
table_name=table_name,
table_qualified_name=table_qualified_name,
)
Loading

0 comments on commit e772fa2

Please sign in to comment.