0 0
Read Time:1 Minute, 52 Second

In this use case, a financial services company has decided to migrate its data warehouse from Oracle to Snowflake. The migration involves not only migrating the data from Oracle to Snowflake but also replicating all views in Snowflake. After successfully migrating several views, the data engineering team noticed discrepancy between the Oracle view definitions and their Snowflake counterparts. These discrepancies potentially lead to errors or unexpected results when querying views in Snowflake.

Challenge

Challenge

While the majority of views worked seamlessly post-migration, certain views presented data type mismatches and column aliasing issues.

The team needed a way to:

  1. Extract the view definitions from Snowflake.
  2. Identify the underlying tables, columns, and their data types.
  3. Compare the column data types in the Snowflake view against the Oracle view to detect discrepancies.

Solution: Snowflake Stored Procedure for View Table and Column Extraction

Solution: Snowflake Stored Procedure for View Table and Column Extraction

To address the discrepancies and help with troubleshooting, the team developed a Snowflake stored procedure that reads the view definition and extracts the table names, columns, and data types used in the view. This procedure allowed the team to:

  1. Identify the underlying tables used in the view.
  2. Extract the column definitions (with alias removal) and compare them with the original Oracle view definitions.
  3. Detect any data type mismatches between Snowflake and Oracle views.

Practical Scenario:

Practical Scenario:

  1. The team ran the GET_VIEW_TABLE_COLUMNS stored procedure to extract the view definition in Snowflake.
  2. The procedure extracted the underlying tables and columns used in the view. It also retrieved the data types of these columns by querying Snowflake’s INFORMATION_SCHEMA.
  3. After reviewing the procedure’s output, they identified that some discrepancy in column datatypes of both systems.
  4. The team used this information to correct the data type definitions in the Snowflake view and ensure that it aligned with the original Oracle definition.

View Datatypes

Execute the Procedure:

Proc output

Key Benefits:

Key Benefits:

  • Automated View Analysis: The stored procedure automated the process of analyzing view definitions and underlying tables, saving manual effort.
  • Error Detection: The procedure helped detect issues such as incorrect data types or missing columns.

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

Your email address will not be published. Required fields are marked *