Skip to content

#1535: extend --dependencies to find tables selected in SQL queries - #2692

Open
valentinatihova wants to merge 3 commits into
Accenture:developfrom
valentinatihova:feature/1535-query-sql-dependencies
Open

valentinatihova wants to merge 3 commits into
Accenture:developfrom
valentinatihova:feature/1535-query-sql-dependencies

Conversation

@valentinatihova

Copy link
Copy Markdown

PR details

What changes did you make? (Give an overview)

--dependencies now also adds the dataExtensions a query reads from (FROM, JOIN, APPLY), not only its target. Works for build, buildTemplate, buildDefinition and createDeltaPkg.

  • Query.getDependentFiles() override. MetadataType.js is unchanged.
  • New lib/util/sqlTables.js: small SQL tokenizer, no dependencies. Skips comments, strings, subqueries, CTEs, functions and data views (_...). Supports [names], ENT., aliases and non-ASCII names.
  • Table names are resolved to keys with DataExtension.retrieveForCache(), once per BU and run.
  • Local DEs are added to the package. Shared DEs get the existing _ParentBU_ warning.
  • Tables that are not found, or cannot be read, are a warning:
    ☇ query myQuery (myQuery): Table Orders_Archive used in the SQL was not found as dataExtension on myCred/myBU
    

Further details (optional)

  • New API calls: 1 on a parent BU, 3 on a child BU. Only if the SQL uses a table that is not a data view.
  • Questions:
    • Should unresolved tables set process.exitCode = 1, or stay a warning?
    • On a child BU, should a shared DE used without ENT. be a warning?
  • Next PR: your idea from the issue. Warning in postRetrieveTasks, block the deploy of the query in preDeployTasks if a table does not exist.

Tests:

  • test/sqlTables.test.js: 39 tests, including 15 realistic queries.
  • test/type.query.test.js: buildTemplate --dependencies with local, shared, missing and unreadable tables, with exact API call counts.
  • npm run lint-and-test and npm run lint-ts pass.

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • test scripts updated
  • Wiki updated (if applicable)

…ncies

Query.getDependentFiles now reads the SQL of each found query, extracts the tables after FROM, JOIN and APPLY with a small dependency-free tokenizer (lib/util/sqlTables.js), resolves their names to keys via DataExtension.retrieveForCache() once per BU and run, and passes the keys to DataExtension.getDependentFiles. Shared dataExtensions keep the existing _ParentBU_ warning. Tables that cannot be resolved or read are reported as warnings.
@valentinatihova

Copy link
Copy Markdown
Author

Hi, a gentle ping on this one. Could a maintainer approve the CI workflows so the checks can run? I’m happy to address any review feedback or rebase on the latest develop if needed. Thanks!

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.

1 participant