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(fulltext_index): allow enable full-text index in SQL and gRPC way #4310

Merged
merged 12 commits into from
Jul 8, 2024

Conversation

zhongzc
Copy link
Contributor

@zhongzc zhongzc commented Jul 7, 2024

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

#4246

depends on GreptimeTeam/greptime-proto#179

What's changed and what's your intention?

  • SQL Parser supports FULLTEXT syntax
  • Pass full-text options to gRPC requests
  • Set full-text options for pipeline

Checklist

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR requires documentation updates.

Summary by CodeRabbit

  • New Features

    • Introduced the handling of fulltext options in column schemas with the addition of new methods and structs to manage these options.
    • Enhanced the CreateTable and CreateExternalTable structures with a new Column struct to encapsulate column properties.
  • Bug Fixes

    • Standardized error handling for column data types and fulltext index validation.
  • Documentation

    • Updated error variants and function signatures to reflect new fulltext options and column properties.
  • Refactor

    • Renamed keys and added new methods to handle fulltext options in ColumnSchema.
    • Refactored column-related structures and function signatures to improve readability and maintainability.

Signed-off-by: Zhenchi <zhongzc_arch@outlook.com>
@github-actions github-actions bot added the docs-not-required This change does not impact docs. label Jul 7, 2024
Copy link
Contributor

coderabbitai bot commented Jul 7, 2024

Walkthrough

Incorporated full-text search options and json serialization updates across various modules:

  • Enhanced error handling with new error variants.
  • Utilized HashMap and serde_json for managing options.
  • Updated dependencies within Cargo.toml.
  • Introduced a new Column struct and refactored related logic for column operations.
  • Ensured consistent default values for new options fields across multiple files.

Changes

File(s) Change Summary
Cargo.toml Updated greptime-proto dependency, prost.workspace = true and added serde_json as workspace dependency.
src/api/src/error.rs Added SerializeJson error, adjusted error mapping, and imported ColumnDataType.
src/api/src/helper.rs, src/common/grpc-expr/src/insert.rs, src/metric-engine/src/... Added a new options field with default values to various structs.
src/api/src/lib.rs Added #![feature(let_chains)] attribute.
src/api/src/v1/column_def.rs Updated try_as_column_schema for FULLTEXT_GRPC_KEY and added methods for column options and fulltext settings.
src/common/grpc-expr/src/error.rs Introduced UnknownColumnDataType and InvalidFulltextColumnType errors.
src/common/meta/src/ddl/test_util/columns.rs Added options field to ColumnDef struct.
src/datatypes/src/schema/column_schema.rs Renamed FULLTEXT_KEY to FULLTEXT_GRPC_KEY, and added methods for handling fulltext options in ColumnSchema.
src/flow/src/adapter/util.rs Modified column_schemas_to_proto function.
src/metric-engine/src/put.rs Added options: Default::default() to columns in MetricEngineInner implementation.
src/mito2/src/request.rs Added options field to WriteRequest struct initialization.
src/mito2/src/test_util.rs, src/operator/src/insert.rs, src/pipeline/tests/... Added options: None to ColumnSchema struct initializations in various test files.
src/operator/src/expr_factory.rs Removed ColumnDef references, renamed Column to SqlColumn, and adjusted function logic.
src/operator/src/req_convert/common.rs Introduced handling for options in columns_to_rows and column_schema functions.
src/operator/src/req_convert/insert/stmt_to_region.rs Added options field to grpc_column_schema.
src/pipeline/src/etl/transform/transformer/greptime/coerce.rs Introduced HashMap for options and serialization of fulltext options using serde_json.
src/pipeline/src/manager/table.rs Added options: None to ColumnDef instances in PipelineTable implementation.
src/sql/src/error.rs Added FulltextInvalidOption and SetFulltextOption error variants.
src/sql/src/statements.rs, src/sql/src/statements/create.rs Refactored column logic, introduced Column struct, managed nullable columns, and updated tests.

Sequence Diagram(s)

With these changes being more about data structure and error handling alterations, and not significantly altering the control flow, sequence diagrams are not applicable here.

Poem

Across the code, the changes fly,
Options bloom where once they were shy.
Fulltext fields now doth abound,
Errors clear, more profound.
From humble lines, new features spring,
In Rabbit's realm, improvements sing. 🌟🐰


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.

Signed-off-by: Zhenchi <zhongzc_arch@outlook.com>
Signed-off-by: Zhenchi <zhongzc_arch@outlook.com>
Copy link
Contributor

@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: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 58f991b and 67688ba.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (42)
  • Cargo.toml (1 hunks)
  • src/api/src/helper.rs (1 hunks)
  • src/api/src/v1/column_def.rs (1 hunks)
  • src/common/grpc-expr/Cargo.toml (1 hunks)
  • src/common/grpc-expr/src/error.rs (3 hunks)
  • src/common/grpc-expr/src/insert.rs (1 hunks)
  • src/common/grpc-expr/src/util.rs (7 hunks)
  • src/common/meta/src/ddl/create_table_template.rs (1 hunks)
  • src/common/meta/src/ddl/test_util/columns.rs (1 hunks)
  • src/datatypes/src/schema.rs (1 hunks)
  • src/datatypes/src/schema/column_schema.rs (4 hunks)
  • src/flow/src/adapter/util.rs (1 hunks)
  • src/metric-engine/src/engine/put.rs (1 hunks)
  • src/metric-engine/src/test_util.rs (2 hunks)
  • src/mito2/src/request.rs (1 hunks)
  • src/mito2/src/sst/index.rs (2 hunks)
  • src/mito2/src/test_util.rs (1 hunks)
  • src/operator/src/expr_factory.rs (8 hunks)
  • src/operator/src/insert.rs (1 hunks)
  • src/operator/src/req_convert/common.rs (2 hunks)
  • src/operator/src/req_convert/insert/stmt_to_region.rs (1 hunks)
  • src/pipeline/src/etl/transform/transformer/greptime/coerce.rs (3 hunks)
  • src/pipeline/src/manager/table.rs (5 hunks)
  • src/pipeline/tests/gsub.rs (1 hunks)
  • src/pipeline/tests/join.rs (1 hunks)
  • src/pipeline/tests/on_failure.rs (4 hunks)
  • src/query/Cargo.toml (1 hunks)
  • src/query/src/error.rs (2 hunks)
  • src/query/src/sql/show_create_table.rs (9 hunks)
  • src/script/src/table.rs (1 hunks)
  • src/servers/src/prom_row_builder.rs (2 hunks)
  • src/sql/Cargo.toml (1 hunks)
  • src/sql/src/error.rs (2 hunks)
  • src/sql/src/lib.rs (1 hunks)
  • src/sql/src/parser.rs (1 hunks)
  • src/sql/src/parsers/create_parser.rs (23 hunks)
  • src/sql/src/statements.rs (12 hunks)
  • src/sql/src/statements/create.rs (3 hunks)
  • src/sql/src/statements/transform/type_alias.rs (2 hunks)
  • src/store-api/src/metadata.rs (1 hunks)
  • tests/cases/standalone/common/create/create_with_fulltext.result (1 hunks)
  • tests/cases/standalone/common/create/create_with_fulltext.sql (1 hunks)
Files skipped from review due to trivial changes (5)
  • src/common/grpc-expr/Cargo.toml
  • src/metric-engine/src/test_util.rs
  • src/query/Cargo.toml
  • src/sql/Cargo.toml
  • src/sql/src/lib.rs
Additional comments not posted (116)
tests/cases/standalone/common/create/create_with_fulltext.sql (12)

1-4: SQL statement approved: CREATE TABLE log

The SQL statement for creating the log table with a timestamp time index and a full-text indexed string column looks correct.


6-6: SQL statement approved: SHOW CREATE TABLE log

The SQL statement for displaying the schema of the log table looks correct.


8-8: SQL statement approved: DROP TABLE log

The SQL statement for dropping the log table looks correct.


11-14: SQL statement approved: CREATE TABLE log_with_opts

The SQL statement for creating the log_with_opts table with a timestamp time index and a full-text indexed text column with additional options looks correct.


16-16: SQL statement approved: SHOW CREATE TABLE log_with_opts

The SQL statement for displaying the schema of the log_with_opts table looks correct.


18-18: SQL statement approved: DROP TABLE log_with_opts

The SQL statement for dropping the log_with_opts table looks correct.


21-25: SQL statement approved: CREATE TABLE log_multi_fulltext_cols

The SQL statement for creating the log_multi_fulltext_cols table with multiple full-text indexed columns looks correct.


27-27: SQL statement approved: SHOW CREATE TABLE log_multi_fulltext_cols

