Semi-structured Formats with Snowflake Support
The number of sources that produce semi-structured data has increased exponentially in recent years. The arrival of Snowflake Data Cloud has made it effortless to process complex datasets. Snowflake supports storing and processing semi-structured data. It supports semi-structured formats enlisted below:- • JSON
- • Avro
- • ORC
- • Parquet
- • XML
- • Variant
- • Flatten
Variant
A variant is a datatype which can hold semi-structured data in a single field. Snowflake stores semi-structured data in the column format when semi-structured data is loaded into a VARIANT column. A single row can contain other underlying data. Let’s demonstrate with the help of examples:
The stored data can be easily retrieved and structured from the above table by a simple query as below:
select
v:time::timestamp as observation_time,
v:city.id::int as city_id,
v:city.name::string as city_name,
v:city.country::string as country,
v:city.coord.lat::float as city_lat,
v:city.coord.lon::float as city_lon,
v:clouds.all::int as clouds,
(v:main.temp::float)-273.15 as temp_avg,
(v:main.temp_min::float)-273.15 as temp_min,
(v:main.temp_max::float)-273.15 as temp_max,
v:weather[0].main::string as weather,
v:weather[0].description::string as weather_desc,
v:weather[0].icon::string as weather_icon,
v:wind.deg::float as wind_dir,
v:wind.speed::float as wind_speed
from json_weather_data
Note: ‘v’ is the Field (Column) name, and the JSON tags are arranged alongside to retrieve datasets.
Flatten
Compound values are flattened into multiple rows with the use of the Snowflake Flatten Command. A tool called Snowflake FLATTEN is used to transform semi-structured data into a relational structure. Relatively complex JSON structures such as nested JSON structures can be structured with FLATTEN function in Snowflake. Here is an example of the same:
The above JSON file stores a single set of conversations between two texters in a single row. If the requirement is to get every individual message as a separate row a FLATTEN function can be used to produce the following result:
Here is the query to generate the above table from semi-structured data:
(SELECTb.value:message_date::TIMESTAMP AS Time_Of_Message,
b.value:conversation_number::STRING AS Conversation_num,
b.value:message:message_text:msg_txt::STRING AS Message,
ROW_NUMBER() OVER ( PARTITION BY b.value:dialogId::STRING ORDER BY
b.value:message_date::TIMESTAMP ASC) as Message_order
FROM customer_messages t,LATERAL FLATTEN(input => t.v) b);
Summing Up
The ability of Snowflake’s assistance is undeniable. It aids you to make better decisions and offers a better overall experience when attempting to get the most out of your data, through features like Flatten and Variant. If you want to be a part of Snowflake’s incredible platform, let us help you. Beinex’s partnership with Snowflake enables us to offer you advanced features like automated tuning and elastic computing, along with analytics modernization services, to help your organisation realise exponential Return on Investment.

Ask Data Phrase Builder: This feature is available on Tableau Server and Tableau Online
Add field would look like as shown in the below screenshot:
Customize View Data: This feature is available on Tableau Server, Desktop and Tableau Online
This feature enables to reshape the tabular data behind your visualisation in the View data interface. One can create new columns, remove columns from the default view, change the order and sort the data using this feature. This reshaped data can also be exported as csv file to be shared with the team.
Change the root table: This feature is available on Tableau Server, Desktop and Tableau Online
Managing multiple data tables becomes easier and flexible with this new feature. One can swap any table to be the root table with a single click. This allows one to change the layout of the table quickly, reshape the data with a different root table and delete a specific table without deleting child nodes. For e.g., let us assume a user had to create a data source for an analysis using 3 tables namely ‘customers’, ‘orders’ and ‘returns’. The user creates the data model such that ‘customers’ is the root table followed by ‘orders’ and ‘returns’. But after performing some analysis the user realises that ‘orders’ should be the main root table. In such cases the user would have to re-create the data again from scratch but with the new ‘Swap with root table’ feature user can do the changes with a few clicks.
Parameter Enhancements in Tableau Prep
In version 2022.1 Tableau Prep is adding even more places where one can use parameters in the flow as well as user enhancements. Now, one can:


Source: AWS
