Merge branch 'main' into dom/remove-partition-queries
commit
cc238c6a8f
|
@ -2166,7 +2166,7 @@ version = "0.1.0"
|
|||
dependencies = [
|
||||
"generated_types",
|
||||
"snafu",
|
||||
"sqlparser 0.24.0",
|
||||
"sqlparser 0.25.0",
|
||||
"workspace-hack",
|
||||
]
|
||||
|
||||
|
@ -3565,7 +3565,7 @@ dependencies = [
|
|||
"schema",
|
||||
"serde_json",
|
||||
"snafu",
|
||||
"sqlparser 0.24.0",
|
||||
"sqlparser 0.25.0",
|
||||
"test_helpers",
|
||||
"workspace-hack",
|
||||
]
|
||||
|
@ -4732,9 +4732,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "sqlparser"
|
||||
version = "0.24.0"
|
||||
version = "0.25.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dac9c312566fdfc45a38ecf1924013c82af2a7d5315e46f67b1cc987f12be260"
|
||||
checksum = "0781f2b6bd03e5adf065c8e772b49eaea9f640d06a1b9130330fe8bd2563f4fd"
|
||||
dependencies = [
|
||||
"log",
|
||||
]
|
||||
|
|
|
@ -53,7 +53,7 @@ pub enum Error {
|
|||
pub type Result<T, E = Error> = std::result::Result<T, E>;
|
||||
|
||||
enum QueryEngine {
|
||||
/// Run queries against the named database on the remote server
|
||||
/// Run queries against the namespace on the remote server
|
||||
Remote(String),
|
||||
|
||||
/// Run queries against a local `Observer` instance
|
||||
|
@ -177,7 +177,7 @@ pub struct Repl {
|
|||
/// Client for running sql
|
||||
flight_client: influxdb_iox_client::flight::Client,
|
||||
|
||||
/// database name against which SQL commands are run
|
||||
/// namespace name against which SQL commands are run
|
||||
query_engine: Option<QueryEngine>,
|
||||
|
||||
/// Formatter to use to format query results
|
||||
|
@ -239,8 +239,8 @@ impl Repl {
|
|||
.map_err(|e| println!("{}", e))
|
||||
.ok();
|
||||
}
|
||||
ReplCommand::UseDatabase { db_name } => {
|
||||
self.use_database(db_name);
|
||||
ReplCommand::UseNamespace { db_name } => {
|
||||
self.use_namespace(db_name);
|
||||
}
|
||||
ReplCommand::SqlCommand { sql } => {
|
||||
self.run_sql(sql).await.map_err(|e| println!("{}", e)).ok();
|
||||
|
@ -302,18 +302,18 @@ impl Repl {
|
|||
self.print_results(&[record_batch])
|
||||
}
|
||||
|
||||
// Run a command against the currently selected remote database
|
||||
// Run a command against the currently selected remote namespace
|
||||
async fn run_sql(&mut self, sql: String) -> Result<()> {
|
||||
let start = Instant::now();
|
||||
|
||||
let batches = match &mut self.query_engine {
|
||||
None => {
|
||||
println!("Error: no database selected.");
|
||||
println!("Hint: Run USE DATABASE <dbname> to select database");
|
||||
println!("Error: no namespace selected.");
|
||||
println!("Hint: Run USE NAMESPACE <dbname> to select namespace");
|
||||
return Ok(());
|
||||
}
|
||||
Some(QueryEngine::Remote(db_name)) => {
|
||||
info!(%db_name, %sql, "Running sql on remote database");
|
||||
info!(%db_name, %sql, "Running sql on remote namespace");
|
||||
|
||||
scrape_query(&mut self.flight_client, db_name, &sql).await?
|
||||
}
|
||||
|
@ -349,9 +349,9 @@ impl Repl {
|
|||
}
|
||||
}
|
||||
|
||||
fn use_database(&mut self, db_name: String) {
|
||||
info!(%db_name, "setting current database");
|
||||
println!("You are now in remote mode, querying database {}", db_name);
|
||||
fn use_namespace(&mut self, db_name: String) {
|
||||
info!(%db_name, "setting current namespace");
|
||||
println!("You are now in remote mode, querying namespace {}", db_name);
|
||||
self.set_query_engine(QueryEngine::Remote(db_name));
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ pub enum ReplCommand {
|
|||
ShowNamespaces,
|
||||
Observer,
|
||||
SetFormat { format: String },
|
||||
UseDatabase { db_name: String },
|
||||
UseNamespace { db_name: String },
|
||||
SqlCommand { sql: String },
|
||||
Exit,
|
||||
}
|
||||
|
@ -64,18 +64,18 @@ impl TryFrom<&str> for ReplCommand {
|
|||
["observer"] => Ok(Self::Observer),
|
||||
["exit"] => Ok(Self::Exit),
|
||||
["quit"] => Ok(Self::Exit),
|
||||
["use", "database"] => {
|
||||
Err("name not specified. Usage: USE DATABASE <name>".to_string())
|
||||
} // USE DATABASE
|
||||
["use", "database", _name] => {
|
||||
// USE DATABASE <name>
|
||||
Ok(Self::UseDatabase {
|
||||
["use", "namespace"] => {
|
||||
Err("name not specified. Usage: USE NAMESPACE <name>".to_string())
|
||||
} // USE NAMESPACE
|
||||
["use", "namespace", _name] => {
|
||||
// USE namespace <name>
|
||||
Ok(Self::UseNamespace {
|
||||
db_name: raw_commands[2].to_string(),
|
||||
})
|
||||
}
|
||||
["use", _command] => {
|
||||
// USE <name>
|
||||
Ok(Self::UseDatabase {
|
||||
Ok(Self::UseNamespace {
|
||||
db_name: raw_commands[1].to_string(),
|
||||
})
|
||||
}
|
||||
|
@ -98,9 +98,9 @@ impl ReplCommand {
|
|||
Available commands (not case sensitive):
|
||||
HELP (this one)
|
||||
|
||||
SHOW NAMESPACES: List databases available on the server
|
||||
SHOW NAMESPACES: List namespaces available on the server
|
||||
|
||||
USE [DATABASE|NAMESPACE] <name>: Set the current remote database to name
|
||||
USE NAMESPACE <name>: Set the current remote namespace to name
|
||||
|
||||
SET FORMAT <format>: Set the output format to Pretty, csv or json
|
||||
|
||||
|
@ -108,9 +108,9 @@ OBSERVER: Locally query unified queryable views of remote system tables
|
|||
|
||||
[EXIT | QUIT]: Quit this session and exit the program
|
||||
|
||||
# Examples: use remote database foo
|
||||
SHOW DATABASES;
|
||||
USE DATABASE foo;
|
||||
# Examples: use remote namespace foo
|
||||
SHOW NAMESPACES;
|
||||
USE foo;
|
||||
|
||||
# Basic IOx SQL Primer
|
||||
|
||||
|
@ -199,35 +199,35 @@ mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn use_database() {
|
||||
let expected = Ok(ReplCommand::UseDatabase {
|
||||
fn use_namespace() {
|
||||
let expected = Ok(ReplCommand::UseNamespace {
|
||||
db_name: "Foo".to_string(),
|
||||
});
|
||||
assert_eq!("use Foo".try_into(), expected);
|
||||
assert_eq!("use Database Foo;".try_into(), expected);
|
||||
assert_eq!("use Database Foo ;".try_into(), expected);
|
||||
assert_eq!(" use Database Foo; ".try_into(), expected);
|
||||
assert_eq!(" use Database Foo; ".try_into(), expected);
|
||||
assert_eq!("use Namespace Foo;".try_into(), expected);
|
||||
assert_eq!("use Namespace Foo ;".try_into(), expected);
|
||||
assert_eq!(" use Namespace Foo; ".try_into(), expected);
|
||||
assert_eq!(" use Namespace Foo; ".try_into(), expected);
|
||||
|
||||
// ensure that database name is case sensitive
|
||||
let expected = Ok(ReplCommand::UseDatabase {
|
||||
// ensure that namespace name is case sensitive
|
||||
let expected = Ok(ReplCommand::UseNamespace {
|
||||
db_name: "FOO".to_string(),
|
||||
});
|
||||
assert_eq!("use FOO".try_into(), expected);
|
||||
assert_eq!("use DATABASE FOO;".try_into(), expected);
|
||||
assert_eq!("USE DATABASE FOO;".try_into(), expected);
|
||||
assert_eq!("use NAMESPACE FOO;".try_into(), expected);
|
||||
assert_eq!("USE NAMESPACE FOO;".try_into(), expected);
|
||||
|
||||
let expected: Result<ReplCommand, String> =
|
||||
Err("name not specified. Usage: USE DATABASE <name>".to_string());
|
||||
assert_eq!("use Database;".try_into(), expected);
|
||||
assert_eq!("use DATABASE".try_into(), expected);
|
||||
assert_eq!("use database".try_into(), expected);
|
||||
Err("name not specified. Usage: USE NAMESPACE <name>".to_string());
|
||||
assert_eq!("use Namespace;".try_into(), expected);
|
||||
assert_eq!("use NAMESPACE".try_into(), expected);
|
||||
assert_eq!("use namespace".try_into(), expected);
|
||||
|
||||
let expected = sql_cmd("use database foo bar");
|
||||
assert_eq!("use database foo bar".try_into(), expected);
|
||||
let expected = sql_cmd("use namespace foo bar");
|
||||
assert_eq!("use namespace foo bar".try_into(), expected);
|
||||
|
||||
let expected = sql_cmd("use database foo BAR");
|
||||
assert_eq!("use database foo BAR".try_into(), expected);
|
||||
let expected = sql_cmd("use namespace foo BAR");
|
||||
assert_eq!("use namespace foo BAR".try_into(), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -4,7 +4,7 @@ version = "0.1.0"
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
sqlparser = "0.24.0"
|
||||
sqlparser = "0.25.0"
|
||||
snafu = "0.7.1"
|
||||
|
||||
generated_types = { path = "../generated_types" }
|
||||
|
|
|
@ -15,7 +15,7 @@ query_functions = { path = "../query_functions"}
|
|||
schema = { path = "../schema" }
|
||||
serde_json = "1.0.83"
|
||||
snafu = "0.7"
|
||||
sqlparser = "0.24.0"
|
||||
sqlparser = "0.25.0"
|
||||
workspace-hack = { path = "../workspace-hack"}
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
Loading…
Reference in New Issue