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

Some BigQuery tweaks [ci skip] #23367

Closed
wants to merge 1 commit into from
Closed

Some BigQuery tweaks [ci skip] #23367

wants to merge 1 commit into from

Conversation

camsaul
Copy link
Member

@camsaul camsaul commented Jun 15, 2022

This is just so I can show @metamben what I'm talking about. It's just a demo it can be closed later.

Discussion is in #23292

(reconcile-temporal-types
((get-method sql.qp/->honeysql [:sql filter-type])
driver
(reconcile-temporal-types clause)))))
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting, reconciling twice.

Copy link
Member Author

Choose a reason for hiding this comment

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

Doesn't really hurt anything

Copy link
Contributor

Choose a reason for hiding this comment

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

In which cases is it useful? (I'm asking because I suppose you have cases in mind I haven't though about.)

Copy link
Member Author

Choose a reason for hiding this comment

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

It wouldn't work if we didn't reconcile after compilation. Not sure if the initial reconciliation before compilation is still needed or not. I didn't check. You can try taking it out and seeing if it works or not

Copy link
Contributor

Choose a reason for hiding this comment

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

Intuitively, I would think it's an abuse of reconciliation if we have to do it twice. I might be wrong though.

(if (or (not add-fn)
(and (not (contains? (temporal-type->supported-units t) unit))
(contains? (temporal-type->supported-units :datetime) unit)))
(recur (->temporal-type :datetime hsql-form))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you give an example when recur happens more than once in this loop?

Copy link
Member Author

@camsaul camsaul Jun 15, 2022

Choose a reason for hiding this comment

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

No... it shouldn't happen more than once

Copy link
Member Author

Choose a reason for hiding this comment

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

If you're pointing out that we don't need to use loop here since it's not a loop at all then I'm not disagreeing with you. Feel free to change it. I just took the existing code and tweaked it a bit and didn't do cleanup like that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Are 1. and 2. the first and the second iteration? Wouldn't we set :datetime after 1. and see it in 2.?
What input for the function do you have in mind?

(defn x []
(mt/with-driver :bigquery-cloud-sdk
(mt/dataset office-checkins
(mt/with-temp-vals-in-db 'Field (mt/id :checkins :timestamp) {:database_type "TIMESTAMP"}
Copy link
Member Author

Choose a reason for hiding this comment

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

For some annoying reason office-checkins.checkins.timestamp is actually a DATETIME for BigQuery so I have to fake making it a TIMESTAMP here.

(AddIntervalForm. hsql-form amount unit)))
(add-interval-form hsql-form amount unit)))

(defn x []
Copy link
Member Author

@camsaul camsaul Jun 15, 2022

Choose a reason for hiding this comment

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

test function for seeing the HoneySQL form we generate in the failing case

[:relative-datetime -2 :year]
[:relative-datetime -1 :year]]))))))

(defn y []
Copy link
Member Author

@camsaul camsaul Jun 15, 2022

Choose a reason for hiding this comment

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

test function to see the compiled SQL

[:field (mt/id :checkins :timestamp) nil]
[:interval 7 :day]]
[:relative-datetime -2 :year]
[:relative-datetime -1 :year]]))))))
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there some good trick to trace the transformation steps? (I guess even that wouldn't tell me at what point things go wrong, but it might give some overview.)

Copy link
Member Author

Choose a reason for hiding this comment

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

(metabase.test/set-ns-log-level! :trace) will set the log level for the current namespace to TRACE and then any log/trace statements in there will get printed out. That's what I usually do. You can do that in metabase.driver.bigquery-cloud-sdk.query-processor and maybe metabase.driver.sql.query-processor as well. Add more log/trace statements if you want to see more stuff

@camsaul camsaul closed this Jul 14, 2022
@camsaul camsaul deleted the SomeBigQueryTweaks branch October 4, 2023 19:25
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.

None yet

2 participants