Skip to content

Add aggregate function support to BigQuery query_table API#306

Merged
wbssbw merged 3 commits into
obelisk:mainfrom
wbssbw:bigquery/allow-aggregate-functions
May 21, 2026
Merged

Add aggregate function support to BigQuery query_table API#306
wbssbw merged 3 commits into
obelisk:mainfrom
wbssbw:bigquery/allow-aggregate-functions

Conversation

@wbssbw
Copy link
Copy Markdown
Collaborator

@wbssbw wbssbw commented May 21, 2026

Summary

Extends the query_table BigQuery API to support aggregate column functions (COUNT, MAX, MIN).
Previously, columns were plain strings; they are now typed Column structs that carry an optional ColumnFunction.
When a function is specified, the generated SQL wraps the column identifier accordingly (e.g., COUNT(col)).

Changes

Code

  • runtime/plaid-stl/src/gcp/bigquery.rs: Added Column struct with identifier: String and function: Option<ColumnFunction>; added ColumnFunction enum (Count, Max, Min) with Display impl; updated QueryTableRequest.columns from Vec<String> to Vec<Column>; updated query_table signature to accept Vec<Column>.
  • runtime/plaid/src/apis/gcp/bigquery.rs: Updated build_query_string parameter from &[String] to &[Column]; identifier validation and column-list construction now read col.identifier and optionally emit FUNCTION(identifier) syntax.

Rationale

Aggregate functions are a common need when querying tables. Encoding the function in the column type keeps the query-building logic centralized and validated server-side, avoiding raw SQL injection risks from caller-supplied function strings.

Security Considerations

Identifier validation now operates on col.identifier as before, ensuring that only allowlisted or validated identifiers pass through. The ColumnFunction enum is a closed set of known-safe SQL keywords rendered via Display, so no user-supplied function names reach the generated SQL. No authentication or authorization surface changes.

Breaking Changes

query_table and QueryTableRequest now require Vec<Column> instead of Vec<String> / impl Iterator<Item = impl Display>. Callers must be updated to construct Column values; a plain column with no function is Column { identifier: "col".into(), function: None }.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Extends the BigQuery query_table API to allow selecting aggregate column functions (COUNT, MAX, MIN) by introducing a typed Column model (identifier + optional function) and updating SQL generation accordingly.

Changes:

  • Introduced Column and ColumnFunction in plaid-stl, and changed QueryTableRequest.columns to Vec<Column>.
  • Updated the runtime BigQuery API to validate Column.identifier and render FUNCTION(\identifier`)` when a function is present.
  • Updated the runtime result-mapping loop to iterate over Column values instead of raw strings.

Reviewed changes

Copilot reviewed 4 out of 6 changed files in this pull request and generated 4 comments.

File Description
runtime/plaid/src/apis/gcp/bigquery.rs Accepts Column inputs, validates identifiers via Column.identifier, and renders aggregate function syntax in generated SQL.
runtime/plaid-stl/src/gcp/bigquery.rs Adds the Column / ColumnFunction request types and updates the public query_table API surface to use them.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread runtime/plaid-stl/src/gcp/bigquery.rs Outdated
Comment thread runtime/plaid/src/apis/gcp/bigquery.rs Outdated
Comment thread runtime/plaid/src/apis/gcp/bigquery.rs Outdated
Comment thread runtime/plaid/src/apis/gcp/bigquery.rs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 6 changed files in this pull request and generated 1 comment.

Comment thread runtime/plaid/src/apis/gcp/bigquery.rs
@wbssbw wbssbw marked this pull request as ready for review May 21, 2026 14:28
@wbssbw wbssbw requested review from michelemin and obelisk May 21, 2026 14:28
@wbssbw wbssbw merged commit 428ad4d into obelisk:main May 21, 2026
19 checks passed
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.

3 participants