@@ -29,23 +29,23 @@ use datafusion::{error::Result, physical_plan::functions::make_scalar_function};
29
29
use datafusion_common:: cast:: as_float64_array;
30
30
use std:: sync:: Arc ;
31
31
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
+ /// ```
33
44
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
-
41
45
// 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) ] ) ?;
49
49
50
50
// declare a new context. In spark API, this corresponds to a new spark SQLsession
51
51
let ctx = SessionContext :: new ( ) ;
0 commit comments