You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "aharpervc (via GitHub)" <gi...@apache.org> on 2025/09/19 21:41:00 UTC

[PR] Add support for procedure parameter default values [datafusion-sqlparser-rs]

aharpervc opened a new pull request, #2041:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2041

   For example, this now parses appropriately:
   
   ```sql
   create procedure test_proc (a int = 42)
   ...
   ```
   
   Syntax documentation reference: https://learn.microsoft.com/en-us/sql/t-sql/statements/create-procedure-transact-sql?view=sql-server-ver17#e-use-a-procedure-with-wildcard-parameters. This is the syntax used by SQL Server, but I've implemented this as a "normal" Option property of the ProcedureParam struct.
   
   I also added a corresponding common unit test


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Add support for procedure parameter default values [datafusion-sqlparser-rs]

Posted by "aharpervc (via GitHub)" <gi...@apache.org>.
aharpervc commented on code in PR #2041:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2041#discussion_r2382773376


##########
tests/sqlparser_common.rs:
##########
@@ -16533,6 +16537,40 @@ fn parse_create_procedure_with_parameter_modes() {
     }
 }
 
+#[test]
+fn create_procedure_with_parameter_default_value() {

Review Comment:
   Hm, I don't understand. A parameter can be in/out and still have/not have a default, right? Are you suggesting like
   
   ```diff
   pub enum ArgMode {
     In,
     Out,
     InOut,
   + InWithDefault(Expr),
   + OutWithDefault(Expr),
   + InOutWithDefault(Expr),
   }
   ```
   
   Perhaps I'm not understanding



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Add support for procedure parameter default values [datafusion-sqlparser-rs]

Posted by "iffyio (via GitHub)" <gi...@apache.org>.
iffyio merged PR #2041:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2041


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Add support for procedure parameter default values [datafusion-sqlparser-rs]

Posted by "aharpervc (via GitHub)" <gi...@apache.org>.
aharpervc commented on code in PR #2041:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2041#discussion_r2406489489


##########
tests/sqlparser_common.rs:
##########
@@ -16533,6 +16537,40 @@ fn parse_create_procedure_with_parameter_modes() {
     }
 }
 
+#[test]
+fn create_procedure_with_parameter_default_value() {

Review Comment:
   Oh yes, I understand now 👍 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Add support for procedure parameter default values [datafusion-sqlparser-rs]

Posted by "iffyio (via GitHub)" <gi...@apache.org>.
iffyio commented on code in PR #2041:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2041#discussion_r2382550074


##########
tests/sqlparser_common.rs:
##########
@@ -16533,6 +16537,40 @@ fn parse_create_procedure_with_parameter_modes() {
     }
 }
 
+#[test]
+fn create_procedure_with_parameter_default_value() {
+    let sql = r#"CREATE PROCEDURE test_proc (a INT = 42) AS BEGIN SELECT 1; END"#;

Review Comment:
   Can we add scenarios demonstrating
   - multiple paramenters having defaults (i.e. `(a INT= 42, b INT=43)`)
   - parameters that include a `mode`



##########
tests/sqlparser_common.rs:
##########
@@ -16533,6 +16537,40 @@ fn parse_create_procedure_with_parameter_modes() {
     }
 }
 
+#[test]
+fn create_procedure_with_parameter_default_value() {

Review Comment:
   Can we merge the test into the existing `parse_create_procedure_with_parameter_modes`? since they cover the same feature



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Add support for procedure parameter default values [datafusion-sqlparser-rs]

Posted by "aharpervc (via GitHub)" <gi...@apache.org>.
aharpervc commented on code in PR #2041:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2041#discussion_r2406487800


##########
tests/sqlparser_common.rs:
##########
@@ -16533,6 +16537,74 @@ fn parse_create_procedure_with_parameter_modes() {
     }
 }
 
