Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version: "1.0.0"
config-version: 2

# This setting configures which "profile" dbt uses for this project.
profile: "livequery"
profile: livequery

# These configurations specify where dbt should look for different types of files.
# The `source-paths` config, for example, states that models in this project can be
Expand Down
46 changes: 46 additions & 0 deletions macros/core/_live.yaml.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,50 @@
NOT NULL
RETURNS NULL ON NULL INPUT
sql: udf_api

- name: {{ schema }}.udf_rest_api_args_only
signature:
- [method, STRING]
- [url, STRING]
- [headers, OBJECT]
- [DATA, VARIANT]
- [SECRET_NAME, STRING]
return_type: OBJECT
func_type: SECURE
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
sql: |
{
'method': method,
'url': url,
'headers': headers,
'data': data,
'secret_name': SECRET_NAME
}

{# - name: {{ schema }}.udf_api
description: |
This function is used to select the appropriate function to call based on the user_id
signature:
- [method, STRING]
- [url, STRING]
- [headers, OBJECT]
- [DATA, VARIANT]
- [user_id, STRING]
- [SECRET, STRING]
return_type: VARIANT
func_type: SECURE
options: |
NOT NULL
RETURNS NULL ON NULL INPUT
sql: |
SELECT
CASE
WHEN user_id ilike 'AWS_%'
THEN {{ schema }}.udf_rest_api_args_only(method, url, headers, DATA, SECRET)::VARIANT
ELSE {{ schema }}._udf_api(method, url, headers, DATA, user_id, SECRET)
END #}


{% endmacro %}
18 changes: 18 additions & 0 deletions macros/core/live.yaml.sql
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,24 @@
secret_name
)

- name: {{ schema }}.udf_api
signature:
- [args, OBJECT]
return_type: VARIANT
options: |
NOT NULL
VOLATILE
sql: |
SELECT
_live.UDF_API(
COALESCE(args:method, 'GET'),
args:url,
COALESCE(args:headers, {}),
COALESCE(args:data, {}),
_utils.UDF_WHOAMI(),
COALESCE(args:secret_name, '')
)

- name: {{ schema }}.udf_rpc
signature:
- [blockchain, STRING]
Expand Down
47 changes: 47 additions & 0 deletions models/deploy/core/_live._yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version: 2
models:
- name: _live
columns:
- name: udf_rest_api_args_only
tests:
- test_udf:
name: test___live_udf_rest_api_args_only
args: >
'GET',
'https://api.example.com',
{'Content-Type': 'application/json'},
{'hello': 'world'},
'my_secret'
assertions:
- |
result = {
'method': 'GET',
'url': 'https://api.example.com',
'headers': {'Content-Type': 'application/json'},
'data': {'hello': 'world'},
'secret_name': 'my_secret'
}
- test_udf:
name: test___live_udf_rest_api_args_only_null
args: null, null, null, null, null
assertions:
- result = {}
- test_udf:
name: test___live_udf_api
args: >
'GET',
'https://api.example.com',
{'Content-Type': 'application/json'},
{'hello': 'world'},
'non_streamline_user'
'my_secret'
assertions:
- |
result = {
'method': 'GET',
'url': 'https://httpbin.org/get',
'headers': {'Content-Type': 'application/json'},
'data': {'hello': 'world'},
'user': 'non_streamline_user',
'secret_name': 'my_secret'
}