Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add command for running glaredb locally #1012

Merged
merged 4 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 125 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions crates/glaredb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ path = "src/bin/main.rs"
logutil = {path = "../logutil"}
sqlexec = {path = "../sqlexec"}
telemetry = {path = "../telemetry"}
datafusion = {workspace = true}
pgsrv = {path = "../pgsrv"}
pgrepr = {path = "../pgrepr"}
object_store = {version = "0.5", features = ["gcp"]}
metastore = {path = "../metastore"}
anyhow = "1.0"
Expand All @@ -20,3 +22,6 @@ clap = { version = "4.2.7", features = ["derive"] }
tracing = "0.1"
uuid = { version = "1.3.3", features = ["v4", "fast-rng", "macro-diagnostics"] }
tonic = { version = "0.9", features = ["transport", "tls", "tls-roots"] }
rustyline = "11.0.0"
once_cell = "1.17.1"
futures = "0.3.28"
60 changes: 53 additions & 7 deletions crates/glaredb/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::{anyhow, Result};
use clap::{Parser, Subcommand};
use glaredb::local::LocalEngine;
use glaredb::metastore::Metastore;
use glaredb::proxy::Proxy;
use glaredb::server::{Server, ServerConfig};
Expand Down Expand Up @@ -33,6 +34,31 @@ struct Cli {

#[derive(Subcommand)]
enum Commands {
/// Starts a local version of GlareDB.
Local {
/// Address to the Metastore.
///
/// If not provided, an in-process metastore will be started.
#[clap(short, long, value_parser)]
metastore_addr: Option<String>,

/// Path to spill temporary files to.
#[clap(long, value_parser)]
spill_path: Option<PathBuf>,

/// Local file path to store database catalog (for a local persistent
/// store).
#[clap(short = 'f', long, value_parser)]
local_file_path: Option<PathBuf>,

/// Execute a query, exiting upon completion.
///
/// Multiple statements may be provided, and results will be printed out
/// one after another.
#[clap(short, long, value_parser)]
query: Option<String>,
},

/// Starts the sql server portion of GlareDB.
Server {
/// TCP address to bind to.
Expand All @@ -59,7 +85,7 @@ enum Commands {
/// Optional file path to store metastore data (to enable persistent
/// data storage when in-process store is launched).
#[clap(short = 'f', long, value_parser)]
local_file_path: Option<String>,
local_file_path: Option<PathBuf>,

/// API key for segment.
#[clap(long, value_parser)]
Expand Down Expand Up @@ -110,17 +136,39 @@ enum Commands {
/// Local file path to store database catalog (for a local persistent
/// store).
#[clap(short = 'f', long, value_parser)]
local_file_path: Option<String>,
local_file_path: Option<PathBuf>,
},
}

fn main() -> Result<()> {
let cli = Cli::parse();
logutil::init(cli.verbose, cli.json_logging);

// Disable logging when running locally since it'll clobber the repl
// _unless_ the user specified a logging related option.
match (&cli.command, cli.json_logging, cli.verbose) {
(Commands::Local { .. }, false, 0) => (),
_ => logutil::init(cli.verbose, cli.json_logging),
}

info!(version = env!("CARGO_PKG_VERSION"), "starting...");

match cli.command {
Commands::Local {
metastore_addr,
spill_path,
local_file_path,
query,
} => {
let runtime = build_runtime("local")?;
runtime.block_on(async move {
let local =
LocalEngine::connect(metastore_addr, local_file_path, spill_path).await?;
match query {
Some(q) => local.execute_one(&q).await,
None => local.run().await,
}
})?;
}
Commands::Server {
bind,
metastore_addr,
Expand Down Expand Up @@ -172,9 +220,7 @@ fn main() -> Result<()> {
bucket,
service_account_path,
},
(None, None, Some(local_file_path)) => {
let p: PathBuf = local_file_path.into();

(None, None, Some(p)) => {
// Error if the path exists and is not a directory else
// create the directory.
if p.exists() && !p.is_dir() {
Expand Down Expand Up @@ -207,7 +253,7 @@ fn begin_server(
metastore_addr: Option<String>,
segment_key: Option<String>,
local: bool,
local_file_path: Option<String>,
local_file_path: Option<PathBuf>,
spill_path: Option<PathBuf>,
) -> Result<()> {
let runtime = build_runtime("server")?;
Expand Down
3 changes: 3 additions & 0 deletions crates/glaredb/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
pub mod local;
pub mod metastore;
pub mod proxy;
pub mod server;

mod util;
Loading