This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreDid you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now
The preview for JSON aggregate functions in Fabric Datawarehouse has begun. You can now take advantage of two powerful JSON aggregate functions during this preview period.
The preview for these two aggregate functions is already live in Azure SQL Database, and we are excited to announce that it is now also available in Fabric Data Warehouse.
JSON_ARRAYAGG is an aggregate function that formats a set of cells within a group into a JSON array. For example, if we select country, state, and county from the geography table, we can observe different values of county within each (country, state) group.
JSON_aggregates_in_Fabric_Datawarehouse_Preview
If we group rows by country and state, we can concatenate all county cells within each group and output them as a single JSON array per group.
JSON_aggregates_in_Fabric_Datawarehouse_Preview
The JSON_ARRAYAGG function is especially useful when you need to represent a set of values as an array, especially when you need to join parent/child rows and return a list of child values for each parent row.
JSON_OBJECTAGG is an aggregate function that takes two columns within a group of rows and formats their cells as key-value pairs in a single JSON object for each group.
For example, imagine we have a T-SQL query that returns average temperatures in Fahrenheit for cities defined by zip codes during the period from October 14, 2010, to October 21, 2020.
JSON_aggregates_in_Fabric_Datawarehouse_Preview
We can observe that within each group of rows, only DateID and AvgTemperatureFahrenheit differ.
By grouping the rows within the same city/county partition, we can obtain the (DateID, AvgTemperatureFahrenheit) pairs and format them as a JSON object. The JSON_OBJECTAGG function allows you to pivot multiple rows and represent pairs of columns as key-value pairs in the aggregated JSON object.
JSON_aggregates_in_Fabric_Datawarehouse_Preview
The JSON_OBJECTAGG function is incredibly useful when you need to pivot values from multiple rows within a group into the properties of a single JSON object associated with that group.
JSON_ARRAYAGG and JSON_OBJECTAGG are significant enhancements in T-SQL language that simplify the complex formatting of JSON objects in queries. Tasks that previously required inline FOR JSON expressions or a combination of STRING_AGG and STRING_ESCAPE functions can now be accomplished more easily.
These two aggregate functions are currently in preview in both Azure SQL Database and Fabric Data Warehouse, and they will become generally available simultaneously.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.