-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement safe_cast + add tests for array, map, named_struct for unit…
… testing
- Loading branch information
1 parent
24bc6c1
commit 4e3b10c
Showing
2 changed files
with
17 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% macro spark__safe_cast(field, type) %} | ||
{%- if cast_from_string_unsupported_for(type) and field is string -%} | ||
cast({{field.strip('"').strip("'")}} as {{type}}) | ||
{%- else -%} | ||
safe_cast({{field}} as {{type}}) | ||
{%- endif -%} | ||
{% endmacro %} | ||
|
||
{% macro cast_from_string_unsupported_for(type) %} | ||
{{ return(type.lower().startswith('struct') or type.lower().startswith('array') or type.lower().startswith('map')) }} | ||
{% endmacro %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters