|
| 1 | +/* |
| 2 | +--title 'Used tables' |
| 3 | +--width 6 |
| 4 | +--overrides '{"spec":{ |
| 5 | + "encodings":{ |
| 6 | + "columns": [ |
| 7 | + {"fieldName": "fullname", "title": "table", "type": "string", "displayAs": "string", "booleanValues": ["false", "true"]}, |
| 8 | + {"fieldName": "is_read", "title": "is_read", "type": "boolean", "displayAs": "boolean", "booleanValues": ["false", "true"]}, |
| 9 | + {"fieldName": "is_write", "title": "is_write", "type": "boolean", "displayAs": "boolean", "booleanValues": ["false", "true"]}, |
| 10 | + {"fieldName": "source", "title": "source", "type": "string", "displayAs": "link", "linkUrlTemplate": "{{ source_link }}", "linkTextTemplate": "{{ @ }}", "linkTitleTemplate": "{{ @ }}", "linkOpenInNewTab": true, "booleanValues": ["false", "true"]}, |
| 11 | + {"fieldName": "timestamp", "title": "last_modified", "type": "datetime", "displayAs": "datetime", "dateTimeFormat": "ll LTS (z)", "booleanValues": ["false", "true"]}, |
| 12 | + {"fieldName": "lineage", "title": "lineage", "type": "string", "displayAs": "link", "linkUrlTemplate": "{{ lineage_link }}", "linkTextTemplate": "{{ @ }}", "linkTitleTemplate": "{{ @ }}", "linkOpenInNewTab": true, "booleanValues": ["false", "true"]}, |
| 13 | + {"fieldName": "lineage_data", "title": "lineage_data", "type": "complex", "displayAs": "json", "booleanValues": ["false", "true"]}, |
| 14 | + {"fieldName": "assessment_start", "title": "assessment_start", "type": "datetime", "displayAs": "datetime", "dateTimeFormat": "ll LTS (z)", "booleanValues": ["false", "true"]}, |
| 15 | + {"fieldName": "assessment_end", "title": "assessment_end", "type": "datetime", "displayAs": "datetime", "dateTimeFormat": "ll LTS (z)", "booleanValues": ["false", "true"]} |
| 16 | + ]}, |
| 17 | + "invisibleColumns": [ |
| 18 | + {"fieldName": "source_link", "title": "source_link", "type": "string", "displayAs": "string", "booleanValues": ["false", "true"]}, |
| 19 | + {"fieldName": "lineage_type", "title": "lineage_type", "type": "string", "displayAs": "string", "booleanValues": ["false", "true"]}, |
| 20 | + {"fieldName": "lineage_id", "title": "lineage_id", "type": "string", "displayAs": "string", "booleanValues": ["false", "true"]}, |
| 21 | + {"fieldName": "lineage_link", "title": "lineage_link", "type": "string", "displayAs": "string", "booleanValues": ["false", "true"]} |
| 22 | + ] |
| 23 | + }}' |
| 24 | +*/ |
| 25 | +SELECT |
| 26 | + fullname, |
| 27 | + is_read, |
| 28 | + is_write, |
| 29 | + if( startswith(source_id, '/'), substring_index(source_id, '@databricks.com/', -1), split_part(source_id, '/', 2)) as source, |
| 30 | + if( startswith(source_id, '/'), concat('/#workspace/', source_id), concat('/sql/editor/', split_part(source_id, '/', 2))) as source_link, |
| 31 | + source_timestamp as `timestamp`, |
| 32 | + case |
| 33 | + when lineage.object_type = 'WORKFLOW' then concat('Workflow: ', lineage.other.name) |
| 34 | + when lineage.object_type = 'TASK' then concat('Task: ', split_part(lineage.object_id, '/', 2)) |
| 35 | + when lineage.object_type = 'NOTEBOOK' then concat('Notebook: ', substring_index(lineage.object_id, '@databricks.com/', -1)) |
| 36 | + when lineage.object_type = 'FILE' then concat('File: ', substring_index(lineage.object_id, '@databricks.com/', -1)) |
| 37 | + when lineage.object_type = 'DASHBOARD' then concat('Dashboard: ', lineage.other.name) |
| 38 | + when lineage.object_type = 'QUERY' then concat('Query: ', lineage.other.name) |
| 39 | + end as lineage, |
| 40 | + lineage.object_type as lineage_type, |
| 41 | + lineage.object_id as lineage_id, |
| 42 | + case |
| 43 | + when lineage.object_type = 'WORKFLOW' then concat('/jobs/', lineage.object_id) |
| 44 | + when lineage.object_type = 'TASK' then concat('/jobs/', split_part(lineage.object_id, '/', 1), '/tasks/', split_part(lineage.object_id, '/', 2)) |
| 45 | + when lineage.object_type = 'NOTEBOOK' then concat('/#workspace/', lineage.object_id) |
| 46 | + when lineage.object_type = 'FILE' then concat('/#workspace/', lineage.object_id) |
| 47 | + when lineage.object_type = 'DASHBOARD' then concat('/sql/dashboards/', lineage.object_id) |
| 48 | + when lineage.object_type = 'QUERY' then concat('/sql/editor/', split_part(lineage.object_id, '/', 2)) |
| 49 | + end as lineage_link, |
| 50 | + lineage.other as lineage_data, |
| 51 | + assessment_start, |
| 52 | + assessment_end |
| 53 | +from (SELECT |
| 54 | + concat( catalog_name, '.', schema_name, '.', table_name) as fullname, |
| 55 | + is_read, |
| 56 | + is_write, |
| 57 | + source_id, |
| 58 | + source_timestamp, |
| 59 | + explode(source_lineage) as lineage, |
| 60 | + assessment_start_timestamp as assessment_start, |
| 61 | + assessment_end_timestamp as assessment_end |
| 62 | +FROM inventory.used_tables) |
0 commit comments