MSCEWI1020

CUSTOM UDF INSERTED.

Severity

Low

Summary

There are several User-Defined Functions (UDF) provided by SnowConvert used to reproduce source language behaviors that are not supported by Snowflake, functionality and descriptions are detailed below.

UDFs Location

UDFs can be found in "UDF Helpers" folder created in output path after migration has occurred.

DATE_TO_INT_UDF

When CAST function is used to cast a DATE type to a NUMERIC type. Because of this behavior is not supported in Snowflake, Mobilize.Net provides an UDF Helpers file, which is used to emulate this cast behaviors in the migrated code.

Code Example

Input Code:

Output Code:

TIMESTAMP_DIFFERENCE UDF

1-Differences between Teradata and Snowflake date time subtraction

Teradata and Snowflake handle date time subtraction different, the syntax, returned type and precision are different.

2-Why is UDF used to date time subtraction?

Due to the differences mentioned above, it is necessary to use an UDF. When SnowConvert migrates a create table like the following

The output of the given input is

The UDF will return a VARCHAR equivalent to Teradata's interval.

Warning

Some operations may produce different day outputs with an error range of 1 unit.

Code Sample

Input Code:

Output Code:

JSON_REGEX_QUERY UDF

This UDF is used to extract information of a snowflake variant object, just like in Teradata with JSON Entity Reference (dot notation), but with regular expression instead.

UDF Signature

  • JSON_DATA : Variant data.

  • REGEX_PATH: Regular expression literal to filter the variant data.

  • RETURN: The filtered JSON data.

Code Sample

Input Code:

Output Code:

Differences between Teradata JSON Entity Reference (dot notation ) and Snowflake JSON query method.

Teradata and Snowflake differ in the methods used for traverse JSON data. In this case Teradata use a way based on JavaScript that use dot notation, array indexing, and other especial operators like wildcard access or double dot. On the other hand, snowflake doesn't support these operators, and it only can access members and arrays.

Why is this UDF used to extract JSON data?

Because Snowflake does not handle JSON dot notation, so to this UDF comes to simulate the Teradata JSON notation, that have some complex operators and array indexing for example the recursive descent operator.

EXTRACT_FROM_INTERVAL UDF

This UDF is used to handle scenarios when there is an extract date-time part from an interval.

UDF Signature

  • INTERVAL_DATA: Formatted varchar returned by TIMESTRAMP_DIFERENCE UDF.

  • INPUT_PART: Formatted varchar, is the original requested part (same as TIMESTAMP_DIFERENCE INPUT_PART) and must be one of these:

    • 'DAY TO HOUR'

    • 'DAT TO MINUTE'

    • 'DAY TO SECOND'

    • 'DAY TO MINUTE'

    • 'HOUR TO MINUTE'

    • 'HOUR TO SECOND'

    • 'MINUTE TO SECOND'

  • REQUEST_PART: Value to be extracted, the request part should be contained in the input part interval, must be 'DAY', 'HOUR', 'MINUTE' or 'SECOND'.

  • RETURN: The extracted value of data type number.

Code Sample

Input Code:

Output Code:

Consider the warning described in the EWI warning when extracting day from the interval.

Differences between Teradata and Snowflake date-time extraction

Teradata and Snowflake differ in the parameters that each function respectively might receive and the return type.

  • Parameters: The main difference between Teradata and Snowflake extract function is that Snowflake does not handle intervals, it only supports dates and times. For further information on this, read Snowflake's EXTRACT function documentation and Teradata's EXTRACT function documentation.

  • Return type: Teradata EXTRACT function returns an integer or decimal(8, 2) value representing the part requested and Snowflake returns a number value representing a date-time of the part requested.

Teradata and Snowflake differ in the parameters that each function respectively might receive and the return type.

Why is this UDF used to extract from interval?

Because Snowflake does not handle intervals, it only supports dates and times. So this UDF comes to complement the Snowflake function EXTRACT.

IS_FOUND_UDF

This UDF is used to indicate if the last ran query returned any rows, if the last executed query returned 0 rows returns FALSE, if the last executed query returned 1 or more rows returns TRUE.

UDF Signature

  • RETURN: Boolean value indicating if the last query ran returned any rows.

Input Code:

Output Code:

Recommendations

  • Check if the UDF Helpers folder is being created with files inside it.

  • If you need more support, you can email us at [email protected]

Last updated