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

Method create_ctx

datafusion-examples/examples/flight/sql_server.rs:98–121  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

96
97impl FlightSqlServiceImpl {
98 async fn create_ctx(&self) -> Result<String, Status> {
99 let uuid = Uuid::new_v4().hyphenated().to_string();
100 let session_config = SessionConfig::from_env()
101 .map_err(|e| Status::internal(format!("Error building plan: {e}")))?
102 .with_information_schema(true);
103 let ctx = Arc::new(SessionContext::new_with_config(session_config));
104
105 // Convert the CSV input into a temporary Parquet directory for querying
106 let dataset = ExampleDataset::Cars;
107 let parquet_temp = write_csv_to_parquet(&ctx, &dataset.path())
108 .await
109 .map_err(|e| status!("Error writing csv to parquet", e))?;
110 let parquet_path = parquet_temp
111 .path_str()
112 .map_err(|e| status!("Error getting parquet path", e))?;
113
114 // register parquet file with the execution context
115 ctx.register_parquet("cars", parquet_path, ParquetReadOptions::default())
116 .await
117 .map_err(|e| status!("Error registering table", e))?;
118
119 self.contexts.insert(uuid.clone(), ctx);
120 Ok(uuid)
121 }
122
123 fn get_ctx<T>(&self, req: &Request<T>) -> Result<Arc<SessionContext>, Status> {
124 // get the token from the authorization header on Request

Callers 1

do_handshakeMethod · 0.80

Calls 10

from_envFunction · 0.85
newFunction · 0.85
write_csv_to_parquetFunction · 0.85
to_stringMethod · 0.45
pathMethod · 0.45
path_strMethod · 0.45
register_parquetMethod · 0.45
insertMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected