Skip to content

Commit fc46b36

Browse files
authored
Minor: Add some comments to scalar_udf example (#8576)
* refine example * clippy
1 parent 65b997b commit fc46b36

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

datafusion-examples/examples/simple_udf.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@ use datafusion::{error::Result, physical_plan::functions::make_scalar_function};
2929
use datafusion_common::cast::as_float64_array;
3030
use std::sync::Arc;
3131

32-
// create local execution context with an in-memory table
32+
/// create local execution context with an in-memory table:
33+
///
34+
/// ```text
35+
/// +-----+-----+
36+
/// | a | b |
37+
/// +-----+-----+
38+
/// | 2.1 | 1.0 |
39+
/// | 3.1 | 2.0 |
40+
/// | 4.1 | 3.0 |
41+
/// | 5.1 | 4.0 |
42+
/// +-----+-----+
43+
/// ```
3344
fn create_context() -> Result<SessionContext> {
34-
use datafusion::arrow::datatypes::{Field, Schema};
35-
// define a schema.
36-
let schema = Arc::new(Schema::new(vec![
37-
Field::new("a", DataType::Float32, false),
38-
Field::new("b", DataType::Float64, false),
39-
]));
40-
4145
// define data.
42-
let batch = RecordBatch::try_new(
43-
schema,
44-
vec![
45-
Arc::new(Float32Array::from(vec![2.1, 3.1, 4.1, 5.1])),
46-
Arc::new(Float64Array::from(vec![1.0, 2.0, 3.0, 4.0])),
47-
],
48-
)?;
46+
let a: ArrayRef = Arc::new(Float32Array::from(vec![2.1, 3.1, 4.1, 5.1]));
47+
let b: ArrayRef = Arc::new(Float64Array::from(vec![1.0, 2.0, 3.0, 4.0]));
48+
let batch = RecordBatch::try_from_iter(vec![("a", a), ("b", b)])?;
4949

5050
// declare a new context. In spark API, this corresponds to a new spark SQLsession
5151
let ctx = SessionContext::new();

0 commit comments

Comments
 (0)