-
Notifications
You must be signed in to change notification settings - Fork 953
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add itertools module #1368 * Manifest v6 #1667 * Add set + zip #1635 * File selector method #1627 * Selector inheritance #1628 * Global config for target-path, log-path #1687 * Update website/docs/reference/dbt-jinja-functions/zip.md Co-authored-by: Anders <[email protected]> * Update website/docs/reference/dbt-jinja-functions/set.md Co-authored-by: Anders <[email protected]> * PR feedback Co-authored-by: Anders <[email protected]>
- Loading branch information
Showing
11 changed files
with
257 additions
and
16 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
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
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
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
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,50 @@ | ||
--- | ||
title: "set" | ||
id: "set" | ||
--- | ||
|
||
### set | ||
|
||
_Not to be confused with the `{% set foo = "bar" ... %}` expression in Jinja!_ | ||
|
||
The `set` context method can be used to convert any iterable to a sequence of iterable elements that are unique (a set). | ||
|
||
__Args__: | ||
- `value`: The iterable to convert (e.g. a list) | ||
- `default`: A default value to return if the `value` argument is not a valid iterable | ||
|
||
### Usage | ||
|
||
``` | ||
{% set my_list = [1, 2, 2, 3] %} | ||
{% set my_set = set(my_list) %} | ||
{% do log(my_set) %} {# {1, 2, 3} #} | ||
``` | ||
|
||
``` | ||
{% set my_invalid_iterable = 1234 %} | ||
{% set my_set = set(my_invalid_iterable) %} | ||
{% do log(my_set) %} {# None #} | ||
``` | ||
|
||
### try_set | ||
|
||
The `try_set` context method can be used to convert any iterable to a sequence of iterable elements that are unique (a set). The difference to the `set` context method is that the `try_set` method will raise an exception on a `TypeError`, if the provided value is not a valid iterable and cannot be converted to a set. | ||
|
||
__Args__: | ||
- `value`: The iterable to convert (e.g. a list) | ||
|
||
``` | ||
{% set my_list = [1, 2, 2, 3] %} | ||
{% set my_set = set(my_list) %} | ||
{% do log(my_set) %} {# {1, 2, 3} #} | ||
``` | ||
|
||
``` | ||
{% set my_invalid_iterable = 1234 %} | ||
{% set my_set = try_set(my_invalid_iterable) %} | ||
{% do log(my_set) %} | ||
Compilation Error in ... (...) | ||
'int' object is not iterable | ||
``` |
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,53 @@ | ||
--- | ||
title: "zip" | ||
id: "zip" | ||
--- | ||
|
||
### zip | ||
|
||
The `zip` context method can be used to used to return an iterator of tuples, where the i-th tuple contains the i-th element from each of the argument iterables. ([Python docs](https://docs.python.org/3/library/functions.html#zip)) | ||
:param | ||
:param | ||
|
||
__Args__: | ||
- `*args`: Any number of iterables | ||
- `default`: A default value to return if `*args` is not iterable | ||
|
||
### Usage | ||
|
||
``` | ||
{% set my_list_a = [1, 2] %} | ||
{% set my_list_b = ['alice', 'bob'] %} | ||
{% set my_zip = zip(my_list_a, my_list_b) | list %} | ||
{% do log(my_zip) %} {# [(1, 'alice'), (2, 'bob')] #} | ||
``` | ||
|
||
``` | ||
{% set my_list_a = 12 %} | ||
{% set my_list_b = ['alice', 'bob'] %} | ||
{% set my_zip = zip(my_list_a, my_list_b, default = []) | list %} | ||
{% do log(my_zip) %} {# [] #} | ||
``` | ||
|
||
### try_zip | ||
|
||
The `try_zip` context method can be used to used to return an iterator of tuples, just like `zip`. The difference to the `zip` context method is that the `try_zip` method will raise an exception on a `TypeError`, if one of the provided values is not a valid iterable. | ||
|
||
__Args__: | ||
- `value`: The iterable to convert (e.g. a list) | ||
|
||
``` | ||
{% set my_list_a = [1, 2] %} | ||
{% set my_list_b = ['alice', 'bob'] %} | ||
{% set my_zip = try_zip(my_list_a, my_list_b) | list %} | ||
{% do log(my_zip) %} {# [(1, 'alice'), (2, 'bob')] #} | ||
``` | ||
|
||
``` | ||
{% set my_list_a = 12 %} | ||
{% set my_list_b = ['alice', 'bob'] %} | ||
{% set my_zip = try_zip(my_list_a, my_list_b) %} | ||
Compilation Error in ... (...) | ||
'int' object is not iterable | ||
``` |
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
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
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
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
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