datafusion_dft/execution/
mod.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18pub mod executor;
19#[cfg(feature = "flightsql")]
20pub mod flightsql;
21#[cfg(feature = "flightsql")]
22pub mod flightsql_benchmarks;
23pub mod local;
24pub mod sql_utils;
25pub mod stats;
26
27pub mod local_benchmarks;
28
29pub use stats::{collect_plan_io_stats, ExecutionStats};
30
31#[cfg(feature = "flightsql")]
32use self::flightsql::{FlightSQLClient, FlightSQLContext};
33use self::local::ExecutionContext;
34use datafusion::prelude::*;
35
36pub enum AppType {
37    Cli,
38    Tui,
39    FlightSQLServer,
40}
41
42/// Provides all core execution functionality for execution queries from either a local
43/// `SessionContext` or a remote `FlightSQL` service
44pub struct AppExecution {
45    context: ExecutionContext,
46    #[cfg(feature = "flightsql")]
47    flightsql_context: FlightSQLContext,
48}
49
50impl AppExecution {
51    pub fn new(context: ExecutionContext) -> Self {
52        Self {
53            context,
54            #[cfg(feature = "flightsql")]
55            flightsql_context: FlightSQLContext::default(),
56        }
57    }
58
59    pub fn execution_ctx(&self) -> &ExecutionContext {
60        &self.context
61    }
62
63    pub fn session_ctx(&self) -> &SessionContext {
64        self.context.session_ctx()
65    }
66
67    #[cfg(feature = "flightsql")]
68    pub fn flightsql_client(&self) -> &FlightSQLClient {
69        self.flightsql_context.client()
70    }
71
72    #[cfg(feature = "flightsql")]
73    pub fn flightsql_ctx(&self) -> &FlightSQLContext {
74        &self.flightsql_context
75    }
76
77    #[cfg(feature = "flightsql")]
78    pub fn with_flightsql_ctx(&mut self, flightsql_ctx: FlightSQLContext) {
79        self.flightsql_context = flightsql_ctx;
80    }
81}