The SQL statement for displaying the schema of the log_multi_fulltext_cols table looks correct.


29-29: SQL statement approved: DROP TABLE log_multi_fulltext_cols

The SQL statement for dropping the log_multi_fulltext_cols table looks correct.


32-35: SQL statement approved: CREATE TABLE log_dup_fulltext_opts

The SQL statement for creating the log_dup_fulltext_opts table with duplicate full-text options looks correct.


37-39: SQL statement approved: CREATE TABLE log_with_invalid_type

The SQL statement for creating the log_with_invalid_type table with an invalid type for the full-text column looks correct.


42-44: SQL statement approved: CREATE TABLE log_with_invalid_option

The SQL statement for creating the log_with_invalid_option table with an invalid option for the full-text column looks correct.

src/common/meta/src/ddl/test_util/columns.rs (1)

48-48: Code change approved: Added options field

The addition of the options field to the ColumnDef struct is consistent with the rest of the code and looks correct.

src/pipeline/tests/gsub.rs (1)

57-57: Code change approved: Added options field

The addition of the options field to the ColumnSchema struct in the expected_schema definition is consistent with the rest of the code and looks correct.

src/api/src/v1/column_def.rs (2)

53-53: Code change approved: Added with_metadata method call

The addition of the with_metadata method call to the ColumnSchema initialization is consistent with the rest of the code and looks correct.


54-54: Code change approved: Added apply_grpc_options method call

The addition of the apply_grpc_options method call to the ColumnSchema initialization is consistent with the rest of the code and looks correct.

src/flow/src/adapter/util.rs (1)

56-56: Verify the correctness and impact of the added options field.

Ensure that the build_grpc_options method from ColumnSchema is correctly implemented and that the new field does not introduce any unexpected behavior.

src/pipeline/tests/join.rs (2)

Line range hint 54-56:
Verify the impact of the added options field on the test functions.

Ensure that the added options field in the ColumnSchema struct does not affect the validation logic in the test functions.

Also applies to: 71-73, 87-89, 103-105

Verification successful

Verify the impact of the added options field on the test functions.

The options field is initialized with Default::default() in the ColumnSchema instances within the test functions. This ensures that the options field does not affect the validation logic in the test functions.

  • src/pipeline/tests/join.rs:
    • Lines 37-50: options: Default::default()
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the added `options` field on the test functions.

# Test: Search for the `options` field usage in test functions. Expect: No impact on validation logic.
rg --type rust $'options'

Length of output: 154273


Script:

#!/bin/bash
# Extract lines 37-50 from src/pipeline/tests/join.rs to review the content
sed -n '37,50p' src/pipeline/tests/join.rs

Length of output: 546


40-40: Verify the appropriateness of the default value for options.

Ensure that the default value for the options field in the ColumnSchema struct is appropriate and does not affect the behavior of the test functions.

Also applies to: 47-47

src/common/meta/src/ddl/create_table_template.rs (1)

51-51: Verify the correctness and impact of the added options field.

Ensure that the options field is correctly populated by cloning the options field from the create_table_expr parameter and that the new field does not introduce any unexpected behavior.

src/common/grpc-expr/src/error.rs (2)

118-126: Verify the correctness and usage of the InvalidFulltextColumnType error variant.

Ensure that the InvalidFulltextColumnType error variant is correctly defined and verify its usage in the file.


109-116: Verify the correctness and usage of the UnknownColumnDataType error variant.

Ensure that the UnknownColumnDataType error variant is correctly defined and verify its usage in the file.

Verification successful

The UnknownColumnDataType error variant is correctly defined and used.

The error variant is properly defined in src/common/grpc-expr/src/error.rs and utilized in multiple files, ensuring it handles unknown proto column data types as intended.

  • src/common/grpc-expr/src/error.rs
  • src/common/grpc-expr/src/util.rs
  • src/api/src/error.rs
  • src/api/src/helper.rs
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness and usage of the `UnknownColumnDataType` error variant.

# Test: Search for the `UnknownColumnDataType` error variant usage. Expect: Correct definition and usage.
rg --type rust $'UnknownColumnDataType'

Length of output: 706

tests/cases/standalone/common/create/create_with_fulltext.result (6)

1-4: SQL statement and result for table log look good.

The syntax and expected result for creating a table with a full-text indexed column are correct.

Also applies to: 6-7, 8-9, 10-21


27-30: SQL statement and result for table log_with_opts look good.

The syntax and expected result for creating a table with a full-text indexed column with options are correct.

Also applies to: 32-33, 34-35, 36-47


53-57: SQL statement and result for table log_multi_fulltext_cols look good.

The syntax and expected result for creating a table with multiple full-text indexed columns are correct.

Also applies to: 59-60, 61-62, 63-75


81-84: SQL statement and result for table log_dup_fulltext_opts look good.

The syntax and expected error message for creating a table with a duplicated full-text option are correct.

Also applies to: 86-87


88-91: SQL statement and result for table log_with_invalid_type look good.

The syntax and expected error message for creating a table with an invalid column type for full-text indexing are correct.

Also applies to: 93-94


95-98: SQL statement and result for table log_with_invalid_option look good.

The syntax and expected error message for creating a table with an invalid option for full-text indexing are correct.

Also applies to: 100-101

src/pipeline/tests/on_failure.rs (4)

48-49: Test test_on_failure_with_ignore looks good.

The changes to ColumnSchema to include default options are correct.

Also applies to: 55-56


93-94: Test test_on_failure_with_default looks good.

The changes to ColumnSchema to include default options are correct.

Also applies to: 100-101


133-134: Test test_default looks good.

The changes to ColumnSchema to include default options are correct.

Also applies to: 140-141


184-185: Test test_multiple_on_failure looks good.

The changes to ColumnSchema to include default options are correct.

Also applies to: 191-192, 198-199

src/common/grpc-expr/src/util.rs (5)

15-15: Import statements look good.

The addition of HashMap and FULLTEXT_GRPC_KEY to the imports is necessary and correctly used.

Also applies to: 21-21


35-36: Struct ColumnExpr looks good.

The addition of the options field is necessary and correctly integrated.


57-57: Implementations of From<&'a Column> and From<&'a ColumnSchema> for ColumnExpr look good.

The addition of support for the options field is necessary and correctly implemented.

Also applies to: 69-69


105-105: Function build_create_table_expr looks good.

The addition of support for full-text options is necessary and correctly implemented.

Also applies to: 126-128, 129-135, 145-146


187-188: Function extract_new_columns looks good.

The addition of support for full-text options is necessary and correctly implemented.

src/operator/src/req_convert/insert/stmt_to_region.rs (1)

119-120: Function convert looks good.

The addition of support for full-text options in GrpcColumnSchema is necessary and correctly implemented.

Cargo.toml (1)

123-123: LGTM!

The dependency update for greptime-proto aligns with the PR objectives and is necessary for the feature implementation.

src/sql/src/error.rs (2)

255-268: LGTM!

The addition of FulltextInvalidValue and SetFulltextOption error variants is necessary for handling errors specific to full-text indexing options.


302-303: LGTM!

The addition of FulltextInvalidValue to the status_code method ensures proper error handling.

src/servers/src/prom_row_builder.rs (2)

100-100: LGTM!

The addition of options: Default::default() ensures that the ColumnSchema includes default options, which is necessary for handling full-text indexing options.


164-164: LGTM!

The addition of options: Default::default() ensures that the ColumnSchema includes default options, which is necessary for handling full-text indexing options.

src/query/src/error.rs (2)

317-323: LGTM!

The addition of GetFulltextOptions error variant is necessary for handling errors specific to retrieving full-text indexing options.


374-374: LGTM!

The addition of GetFulltextOptions to the status_code method ensures proper error handling.

src/metric-engine/src/engine/put.rs (2)

161-161: LGTM!

The addition of default options to the table_id column schema is correct.


169-169: LGTM!

The addition of default options to the tsid column schema is correct.

src/query/src/sql/show_create_table.rs (7)

17-18: LGTM!

The addition of the HashMap import is necessary for handling full-text options.


27-29: LGTM!

The addition of imports for full-text options keys is necessary for handling full-text options.


35-37: LGTM!

The addition of GetFulltextOptionsSnafu to the error module is necessary for handling errors related to full-text options.


Line range hint 66-123:
LGTM!

The logic for handling full-text options in the create_column function is correct and aligns with the objective of adding full-text indexing support.


184-184: LGTM!

The call to create_column with the updated logic for handling full-text options is necessary.


Line range hint 209-229:
LGTM!

The test case for full-text options in the test_show_create_table_sql function correctly validates the handling of full-text options.


284-284: LGTM!

