From 38cae32439a54dd7412d89a82340b56043625170 Mon Sep 17 00:00:00 2001 From: ClSlaid Date: Wed, 21 Sep 2022 16:17:23 +0800 Subject: [PATCH] fix: name scheme with port number Signed-off-by: ClSlaid --- src/query/ast/src/parser/statement.rs | 10 ++- src/query/ast/tests/it/parser.rs | 4 ++ src/query/ast/tests/it/testdata/statement.txt | 72 +++++++++++++++++++ 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/src/query/ast/src/parser/statement.rs b/src/query/ast/src/parser/statement.rs index 9d84c5e2b96a..74fcc674d999 100644 --- a/src/query/ast/src/parser/statement.rs +++ b/src/query/ast/src/parser/statement.rs @@ -1425,8 +1425,14 @@ pub fn uri_location(i: Input) -> IResult { protocol: parsed.scheme().to_string(), name: parsed .host_str() - .ok_or(ErrorKind::Other("invalid uri location"))? - .to_string(), + .map(|hostname| { + if let Some(port) = parsed.port() { + format!("{}:{}", hostname, port) + } else { + hostname.to_string() + } + }) + .ok_or(ErrorKind::Other("invalid uri location"))?, path: if parsed.path().is_empty() { "/".to_string() } else { diff --git a/src/query/ast/tests/it/parser.rs b/src/query/ast/tests/it/parser.rs index 5e42b8f21df6..13af9d0a66fe 100644 --- a/src/query/ast/tests/it/parser.rs +++ b/src/query/ast/tests/it/parser.rs @@ -190,6 +190,10 @@ fn test_statement() { skip_header = 1 ) size_limit=10;"#, + r#"COPY INTO mytable + FROM 'https://127.0.0.1:9900';"#, + r#"COPY INTO mytable + FROM 'https://127.0.0.1:';"#, r#"COPY INTO mytable FROM @my_stage FILE_FORMAT = ( diff --git a/src/query/ast/tests/it/testdata/statement.txt b/src/query/ast/tests/it/testdata/statement.txt index 0cf249e634bd..25c91e83ee74 100644 --- a/src/query/ast/tests/it/testdata/statement.txt +++ b/src/query/ast/tests/it/testdata/statement.txt @@ -5600,6 +5600,78 @@ Copy( ) +---------- Input ---------- +COPY INTO mytable + FROM 'https://127.0.0.1:9900'; +---------- Output --------- +COPY INTO mytable FROM 'https://127.0.0.1:9900/' PURGE = false FORCE = false +---------- AST ------------ +Copy( + CopyStmt { + src: UriLocation( + UriLocation { + protocol: "https", + name: "127.0.0.1:9900", + path: "/", + connection: {}, + }, + ), + dst: Table { + catalog: None, + database: None, + table: Identifier { + name: "mytable", + quote: None, + span: Ident(10..17), + }, + }, + files: [], + pattern: "", + file_format: {}, + validation_mode: "", + size_limit: 0, + purge: false, + force: false, + }, +) + + +---------- Input ---------- +COPY INTO mytable + FROM 'https://127.0.0.1:'; +---------- Output --------- +COPY INTO mytable FROM 'https://127.0.0.1/' PURGE = false FORCE = false +---------- AST ------------ +Copy( + CopyStmt { + src: UriLocation( + UriLocation { + protocol: "https", + name: "127.0.0.1", + path: "/", + connection: {}, + }, + ), + dst: Table { + catalog: None, + database: None, + table: Identifier { + name: "mytable", + quote: None, + span: Ident(10..17), + }, + }, + files: [], + pattern: "", + file_format: {}, + validation_mode: "", + size_limit: 0, + purge: false, + force: false, + }, +) + + ---------- Input ---------- COPY INTO mytable FROM @my_stage