MCPcopy Create free account
hub / github.com/apache/datafusion / test_read_batches

Function test_read_batches

datafusion/core/tests/dataframe/mod.rs:4951–5005  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4949
4950#[tokio::test]
4951async fn test_read_batches() -> Result<()> {
4952 let config = SessionConfig::new();
4953 let runtime = Arc::new(RuntimeEnv::default());
4954 let state = SessionStateBuilder::new()
4955 .with_config(config)
4956 .with_runtime_env(runtime)
4957 .with_default_features()
4958 .build();
4959 let ctx = SessionContext::new_with_state(state);
4960
4961 let schema = Arc::new(Schema::new(vec![
4962 Field::new("id", DataType::Int32, false),
4963 Field::new("number", DataType::Float32, false),
4964 ]));
4965
4966 let batches = vec![
4967 RecordBatch::try_new(
4968 schema.clone(),
4969 vec![
4970 Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5])),
4971 Arc::new(Float32Array::from(vec![1.12, 3.40, 2.33, 9.10, 6.66])),
4972 ],
4973 )
4974 .unwrap(),
4975 RecordBatch::try_new(
4976 schema.clone(),
4977 vec![
4978 Arc::new(Int32Array::from(vec![3, 4, 5])),
4979 Arc::new(Float32Array::from(vec![1.11, 2.22, 3.33])),
4980 ],
4981 )
4982 .unwrap(),
4983 ];
4984 let df = ctx.read_batches(batches).unwrap();
4985 df.clone().show().await.unwrap();
4986 let results = df.collect().await?;
4987 assert_snapshot!(
4988 batches_to_sort_string(&results),
4989 @r"
4990 +----+--------+
4991 | id | number |
4992 +----+--------+
4993 | 1 | 1.12 |
4994 | 2 | 3.4 |
4995 | 3 | 1.11 |
4996 | 3 | 2.33 |
4997 | 4 | 2.22 |
4998 | 4 | 9.1 |
4999 | 5 | 3.33 |
5000 | 5 | 6.66 |
5001 +----+--------+
5002 "
5003 );
5004 Ok(())
5005}
5006#[tokio::test]
5007async fn test_read_batches_empty() -> Result<()> {
5008 let config = SessionConfig::new();

Callers

nothing calls this directly

Calls 9

newFunction · 0.85
with_default_featuresMethod · 0.80
read_batchesMethod · 0.80
showMethod · 0.80
collectMethod · 0.80
buildMethod · 0.45
with_runtime_envMethod · 0.45
with_configMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…