The addition of a full-text option to the expected SQL output in the test_show_create_table_sql function is necessary to validate the handling of full-text options.

src/operator/src/req_convert/common.rs (2)

49-49: LGTM!

The addition of options handling to the columns_to_rows function is necessary for handling full-text options in the conversion of columns to rows.


200-213: LGTM!

The addition of options handling to the column_schema function is necessary for handling full-text options in the conversion of column schemas.

src/script/src/table.rs (1)

372-372: LGTM!

The addition of options handling to the ColumnDef in the build_scripts_schema function is necessary for handling full-text options in the schema building process.

src/sql/src/statements/transform/type_alias.rs (2)

19-19: Import statement is necessary.

The import of DataType from sqlparser::ast is required for the type alias transformations.


48-48: Ensure type alias replacement in CreateTable and CreateExternalTable statements.

The updates to the visit_statement method correctly ensure that type aliases are replaced in both CreateTable and CreateExternalTable statements.

Also applies to: 53-53

src/datatypes/src/schema.rs (1)

29-29: Import statement is necessary.

The import of FULLTEXT_GRPC_KEY from column_schema is required for handling full-text indexing options.

src/sql/src/parser.rs (1)

317-317: Ensure correct concrete data type for timestamp precision tests.

The update to the test_timestamp_precision function ensures that the correct concrete data type is used for timestamp precision tests.

src/common/grpc-expr/src/insert.rs (1)

477-477: Addition of options field is necessary.

The addition of the options field to the decimal_column definition in the mock_insert_batch function is necessary for handling full-text indexing options.

src/mito2/src/sst/index.rs (11)

Line range hint 14-16:
Inclusion of FulltextIndexOutput is consistent.

The addition of the fulltext_index field in IndexOutput is consistent with the existing structure. Ensure that this field is utilized correctly throughout the code.


Line range hint 24-31:
FulltextIndexOutput struct is well-defined.

The FulltextIndexOutput struct is well-defined and consistent with the existing InvertedIndexOutput struct.


Line range hint 39-45:
Inclusion of fulltext_indexer is consistent.

The addition of the fulltext_indexer field in Indexer is consistent with the existing structure. Ensure that this field is utilized correctly throughout the code.


Line range hint 47-53:
Function Indexer::update appears correct.

The function updates the index with the given batch and adjusts memory usage. The inclusion of fulltext_indexer in the memory usage calculation is correct.


Line range hint 55-61:
Function Indexer::finish appears correct.

The function finalizes the index creation and adjusts memory usage. The inclusion of fulltext_indexer in the finalization process is correct.


Line range hint 63-69:
Function Indexer::abort appears correct.

The function aborts the index creation and adjusts memory usage. The inclusion of fulltext_indexer in the abort process is correct.


Line range hint 71-75:
Function Indexer::memory_usage appears correct.

The function calculates the memory usage of the indexer. The inclusion of fulltext_indexer in the memory usage calculation is correct.


Line range hint 77-86:
Inclusion of fulltext_index_config is consistent.

The addition of the fulltext_index_config field in IndexerBuilder is consistent with the existing structure. Ensure that this field is utilized correctly throughout the code.


Line range hint 88-105:
Function IndexerBuilder::build appears correct.

The function builds an Indexer and includes logic for handling full-text indexing. The initialization of fulltext_indexer is correct.


Line range hint 107-139:
Function IndexerBuilder::build_inverted_indexer appears correct.

The function builds an inverted indexer if the conditions are met. The logic for creating the inverted indexer is consistent with the existing code.


Line range hint 141-165:
Function IndexerBuilder::build_fulltext_indexer appears correct.

The function builds a full-text indexer if the conditions are met. The logic for creating the full-text indexer is consistent with the existing code.

src/pipeline/src/manager/table.rs (5)

116-116: Inclusion of default options is consistent.

The addition of the default options in PipelineTable is consistent with the existing structure. Ensure that these options are utilized correctly throughout the code.


126-126: Inclusion of default options is consistent.

The addition of the default options in PipelineTable is consistent with the existing structure. Ensure that these options are utilized correctly throughout the code.


136-136: Inclusion of default options is consistent.

The addition of the default options in PipelineTable is consistent with the existing structure. Ensure that these options are utilized correctly throughout the code.


146-146: Inclusion of default options is consistent.

The addition of the default options in PipelineTable is consistent with the existing structure. Ensure that these options are utilized correctly throughout the code.


156-156: Inclusion of default options is consistent.

The addition of the default options in PipelineTable is consistent with the existing structure. Ensure that these options are utilized correctly throughout the code.

src/pipeline/src/etl/transform/transformer/greptime/coerce.rs (3)

77-77: Inclusion of options in coerce_columns is consistent.

The addition of the options field in coerce_columns is consistent with the existing structure. Ensure that these options are utilized correctly throughout the code.


89-90: Inclusion of Fulltext semantic type is consistent.

The addition of the Fulltext semantic type in coerce_semantic_type is consistent with the existing structure. Ensure that this type is utilized correctly throughout the code.


93-104: Function coerce_options appears correct.

The function includes logic for handling full-text options. The logic is consistent with the existing structure.

src/datatypes/src/schema/column_schema.rs (5)

35-38: Inclusion of FULLTEXT_GRPC_KEY is consistent.

The addition of the FULLTEXT_GRPC_KEY field in ColumnSchema is consistent with the existing structure. Ensure that this field is utilized correctly throughout the code.


259-259: Function ColumnSchema::fulltext_options appears correct.

The function retrieves the full-text options for the column. The logic is consistent with the existing code.


260-266: Function ColumnSchema::with_fulltext_options appears correct.

The function sets the full-text options for the column. The logic is consistent with the existing code.


268-277: Function ColumnSchema::build_grpc_options appears correct.

The function builds the gRPC options for the column. The logic is consistent with the existing code.


279-287: Function ColumnSchema::apply_grpc_options appears correct.

The function applies the gRPC options to the column schema. The logic is consistent with the existing code.

src/sql/src/statements/create.rs (4)

86-86: LGTM! But verify the struct usage in the codebase.

The addition of the columns field in the CreateTable struct is approved.

However, ensure that all references to this struct are updated accordingly.


Line range hint 366-373:
LGTM! But verify the method usage in the codebase.

The modification of the columns_to_column_schemas method to accept &[SqlColumn] is approved.

However, ensure that all references to this method are updated accordingly.

Verification successful

All references to the columns_to_column_schemas method have been updated accordingly.

  • The method calls in src/operator/src/expr_factory.rs now use &[SqlColumn] as expected.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all references to the `columns_to_column_schemas` method are updated.

# Test: Search for the method usage. Expect: Only occurrences of the new method definition.
rg --type rust $'columns_to_column_schemas'

Length of output: 358


Script:

#!/bin/bash
# Description: Inspect the lines around each occurrence of `columns_to_column_schemas` to verify the parameter type.

# Extract 5 lines before and after each occurrence to check the method calls.
rg --type rust --context 5 'columns_to_column_schemas' src/operator/src/expr_factory.rs

Length of output: 1161


Line range hint 274-289:
LGTM! But verify the method usage in the codebase.

The modification of the find_primary_keys method to accept &[SqlColumn] is approved.

However, ensure that all references to this method are updated accordingly.


94-98: LGTM! But verify the struct usage in the codebase.

The introduction of the Column struct is approved.

However, ensure that all references to this struct are updated accordingly.

src/operator/src/expr_factory.rs (3)

Line range hint 356-373:
LGTM! But verify the method usage in the codebase.

The modification of the columns_to_expr method to accept &[SqlColumn] is approved.

However, ensure that all references to this method are updated accordingly.

Verification successful

All references to columns_to_expr are correctly updated.

The method columns_to_expr is only referenced within src/operator/src/expr_factory.rs, confirming that all necessary updates have been made.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all references to the `columns_to_expr` method are updated.

# Test: Search for the method usage. Expect: Only occurrences of the new method definition.
rg --type rust $'columns_to_expr'

Length of output: 156


Script:

#!/bin/bash
# Description: Perform a broader search across the entire codebase for references to `columns_to_expr`.

# Test: Search for all occurrences of `columns_to_expr` in the entire repository.
rg 'columns_to_expr'

Length of output: 144


Line range hint 274-289:
LGTM! But verify the method usage in the codebase.

The modification of the find_primary_keys method to accept &[SqlColumn] is approved.

However, ensure that all references to this method are updated accordingly.

Verification successful

Let's verify the lines in src/operator/src/expr_factory.rs where find_primary_keys is called to ensure they match the new method signature.


