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

fix(query): tuple field name can not contain special char #15126

Merged
merged 2 commits into from
Mar 31, 2024

Conversation

TCeason
Copy link
Collaborator

@TCeason TCeason commented Mar 29, 2024

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

This bug maybe cause session panic:

create table t(d tuple("A-a" int, b int));

panicked at src/query/ast/src/parser/parser.rs:67:13:

SyntaxException. Code: 1005, Text = error: 
  --> SQL:1:27
  |
1 | CREATE TABLE tc (d TUPLE(A-a Int32, b Int32))
  | ------           - -----  ^ unexpected `-`, expecting `BOOLEAN`, `BOOL`, `UINT8`, `TINYINT`, `UINT16`, `SMALLINT`, `UINT32`, `INT`, `INTEGER`, `UINT64`, `UNSIGNED`, `BIGINT`, `INT8`, `INT16`, `INT32`, `INT64`, `SIGNED`, `FLOAT32`, `FLOAT`, `FLOAT64`, `DOUBLE`, `DECIMAL`, `ARRAY`, `MAP`, `BITMAP`, `TUPLE`, `DATE`, `DATETIME`, `TIMESTAMP`, `BINARY`, `VARBINARY`, `LONGBLOB`, `MEDIUMBLOB`, `TINYBLOB`, `BLOB`, `STRING`, `VARCHAR`, `CHAR`, `CHARACTER`, `TEXT`, `VARIANT`, `JSON`, `GEOMETRY`, or `NULLABLE`
  | |                | |       
  | |                | while parsing TUPLE(<name> <type>, ...)
  | |                | while parsing type name
  | |                while parsing `<column name> <type> [DEFAULT <expr>] [AS (<expr>) VIRTUAL] [AS (<expr>) STORED] [COMMENT '<comment>']`
  | while parsing `CREATE [OR REPLACE] TABLE [IF NOT EXISTS] [<database>.]<table> [<source>] [<table_options>]`

Modify

Modify tuple type parser.

Add a check, if tuple filed name contain char that is not alphanumeric characters, will directly return error.

Tests

  • Unit Test

Type of change

  • Bug Fix (non-breaking change which fixes an issue)

@TCeason TCeason requested a review from b41sh March 29, 2024 07:40
@github-actions github-actions bot added the pr-bugfix this PR patches a bug in codebase label Mar 29, 2024
@TCeason TCeason requested a review from andylokandy March 29, 2024 07:40
Copy link

what-the-diff bot commented Mar 29, 2024

PR Summary

  • Validation Added in expr.rs for Field Names
    Introduced validation for tuple field names to permit only alphanumeric characters for better consistency and accuracy in data handling.

  • New Test Case in parser.rs
    Implemented a new test case to verify the functionality of creating a table where tuple fields include non-alphanumeric characters. This will help ensure the robustness of our table creation functionality.

  • Error Messages Updated in statement-error.txt
    Enhanced error reporting by adding a specific error message and highlighting for invalid tuple field names when attempting to create a new table. This improvement will make troubleshooting easier and more intuitive.

@BohuTANG BohuTANG merged commit 4e894ae into databendlabs:main Mar 31, 2024
72 checks passed
.iter()
.any(|field_name| !field_name.chars().all(|c| c.is_ascii_alphanumeric()))
{
return Err(nom::Err::Error(ErrorKind::Other(
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using failure:

Suggested change
return Err(nom::Err::Error(ErrorKind::Other(
return Err(nom::Err::Failure(ErrorKind::Other(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-bugfix this PR patches a bug in codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: tuple field with special char will cause session panic
4 participants