Skip to content

Commit 187d029

Browse files
committed
Add create method to Column
1 parent 3d08481 commit 187d029

File tree

5 files changed

+177
-1
lines changed

5 files changed

+177
-1
lines changed

HISTORY.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.0.22 (Apr 12, 2023)
2+
3+
* Added create metho to Column
4+
* Updated Schema.create method to add schema to Database schemas collection
5+
* Updated Table.create method to add table to Schema tables collection
6+
*
17
## 0.0.21 (Apr 11, 2023)
28

39
* Added relation_attributes parameter to IndexSearchRequest to specify the attributes to be included in each relationship that is included in the results of the search

pyatlan/generator/templates/entity.jinja2

+57
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,63 @@ class {{ entity_def.name }}({{super_classes[0]}} {%- if "Asset" in super_classes
496496
connector_name=connector_type.value,
497497
atlan_schema=Schema.ref_by_qualified_name(schema_qualified_name),
498498
)
499+
{%- elif entity_def.name == "Column" %}
500+
@classmethod
501+
# @validate_arguments()
502+
def create(
503+
cls, *, name: str, parent_qualified_name: str, parent_type: type, order: int
504+
) -> Column.Attributes:
505+
if not name:
506+
raise ValueError("name cannot be blank")
507+
validate_required_fields(["parent_qualified_name"], [parent_qualified_name])
508+
fields = parent_qualified_name.split("/")
509+
if len(fields) != 6:
510+
raise ValueError("Invalid parent_qualified_name")
511+
try:
512+
connector_type = AtlanConnectorType(fields[1]) # type:ignore
513+
except ValueError as e:
514+
raise ValueError("Invalid parent_qualified_name") from e
515+
ret_value = Column.Attributes(
516+
name=name,
517+
qualified_name=f"{parent_qualified_name}/{name}",
518+
connector_name=connector_type.value,
519+
schema_name=fields[4],
520+
schema_qualified_name=f"{fields[0]}/{fields[1]}/{fields[2]}/{fields[3]}/{fields[4]}",
521+
database_name=fields[3],
522+
database_qualified_name=f"{fields[0]}/{fields[1]}/{fields[2]}/{fields[3]}",
523+
connection_qualified_name=f"{fields[0]}/{fields[1]}/{fields[2]}",
524+
order=order,
525+
)
526+
if parent_type == Table:
527+
ret_value.table_qualified_name = parent_qualified_name
528+
ret_value.table = Table.ref_by_qualified_name(parent_qualified_name)
529+
elif parent_type == View:
530+
ret_value.view_qualified_name = parent_qualified_name
531+
ret_value.view = View.ref_by_qualified_name(parent_qualified_name)
532+
elif parent_type == MaterialisedView:
533+
ret_value.view_qualified_name = parent_qualified_name
534+
ret_value.materialised_view = MaterialisedView.ref_by_qualified_name(
535+
parent_qualified_name
536+
)
537+
else:
538+
raise ValueError(
539+
f"parent_type must be either Table, View or MaterializeView"
540+
)
541+
return ret_value
542+
543+
@classmethod
544+
# @validate_arguments()
545+
def create(
546+
cls, *, name: str, parent_qualified_name: str, parent_type: type, order: int
547+
) -> Column:
548+
return Column(
549+
attributes=Column.Attributes.create(
550+
name=name,
551+
parent_qualified_name=parent_qualified_name,
552+
parent_type=parent_type,
553+
order=order,
554+
)
555+
)
499556
{%- elif entity_def.name == "S3Bucket" %}
500557
@classmethod
501558
# @validate_arguments()

pyatlan/model/assets.py

+57
Original file line numberDiff line numberDiff line change
@@ -10022,6 +10022,63 @@ class Attributes(SQL.Attributes):
1002210022
None, description="", alias="columnDbtModelColumns"
1002310023
) # relationship
1002410024