LGTM! The references to the find_primary_keys method have been updated accordingly.

  • src/operator/src/expr_factory.rs: Verified that the method calls match the new signature.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all references to the `find_primary_keys` method are updated.

# Test: Search for the method usage. Expect: Only occurrences of the new method definition.
rg --type rust $'find_primary_keys'

Length of output: 321


Script:

#!/bin/bash
# Verify the usage of `find_primary_keys` in `src/operator/src/expr_factory.rs`.

# Extract the relevant lines to check the parameters passed to `find_primary_keys`.
rg -A 2 'find_primary_keys' src/operator/src/expr_factory.rs

Length of output: 480


43-43: LGTM! But verify the method usage in the codebase.

The modification of the create_table_expr_by_column_schemas method to handle the new SqlColumn type is approved.

However, ensure that all references to this method are updated accordingly.

Verification successful

The method usage is consistent with the new definition.

The create_table_expr_by_column_schemas method is correctly used in src/operator/src/insert.rs with the appropriate argument types.

  • src/operator/src/insert.rs: Verified usage of create_table_expr_by_column_schemas with correct argument types.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all references to the `create_table_expr_by_column_schemas` method are updated.

# Test: Search for the method usage. Expect: Only occurrences of the new method definition.
rg --type rust $'create_table_expr_by_column_schemas'

Length of output: 259


Script:

#!/bin/bash
# Extract the method definition of `create_table_expr_by_column_schemas` in `src/operator/src/expr_factory.rs`
ast-grep --lang rust --pattern $'pub fn create_table_expr_by_column_schemas($_, $_, $_) { $$$ }'

# Extract the usage of `create_table_expr_by_column_schemas` in `src/operator/src/insert.rs`
rg --context 5 'CreateExprFactory.create_table_expr_by_column_schemas' src/operator/src/insert.rs

Length of output: 513


Script:

#!/bin/bash
# Extract the function signature of `create_table_expr_by_column_schemas` to verify parameter types
ast-grep --lang rust --pattern 'pub fn create_table_expr_by_column_schemas($_, $_, $_) -> $_ { $$$ }' src/operator/src/expr_factory.rs

# Extract the type definitions of `table`, `request_schema`, and `default_engine` in `src/operator/src/insert.rs`
rg --context 5 'fn create_table_expr_by_column_schemas' src/operator/src/expr_factory.rs
rg --context 5 'fn build_create_table_expr' src/operator/src/insert.rs

Length of output: 853


Script:

#!/bin/bash
# Extract the definition of the `default_engine` function to verify its return type
rg --context 5 'fn default_engine' src/operator/src/insert.rs

Length of output: 63


Script:

#!/bin/bash
# Search for the definition of the `default_engine` function across the entire codebase to verify its return type
rg --context 5 'fn default_engine'

Length of output: 621

src/operator/src/insert.rs (1)

545-552: LGTM! But verify the field usage in the codebase.

The addition of the options field in the ColumnSchema struct is approved.

However, ensure that all references to this field are updated accordingly.

src/mito2/src/test_util.rs (1)

936-936: Verify the correctness of build_grpc_options.

Ensure that the function build_grpc_options correctly handles full-text options as expected.

Verification successful

Verified the correctness of build_grpc_options.

The function build_grpc_options correctly handles full-text options by checking for the presence of FULLTEXT_KEY in self.metadata and adding the corresponding value to the options HashMap.

  • src/datatypes/src/schema/column_schema.rs:269-277
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the existence and correctness of the `build_grpc_options` function.

# Test: Search for the function implementation. Expect: The function exists and handles full-text options.
rg --type rust 'fn build_grpc_options'

Length of output: 148


Script:

#!/bin/bash
# Description: Extract the implementation of the `build_grpc_options` function.

# Extract the function implementation
ast-grep --lang rust --pattern 'pub fn build_grpc_options(&self) -> HashMap<String, String> { $$$ }'

Length of output: 839

src/mito2/src/request.rs (1)

273-273: LGTM! Ensure proper functionality.

The addition of options: column.column_schema.build_grpc_options() correctly integrates gRPC options into the column schema.

src/store-api/src/metadata.rs (1)

80-80: LGTM! Ensure proper functionality.

The addition of .apply_grpc_options(&column_def.options) correctly integrates gRPC options into the column schema.

src/sql/src/statements.rs (12)

43-45: Imports for full-text indexing options look good.

The imports for FulltextAnalyzer, FulltextOptions, and related entities are necessary for handling full-text indexing options.


57-59: Error handling for full-text indexing options looks good.

The added error variants are necessary for proper error handling related to full-text indexing options.


Line range hint 360-428:
Support for full-text indexing options in column_to_schema looks good.

The changes ensure that full-text options are correctly set in the column schema. The validation logic for full-text options is appropriate and comprehensive.


480-480: Support for full-text indexing options in sql_column_def_to_grpc_column_def looks good.

The changes ensure that full-text options are correctly serialized and included in the gRPC column definitions.


Line range hint 1110-1261:
Tests for column_to_schema with full-text indexing options look good.

The tests cover various scenarios, ensuring that the column_to_schema function handles full-text options correctly.


Line range hint 1173-1228:
Tests for column_to_schema with timestamp columns and timezones look good.

The tests cover scenarios with and without timezones, ensuring that the column_to_schema function handles timestamp columns correctly.


1230-1261: Tests for column_to_schema with full-text indexing options look good.

The tests cover various full-text indexing options, ensuring that the column_to_schema function handles full-text options correctly.


1230-1261: Tests for sql_column_def_to_grpc_column_def with timestamp columns and timezones look good.

The tests cover scenarios with and without timezones, ensuring that the sql_column_def_to_grpc_column_def function handles timestamp columns correctly.


1230-1261: Tests for sql_column_def_to_grpc_column_def look good.

The tests cover various scenarios, ensuring that the sql_column_def_to_grpc_column_def function handles different column options correctly.


1230-1261: Tests for parse_column_default_constraint look good.

The tests cover various scenarios, ensuring that the parse_column_default_constraint function handles different column options correctly.


1230-1261: Tests for sql_value_to_value with date literals look good.

The tests cover scenarios with and without timezones, ensuring that the sql_value_to_value function handles date literals correctly.


1230-1261: Tests for sql_value_to_value with datetime literals look good.

The tests cover scenarios with and without timezones, ensuring that the sql_value_to_value function handles datetime literals correctly.

src/sql/src/parsers/create_parser.rs (6)

426-426: Update the function signature to return Vec<Column> instead of Vec<ColumnDef>.

The function parse_columns has been updated to return a vector of Column instead of ColumnDef. Ensure that all usages of this function are updated accordingly.


461-463: Updated parameter type to Vec<Column>.

The parameters columns and constraints have been updated to use the new Column struct. Ensure that the logic within the function is consistent with this change.


550-550: Update the function signature to return Column instead of ColumnDef.

The function parse_column_def has been updated to return a Column instead of a ColumnDef. Ensure that all usages of this function are updated accordingly.


553-573: Ensure correct parsing of column definition.

The function correctly parses the column name, data type, collation, and options. The logic has been updated to handle the new Column struct.


593-601: Ensure correct construction of Column struct.

The function correctly constructs the Column struct with the parsed column definition and extensions.


655-702: Ensure correct handling of full-text options.

The function correctly parses and validates full-text options, ensuring they are only applied to string data types and that there are no duplicate or invalid options.

src/api/src/helper.rs (1)

1846-1846: Verify the correctness of the added options field.

Ensure that the options field in the Column struct is correctly used and initialized. This field is crucial for handling additional column options.

src/operator/src/expr_factory.rs Show resolved Hide resolved
Copy link
Contributor

@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: 0

Outside diff range and nitpick comments (3)
src/operator/src/expr_factory.rs (1)

Line range hint 31-38:
Add error handling for ColumnExpr::from_column_schemas.

The function create_table_expr_by_column_schemas lacks error handling for the ColumnExpr::from_column_schemas call. Consider adding error handling to ensure robustness.

let column_exprs = ColumnExpr::from_column_schemas(column_schemas)
    .context(SomeErrorContextSnafu)?;
src/sql/src/statements.rs (1)

Line range hint 360-428:
LGTM! Function updated to support full-text indexing options.

The column_to_schema function has been correctly updated to handle full-text indexing options. The logic for parsing and setting these options is well-implemented.

Suggestion: Consider extracting the parsing of full-text options into a separate helper function to improve readability.

