An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
Hi Karthikaeya,
I agree with you that the SQL example given under the heading "Querying JSON files" in the learn module is incorrect. The example is using the OPENROWSET() function with the FORMAT = 'csv' option, which is only valid for CSV files.
To query JSON files, you should use the FORMAT = 'json' option. The following is a corrected version of the example:
SQL
SELECT doc
FROM
OPENROWSET(
BULK 'https://mydatalake.blob.core.windows.net/data/files/*.json',
FORMAT = 'json'
) WITH (doc NVARCHAR(MAX)) as rows
This example will correctly load the JSON data from the specified Azure Blob Storage container and return the doc column, which contains the entire JSON document as a single string.
Here is a more detailed explanation of the changes I made:
- I changed the
FORMAToption from'csv'to'json'. This tells theOPENROWSET()function to expect JSON data. - I removed the
FIELDTERMINATORandFIELDQUOTEoptions. These options are only used for CSV data. - I added the
ROWTERMINATORoption with the value'0x0b'. This tells theOPENROWSET()function to use the carriage return (\r) character as a row terminator.
I hope this helps! Let me know if you have any other questions.
Sincerely,
Bruno Gomes.