Repository navigation
let BigQueryGetData operator take a list of fields for the "order by" clause #39127
Description
Activity
- addedkind:featureFeature RequestsFeature Requestsneeds-triagelabel for new issues that we didn't triage yetlabel for new issues that we didn't triage yet
on Apr 19, 2024 - addedprovider:googleGoogle (including GCP) related issuesGoogle (including GCP) related issuesand removedneeds-triagelabel for new issues that we didn't triage yetlabel for new issues that we didn't triage yet
on Apr 19, 2024 @eladkal Could you please assign me?
BigQueryGetData'sgenerate_query()method is used for submitting deferred jobs, while normally, the operator utilizes the hook's methodlist_rows. The latter utilizes BigQuery's API directly, which does not support ordering clauses. Having the feature available only for queries the deferred operator makes is discouraged.There are two options left:
- Running the explicit query (including the ORDER BY clause) via
BigQueryInsertJobOperator. - Performing the ordering in Python as part of the operator logic, but I'm not sure there is a real advantage compared to the alternative.
@eladkal What do you think?
- Running the explicit query (including the ORDER BY clause) via
1. Running the explicit query (including the ORDER BY clause) via `BigQueryInsertJobOperator`.I might prefer this one. I think the performance would be better than 2
Reacted by Shahar EpsteinBut, how do you get the result when using
BigQueryInsertJobOperator? As far as I understood it it returns the job_id, not the result 🤔Reacted by Shahar EpsteinBut, how do you get the result when using
BigQueryInsertJobOperator? As far as I understood it, it returns the job_id, not the result 🤔You got me on that one, as indeed - it only returns
job_id.
UsingBigQueryInsertJobOperator, the only option is to write the results into a BigQuery table, so it might make sense to create an alternative for outputting the results into an XCOM instead.
One possible implementation would be by adding a flag to the current operator, but then it will also have to wait until the job is actually completed.
A better option, IMO, would be to create a dedicated operator that will return the results into the XCOM given ajob_id, to keep operations atomic.@Lee-W, What are your thoughts about this one?
A better option, IMO, would be to create a dedicated operator that will return the results into the XCOM given a job_id, to keep operations atomic.
This sounds to be a better solution 👍
A better option, IMO, would be to create a dedicated operator that will return the results into the XCOM given a job_id, to keep operations atomic.
This sounds to be a better solution 👍
Thanks :)
I've been trying out different configurations, and after discussing with @eladkal we came to the conclusion that querying data byjob_idcould be merged with the existingBigQueryGetDataoperator, as logic is very similar (also in the deferrable mode).
I'll create a PR and tag you when I'm done.Fixed in #39315
Description
Sometimes you just need a the latest value of a field (e.g.
updatedAt) so further operators downstream could use said value in their own query.This can be done by
SELECT MAX(updatedAt) [...]but that would required a lot of re-write, when simply adding a new paramordering_fieldscould solve the same issue, allowing to create a query similar to:SELECT updatedAt FROM [...] LIMIT 1 ORDER BY updatedAt DESCExample implementation (not tested):
Use case/motivation
The operator BigQueryGetData should have 1 more params
ordering_fieldsso the generated query would also include theORDER BYclause.Related issues
#24460
Are you willing to submit a PR?
Code of Conduct