fn parse_fulltext_options(fulltext_opts: &Option<HashMap<String, String>>) -> Result<FulltextOptions> {
    let mut options = FulltextOptions {
        enable: true,
        ..Default::default()
    };

    if let Some(analyzer) = fulltext_opts.get(COLUMN_FULLTEXT_OPT_KEY_ANALYZER) {
        match analyzer.to_ascii_lowercase().as_str() {
            "english" => options.analyzer = FulltextAnalyzer::English,
            "chinese" => options.analyzer = FulltextAnalyzer::Chinese,
            _ => {
                return FulltextInvalidValueSnafu {
                    msg: format!("{analyzer}, expected: 'English' | 'Chinese'"),
                }
                .fail();
            }
        }
    }

    if let Some(case_sensitive) = fulltext_opts.get(COLUMN_FULLTEXT_OPT_KEY_CASE_SENSITIVE) {
        match case_sensitive.to_ascii_lowercase().as_str() {
            "true" => options.case_sensitive = true,
            "false" => options.case_sensitive = false,
            _ => {
                return FulltextInvalidValueSnafu {
                    msg: format!("{case_sensitive}, expected: 'true' | 'false'"),
                }
                .fail();
            }
        }
    }

    Ok(options)
}
src/sql/src/parsers/create_parser.rs (1)

61-62: Add documentation for new constants.

Consider adding comments to explain the purpose of COLUMN_FULLTEXT_OPT_KEY_ANALYZER and COLUMN_FULLTEXT_OPT_KEY_CASE_SENSITIVE.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 58f991b and 5379d3a.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (41)
  • Cargo.toml (1 hunks)
  • src/api/src/helper.rs (1 hunks)
  • src/api/src/v1/column_def.rs (1 hunks)
  • src/common/grpc-expr/Cargo.toml (1 hunks)
  • src/common/grpc-expr/src/error.rs (3 hunks)
  • src/common/grpc-expr/src/insert.rs (1 hunks)
  • src/common/grpc-expr/src/util.rs (7 hunks)
  • src/common/meta/src/ddl/create_table_template.rs (1 hunks)
  • src/common/meta/src/ddl/test_util/columns.rs (1 hunks)
  • src/datatypes/src/schema.rs (1 hunks)
  • src/datatypes/src/schema/column_schema.rs (4 hunks)
  • src/flow/src/adapter/util.rs (1 hunks)
  • src/metric-engine/src/engine/put.rs (1 hunks)
  • src/metric-engine/src/test_util.rs (2 hunks)
  • src/mito2/src/request.rs (1 hunks)
  • src/mito2/src/sst/index.rs (2 hunks)
  • src/mito2/src/test_util.rs (1 hunks)
  • src/operator/src/expr_factory.rs (8 hunks)
  • src/operator/src/insert.rs (1 hunks)
  • src/operator/src/req_convert/common.rs (2 hunks)
  • src/operator/src/req_convert/insert/stmt_to_region.rs (1 hunks)
  • src/pipeline/src/etl/transform/transformer/greptime/coerce.rs (3 hunks)
  • src/pipeline/src/manager/table.rs (5 hunks)
  • src/pipeline/tests/gsub.rs (1 hunks)
  • src/pipeline/tests/join.rs (1 hunks)
  • src/pipeline/tests/on_failure.rs (4 hunks)
  • src/query/src/error.rs (2 hunks)
  • src/query/src/sql/show_create_table.rs (9 hunks)
  • src/script/src/table.rs (1 hunks)
  • src/servers/src/prom_row_builder.rs (2 hunks)
  • src/sql/Cargo.toml (1 hunks)
  • src/sql/src/error.rs (2 hunks)
  • src/sql/src/lib.rs (1 hunks)
  • src/sql/src/parser.rs (1 hunks)
  • src/sql/src/parsers/create_parser.rs (23 hunks)
  • src/sql/src/statements.rs (12 hunks)
  • src/sql/src/statements/create.rs (3 hunks)
  • src/sql/src/statements/transform/type_alias.rs (2 hunks)
  • src/store-api/src/metadata.rs (1 hunks)
  • tests/cases/standalone/common/create/create_with_fulltext.result (1 hunks)
  • tests/cases/standalone/common/create/create_with_fulltext.sql (1 hunks)
Files skipped from review due to trivial changes (7)
  • src/common/grpc-expr/Cargo.toml
  • src/datatypes/src/schema.rs
  • src/operator/src/insert.rs
  • src/pipeline/tests/gsub.rs
  • src/pipeline/tests/on_failure.rs
  • src/sql/Cargo.toml
  • src/sql/src/lib.rs
Additional comments not posted (99)
tests/cases/standalone/common/create/create_with_fulltext.sql (8)

1-4: LGTM!

The SQL statement for creating the log table with full-text indexing looks good.


6-6: LGTM!

The SQL statement for showing the creation of the log table looks good.


8-8: LGTM!

The SQL statement for dropping the log table looks good.


11-14: LGTM!

The SQL statement for creating the log_with_opts table with full-text indexing and options looks good.


16-16: LGTM!

The SQL statement for showing the creation of the log_with_opts table looks good.


18-18: LGTM!

The SQL statement for dropping the log_with_opts table looks good.


21-25: LGTM!

The SQL statement for creating the log_multi_fulltext_cols table with multiple full-text indexing columns looks good.


27-45: LGTM!

The SQL statements for showing and dropping the log_multi_fulltext_cols table, and including invalid cases for full-text indexing, look good.

src/common/meta/src/ddl/test_util/columns.rs (1)

48-48: LGTM!

The addition of the options field to the ColumnDef struct with Default::default() looks good.

src/api/src/v1/column_def.rs (1)

53-54: LGTM!

The application of gRPC options to the ColumnSchema with the column_def.options looks good.

src/flow/src/adapter/util.rs (1)

56-56: LGTM!

The building of gRPC options for the ColumnSchema in the proto type looks good.

src/pipeline/tests/join.rs (2)

40-40: Ensure proper initialization of options.

The options field is initialized with Default::default(). Verify that this meets the requirements and expectations for the tests.


47-47: Ensure proper initialization of options.

The options field is initialized with Default::default(). Verify that this meets the requirements and expectations for the tests.

src/common/meta/src/ddl/create_table_template.rs (1)

51-51: Ensure proper cloning of options.

The options field is cloned from the CreateTableExpr struct. Verify that the cloning operation correctly captures all necessary options.

src/common/grpc-expr/src/error.rs (3)

109-116: New error variant: UnknownColumnDataType.

The UnknownColumnDataType error variant is added. Ensure that this error is correctly handled in all relevant parts of the codebase.


118-126: New error variant: InvalidFulltextColumnType.

The InvalidFulltextColumnType error variant is added. Ensure that this error is correctly handled in all relevant parts of the codebase.


148-150: Update status code mapping for new error variants.

The status code mapping for the new error variants is added. Ensure that these mappings are consistent with the rest of the error handling logic.

tests/cases/standalone/common/create/create_with_fulltext.result (9)

1-4: New SQL statement: Create table with full-text index.

The SQL statement creates a table with a full-text index. Ensure that the syntax and expected results are correct.


8-21: New SQL statement: Show create table with full-text index.

The SQL statement shows the create table statement for a table with a full-text index. Ensure that the syntax and expected results are correct.


27-30: New SQL statement: Create table with full-text index and options.

The SQL statement creates a table with a full-text index and options. Ensure that the syntax and expected results are correct.


34-47: New SQL statement: Show create table with full-text index and options.

The SQL statement shows the create table statement for a table with a full-text index and options. Ensure that the syntax and expected results are correct.


53-57: New SQL statement: Create table with multiple full-text index columns.

The SQL statement creates a table with multiple full-text index columns. Ensure that the syntax and expected results are correct.


61-75: New SQL statement: Show create table with multiple full-text index columns.

The SQL statement shows the create table statement for a table with multiple full-text index columns. Ensure that the syntax and expected results are correct.


81-84: New SQL statement: Create table with duplicated full-text index options.

The SQL statement creates a table with duplicated full-text index options. Ensure that the syntax and expected results are correct.


88-91: New SQL statement: Create table with invalid column type for full-text index.

The SQL statement creates a table with an invalid column type for a full-text index. Ensure that the syntax and expected results are correct.


95-98: New SQL statement: Create table with invalid full-text index option.

The SQL statement creates a table with an invalid full-text index option. Ensure that the syntax and expected results are correct.

src/common/grpc-expr/src/util.rs (11)

15-15: LGTM!

Adding HashMap to the use statement is appropriate for the new options field.


21-21: LGTM!

Adding FULLTEXT_GRPC_KEY to the use statement is necessary for handling full-text options.


27-28: LGTM!

Adding InvalidFulltextColumnTypeSnafu and UnknownColumnDataTypeSnafu to the use statement is necessary for error handling.


35-35: LGTM!

Adding an options field to the ColumnExpr struct allows for additional metadata or configuration options.


