Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IBCDPE-832] Add script to get data size for Synapse entity #32

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions analytics/folder_stats.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
This script contains two parts: 1. lay out folder structure of the targeted FOLDER_IDs;
danlu1 marked this conversation as resolved.
Show resolved Hide resolved
2. calculate total data size in GiB for each FOLDER_ID.
FOLDER_IDs can be a single Synapse folder ID or a list of Synapse folder IDs seperated by comma
*/

USE ROLE DATA_ANALYTICS;
USE DATABASE synapse_data_warehouse;
USE WAREHOUSE COMPUTE_XSMALL;

-- The list of folders to be checked
SET
FOLDER_IDs = '';
danlu1 marked this conversation as resolved.
Show resolved Hide resolved

-- Lay Out Data Structure
WITH RECURSIVE nodesnapshots
-- Column list of the "view"
(
ID,
PARENT_ID,
NAME,
NODE_TYPE,
FILE_HANDLE_ID,
FOLDER_ID
)
AS
-- Common Table Expression
(
-- Anchor Clause
SELECT
ID,
PARENT_ID,
NAME,
NODE_TYPE,
FILE_HANDLE_ID,
ID AS FOLDER_ID
FROM
synapse_data_warehouse.synapse.node_latest
WHERE
ID IN (
SELECT
REPLACE(VALUE, 'syn', '')
FROM
TABLE(SPLIT_TO_TABLE($FOLDER_IDs, ','))
)

UNION ALL

-- Recursive Clause
SELECT
node.ID,
node.PARENT_ID,
node.NAME,
node.NODE_TYPE,
node.FILE_HANDLE_ID,
nodesnapshots.FOLDER_ID
FROM
synapse_data_warehouse.synapse.node_latest AS node
JOIN
nodesnapshots
ON
node.PARENT_ID = nodesnapshots.ID
)
-- This is the "main select".
SELECT
'syn' || nodesnapshots.FOLDER_ID AS FOLDER_ID,
'syn' || nodesnapshots.PARENT_ID AS PARENT_ID,
'syn' || nodesnapshots.ID AS ID,
COUNT(nodesnapshots.ID) AS COUNTS,
nodesnapshots.NAME,
nodesnapshots.NODE_TYPE,
nodesnapshots.FILE_HANDLE_ID,
filesnapshots.CONTENT_SIZE
FROM
nodesnapshots
JOIN
synapse_data_warehouse.synapse.file_latest AS filesnapshots
ON nodesnapshots.file_handle_id = filesnapshots.ID
GROUP BY nodesnapshots.FOLDER_ID;

-- Calculate Data Size
WITH RECURSIVE nodesnapshots
-- Column list of the "view"
(
ID,
PARENT_ID,
NAME,
NODE_TYPE,
FILE_HANDLE_ID,
FOLDER_ID
)
AS
-- Common Table Expression
(
-- Anchor Clause
SELECT
ID,
PARENT_ID,
NAME,
NODE_TYPE,
FILE_HANDLE_ID,
ID AS FOLDER_ID
FROM
synapse_data_warehouse.synapse.node_latest
WHERE
ID IN (
SELECT
REPLACE(VALUE, 'syn', '')
FROM
TABLE(SPLIT_TO_TABLE($FOLDER_IDs, ','))
)

UNION ALL

-- Recursive Clause
SELECT
node.ID,
node.PARENT_ID,
node.NAME,
node.NODE_TYPE,
node.FILE_HANDLE_ID,
nodesnapshots.FOLDER_ID
FROM
synapse_data_warehouse.synapse.node_latest AS node
JOIN
nodesnapshots
ON
node.PARENT_ID = nodesnapshots.ID
)
-- This is the "main select".
SELECT
'syn' || nodesnapshots.FOLDER_ID AS FOLDER_ID,
sum(filesnapshots.CONTENT_SIZE)/ power(2, 30) AS CONTENT_SIZE_in_GiB
FROM
nodesnapshots
JOIN
synapse_data_warehouse.synapse.file_latest AS filesnapshots
ON
nodesnapshots.file_handle_id = filesnapshots.ID
GROUP BY
nodesnapshots.FOLDER_ID;