@@ -2605,7 +2605,7 @@ pub fn statement_body(i: Input) -> IResult<Statement> {
26052605 rule ! (
26062606 #conditional_multi_table_insert( ) : "`INSERT [OVERWRITE] {FIRST|ALL} { WHEN <condition> THEN intoClause [ ... ] } [ ... ] [ ELSE intoClause ] <subquery>`"
26072607 | #unconditional_multi_table_insert( ) : "`INSERT [OVERWRITE] ALL intoClause [ ... ] <subquery>`"
2608- | #insert_stmt( false ) : "`INSERT INTO [TABLE] <table> [(<column>, ...)] (FORMAT <format> | VALUES <values> | <query>)`"
2608+ | #insert_stmt( false , false ) : "`INSERT INTO [TABLE] <table> [(<column>, ...)] (VALUES <values> | <query>)`"
26092609 | #replace_stmt( false ) : "`REPLACE INTO [TABLE] <table> [(<column>, ...)] (FORMAT <format> | VALUES <values> | <query>)`"
26102610 | #merge : "`MERGE INTO <target_table> USING <source> ON <join_expr> { matchedClause | notMatchedClause } [ ... ]`"
26112611 | #delete : "`DELETE FROM <table> [WHERE ...]`"
@@ -2798,10 +2798,15 @@ pub fn parse_create_option(
27982798 }
27992799}
28002800
2801- pub fn insert_stmt ( allow_raw : bool ) -> impl FnMut ( Input ) -> IResult < Statement > {
2801+ pub fn insert_stmt (
2802+ allow_raw : bool ,
2803+ in_streaming_load : bool ,
2804+ ) -> impl FnMut ( Input ) -> IResult < Statement > {
28022805 move |i| {
2803- let insert_source_parser = if allow_raw {
2804- raw_insert_source
2806+ let insert_source_parser = if in_streaming_load {
2807+ insert_source_file
2808+ } else if allow_raw {
2809+ insert_source_fast_values
28052810 } else {
28062811 insert_source
28072812 } ;
@@ -2935,7 +2940,7 @@ fn else_clause(i: Input) -> IResult<ElseClause> {
29352940pub fn replace_stmt ( allow_raw : bool ) -> impl FnMut ( Input ) -> IResult < Statement > {
29362941 move |i| {
29372942 let insert_source_parser = if allow_raw {
2938- raw_insert_source
2943+ insert_source_fast_values
29392944 } else {
29402945 insert_source
29412946 } ;
@@ -3005,20 +3010,38 @@ pub fn insert_source(i: Input) -> IResult<InsertSource> {
30053010 ) ( i)
30063011}
30073012
3008- // `INSERT INTO ... VALUES` statement will
3009- // stop the parser immediately and return the rest tokens in `InsertSource`.
3010- //
3011- // This is a hack to parse large insert statements.
3012- pub fn raw_insert_source ( i : Input ) -> IResult < InsertSource > {
3013- let streaming = map (
3013+ pub fn insert_source_file ( i : Input ) -> IResult < InsertSource > {
3014+ let value = map (
30143015 rule ! {
3015- #file_format_clause ~ ( ON_ERROR ~ ^ "=" ~ ^#ident ) ?
3016+ "(" ~ #comma_separated_list1 ( expr ) ~ ")"
30163017 } ,
3017- |( options, on_error_opt) | InsertSource :: StreamingLoad {
3018+ |( _, values, _) | values,
3019+ ) ;
3020+ map (
3021+ rule ! {
3022+ VALUES ~ #value? ~ #file_format_clause ~ ( ON_ERROR ~ ^"=" ~ ^#ident) ?
3023+ } ,
3024+ |( _, value, options, on_error_opt) | InsertSource :: StreamingLoad {
30183025 format_options : options,
30193026 on_error_mode : on_error_opt. map ( |v| v. 2 . to_string ( ) ) ,
3027+ value,
30203028 } ,
3021- ) ;
3029+ ) ( i)
3030+ // TODO: support query later
3031+ // let query = map(query, |query| InsertSource::Select {
3032+ // query: Box::new(query),
3033+ // });
3034+ // rule!(
3035+ // #file
3036+ // | #query
3037+ // )(i)
3038+ }
3039+
3040+ // `INSERT INTO ... VALUES` statement will
3041+ // stop the parser immediately and return the rest tokens in `InsertSource`.
3042+ //
3043+ // This is a hack to parse large insert statements.
3044+ pub fn insert_source_fast_values ( i : Input ) -> IResult < InsertSource > {
30223045 let values = map (
30233046 rule ! {
30243047 VALUES ~ #rest_str
@@ -3037,7 +3060,6 @@ pub fn raw_insert_source(i: Input) -> IResult<InsertSource> {
30373060 rule ! (
30383061 #values
30393062 | #query
3040- | #streaming
30413063 ) ( i)
30423064}
30433065
0 commit comments