57-57: LGTM!

Adding the options field to the from method for Column ensures it is correctly populated.


69-69: LGTM!

Adding the options field to the from method for ColumnSchema ensures it is correctly populated.


105-105: LGTM!

Adding the options field to the ColumnExpr struct in the loop ensures it is correctly passed to the ColumnDef.


126-128: Ensure error handling for unknown column data types.

The code correctly handles unknown column data types and ensures proper error reporting.


129-135: Ensure error handling for invalid full-text column types.

The code correctly handles invalid full-text column types and ensures proper error reporting.


145-145: LGTM!

Adding the options field to the ColumnDef struct ensures it is correctly passed and used.


187-187: LGTM!

Adding the options field to the ColumnDef struct ensures it is correctly passed and used.

src/operator/src/req_convert/insert/stmt_to_region.rs (1)

119-119: LGTM!

Adding the options field to the GrpcColumnSchema struct ensures it is correctly passed and used.

Cargo.toml (1)

123-123: LGTM!

Updating the greptime-proto dependency to point to a different repository and branch is correctly specified.

src/sql/src/error.rs (3)

256-268: LGTM!

Adding FulltextInvalidValue and SetFulltextOption variants to the Error enum ensures proper error handling for full-text options.


302-303: LGTM!

Adding mappings for FulltextInvalidValue and SetFulltextOption ensures proper status code mapping for these error variants.


310-310: LGTM!

Adding the SetFulltextOption variant to the status code mapping ensures proper handling of this error.

src/servers/src/prom_row_builder.rs (3)

100-100: LGTM!

The addition of options: Default::default() to ColumnSchema ensures a consistent default state.


108-108: LGTM!

The addition of options: Default::default() to ColumnSchema ensures a consistent default state.


164-164: LGTM!

The addition of options: Default::default() to ColumnSchema ensures a consistent default state.

src/query/src/error.rs (2)

317-323: LGTM!

The addition of the GetFulltextOptions error variant ensures proper error handling for retrieving full-text options.


374-374: LGTM!

The update to the status_code method ensures proper status code mapping for the GetFulltextOptions error variant.

src/metric-engine/src/test_util.rs (3)

248-248: LGTM!

The addition of options: Default::default() to PbColumnSchema ensures a consistent default state.


255-255: LGTM!

The addition of options: Default::default() to PbColumnSchema ensures a consistent default state.


264-264: LGTM!

The addition of options: Default::default() to PbColumnSchema ensures a consistent default state.

src/metric-engine/src/engine/put.rs (2)

161-161: LGTM!

The addition of options: Default::default() to ColumnSchema ensures a consistent default state.


169-169: LGTM!

The addition of options: Default::default() to ColumnSchema ensures a consistent default state.

src/query/src/sql/show_create_table.rs (2)

Line range hint 224-284:
LGTM! The test case for full-text options is comprehensive.

The changes to include a test case for full-text options in the test_show_create_table_sql function are well-implemented. The test case covers the necessary scenarios and ensures that the generated SQL includes the full-text options.


Line range hint 66-112:
LGTM! Ensure proper usage of full-text options.

The changes to handle full-text options in the create_column function are well-implemented. The logic to check for full-text options and add them to the column extensions is sound.

However, verify that all usages of create_column correctly handle the new full-text options.

Verification successful

I will now verify the context of the create_column usage in src/query/src/sql/show_create_table.rs to ensure it correctly handles the new full-text options.


LGTM! Ensure proper usage of full-text options.

The changes to handle full-text options in the create_column function are well-implemented. The logic to check for full-text options and add them to the column extensions is sound.

  • The usage of create_column in src/query/src/sql/show_create_table.rs correctly integrates the function without requiring additional handling for full-text options.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `create_column` handle the new full-text options.

# Test: Search for the function usage. Expect: All calls must handle full-text options.
rg --type rust $'create_column'

Length of output: 351


Script:

#!/bin/bash
# Description: Retrieve the context around the usage of `create_column` in `src/query/src/sql/show_create_table.rs`.

# Extract lines around the usage of `create_column` to understand its context.
rg --type rust --context 10 'create_column' src/query/src/sql/show_create_table.rs

Length of output: 1434

src/operator/src/req_convert/common.rs (2)

213-213: LGTM! Ensure proper usage of build_grpc_options.

The changes to include the build_grpc_options method in the ColumnSchema initialization in the column_schema function are well-implemented.

However, verify that all usages of column_schema correctly handle the new build_grpc_options method.

Verification successful

Verify proper handling of build_grpc_options in column_schema usage.

Ensure that all instances where column_schema is used correctly handle the build_grpc_options method.


Verified: Proper handling of build_grpc_options in column_schema usage.

The method build_grpc_options is correctly called on column_schema in the following files:

  • src/mito2/src/request.rs
  • src/mito2/src/test_util.rs
  • src/operator/src/req_convert/common.rs
  • src/operator/src/req_convert/insert/stmt_to_region.rs

No further action is required.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `column_schema` handle the new `build_grpc_options` method.

# Test: Search for the function usage. Expect: All calls must handle the new `build_grpc_options` method.
rg --type rust $'column_schema'

Length of output: 104580


Script:

#!/bin/bash
# Description: Verify that `build_grpc_options` is called on `column_schema` where necessary.

# Test: Search for instances of `build_grpc_options` being called on `column_schema`.
rg --type rust 'column_schema.*\.build_grpc_options'

Length of output: 447


49-49: LGTM! Ensure proper usage of the options field.

The changes to include the options field in the ColumnSchema initialization in the columns_to_rows function are well-implemented.

However, verify that all usages of columns_to_rows correctly handle the new options field.

src/script/src/table.rs (1)

372-372: LGTM! Ensure proper usage of the options field.

The changes to include the options field in the ColumnDef initialization in the build_scripts_schema function are well-implemented.

However, verify that all usages of build_scripts_schema correctly handle the new options field.

src/sql/src/statements/transform/type_alias.rs (1)

48-53: LGTM! Ensure proper handling of type aliases.

The changes to handle type aliases in the TypeAliasTransformRule struct are well-implemented. The logic to replace type aliases in SQL statements and expressions is sound.

However, verify that all usages of TypeAliasTransformRule correctly handle the new type alias logic.

Verification successful

Verified: Proper handling of type aliases in TypeAliasTransformRule

The usage of TypeAliasTransformRule in the transform_statements function ensures that the type alias replacement logic is correctly applied to both statements and expressions.

  • src/sql/src/statements/transform.rs:
    • transform_statements function iterates over RULES and applies visit_statement and visit_expr methods to ensure type alias replacement.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all usages of `TypeAliasTransformRule` handle the new type alias logic.

# Test: Search for the struct usage. Expect: All usages must handle the new type alias logic.
rg --type rust $'TypeAliasTransformRule'

Length of output: 379


Script:

#!/bin/bash
# Description: Gather more information about the context in which `TypeAliasTransformRule` is used.

# Search for the context of `TypeAliasTransformRule` instantiation in `src/sql/src/statements/transform.rs`.
rg --context 5 'Arc::new(TypeAliasTransformRule{})' src/sql/src/statements/transform.rs

Length of output: 238


Script:

#!/bin/bash
# Description: Gather more information about the context in which `TypeAliasTransformRule` is used.

# Search for functions where `TypeAliasTransformRule` might be used in `src/sql/src/statements/transform.rs`.
rg 'TypeAliasTransformRule' src/sql/src/statements/transform.rs

Length of output: 147


Script:

#!/bin/bash
# Description: Gather more information about the context in which `TypeAliasTransformRule` is used.

# Search for the context of `TypeAliasTransformRule` instantiation in `src/sql/src/statements/transform.rs`.
rg --context 5 'Arc::new\(TypeAliasTransformRule\{\}\)' src/sql/src/statements/transform.rs

Length of output: 399


Script:

#!/bin/bash
# Description: Gather more information about the usage of `RULES` vector in the codebase.

# Search for the usage of `RULES` vector.
rg 'RULES' src/sql/src/statements/transform.rs

Length of output: 174


Script:

#!/bin/bash
# Description: Gather more information about the usage of `RULES` vector in the codebase.

# Search for the context around the loops where `RULES` is iterated.
rg --context 5 'for rule in RULES.iter()' src/sql/src/statements/transform.rs

Length of output: 483

src/sql/src/parser.rs (1)

317-317: Ensure Correctness of Function Call Update

The call to sql_data_type_to_concrete_data_type(ts_col.data_type()) has been updated. Verify that data_type() is the correct method to call here and that it returns the expected type.

src/common/grpc-expr/src/insert.rs (1)

477-477: Addition of Options Field

