Open row source

Vineet S 750 Reputation points
2024-09-02T15:47:54.2266667+00:00

nsnapshot.txt

Hi, how to run json file on synapse workspace.. Tried with open row set but not working.. Pls share screenshot if sny

Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
4,844 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 22,691 Reputation points
    2024-09-03T07:22:17.34+00:00

    You'll need to use the built-in serverless SQL pool or a dedicated SQL pool to query JSON files directly from Azure Data Lake Storage or Azure Blob Storage.

    Upload your JSON file to a storage account linked to your Synapse workspace.

    You can query the JSON file directly using the OPENROWSET function in a Synapse SQL query.

    
    SELECT *
    
    FROM OPENROWSET(
    
        BULK 'https://<storageaccount>.blob.core.windows.net/<container>/<path_to_json_file>.json',
    
        FORMAT='SINGLE_CLOB'
    
    ) AS json_file
    
    CROSS APPLY OPENJSON(BulkColumn)
    
    WITH (
    
        id INT '$.id',
    
        customer_id INT '$.customer_id',
    
        DEBUG_ASYNC VARCHAR(100) '$.data.DEBUG_ASYNC',
    
        DEBUG_RATING VARCHAR(100) '$.data.DEBUG_RATING',
    
        currency VARCHAR(10) '$.data.al_avn_52_limit.currency',
    
        limit FLOAT '$.data.al_avn_52_limit.limit',
    
        al_brokerage_hull FLOAT '$.data.al_brokerage_hull',
    
        al_brokerage_liab FLOAT '$.data.al_brokerage_liab',
    
        off_rate FLOAT '$.data.al_cargo.off_rate',
    
        own_rate FLOAT '$.data.al_cargo.own_rate',
    
        value FLOAT '$.data.al_cargo.value',
    
        perc_calculated FLOAT '$.data.al_dep_min_prem_dep.perc.calculated',
    
        perc_selected FLOAT '$.data.al_dep_min_prem_dep.perc.selected',
    
        value_calculated FLOAT '$.data.al_dep_min_prem_dep.value.calculated',
    
        value_selected FLOAT '$.data.al_dep_min_prem_dep.value.selected',
    
        min_prem_est FLOAT '$.data.al_dep_min_prem_est.value',
    
        min_prem_min_calculated FLOAT '$.data.al_dep_min_prem_min.value.calculated',
    
        min_prem_min_selected FLOAT '$.data.al_dep_min_prem_min.value.selected'
    
    // complete the other fields
    
    ) AS json_data;
    
    • OPENROWSET: Reads the file as a single string (SINGLE_CLOB).
    • OPENJSON: Parses the JSON string and allows you to extract individual elements.
    • CROSS APPLY: Applies the OPENJSON function to the rows returned by OPENROWSET.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.