-
Notifications
You must be signed in to change notification settings - Fork 27
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
Conversation
d14ec20
to
e0d6642
Compare
WalkthroughThe update enhances the Changes
Poem
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this 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 SuggestionIt'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
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 fieldcolumns
added toCreateViewExpr
.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 fieldplan_columns
added toCreateViewExpr
.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 thecolumns
field, it's important to ensure that this field is properly managed across the system.
77-77
: New fielddefinition
added toCreateViewExpr
.The
string definition = 10;
field stores the SQL definition of the view, which is critical for operations likeSHOW 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 constructorThe constructor of
CreateViewExpr
has been updated to initialize new fieldscolumns
,plan_columns
, anddefinition
. This is a necessary change to ensure that these fields are properly initialized to their default states when an instance ofCreateViewExpr
is created.
478-480
: Field offset definitions addedThe addition of field offsets for
columns
,plan_columns
, anddefinition
in theCreateViewExpr
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 definitionThe protobuf message definition for
CreateViewExpr
has been correctly updated to include new fieldscolumns
,plan_columns
, anddefinition
. 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 constructorThe copy constructor for
CreateViewExpr
now includes the copying ofcolumns
,plan_columns
, anddefinition
. 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 constructorThe
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 constructorThe use of arenas for allocating
columns
,plan_columns
, anddefinition
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 macroThe code ensures that
definition
is initialized to an empty string under thePROTOBUF_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 destructorThe destructor correctly handles the destruction of new fields
columns
,plan_columns
, anddefinition
. This is essential to prevent resource leaks and ensure that resources are properly released when an instance ofCreateViewExpr
is destroyed.
2679-2685
: Clear method updated to handle new fieldsThe
Clear
method now includes logic to clearcolumns
,plan_columns
, anddefinition
. 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 fieldsThe parsing logic has been updated to handle the new repeated fields
columns
andplan_columns
, and the singular fielddefinition
. This ensures that these fields are correctly parsed from the binary format during deserialization. The use ofPROTOBUF_PREDICT_TRUE
and UTF-8 verification are best practices for performance and data integrity.
2891-2920
: Serialization logic for new fieldsThe serialization logic now correctly handles
columns
,plan_columns
, anddefinition
. 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 fieldsThe byte size calculation has been updated to include the sizes of
columns
andplan_columns
. This is necessary for efficient memory allocation and serialization, especially in performance-critical applications.
2988-2993
: Byte size calculation fordefinition
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 fieldsThe
MergeFrom
method has been updated to includecolumns
andplan_columns
. This ensures that these fields are correctly merged when combining two instances ofCreateViewExpr
.
3038-3040
: Conditional field setting in merge logicThe 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 fieldsThe
InternalSwap
method now includes logic to swapcolumns
,plan_columns
, anddefinition
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 CreateViewExprThe addition of constants
kColumnsFieldNumber
,kPlanColumnsFieldNumber
, andkDefinitionFieldNumber
aligns with the new fields added to theCreateViewExpr
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 fieldsThe fields
columns_
,plan_columns_
, anddefinition_
are properly declared within theImpl_
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 ColumnsThe methods added for managing
columns
are consistent with the protobuf standard for repeated fields. These methods enable efficient handling and access to thecolumns
field, which is crucial for the functionality of theCreateViewExpr
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 ColumnsSimilar to the methods for
columns
, these methods manage theplan_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 theCreateViewExpr
class. The implementation follows Java best practices and protobuf standards.[APROVED]
6059-6069
: New Methods for Accessing DefinitionThe 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 ConstructorThe constructor initializes the new fields
columns_
,planColumns_
, anddefinition_
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_
andplanColumns_
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 FieldsThe parsing logic for the new fields
columns_
,planColumns_
, anddefinition
has been added to the_InternalParse
method. This ensures that these fields are correctly populated from the protobuf data during deserialization.
columns_
andplanColumns_
use aLazyStringArrayList
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 ConstructionThis change ensures that the
columns_
andplanColumns_
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
8e75b5e
to
04578d7
Compare
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 forshow create view
.columns
: the view's columns, used for projection.plan_columns
: the original plan columns, used for validation.Checklist
Summary by CodeRabbit
New Features
CreateViewExpr
functionality by adding support forcolumns
,plan_columns
, anddefinition
fields. This allows users to handle additional data when creating views.API Enhancements
columns
,plan_columns
, anddefinition
in theCreateViewExpr
interface, providing more control over view creation attributes.