-
Notifications
You must be signed in to change notification settings - Fork 32
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
BREAKING CHANGE: Relative queries #416
BREAKING CHANGE: Relative queries #416
Conversation
π¦ Changeset detectedLatest commit: 8a6b394 The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
439d804
to
23e5c64
Compare
async function buildConnector(queryPath: string) { | ||
const source = await sourceManager.loadFromQuery(queryPath) | ||
|
||
if (!source['_connector']) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's this check about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
connector
is lazy loaded when a source compiles a query. Until that moment connector is not initialized
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done to avoid injecting source
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't get it sorry could you add a comment with explanations as to why we need this defense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to have expectations on the underlying connector. But the connector is not accessible from the outside. On top of that _connector
is null
until you load the good query because it's lazily evaluated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm ok, the comment is good enough for now ππΌ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GPT4o
did for me. Is so nice
query, | ||
queryParams, | ||
force, | ||
}: { | ||
source: Source |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
much better ππΌ
-- queries/users/orders/query.sql | ||
SELECT * FROM {ref('../query.sql')} -- This will reference queries/users/query.sql | ||
``` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
review the rest of this documentation because i think there are some things wrong now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also we should explain the difference between /query_path query_path and ./query_path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -96,6 +81,9 @@ export default async function createConnectorFactory({ | |||
connectorOptions: ConnectorOptions<ConnectorAttributes> | |||
}): Promise<BaseConnector> { | |||
const packageName = getConnectorPackage(type) | |||
const ConnectorClass = await importConnector(packageName) | |||
const ConnectorClass = !packageName | |||
? TestConnector // If no package is found, use the test connector |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a bit worried about all the code changes caused by the tests. Not blocking but I'd love if we could find ways to test code without having to adapt it to tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The factory is super magic. It expects an npm package to exist with that name and to be installed in the source_manager
. This is super annoying for testing. The way it is done now is that the test connector is a local file in this package.
request: CompileQueryRequest | ||
// Parameters used in the query | ||
accessedParams: QueryParams | ||
// Parameters resolved by the connector, in order of appearance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still get confused by the resolved name. What does it mean to resolve a parameter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it means computing their value. cc @csansoon
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work! This is super delicate though βΒ We need to manually test query references in multiple scenarios:
/query
source.yml
query1.sql
/folder1/query2.sql -- references query1
/folder1/source2.yml
/folder1/query3.sql -- uses source2.yml
/folder1/folder2/query4.sql -- references query3
Running query1, query2, query3 and query4 should work βπΌ
f7a3f23
to
2d36079
Compare
We want to move the responsability of fining the query in the file system from the connector to the source. After the last refactor now this is easier to todo because we have access to the source and the source manager in the connector. With this change is easier to pass the the full path of the query and look for relative paths and paths that lives outside the source of the connector. We want to do both things in the upcoming changes
2d36079
to
8a6b394
Compare
Describe your changes
Until now we were requiring users to specify the queries in the ref function from the root of the source folder. Example:
Given that folder structure in
query.sql
Before π«
Now β
Or β
Or β
Issue ticket number and link
#369
Dependency
https://github.com/latitude-dev/latitude/pull/414/files
TODO
runQuery
π. I introduced the bug hereref
method the SQL