forked from datafusion-contrib/datafusion-dft
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
111 lines (100 loc) · 3.62 KB
/
main.rs
File metadata and controls
111 lines (100 loc) · 3.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
use clap::Parser;
use color_eyre::Result;
use datafusion_dft::args::Command;
#[cfg(any(feature = "flightsql", feature = "http"))]
use datafusion_dft::server;
use datafusion_dft::{args::DftArgs, cli, config::create_config, tpch, tui};
#[cfg(feature = "http")]
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
fn main() -> Result<()> {
let cli = DftArgs::parse();
// With Runtimes configured correctly the main Tokio runtime should only be used for network
// IO, in which a single thread should be sufficient.
//
// Ref: https://github.com/datafusion-contrib/datafusion-dft/pull/247#discussion_r1848270250
let runtime = tokio::runtime::Builder::new_multi_thread()
.worker_threads(1)
.enable_all()
.build()?;
let entry_point = app_entry_point(cli);
runtime.block_on(entry_point)
}
// TODO: FlightSQL should use tracing
fn should_init_env_logger(cli: &DftArgs) -> bool {
#[cfg(feature = "flightsql")]
if let Some(Command::ServeFlightSql { .. }) = cli.command {
return true;
}
if let Some(Command::GenerateTpch { .. }) = cli.command {
return true;
}
if !cli.files.is_empty() || !cli.commands.is_empty() {
return true;
}
false
}
async fn app_entry_point(cli: DftArgs) -> Result<()> {
if should_init_env_logger(&cli) {
env_logger::init();
}
let cfg = create_config(cli.config_path());
if let Some(Command::GenerateTpch {
scale_factor,
format,
}) = cli.command
{
tpch::generate(cfg.clone(), scale_factor, format).await?;
return Ok(());
}
#[cfg(feature = "flightsql")]
{
if matches!(cli.command, Some(Command::FlightSql { .. })) {
cli::try_run(cli, cfg).await?;
return Ok(());
} else if let Some(Command::ServeFlightSql { .. }) = cli.command {
server::flightsql::try_run(cli.clone(), cfg.clone()).await?;
return Ok(());
}
}
#[cfg(feature = "http")]
{
if let Some(Command::ServeHttp { .. }) = cli.command {
tracing_subscriber::registry()
.with(
tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| {
format!(
"{}=debug,tower_http=debug,axum=trace",
env!("CARGO_CRATE_NAME")
)
.into()
}),
)
.with(tracing_subscriber::fmt::layer().without_time())
.init();
server::http::try_run(cli.clone(), cfg.clone()).await?;
return Ok(());
}
}
if !cli.files.is_empty() || !cli.commands.is_empty() {
cli::try_run(cli, cfg).await?;
} else {
tui::try_run(cli, cfg).await?;
}
Ok(())
}