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

feat: adds view definition to CreateViewExpr #176

Merged
merged 4 commits into from
Jul 9, 2024

Conversation

killme2008
Copy link
Contributor

@killme2008 killme2008 commented May 31, 2024

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

For GreptimeTeam/greptimedb#4086

What's changed and what's your intention?

Adds the following fields to CreateViewExpr:

  • definition: the SQL to create the view, used for show create view.
  • columns: the view's columns, used for projection.
  • plan_columns: the original plan columns, used for validation.

Checklist

  • I have written the necessary comments.
  • I have added the necessary unit tests and integration tests.

Summary by CodeRabbit

  • New Features

    • Enhanced the CreateViewExpr functionality by adding support for columns, plan_columns, and definition fields. This allows users to handle additional data when creating views.
  • API Enhancements

    • Introduced new methods for managing columns, plan_columns, and definition in the CreateViewExpr interface, providing more control over view creation attributes.

@killme2008 killme2008 marked this pull request as draft May 31, 2024 22:05
@killme2008 killme2008 force-pushed the feature/create-str branch from d14ec20 to e0d6642 Compare June 18, 2024 16:06
Copy link

coderabbitai bot commented Jun 22, 2024

Walkthrough

The update enhances the CreateViewExpr class across several files by adding new fields: columns, plan_columns, and definition. These modifications improve the functionality and structure of CreateViewExpr, ensuring these fields are included in initialization, serialization, parsing, and merging processes in both the C++ and Java implementations.

Changes

Files Change Summary
c++/.../ddl.pb.cc, c++/.../ddl.pb.h Added fields columns, plan_columns, and definition to CreateViewExpr with necessary methods.
java/.../io/greptime/v1/Ddl.java Included methods for handling columns, plan_columns, and definition in CreateViewExpr interface.
proto/.../ddl.proto Updated CreateViewExpr message to include columns, plan_columns, and definition fields.

Poem

In fields of code where bytes do flow,
New columns, plans, definitions grow.
Views now flourish, structured bright,
Enhancing functions day and night.
With each commit, progression seen,
In Greptime's garden, code turned green.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@killme2008 killme2008 marked this pull request as ready for review June 22, 2024 05:38
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range and nitpick comments (1)
c++/greptime/v1/ddl.pb.cc (1)

677-677: Maintainability Improvement Suggestion

It's good practice to add a comment here explaining what these numbers represent and how they are used. This can improve code readability and maintainability, especially for developers unfamiliar with this part of the codebase.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a70a6af and 8e75b5e.

