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

Function query_memtable

datafusion-examples/examples/sql_ops/query.rs:45–80  ·  view source on GitHub ↗

Run a simple query against a [`MemTable`]

()

Source from the content-addressed store, hash-verified

43
44/// Run a simple query against a [`MemTable`]
45pub async fn query_memtable() -> Result<()> {
46 let mem_table = create_memtable()?;
47
48 // create local execution context
49 let ctx = SessionContext::new();
50
51 // Register the in-memory table containing the data
52 ctx.register_table("users", Arc::new(mem_table))?;
53
54 // running a SQL query results in a "DataFrame", which can be used
55 // to execute the query and collect the results
56 let dataframe = ctx.sql("SELECT * FROM users;").await?;
57
58 // Calling 'show' on the dataframe will execute the query and
59 // print the results
60 dataframe.clone().show().await?;
61
62 // calling 'collect' on the dataframe will execute the query and
63 // buffer the results into a vector of RecordBatch. There are other
64 // APIs on DataFrame for incrementally generating results (e.g. streaming)
65 let result = dataframe.collect().await?;
66
67 // Use the assert_batches_eq macro to compare the results
68 assert_batches_eq!(
69 [
70 "+----+--------------+",
71 "| id | bank_account |",
72 "+----+--------------+",
73 "| 1 | 9000 |",
74 "+----+--------------+",
75 ],
76 &result
77 );
78
79 Ok(())
80}
81
82fn create_memtable() -> Result<MemTable> {
83 MemTable::try_new(get_schema(), vec![vec![create_record_batch()?]])

Callers 1

queryFunction · 0.85

Calls 7

newFunction · 0.85
sqlMethod · 0.80
showMethod · 0.80
collectMethod · 0.80
create_memtableFunction · 0.70
register_tableMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…