+#[test]
+fn create_procedure_with_parameter_default_value() {
+    let sql = r#"CREATE PROCEDURE test_proc (IN a INTEGER = 1, OUT b TEXT = '2', INOUT c TIMESTAMP = NULL, d BOOL = 0) AS BEGIN SELECT 1; END"#;
+    match verified_stmt(sql) {
+        Statement::CreateProcedure {
+            or_alter,
+            name,
+            params,
+            ..
+        } => {
+            assert_eq!(or_alter, false);
+            assert_eq!(name.to_string(), "test_proc");
+            let fake_span = Span {
+                start: Location { line: 0, column: 0 },
+                end: Location { line: 0, column: 0 },
+            };
+            assert_eq!(
+                params,
+                Some(vec![
+                    ProcedureParam {
+                        name: Ident {
+                            value: "a".into(),
+                            quote_style: None,
+                            span: fake_span,
+                        },

Review Comment:
   Yes, certainly. I did it this way because that's how the similar modes test did it, but I will simplify



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Add support for procedure parameter default values [datafusion-sqlparser-rs]

Posted by "aharpervc (via GitHub)" <gi...@apache.org>.
aharpervc commented on code in PR #2041:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2041#discussion_r2382828381


##########
tests/sqlparser_common.rs:
##########
@@ -16533,6 +16537,40 @@ fn parse_create_procedure_with_parameter_modes() {
     }
 }
 
+#[test]
+fn create_procedure_with_parameter_default_value() {
+    let sql = r#"CREATE PROCEDURE test_proc (a INT = 42) AS BEGIN SELECT 1; END"#;

Review Comment:
   Done 👍. I've also added an additional unit test for SQL Server, since the parameter identifier syntax is different there.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Add support for procedure parameter default values [datafusion-sqlparser-rs]

Posted by "iffyio (via GitHub)" <gi...@apache.org>.
iffyio commented on code in PR #2041:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2041#discussion_r2403803588


##########
tests/sqlparser_mssql.rs:
##########
@@ -198,6 +200,12 @@ fn parse_mssql_create_procedure() {
     let _ = ms().verified_stmt("CREATE PROCEDURE [foo] AS BEGIN UPDATE bar SET col = 'test'; SELECT [foo] FROM BAR WHERE [FOO] > 10; END");
 }
 
+#[test]
+fn parse_mssql_create_procedure_with_parameter_default_value() {
+    let sql = r#"CREATE PROCEDURE foo (IN @a INTEGER = 1, OUT @b TEXT = '2', INOUT @c DATETIME = NULL, @d BOOL = 0) AS BEGIN SELECT 1; END"#;
+    let _ = ms().verified_stmt(sql);
+}

Review Comment:
   Similar comment here that we can inline this scenario into the `parse_mssql_create_procedure` function above



##########
tests/sqlparser_common.rs:
##########
@@ -16533,6 +16537,74 @@ fn parse_create_procedure_with_parameter_modes() {
     }
 }
 
+#[test]
+fn create_procedure_with_parameter_default_value() {
+    let sql = r#"CREATE PROCEDURE test_proc (IN a INTEGER = 1, OUT b TEXT = '2', INOUT c TIMESTAMP = NULL, d BOOL = 0) AS BEGIN SELECT 1; END"#;
+    match verified_stmt(sql) {
+        Statement::CreateProcedure {
+            or_alter,
+            name,
+            params,
+            ..
+        } => {
+            assert_eq!(or_alter, false);
+            assert_eq!(name.to_string(), "test_proc");
+            let fake_span = Span {
+                start: Location { line: 0, column: 0 },
+                end: Location { line: 0, column: 0 },
+            };
+            assert_eq!(
+                params,
+                Some(vec![
+                    ProcedureParam {
+                        name: Ident {
+                            value: "a".into(),
+                            quote_style: None,
+                            span: fake_span,
+                        },

Review Comment:
   ```suggestion
                           name: Ident::new("a"),
   ```
   I think this can be simplified? that would let us skip introducing the fake span as well



##########
tests/sqlparser_common.rs:
##########
@@ -16533,6 +16537,40 @@ fn parse_create_procedure_with_parameter_modes() {
     }
 }
 
+#[test]
+fn create_procedure_with_parameter_default_value() {

Review Comment:
   Ah no I meant to only inline this test case into that `parse_create_procedure_with_parameter_modes` function vs having one function per test case



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [PR] Add support for procedure parameter default values [datafusion-sqlparser-rs]

Posted by "aharpervc (via GitHub)" <gi...@apache.org>.
aharpervc commented on code in PR #2041:
URL: https://github.com/apache/datafusion-sqlparser-rs/pull/2041#discussion_r2406506480


##########
tests/sqlparser_mssql.rs:
##########
@@ -198,6 +200,12 @@ fn parse_mssql_create_procedure() {
     let _ = ms().verified_stmt("CREATE PROCEDURE [foo] AS BEGIN UPDATE bar SET col = 'test'; SELECT [foo] FROM BAR WHERE [FOO] > 10; END");
 }
 
+#[test]
+fn parse_mssql_create_procedure_with_parameter_default_value() {
+    let sql = r#"CREATE PROCEDURE foo (IN @a INTEGER = 1, OUT @b TEXT = '2', INOUT @c DATETIME = NULL, @d BOOL = 0) AS BEGIN SELECT 1; END"#;
+    let _ = ms().verified_stmt(sql);
+}

Review Comment:
   Done 👍 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org