NGA-TRAN commented on code in PR #7785:
URL: https://github.com/apache/arrow-datafusion/pull/7785#discussion_r1358380320
##########
datafusion/sql/tests/sql_integration.rs:
##########
@@ -3684,6 +3684,19 @@ fn test_prepare_statement_should_infer_types() {
assert_eq!(actual_types, expected_types);
}
+#[test]
+fn test_non_prepare_statement_should_infer_types() {
+ // Non prepared statements (like SELECT) should also have their parameter
types inferred
+ let sql = "SELECT 1 + $1";
Review Comment:
Nice
##########
datafusion/core/src/dataframe.rs:
##########
@@ -1218,7 +1218,42 @@ impl DataFrame {
Ok(DataFrame::new(self.session_state, project_plan))
}
- /// Convert a prepare logical plan into its inner logical plan with all
params replaced with their corresponding values
+ /// Replace all parameters in logical plan with the specified
+ /// values, in preparation for execution.
+ ///
+ /// # Example
+ ///
+ /// ```
+ /// use datafusion::prelude::*;
+ /// # use datafusion::{error::Result, assert_batches_eq};
+ /// # #[tokio::main]
+ /// # async fn main() -> Result<()> {
+ /// # use datafusion_common::ScalarValue;
+ /// let mut ctx = SessionContext::new();
+ /// # ctx.register_csv("example", "tests/data/example.csv",
CsvReadOptions::new()).await?;
+ /// let results = ctx
+ /// .sql("SELECT a FROM example WHERE b = $1")
+ /// .await?
+ /// // replace $1 with value 2
+ /// .with_param_values(vec![
+ /// // value at index 0 --> $1
+ /// ScalarValue::from(2i64)
+ /// ])?
+ /// .collect()
+ /// .await?;
+ /// assert_batches_eq!(
+ /// &[
+ /// "+---+",
+ /// "| a |",
+ /// "+---+",
+ /// "| 1 |",
+ /// "+---+",
+ /// ],
+ /// &results
+ /// );
+ /// # Ok(())
+ /// # }
+ /// ```
Review Comment:
❤️
##########
datafusion/expr/src/expr_fn.rs:
##########
@@ -80,6 +80,22 @@ pub fn ident(name: impl Into<String>) -> Expr {
Expr::Column(Column::from_name(name))
}
+// Create placeholder value that will be filled in (such as `$1`):
+///
+/// For example:
+///
+/// ```rust
+/// # use datafusion_expr::{placeholder};
Review Comment:
❤️
##########
datafusion/core/src/dataframe.rs:
##########
@@ -1218,7 +1218,42 @@ impl DataFrame {
Ok(DataFrame::new(self.session_state, project_plan))
}
- /// Convert a prepare logical plan into its inner logical plan with all
params replaced with their corresponding values
+ /// Replace all parameters in logical plan with the specified
+ /// values, in preparation for execution.
+ ///
+ /// # Example
+ ///
+ /// ```
+ /// use datafusion::prelude::*;
+ /// # use datafusion::{error::Result, assert_batches_eq};
+ /// # #[tokio::main]
+ /// # async fn main() -> Result<()> {
+ /// # use datafusion_common::ScalarValue;
+ /// let mut ctx = SessionContext::new();
+ /// # ctx.register_csv("example", "tests/data/example.csv",
CsvReadOptions::new()).await?;
+ /// let results = ctx
+ /// .sql("SELECT a FROM example WHERE b = $1")
+ /// .await?
+ /// // replace $1 with value 2
+ /// .with_param_values(vec![
+ /// // value at index 0 --> $1
+ /// ScalarValue::from(2i64)
+ /// ])?
+ /// .collect()
+ /// .await?;
+ /// assert_batches_eq!(
+ /// &[
+ /// "+---+",
+ /// "| a |",
+ /// "+---+",
+ /// "| 1 |",
+ /// "+---+",
+ /// ],
+ /// &results
+ /// );
+ /// # Ok(())
+ /// # }
+ /// ```
Review Comment:
❤️
##########
datafusion/expr/src/expr_fn.rs:
##########
@@ -80,6 +80,22 @@ pub fn ident(name: impl Into<String>) -> Expr {
Expr::Column(Column::from_name(name))
}
+// Create placeholder value that will be filled in (such as `$1`):
+///
+/// For example:
+///
+/// ```rust
+/// # use datafusion_expr::{placeholder};
Review Comment:
❤️
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]