Files ignored due to path filters (1)
  • go/greptime/v1/ddl.pb.go is excluded by !**/*.pb.go
Files selected for processing (4)
  • c++/greptime/v1/ddl.pb.cc (18 hunks)
  • c++/greptime/v1/ddl.pb.h (5 hunks)
  • java/src/main/java/io/greptime/v1/Ddl.java (15 hunks)
  • proto/greptime/v1/ddl.proto (1 hunks)
Additional comments not posted (27)
proto/greptime/v1/ddl.proto (3)

75-75: New field columns added to CreateViewExpr.

The addition of repeated string columns = 8; allows for specifying the columns of the view. This is a crucial enhancement for defining the structure of views, especially when views are created dynamically based on user input or application logic. Ensure that the handling of this field is implemented consistently across all related components (serialization, deserialization, etc.).


76-76: New field plan_columns added to CreateViewExpr.

The repeated string plan_columns = 9; field is intended for storing the original plan columns, which is essential for validation processes. This field should be used to verify that the columns used in the view's definition match the intended layout or schema expectations. Similar to the columns field, it's important to ensure that this field is properly managed across the system.


77-77: New field definition added to CreateViewExpr.

The string definition = 10; field stores the SQL definition of the view, which is critical for operations like SHOW CREATE VIEW. This addition enhances the transparency and manageability of view definitions within the database. Care should be taken to ensure that this field is correctly handled in terms of security, especially to avoid SQL injection vulnerabilities if user input is involved.

c++/greptime/v1/ddl.pb.cc (16)

91-97: Initialization of new fields in constructor

The constructor of CreateViewExpr has been updated to initialize new fields columns, plan_columns, and definition. This is a necessary change to ensure that these fields are properly initialized to their default states when an instance of CreateViewExpr is created.


478-480: Field offset definitions added

The addition of field offsets for columns, plan_columns, and definition in the CreateViewExpr class is crucial for memory layout and serialization/deserialization processes. This ensures that the protobuf library can correctly handle the memory offsets of these fields.


754-823: Update to protobuf message definition

The protobuf message definition for CreateViewExpr has been correctly updated to include new fields columns, plan_columns, and definition. This is essential for the correct serialization and deserialization of these fields. Ensure that the field numbers are unique and do not overlap with existing fields to maintain backward compatibility.


2550-2556: Proper copying of fields in copy constructor

The copy constructor for CreateViewExpr now includes the copying of columns, plan_columns, and definition. This is necessary to ensure that all relevant data is correctly copied when a new instance is created from an existing one.


2594-2601: Initialization and conditional copying in copy constructor

The definition field is being conditionally copied based on its presence in the source object. This is a robust approach to handle optional fields. However, ensure that similar checks and initializations are applied consistently across all optional fields for uniformity.


2614-2620: Arena allocation in constructor

The use of arenas for allocating columns, plan_columns, and definition is a performance optimization in protobufs to manage memory more efficiently. This is a good practice, especially in environments with a high rate of message creation and destruction.


2641-2644: Forced default initialization under specific macro

The code ensures that definition is initialized to an empty string under the PROTOBUF_FORCE_COPY_DEFAULT_STRING macro. This is crucial for environments where string fields must be explicitly initialized to maintain certain invariants or behaviors.


2659-2665: Destruction of fields in destructor

The destructor correctly handles the destruction of new fields columns, plan_columns, and definition. This is essential to prevent resource leaks and ensure that resources are properly released when an instance of CreateViewExpr is destroyed.


2679-2685: Clear method updated to handle new fields

The Clear method now includes logic to clear columns, plan_columns, and definition. This is necessary to reset the object's state back to its initial configuration and is particularly useful in object pooling scenarios.


2766-2805: Parsing logic for new fields

The parsing logic has been updated to handle the new repeated fields columns and plan_columns, and the singular field definition. This ensures that these fields are correctly parsed from the binary format during deserialization. The use of PROTOBUF_PREDICT_TRUE and UTF-8 verification are best practices for performance and data integrity.


2891-2920: Serialization logic for new fields

The serialization logic now correctly handles columns, plan_columns, and definition. This includes UTF-8 validation and proper string serialization. This is crucial for ensuring that the data is correctly encoded into the binary format.


2944-2959: Byte size calculation for new fields

The byte size calculation has been updated to include the sizes of columns and plan_columns. This is necessary for efficient memory allocation and serialization, especially in performance-critical applications.


2988-2993: Byte size calculation for definition

The byte size calculation for the definition field is correctly implemented. This ensures that the total size of the message is accurately computed, which is critical for performance optimizations in serialization processes.


3024-3025: Merge logic for new fields

The MergeFrom method has been updated to include columns and plan_columns. This ensures that these fields are correctly merged when combining two instances of CreateViewExpr.


3038-3040: Conditional field setting in merge logic

The merge logic conditionally sets the definition field if it is present in the source object. This is a robust approach to handle optional fields during the merging process.


Line range hint 3067-3088: Swapping logic for new fields

The InternalSwap method now includes logic to swap columns, plan_columns, and definition between two instances. This is essential for efficient object management and resource reallocation in environments that use object pooling.

c++/greptime/v1/ddl.pb.h (2)

1197-1203: Addition of field number constants for new fields in CreateViewExpr

The addition of constants kColumnsFieldNumber, kPlanColumnsFieldNumber, and kDefinitionFieldNumber aligns with the new fields added to the CreateViewExpr class. These constants are crucial for protobuf's internal mapping and should be correctly set to ensure proper serialization and deserialization of these fields.


1370-1376: Proper initialization of new repeated and string fields

The fields columns_, plan_columns_, and definition_ are properly declared within the Impl_ structure. This setup is essential for the correct functioning of these fields within the protobuf framework, ensuring that they are handled correctly in memory.

java/src/main/java/io/greptime/v1/Ddl.java (6)

6009-6032: New Methods for Managing Columns

The methods added for managing columns are consistent with the protobuf standard for repeated fields. These methods enable efficient handling and access to the columns field, which is crucial for the functionality of the CreateViewExpr class.

  • getColumnsList() provides a list of columns.
  • getColumnsCount() returns the number of columns.
  • getColumns(int index) retrieves a column by index.
  • getColumnsBytes(int index) retrieves the binary representation of a column.

These additions are necessary for the new functionality introduced in the CreateViewExpr class and follow proper Java conventions for method naming and protobuf interaction.


6034-6057: New Methods for Managing Plan Columns

Similar to the methods for columns, these methods manage the plan_columns field:

  • getPlanColumnsList() provides a list of plan columns.
  • getPlanColumnsCount() returns the count of plan columns.
  • getPlanColumns(int index) retrieves a plan column by index.
  • getPlanURLBytes(int index) retrieves the binary representation of a plan column.

These methods are well-defined and necessary for managing the plan_columns attribute in the CreateViewExpr class. The implementation follows Java best practices and protobuf standards.

[APROVED]


6059-6069: New Methods for Accessing Definition

The newly introduced methods for accessing the definition field are:

  • getDefinition() returns the SQL definition of the view.
  • getDefinitionBytes() provides the binary representation of the definition.

These methods are crucial for accessing the view definition in a consistent and efficient manner. The implementation adheres to established Java and protobuf practices.


6093-6095: Initialization of New Fields in Constructor

The constructor initializes the new fields columns_, planColumns_, and definition_ with default values. This is a necessary update to ensure that these fields are properly set up when an instance of the class is created.

  • columns_ and planColumns_ are initialized as empty lazy string lists.
  • definition_ is initialized as an empty string.

This initialization is crucial for the correct operation of the CreateViewExpr class, ensuring that these fields are never null and are ready for use immediately after instantiation.


6171-6193: Parsing Logic for New Fields

The parsing logic for the new fields columns_, planColumns_, and definition has been added to the _InternalParse method. This ensures that these fields are correctly populated from the protobuf data during deserialization.

  • columns_ and planColumns_ use a LazyStringArrayList for efficient storage and access.
  • definition_ directly stores the string value.

This update is essential for the correct deserialization of the CreateViewExpr instances and adheres to protobuf's recommended practices for handling repeated and singular fields.


6215-6220: Making Fields Unmodifiable After Construction

This change ensures that the columns_ and planColumns_ fields are made unmodifiable after the object's construction is complete. This is an important change for immutability, which is a desirable property in many Java objects to prevent accidental alteration of internal state.

  • The getUnmodifiableView() method is used, which is a standard approach in Java to provide read-only access to collections.

This enhancement increases the robustness of the class by ensuring that the internal state cannot be changed once the object is fully constructed.

c++/greptime/v1/ddl.pb.h Show resolved Hide resolved
c++/greptime/v1/ddl.pb.h Show resolved Hide resolved
Copy link
Contributor

@fengjiachun fengjiachun left a comment

Choose a reason for hiding this comment

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

LGTM

@killme2008 killme2008 force-pushed the feature/create-str branch from 8e75b5e to 04578d7 Compare July 9, 2024 17:52
@killme2008 killme2008 merged commit 5c80165 into GreptimeTeam:main Jul 9, 2024
6 checks passed
@killme2008 killme2008 deleted the feature/create-str branch July 9, 2024 17:57
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