This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new fc46b36a40 Minor: Add some comments to scalar_udf example (#8576)
fc46b36a40 is described below
commit fc46b36a4078a7fdababfc2d3735e83caf1326f7
Author: Andrew Lamb <[email protected]>
AuthorDate: Mon Dec 18 14:27:32 2023 -0500
Minor: Add some comments to scalar_udf example (#8576)
* refine example
* clippy
---
datafusion-examples/examples/simple_udf.rs | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/datafusion-examples/examples/simple_udf.rs
b/datafusion-examples/examples/simple_udf.rs
index dba4385b8e..5919917865 100644
--- a/datafusion-examples/examples/simple_udf.rs
+++ b/datafusion-examples/examples/simple_udf.rs
@@ -29,23 +29,23 @@ use datafusion::{error::Result,
physical_plan::functions::make_scalar_function};
use datafusion_common::cast::as_float64_array;
use std::sync::Arc;
-// create local execution context with an in-memory table
+/// create local execution context with an in-memory table:
+///
+/// ```text
+/// +-----+-----+
+/// | a | b |
+/// +-----+-----+
+/// | 2.1 | 1.0 |
+/// | 3.1 | 2.0 |
+/// | 4.1 | 3.0 |
+/// | 5.1 | 4.0 |
+/// +-----+-----+
+/// ```
fn create_context() -> Result<SessionContext> {
- use datafusion::arrow::datatypes::{Field, Schema};
- // define a schema.
- let schema = Arc::new(Schema::new(vec![
- Field::new("a", DataType::Float32, false),
- Field::new("b", DataType::Float64, false),
- ]));
-
// define data.
- let batch = RecordBatch::try_new(
- schema,
- vec![
- Arc::new(Float32Array::from(vec![2.1, 3.1, 4.1, 5.1])),
- Arc::new(Float64Array::from(vec![1.0, 2.0, 3.0, 4.0])),
- ],
- )?;
+ let a: ArrayRef = Arc::new(Float32Array::from(vec![2.1, 3.1, 4.1, 5.1]));
+ let b: ArrayRef = Arc::new(Float64Array::from(vec![1.0, 2.0, 3.0, 4.0]));
+ let batch = RecordBatch::try_from_iter(vec![("a", a), ("b", b)])?;
// declare a new context. In spark API, this corresponds to a new spark
SQLsession
let ctx = SessionContext::new();