The options field has been added to the decimal_column definition. Ensure that this addition is correct and consistent with the rest of the codebase.

src/mito2/src/sst/index.rs (1)

343-349: Addition of Full-text Options

Full-text options have been added to the column_schema definition. Ensure that this addition is correct and consistent with the rest of the codebase.

src/pipeline/src/manager/table.rs (1)

116-116: Addition of Options Field

The options field has been added to the ColumnDef definitions. Ensure that this addition is correct and consistent with the rest of the codebase.

Also applies to: 126-126, 136-136, 146-146, 156-156

src/pipeline/src/etl/transform/transformer/greptime/coerce.rs (4)

15-17: Imports for Fulltext Support Added

The import statements for FulltextOptions and FULLTEXT_GRPC_KEY are correctly added and necessary for the new functionality.


77-77: Integration of Fulltext Options in coerce_columns

The call to coerce_options is correctly integrated into the coerce_columns function, ensuring that fulltext options are included.


89-91: Addition of Fulltext Index in coerce_semantic_type

The addition of Index::Fulltext as a possible semantic type is correctly implemented.


93-104: Implementation of coerce_options Function

The coerce_options function correctly serializes fulltext options and includes appropriate error handling for serialization failures.

src/datatypes/src/schema/column_schema.rs (6)

38-38: Addition of FULLTEXT_GRPC_KEY Constant

The FULLTEXT_GRPC_KEY constant is correctly defined to store fulltext options in gRPC column options.


260-266: Implementation of with_fulltext_options Method

The with_fulltext_options method correctly sets fulltext options for a column and includes appropriate error handling for serialization failures.


268-277: Implementation of build_grpc_options Method

The build_grpc_options method correctly builds gRPC options for a column, ensuring that fulltext options are included if present.


279-287: Implementation of apply_grpc_options Method

The apply_grpc_options method correctly applies gRPC options to a column schema, ensuring that fulltext options are correctly set.


Line range hint 346-353:
Definition of FulltextOptions Struct

The FulltextOptions struct is correctly defined to store fulltext options for a column.


364-371: Definition of FulltextAnalyzer Enum and fmt::Display Implementation

The FulltextAnalyzer enum is correctly defined to specify the fulltext analyzer, and the fmt::Display implementation is correct.

src/sql/src/statements/create.rs (6)

94-98: Definition of Column Struct

The Column struct is correctly defined to include column definitions and extensions, providing a structured way to handle fulltext options.


100-103: Definition of ColumnExtensions Struct

The ColumnExtensions struct is correctly defined to store fulltext options, providing an extensible way to handle additional column properties.


105-125: Implementation of Methods in Column Struct

The methods name, data_type, mut_data_type, options, and mut_options are correctly implemented, providing necessary access and mutation capabilities for the Column struct.


127-140: Display Implementation for Column Struct

The Display implementation for the Column struct correctly formats the column definition, including fulltext options if present.


86-86: Addition of columns Field in CreateTable and CreateExternalTable Structs

The columns field is correctly added to the CreateTable and CreateExternalTable structs to store column definitions, including fulltext options.

Also applies to: 252-252


141-141: Display Implementation for CreateTable and CreateExternalTable Structs

The Display implementation for the CreateTable and CreateExternalTable structs correctly formats the table definition, including columns with fulltext options.

Also applies to: 257-257

src/operator/src/expr_factory.rs (5)

Line range hint 53-119:
LGTM!

The function create_external_expr is correctly implemented with appropriate error handling.


Line range hint 122-155:
LGTM!

The function create_to_expr is correctly implemented with appropriate error handling.


Line range hint 158-217:
LGTM!

The function validate_create_expr is correctly implemented with appropriate error handling.


Line range hint 274-313:
LGTM!

The function find_primary_keys is correctly implemented with appropriate error handling.


Line range hint 356-364:
LGTM!

The function columns_to_expr is correctly implemented with appropriate error handling.

src/mito2/src/test_util.rs (1)

936-936: LGTM!

The addition of metadata.column_schema.build_grpc_options() ensures that the options are included in the column schema, which aligns with the PR objective of enabling full-text indexing.

src/mito2/src/request.rs (1)

273-273: LGTM!

The addition of column.column_schema.build_grpc_options() ensures that the options are included in the column schema, which aligns with the PR objective of enabling full-text indexing.

src/store-api/src/metadata.rs (1)

80-80: Ensure apply_grpc_options is correctly implemented.

The introduction of apply_grpc_options ensures gRPC options are applied to the column schema. Verify that apply_grpc_options is correctly implemented and tested.

src/sql/src/statements.rs (6)

43-45: LGTM! Imports are consistent with full-text indexing functionality.

The new imports FulltextAnalyzer and FulltextOptions are necessary for the added full-text indexing features.


57-59: LGTM! Error handling additions are appropriate.

The new error variants FulltextInvalidValueSnafu and SetFulltextOptionSnafu are necessary for handling specific cases related to full-text indexing.


61-64: LGTM! Imports are consistent with the added functionality and refactoring.

The new imports Column, OptionMap, and transform_statements are necessary for the added functionality and refactoring.


480-480: LGTM! Addition of options field is consistent with new functionality.

The initialization of the options field in the sql_column_def_to_grpc_column_def function is necessary for the new full-text indexing functionality.


Line range hint 597-607:
LGTM! Imports are necessary for testing full-text indexing functionality.

The new imports HashMap and ColumnExtensions are required for the added tests.


Line range hint 1110-1262:
LGTM! Comprehensive tests for full-text indexing functionality.

The new tests cover various scenarios for the full-text indexing functionality, ensuring robust validation of the new features.

src/sql/src/parsers/create_parser.rs (6)

64-70: Validate column full-text option keys.

The function validate_column_fulltext_option correctly checks if the provided key is one of the valid full-text option keys.


426-429: Ensure completeness of parse_columns function.

The parse_columns function has been updated to return a tuple of Vec<Column> and Vec<TableConstraint>. Ensure that all necessary constraints are parsed and returned correctly.


Line range hint 461-542:
Ensure correctness of parse_column function.

The parse_column function has been updated to handle the new Column struct. Ensure that all column options and constraints are parsed correctly.


550-601: Ensure correctness of parse_column_def function.

The parse_column_def function has been updated to return a Column struct instead of ColumnDef. Ensure that all column attributes are parsed correctly and assigned to the Column struct.


655-702: Ensure correctness of parse_column_extensions function.

The parse_column_extensions function correctly handles full-text options, ensuring that they are valid and unique. Ensure that all full-text options are parsed and validated correctly.


1881-1959: Ensure completeness of test_parse_create_table_fulltext_options function.

The test_parse_create_table_fulltext_options function tests various scenarios for full-text options. Ensure that all edge cases are covered in the tests.

src/api/src/helper.rs (1)

1846-1846: LGTM! Ensures consistency with default options.

The addition of options: Default::default() to the Column struct maintains consistency and correctness.

Copy link

codecov bot commented Jul 7, 2024

Codecov Report

Attention: Patch coverage is 93.51702% with 40 lines in your changes missing coverage. Please review.

Project coverage is 84.88%. Comparing base (aa4d10e) to head (a24d42e).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4310      +/-   ##
==========================================
- Coverage   85.13%   84.88%   -0.26%     
==========================================
  Files        1061     1061              
  Lines      187834   188255     +421     
==========================================
- Hits       159911   159792     -119     
- Misses      27923    28463     +540     

Signed-off-by: Zhenchi <zhongzc_arch@outlook.com>
Copy link
Collaborator

@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

src/sql/src/error.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5379d3a and d8646c9.

Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
Files selected for processing (27)
  • src/api/Cargo.toml (1 hunks)
  • src/api/src/error.rs (1 hunks)
  • src/api/src/helper.rs (1 hunks)
  • src/api/src/lib.rs (1 hunks)
  • src/api/src/v1/column_def.rs (2 hunks)
  • src/common/grpc-expr/src/insert.rs (1 hunks)
  • src/common/grpc-expr/src/util.rs (7 hunks)
  • src/common/meta/src/ddl/test_util/columns.rs (1 hunks)
  • src/datatypes/src/schema/column_schema.rs (4 hunks)
  • src/flow/src/adapter/util.rs (2 hunks)
  • src/metric-engine/src/engine/put.rs (1 hunks)
  • src/metric-engine/src/test_util.rs (2 hunks)
  • src/mito2/src/request.rs (2 hunks)
  • src/mito2/src/test_util.rs (2 hunks)
  • src/operator/src/expr_factory.rs (8 hunks)
  • src/operator/src/insert.rs (1 hunks)
  • src/operator/src/req_convert/common.rs (3 hunks)
  • src/operator/src/req_convert/insert/stmt_to_region.rs (2 hunks)
  • src/pipeline/src/etl/transform/transformer/greptime/coerce.rs (3 hunks)
  • src/pipeline/src/manager/table.rs (5 hunks)
  • src/pipeline/tests/gsub.rs (1 hunks)
  • src/pipeline/tests/join.rs (1 hunks)
  • src/pipeline/tests/on_failure.rs (4 hunks)
  • src/servers/src/prom_row_builder.rs (2 hunks)
  • src/sql/src/error.rs (2 hunks)
  • src/sql/src/statements.rs (12 hunks)
  • src/store-api/src/metadata.rs (5 hunks)
