Skip to content

add url function #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 19, 2024
Merged

add url function #12

merged 4 commits into from
Sep 19, 2024

Conversation

lmangani
Copy link
Collaborator

Basic macro for url function reading all the supported formats.

Parameters

  • url
  • format (JSON, CSV, PARQUET, TEXT, BLOB)

Usage

SELECT * FROM url('https://urleng.com/test', 'JSON')

Credits

Thanks @carlopi for the TABLE MACRO solution!

@lmangani lmangani marked this pull request as ready for review September 19, 2024 21:19
@lmangani lmangani merged commit 8c03d92 into main Sep 19, 2024
11 checks passed
@lmangani lmangani deleted the url-function branch September 19, 2024 21:19
@carlopi
Copy link

carlopi commented Sep 19, 2024

Cool!

I guess you can make it slightly more robust like:

CREATE OR REPLACE MACRO url(url, format) AS TABLE (
    WITH "internal_JSON" as (SELECT * FROM read_json_auto(url))
        , "internal_CSV" as (SELECT * FROM read_csv(url))
      --- ....
         convert_format as (CASE WHEN format ILIKE 'json' THEN 'internal_JSON'
                             WHEN formal ILIKE 'csv' THEN 'internal_CSV'
                             ------ ....
                             ELSE error('Unsupported parameter, try CSV or JSON') END )
    FROM query_table(convert_format)
);
FROM url('some.csv', 'asdfasdfasdf');
Invalid Input Error: Unsupported parameter, try CSV or JSON

(error is another obscure but quite cool feature, that I am not sure if here is working as intended)

@lmangani
Copy link
Collaborator Author

Thanks for sharing this pattern: I had no idea the error feature existed this is really really cool!
Since this is an experimental extension with no critical mass I guess we can take the risk and adopt obscure tricks ;)

@lmangani
Copy link
Collaborator Author

@carlopi I actually can't make this work with the above example no matter how simple I keep it. Could you share a minimalistic working version? Or does this require 1.1.1?

NOTE: this query drives the Motherduck AI autofix feature nuts :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants