From 21c2f1128dd968e11470d0dfbe8a6ed09c66cfed Mon Sep 17 00:00:00 2001 From: Yang Xiufeng Date: Mon, 21 Jul 2025 20:10:43 +0800 Subject: [PATCH] fix: insert_stmt allow `;` at the end. --- src/query/ast/src/parser/statement.rs | 4 ++-- .../09_0002_sql_ends_semicolon.result | 10 ++++++++++ .../09_http_handler/09_0002_sql_ends_semicolon.sh | 14 ++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100755 tests/suites/1_stateful/09_http_handler/09_0002_sql_ends_semicolon.result create mode 100755 tests/suites/1_stateful/09_http_handler/09_0002_sql_ends_semicolon.sh diff --git a/src/query/ast/src/parser/statement.rs b/src/query/ast/src/parser/statement.rs index cef4e684a80b..93724d035976 100644 --- a/src/query/ast/src/parser/statement.rs +++ b/src/query/ast/src/parser/statement.rs @@ -2989,9 +2989,9 @@ pub fn insert_source_file(i: Input) -> IResult { ); map( rule! { - (VALUES ~ #value?)? ~ FROM ~ #at_string ~ #file_format_clause + (VALUES ~ #value?)? ~ FROM ~ #at_string ~ #file_format_clause ~ ";"? ~ &EOI }, - |(values, _, location, format_options)| InsertSource::LoadFile { + |(values, _, location, format_options, _, _)| InsertSource::LoadFile { value: values.map(|(_, value)| value).unwrap_or_default(), location, format_options, diff --git a/tests/suites/1_stateful/09_http_handler/09_0002_sql_ends_semicolon.result b/tests/suites/1_stateful/09_http_handler/09_0002_sql_ends_semicolon.result new file mode 100755 index 000000000000..c25948b90855 --- /dev/null +++ b/tests/suites/1_stateful/09_http_handler/09_0002_sql_ends_semicolon.result @@ -0,0 +1,10 @@ +>>>> create or replace table t_09_0002 (a int) +<<<< +"Succeeded" +null +"Succeeded" +null +"Succeeded" +null +"Succeeded" +null diff --git a/tests/suites/1_stateful/09_http_handler/09_0002_sql_ends_semicolon.sh b/tests/suites/1_stateful/09_http_handler/09_0002_sql_ends_semicolon.sh new file mode 100755 index 000000000000..f37f7e90c22c --- /dev/null +++ b/tests/suites/1_stateful/09_http_handler/09_0002_sql_ends_semicolon.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +. "$CURDIR"/../../../shell_env.sh + +query "create or replace table t_09_0002 (a int)" + +# insert_stmt +curl -s --header 'Content-Type: application/json' --request POST '127.0.0.1:8000/v1/query/' --data-raw '{"sql": "insert into t_09_0002 from @~/not_exist file_format=(type=csv);", "pagination": { "wait_time_secs": 5}}' -u root: | jq -c ".state",".error" +curl -s --header 'Content-Type: application/json' --request POST '127.0.0.1:8000/v1/query/' --data-raw '{"sql": "insert into t_09_0002 select 1;", "pagination": { "wait_time_secs": 5}}' -u root: | jq -c ".state",".error" +curl -s --header 'Content-Type: application/json' --request POST '127.0.0.1:8000/v1/query/' --data-raw '{"sql": "insert into t_09_0002 values (1);", "pagination": { "wait_time_secs": 5}}' -u root: | jq -c ".state",".error" + +# statement +curl -s --header 'Content-Type: application/json' --request POST '127.0.0.1:8000/v1/query/' --data-raw '{"sql": "select 1;", "pagination": { "wait_time_secs": 2}}' -u root: | jq -c ".state",".error"