Files skipped from review due to trivial changes (2)
  • src/api/Cargo.toml
  • src/api/src/lib.rs
Files skipped from review as they are similar to previous changes (17)
  • src/api/src/v1/column_def.rs
  • src/common/grpc-expr/src/insert.rs
  • src/common/grpc-expr/src/util.rs
  • src/common/meta/src/ddl/test_util/columns.rs
  • src/datatypes/src/schema/column_schema.rs
  • src/flow/src/adapter/util.rs
  • src/mito2/src/request.rs
  • src/operator/src/expr_factory.rs
  • src/operator/src/insert.rs
  • src/operator/src/req_convert/common.rs
  • src/pipeline/src/etl/transform/transformer/greptime/coerce.rs
  • src/pipeline/src/manager/table.rs
  • src/pipeline/tests/gsub.rs
  • src/pipeline/tests/join.rs
  • src/pipeline/tests/on_failure.rs
  • src/servers/src/prom_row_builder.rs
  • src/sql/src/error.rs
Additional comments not posted (23)
src/api/src/error.rs (1)

61-68: New error variant SerializeJson looks good.

The SerializeJson error variant is correctly added to handle JSON serialization errors. The status_code method is updated accordingly.

src/operator/src/req_convert/insert/stmt_to_region.rs (2)

16-16: New import options_from_column_schema looks good.

The import is necessary for the new functionality and is used correctly to populate the options field in GrpcColumnSchema.


120-120: Addition of options field in GrpcColumnSchema looks good.

The options field is correctly added to the GrpcColumnSchema struct and is populated using options_from_column_schema.

src/metric-engine/src/test_util.rs (1)

248-248: Addition of options field in PbColumnSchema looks good.

The options field is correctly added to the PbColumnSchema struct and is set to None for default values.

Also applies to: 255-255, 264-264

src/metric-engine/src/engine/put.rs (2)

161-161: Addition of options field in ColumnSchema looks good.

The options field is correctly added to the ColumnSchema struct and is set to None for default values.

Also applies to: 169-169


169-169: Updates to fill_internal_columns function look good.

The function correctly handles the new options field, ensuring that internal columns are filled appropriately.

src/mito2/src/test_util.rs (2)

32-32: Import looks good!

The import options_from_column_schema is necessary for the new function column_metadata_to_column_schema.


937-939: New function column_metadata_to_column_schema looks good!

This function correctly converts ColumnMetadata to api::v1::ColumnSchema using the new options_from_column_schema.

src/store-api/src/metadata.rs (5)

24-24: Import looks good!

The import try_as_column_schema is necessary for the function try_from_column_def.


26-26: Import looks good!

The import SemanticType is necessary for the ColumnMetadata struct and its methods.


31-31: Import looks good!

The import ColumnSchema is necessary for the ColumnMetadata struct and its methods.


73-75: Function update looks good!

The update to use try_as_column_schema in the function try_from_column_def ensures correct conversion of RegionColumnDef to ColumnMetadata.


734-740: New error variant ConvertColumnSchema looks good!

This error variant correctly handles errors related to the conversion of column schemas.

src/sql/src/statements.rs (8)

43-45: Imports look good!

The new imports for FulltextAnalyzer, FulltextOptions, COMMENT_KEY, and others are necessary for the added functionality related to full-text indexing.


57-59: Error handling updates are appropriate.

The new error variants FulltextInvalidOptionSnafu and SetFulltextOptionSnafu are necessary for handling errors related to full-text options.


61-64: New exports are appropriate.

The new exports for Column, OptionMap, and transform_statements are necessary for supporting the new functionality related to full-text indexing.


481-481: Addition of the options field in sql_column_def_to_grpc_column_def is appropriate.

The new options field is necessary for passing metadata and configuration through gRPC.


Line range hint 1119-1270:
Test function test_column_to_schema updates are appropriate.

The added test cases ensure that full-text options are correctly handled and applied.


Line range hint 1182-1237:
New test function test_column_to_schema_timestamp_with_timezone is appropriate.

The new test function ensures that timestamp columns with timezones are correctly handled.


1238-1270: New test function test_column_to_schema_with_fulltext is appropriate.

The new test function ensures that columns with full-text options are correctly handled.


Line range hint 361-430:
Review the handling of full-text options in column_to_schema.

The function has been updated to handle full-text options. The logic appears correct, but ensure the following:

  1. The fulltext_options are correctly extracted and applied.
  2. Error handling for invalid options is robust.
  3. The function integrates well with other parts of the codebase.
Verification successful

Review the handling of full-text options in column_to_schema.

The function column_to_schema correctly handles full-text options and integrates well with other parts of the codebase. The presence of the test_column_to_schema_with_fulltext test function ensures that the full-text options are adequately tested.

  • src/sql/src/statements.rs:
    • test_column_to_schema_with_fulltext tests the handling of full-text options.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `column_to_schema` to ensure it integrates well with other parts of the codebase.

# Test: Search for the function usage. Expect: Correct handling of full-text options.
rg --type rust $'column_to_schema'

Length of output: 1166


Script:

#!/bin/bash
# Extract the test functions related to column_to_schema to review their handling of full-text options

# Get the content of test functions from statements.rs
rg --type rust -A 20 'fn test_column_to_schema' src/sql/src/statements.rs

# Get the content of the usage in expr_factory.rs
rg --type rust -A 10 'column_to_schema' src/operator/src/expr_factory.rs

Length of output: 3451

src/api/src/helper.rs (2)

1846-1846: Addition of options field in Column struct.

The options field has been added to the Column struct. Ensure that this field is correctly utilized in all relevant functions and scenarios.


1846-1848: Update in is_column_type_value_eq function.

The function has been updated to include the options field. Ensure that the logic is consistent and correctly handles the options.

Signed-off-by: Zhenchi <zhongzc_arch@outlook.com>
Copy link
Contributor

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d8646c9 and d079159.

Files selected for processing (2)
  • src/sql/src/parsers/create_parser.rs (23 hunks)
  • tests/cases/standalone/common/create/create_with_fulltext.result (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/sql/src/parsers/create_parser.rs
  • tests/cases/standalone/common/create/create_with_fulltext.result

src/api/src/v1/column_def.rs Show resolved Hide resolved
src/common/grpc-expr/src/error.rs Outdated Show resolved Hide resolved
src/sql/src/statements/create.rs Show resolved Hide resolved
src/sql/src/statements.rs Outdated Show resolved Hide resolved
Signed-off-by: Zhenchi <zhongzc_arch@outlook.com>
Copy link
Contributor

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d079159 and af95fd8.

Files selected for processing (5)
  • src/api/src/v1/column_def.rs (2 hunks)
  • src/common/grpc-expr/src/error.rs (3 hunks)
  • src/datatypes/src/schema/column_schema.rs (4 hunks)
  • src/sql/src/statements.rs (12 hunks)
  • src/sql/src/statements/create.rs (3 hunks)
Files skipped from review as they are similar to previous changes (5)
  • src/api/src/v1/column_def.rs
  • src/common/grpc-expr/src/error.rs
  • src/datatypes/src/schema/column_schema.rs
  • src/sql/src/statements.rs
  • src/sql/src/statements/create.rs

Copy link
Contributor

@killme2008 killme2008 left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you.

Signed-off-by: Zhenchi <zhongzc_arch@outlook.com>
@killme2008 killme2008 enabled auto-merge July 8, 2024 20:06
Copy link
Contributor

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between af95fd8 and a24d42e.

Files selected for processing (2)
  • src/api/src/v1/column_def.rs (2 hunks)
  • src/pipeline/src/etl/transform/transformer/greptime/coerce.rs (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/api/src/v1/column_def.rs
  • src/pipeline/src/etl/transform/transformer/greptime/coerce.rs

@killme2008 killme2008 added this pull request to the merge queue Jul 8, 2024
Merged via the queue into GreptimeTeam:main with commit 0030821 Jul 8, 2024
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-not-required This change does not impact docs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants