Skip to content

[DRAFT] feat(firestore): add new pipeline expressions#16151

Draft
daniel-sanche wants to merge 6 commits intomainfrom
firestore_pipelines_misc_expressions
Draft

[DRAFT] feat(firestore): add new pipeline expressions#16151
daniel-sanche wants to merge 6 commits intomainfrom
firestore_pipelines_misc_expressions

Conversation

@daniel-sanche
Copy link
Contributor

Adds the following expressions:

  • cmp
  • timestamp_trunc
  • timestamp_diff
  • timestamp_extract
  • if_null
  • map_set
  • map_keys
  • map_values
  • map_entries
  • type
  • is_type

TODO: Make sure docstrings and arguments align with other languages

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly expands the capabilities of Firestore pipeline expressions by adding a suite of new functions. These additions enhance data manipulation for arrays, timestamps, and maps, and introduce general utility expressions for comparisons and type checking. The changes aim to provide more powerful and flexible ways to process data directly within Firestore queries.

Highlights

  • New Array Manipulation Expressions: Introduced array_maximum, array_minimum, array_first, array_first_n, array_last, array_last_n, array_maximum_n, array_minimum_n, array_index_of, array_index_of_all, and array_slice for advanced array operations within Firestore pipeline expressions.
  • New Timestamp Functions: Added timestamp_trunc, timestamp_extract, and timestamp_diff to enable precise manipulation and comparison of timestamp values in pipeline expressions.
  • New Map Operations: Implemented map_set, map_keys, map_values, and map_entries for enhanced map data handling through pipeline expressions.
  • General Utility Expressions: Introduced cmp for comparison, if_null for handling null values, and type and is_type for runtime type checking within pipeline expressions.
  • Comprehensive Testing: Added both unit and system tests for all newly introduced pipeline expressions to ensure correctness and proper functionality.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a number of new pipeline expressions, along with corresponding unit and end-to-end tests. The changes are well-structured. I have a few suggestions to improve the implementation and tests:

  • Add client-side validation for map_set arguments to provide better error feedback.
  • Add assertions to an end-to-end test for timestamp functions to ensure it properly validates the behavior.
  • Fix formatting issues in some of the test files.

Overall, this is a great addition. Please see my detailed comments.

Comment on lines +104 to +127
- description: testTimestampTruncExtractDiff
pipeline:
- Collection: timestamps
- Limit: 1
- Select:
- AliasedExpression:
- FunctionExpression.timestamp_trunc:
- Field: time
- Constant: "day"
- "trunc_day"
- AliasedExpression:
- FunctionExpression.timestamp_extract:
- Field: time
- Constant: "year"
- "extract_year"
- AliasedExpression:
- FunctionExpression.timestamp_diff:
- FunctionExpression.timestamp_add:
- Field: time
- Constant: "day"
- Constant: 1
- Field: time
- Constant: "hour"
- "diff_hours"
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The test case testTimestampTruncExtractDiff is missing assert_results and/or assert_proto blocks. Without assertions, the test only verifies that the pipeline executes without errors, but it doesn't validate the correctness of the results. Please add assertions to ensure the new expressions work as expected.

Returns:
A new `Map` expression representing the map_set operation.
"""
args = [
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The map_set function accepts a variable number of key-value arguments. If an odd number of arguments is provided in *more_key_values, it will cause a server-side error. It would be better to add a client-side validation to check for an even number of arguments and raise a ValueError if the check fails. This will improve the developer experience by providing immediate and clear feedback.

        if len(more_key_values) % 2 != 0:
            raise ValueError(
                "map_set expects an even number of key-value arguments after the first pair."
            )
        args = [

- integerValue: '1'
- integerValue: '2'
name: array_slice
name: select No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Please add a newline at the end of the file. It's a common convention and helps prevent issues with some tools.

- "val_is_string"
assert_results:
- val_type: "string"
val_is_string: true No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Please add a newline at the end of the file. It's a common convention and helps prevent issues with some tools.

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