Fix: Add tags_json to msih_view and make tag columns null-safe#1443
Fix: Add tags_json to msih_view and make tag columns null-safe#1443ihartzaws wants to merge 1 commit intoaws-solutions-library-samples:mainfrom
Conversation
The Media Services Insights dashboard deployment fails with CONTEXTUAL_UNKNOWN_SYMBOL error on tag_cost_center because the Athena view doesn't include tags_json, which the QuickSight dataset definition depends on.
Changes:
1. msih_view SQL — Added tags_json column derived from CUR2 resource_tags MAP, using json_format for Athena VARCHAR compatibility:
sql
IF(cardinality(MAP_FILTER(resource_tags, (k, v) -> v IS NOT NULL AND v <> '')) > 0,
json_format(CAST(MAP_FILTER(resource_tags, (k, v) -> v IS NOT NULL AND v <> '') AS JSON)),
NULL) "tags_json"
2. QuickSight dataset definition — Made tag_cost_center and tag_business_unit calculated columns null-safe to handle customers with no tags:
ifelse(isNull({tags_json}) OR {tags_json} = '{}', NULL, parseJson({tags_json}, '$.tag_cost_center'))
Root cause:
The Athena view (msih_view) did not include tags_json in its SELECT, but the QuickSight dataset unconditionally referenced it via parseJson, causing CreateDataSet to fail for any customer where the view lacked tag data.
Notes:
- Empty tag maps return NULL instead of '{}' to avoid Athena cast errors on empty JSON objects
- Athena views don't support JSON column types, so json_format() is used to output VARCHAR
- The null-safe ifelse in QuickSight handles both NULL and empty '{}' cases
Testing:
Verified against a customer deployment where the original error occurred. Dashboard deploys and SPICE syncs successfully after the fix.
|
Update: The Media Services Insights dashboard deployment fails with CONTEXTUAL_UNKNOWN_SYMBOL error on tag_cost_center because the Athena view doesn't include tags_json, which the QuickSight dataset definition depends on. Additionally, the Changes:
To: Expression: ifelse(isNull({tags_json}) OR {tags_json} = '{}', NULL, parseJson({tags_json}, '$.tag_cost_center')) Notes:
Testing: Verified against a customer deployment where the original errors occurred. Dashboard deploys and SPICE syncs successfully after the fix. |
The Media Services Insights dashboard deployment fails with CONTEXTUAL_UNKNOWN_SYMBOL error on tag_cost_center because the Athena view doesn't include tags_json, which the QuickSight dataset definition depends on.
Changes:
msih_view SQL — Added tags_json column derived from CUR2 resource_tags MAP, using json_format for Athena VARCHAR compatibility: sql IF(cardinality(MAP_FILTER(resource_tags, (k, v) -> v IS NOT NULL AND v <> '')) > 0, json_format(CAST(MAP_FILTER(resource_tags, (k, v) -> v IS NOT NULL AND v <> '') AS JSON)), NULL) "tags_json"
QuickSight dataset definition — Made tag_cost_center and tag_business_unit calculated columns null-safe to handle customers with no tags:
ifelse(isNull({tags_json}) OR {tags_json} = '{}', NULL, parseJson({tags_json}, '$.tag_cost_center'))
Root cause:
The Athena view (msih_view) did not include tags_json in its SELECT, but the QuickSight dataset unconditionally referenced it via parseJson, causing CreateDataSet to fail for any customer where the view lacked tag data.
Notes:
Testing:
Verified against a customer deployment where the original error occurred. Dashboard deploys and SPICE syncs successfully after the fix.
Issue #, if available:
Description of changes:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.