Skip to content
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

Add regex to star #466

Closed

Conversation

robertdefilippi
Copy link

@robertdefilippi robertdefilippi commented Dec 18, 2021

This is a:

  • bug fix PR with no breaking changes — please ensure the base branch is master
  • new functionality — please ensure the base branch is the latest dev/ branch
  • a breaking change — please ensure the base branch is the latest dev/ branch

Description & motivation

Adding regex functionality to dbt_utils.star

Checklist

  • I have verified that these changes work locally on the following warehouses (Note: it's okay if you do not have access to all warehouses, this helps us understand what has been covered)
    • BigQuery
    • Postgres
    • Redshift
    • Snowflake
  • I followed guidelines to ensure that my changes will work on "non-core" adapters by:
    • dispatching any new macro(s) so non-core adapters can also use them (e.g. the star() source)
    • using the limit_zero() macro in place of the literal string: limit 0
    • using dbt_utils.type_* macros instead of explicit datatypes (e.g. dbt_utils.type_timestamp() instead of TIMESTAMP
  • I have updated the README.md (if applicable)
  • I have added tests & descriptions to my models (and macros if applicable)
  • I have added an entry to CHANGELOG.md

@robertdefilippi
Copy link
Author

robertdefilippi commented Dec 18, 2021

I'm having some issues testing this from the instructions in the ./integration_tests.

When I try to test I get the following error:

# ./dbt-utils/integration_tests

$ make test target=postgres
docker-compose -f ../docker-compose.yml up dbt
[+] Running 2/2
 ⠿ Container dbt-utils_postgres_1  Created                                                                                                                                   0.0s
 ⠿ Container dbt-utils_dbt_1       Recreated                                                                                                                                 0.2s
Attaching to dbt_1
dbt_1  | Running with dbt=1.0.0-b2
dbt_1  | No profile "integration_tests" found, continuing with no target
dbt_1  | Installing ../
dbt_1  |   Installed from <local @ ../>
dbt_1  | Running with dbt=1.0.0-b2
dbt_1  | Encountered an error while reading profiles:
dbt_1  |   ERROR Runtime Error
dbt_1  |   Compilation Error
dbt_1  |     Could not render {{ env_var('POSTGRES_TEST_HOST') }}: Env var required but not provided: 'POSTGRES_TEST_HOST'
dbt_1  | Defined profiles:
dbt_1  |  - integration_tests
dbt_1  |
dbt_1  | For more information on configuring profiles, please consult the dbt docs:
...

Should the profile integration_tests be loaded when I run the docker container?

How can I fix this so I can test my PR.

Thanks!

@joellabes
Copy link
Contributor

@robertdefilippi have a look at the https://github.com/dbt-labs/dbt-utils/blob/main/run_test.sh script which is triggered by Circle.

It looks like the profile is populated by copying from ci/sample.profiles.yml, which doesn't actually exist in this project anymore 😕

I just tried to look at the webhook history for this, but GitHub only retains them for a month.

Could you push something else up to this PR branch? I think that should trigger another webhook and then I can see what happens after that.

I'm broadly on board with bringing this in though, once we get the tests working 👍

@robertdefilippi
Copy link
Author

@joellabes Just pushed a changed. Would love to figure out what the issues is 😄

@joellabes
Copy link
Contributor

OK I've opened an issue with circle ci's support team - the webhook was rejected but I don't know why :(

@robertdefilippi
Copy link
Author

Not a problem @joellabes ! This has been sitting for a month, so a little longer won't be an issue. Thank you for looking into this 😃

@joellabes
Copy link
Contributor

OK I heard back from them! Sounds like if you try again it'll work? 🤞

When checking our logs for the X-GitHub-Delivery id XXXXXX, I saw that we were getting 401 errors for the user robertdefilippi from Github.

This can happen when a user has a CircleCI account, but hasn't logged in to CircleCI in a long time, and we have a stale token cached for them on our end. When this happens, builds may be blocked, and you will see a 400 webhook error on Github.

For PRs created/updated by users who do not have a CircleCI account, this issue should not block your builds.

I have refreshed the cache for the user `robertdefilippi, but could you have them try to push another commit to the branch that has an open PR?

@robertdefilippi
Copy link
Author

robertdefilippi commented Jan 27, 2022

Looks like that worked! Looks like I'll have to keep an eye out on my circle-ci account from now on. Thanks for your help @joellabes

Now I just need to fix these errors 👍

@robertdefilippi
Copy link
Author

@joellabes finally got this all figured out 🙂 Thanks for all your help through this!

@joellabes
Copy link
Contributor

Hurrah! I'll check it out start of next week 🔜

@joellabes
Copy link
Contributor

@robertdefilippi sorry for the slow moving here! My current plan is to ship 0.8.1 tomorrow-ish, and then include your changes in 0.9.0 of utils sometime after that (because the change of method signature will be a breaking change for anyone using positional arguments), which will be a wee way away because it will also be where we pull some stuff out of utils as discussed in #487

Fair warning, 0.8.1 includes a fair bit of movement around the star macro - shouldn't be insurmountable but I think you'll find some merge conflicts sorry. It'd be worth changing the target branch to next/minor once 0.8.1 is out.

@joellabes joellabes removed the pending label Feb 21, 2022
@robertdefilippi
Copy link
Author

@joellabes got it! Thanks for all your help so far, and the heads up with the potential changes coming my way 😄

Once 8.1 is out I'll have a go and fixing the conflicts.

* Update README.md

* add some flexibility to expression_is_true execution plan and add a few new tests

* catch duplicate field name exception when the expression_is_true test is invoked

* expression is true - rename seeds, format sql and get rid of dupe column handler from PR comments

Co-authored-by: Joel Labes <joel.labes@dbtlabs.com>
Comment on lines 1 to 5
{% macro star(from, relation_alias=False, except=[], regex='', prefix='', suffix='') -%}
{{ return(adapter.dispatch('star', 'dbt_utils')(from, relation_alias, except, regex, prefix, suffix)) }}
{% endmacro %}

{% macro default__star(from, relation_alias=False, except=[], prefix='', suffix='') -%}
{% macro default__star(from, relation_alias=False, except=[], regex='', prefix='', suffix='') -%}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to add the optional regex argument to the end of the signature. That way, this new feature will be guaranteed to be non-breaking for all users.

Do you have any thoughts about the order of parameters?

I think the change would be as simple as the following:

{% macro star(from, relation_alias=False, except=[], prefix='', suffix='', regex='') -%}
    {{ return(adapter.dispatch('star', 'dbt_utils')(from, relation_alias, except, prefix, suffix, regex)) }}
{% endmacro %}

{% macro default__star(from, relation_alias=False, except=[], prefix='', suffix='', regex='') -%}

Copy link
Contributor

@dbeatty10 dbeatty10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to add the optional regex argument to the end of the signature. That way, this new feature will be guaranteed to be non-breaking for all users.

Do you have any thoughts about the order of parameters?

See inline comments for suggested updates.

@robertdefilippi
Copy link
Author

@dbeatty10 This fell off my radar for a bit, but you make a good suggestion. I'll have a look when I get some time. Thanks!

@robertdefilippi
Copy link
Author

I'm going to close this PR and reopen with a fresh branch.

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

Successfully merging this pull request may close these issues.

4 participants