10025+
@classmethod
10026+
# @validate_arguments()
10027+
def create(
10028+
cls, *, name: str, parent_qualified_name: str, parent_type: type, order: int
10029+
) -> Column.Attributes:
10030+
if not name:
10031+
raise ValueError("name cannot be blank")
10032+
validate_required_fields(["parent_qualified_name"], [parent_qualified_name])
10033+
fields = parent_qualified_name.split("/")
10034+
if len(fields) != 6:
10035+
raise ValueError("Invalid parent_qualified_name")
10036+
try:
10037+
connector_type = AtlanConnectorType(fields[1]) # type:ignore
10038+
except ValueError as e:
10039+
raise ValueError("Invalid parent_qualified_name") from e
10040+
ret_value = Column.Attributes(
10041+
name=name,
10042+
qualified_name=f"{parent_qualified_name}/{name}",
10043+
connector_name=connector_type.value,
10044+
schema_name=fields[4],
10045+
schema_qualified_name=f"{fields[0]}/{fields[1]}/{fields[2]}/{fields[3]}/{fields[4]}",
10046+
database_name=fields[3],
10047+
database_qualified_name=f"{fields[0]}/{fields[1]}/{fields[2]}/{fields[3]}",
10048+
connection_qualified_name=f"{fields[0]}/{fields[1]}/{fields[2]}",
10049+
order=order,
10050+
)
10051+
if parent_type == Table:
10052+
ret_value.table_qualified_name = parent_qualified_name
10053+
ret_value.table = Table.ref_by_qualified_name(parent_qualified_name)
10054+
elif parent_type == View:
10055+
ret_value.view_qualified_name = parent_qualified_name
10056+
ret_value.view = View.ref_by_qualified_name(parent_qualified_name)
10057+
elif parent_type == MaterialisedView:
10058+
ret_value.view_qualified_name = parent_qualified_name
10059+
ret_value.materialised_view = MaterialisedView.ref_by_qualified_name(
10060+
parent_qualified_name
10061+
)
10062+
else:
10063+
raise ValueError(
10064+
"parent_type must be either Table, View or MaterializeView"
10065+
)
10066+
return ret_value
10067+
10068+
@classmethod
10069+
# @validate_arguments()
10070+
def create(
10071+
cls, *, name: str, parent_qualified_name: str, parent_type: type, order: int
10072+
) -> Column:
10073+
return Column(
10074+
attributes=Column.Attributes.create(
10075+
name=name,
10076+
parent_qualified_name=parent_qualified_name,
10077+
parent_type=parent_type,
10078+
order=order,
10079+
)
10080+
)
10081+
1002510082
attributes: "Column.Attributes" = Field(
1002610083
None,
1002710084
description="Map of attributes in the instance and their values. The specific keys of this map will vary by "

pyatlan/version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.21
1+
0.0.22

tests/integration/test_entity_model.py

+56
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ def cleanup(atlan_host, headers, atlan_api_key):
187187
"Database",
188188
"Connection",
189189
"View",
190+
"Column",
190191
]
191192
for type_name in type_names:
192193
print()
@@ -670,6 +671,61 @@ def test_create_view(client: AtlanClient, increment_counter):
670671
assert guid == view.guid
671672

672673

674+
def test_create_column(client: AtlanClient, increment_counter):
675+
role = RoleCache.get_id_for_name("$admin")
676+
assert role
677+
suffix = increment_counter()
678+
# connection = Connection.create(
679+
# name=f"Integration {suffix}",
680+
# connector_type=AtlanConnectorType.SNOWFLAKE,
681+
# admin_roles=[role],
682+
# admin_groups=["admin"],
683+
# )
684+
# response = client.upsert(connection)
685+
# assert response.mutated_entities
686+
# assert response.mutated_entities.CREATE
687+
# assert isinstance(response.mutated_entities.CREATE[0], Connection)
688+
# connection = response.mutated_entities.CREATE[0]
689+
# time.sleep(30)
690+
connection = client.get_asset_by_guid(TEMP_CONNECTION_GUID, Connection)
691+
database = Database.create(
692+
name=f"Integration_{suffix}",
693+
connection_qualified_name=connection.attributes.qualified_name,
694+
)
695+
response = client.upsert(database)
696+
assert (databases := response.assets_created(asset_type=Database))
697+
database = client.get_asset_by_guid(databases[0].guid, Database)
698+
schema = Schema.create(
699+
name=f"Integration_{suffix}",
700+
database_qualified_name=database.attributes.qualified_name,
701+
)
702+
response = client.upsert(schema)
703+
assert (schemas := response.assets_created(asset_type=Schema))
704+
schema = client.get_asset_by_guid(schemas[0].guid, Schema)
705+
table = Table.create(
706+
name=f"Integration_{suffix}",
707+
schema_qualified_name=schema.attributes.qualified_name,
708+
)
709+
response = client.upsert(table)
710+
assert (tables := response.assets_created(asset_type=Table))
711+
table = client.get_asset_by_guid(guid=tables[0].guid, asset_type=Table)
712+
column = Column.create(
713+
name=f"Integration_{suffix}_column",
714+
parent_qualified_name=table.qualified_name,
715+
parent_type=Table,
716+
order=1,
717+
)
718+
response = client.upsert(column)
719+
assert (columns := response.assets_created(asset_type=Column))
720+
assert len(columns) == 1
721+
column = client.get_asset_by_guid(asset_type=Column, guid=columns[0].guid)
722+
table = client.get_asset_by_guid(asset_type=Table, guid=table.guid)
723+
assert table.attributes.columns
724+
columns = table.attributes.columns
725+
assert len(columns) == 1
726+
assert columns[0].guid == column.guid
727+
728+
673729
def test_add_and_remove_classifications(client: AtlanClient):
674730
glossary = AtlasGlossary.create(name="Integration Classification Test")
675731
glossary.attributes.user_description = "This is a description of the glossary"

0 commit comments

Comments
 (0)