Skip to content

Commit

Permalink
better messages for update
Browse files Browse the repository at this point in the history
  • Loading branch information
Iakov Gan authored and darken99 committed May 9, 2022
1 parent 54e86d6 commit 1eec42b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cid/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ def create_or_update_dataset(self, dataset_definition: dict, arn: str=None,recur
# Read dataset definition from template
dataset_file = dataset_definition.get('File')
if not dataset_file:
logger.critical(f"Error: {dataset_definition.get('Name')} definition is broken")
logger.critical("Error: definition is broken. Check resources file.")
exit(1)

if not len(self.qs.athena_datasources):
Expand All @@ -878,13 +878,16 @@ def create_or_update_dataset(self, dataset_definition: dict, arn: str=None,recur
resource_name=f'data/datasets/{dataset_file}',
).decode('utf-8'))

pre_compiled_dataset = json.loads(template.safe_substitute())
dataset_name = pre_compiled_dataset.get('Name')

# let's find the schema/database name
schemas = []
if arn:
dataset_id = arn.split('/')[-1]
schemas = list(set(self.qs.get_datasets(id=dataset_id)[0].schemas))
else: # try to find dataset and get athena database
found_datasets = self.qs.get_datasets(name=dataset_definition.get('Name'))
found_datasets = self.qs.get_datasets(name=dataset_name)
if found_datasets:
schemas = list(set(sum([d.schemas for d in found_datasets], [])))

Expand Down Expand Up @@ -929,8 +932,8 @@ def create_or_update_dataset(self, dataset_definition: dict, arn: str=None,recur
if isinstance(found_dataset, Dataset):
if update:
self.qs.update_dataset(compiled_dataset)
elif found_dataset.name != dataset_definition.get('Name'):
print(f'Dataset found with name {found_dataset.name}, but {dataset_definition.get('Name')} expected. Updating.')
elif found_dataset.name != dataset_name:
print(f"Dataset found with name {found_dataset.name}, but {dataset_name} expected. Updating.")
self.qs.update_dataset(compiled_dataset)
else:
print(f'No update requested for dataset {compiled_dataset.get("DataSetId")}')
Expand Down

0 comments on commit 1eec42b

Please sign in to comment.