chore: unify code styling (#1523)

This commit is contained in:
Weny Xu
2023-05-10 12:10:39 +09:00
committed by GitHub
parent a1587595d9
commit fbb7db42aa
12 changed files with 46 additions and 43 deletions

View File

@@ -9,6 +9,7 @@ api = { path = "../api" }
catalog = { path = "../catalog" }
common-base = { path = "../common/base" }
common-catalog = { path = "../common/catalog" }
common-datasource = { path = "../common/datasource" }
common-error = { path = "../common/error" }
common-time = { path = "../common/time" }
datafusion-sql.workspace = true

View File

@@ -68,7 +68,7 @@ impl<'a> ParserContext<'a> {
let with = options
.into_iter()
.filter_map(|option| {
parse_option_string(option.value).map(|v| (option.name.value.to_uppercase(), v))
parse_option_string(option.value).map(|v| (option.name.value.to_lowercase(), v))
})
.collect();
@@ -80,7 +80,7 @@ impl<'a> ParserContext<'a> {
let connection = connection_options
.into_iter()
.filter_map(|option| {
parse_option_string(option.value).map(|v| (option.name.value.to_uppercase(), v))
parse_option_string(option.value).map(|v| (option.name.value.to_lowercase(), v))
})
.collect();
Ok(CopyTableArgument {
@@ -109,7 +109,7 @@ impl<'a> ParserContext<'a> {
let with = options
.into_iter()
.filter_map(|option| {
parse_option_string(option.value).map(|v| (option.name.value.to_uppercase(), v))
parse_option_string(option.value).map(|v| (option.name.value.to_lowercase(), v))
})
.collect();
@@ -121,7 +121,7 @@ impl<'a> ParserContext<'a> {
let connection = connection_options
.into_iter()
.filter_map(|option| {
parse_option_string(option.value).map(|v| (option.name.value.to_uppercase(), v))
parse_option_string(option.value).map(|v| (option.name.value.to_lowercase(), v))
})
.collect();
@@ -243,7 +243,7 @@ mod tests {
Test {
sql: "COPY catalog0.schema0.tbl FROM 'tbl_file.parquet' WITH (PATTERN = 'demo.*') CONNECTION (FOO='Bar', ONE='two')",
expected_pattern: Some("demo.*".into()),
expected_connection: [("FOO","Bar"),("ONE","two")].into_iter().map(|(k,v)|{(k.to_string(),v.to_string())}).collect()
expected_connection: [("foo","Bar"),("one","two")].into_iter().map(|(k,v)|{(k.to_string(),v.to_string())}).collect()
},
];
@@ -280,11 +280,11 @@ mod tests {
},
Test {
sql: "COPY catalog0.schema0.tbl TO 'tbl_file.parquet' CONNECTION (FOO='Bar', ONE='two')",
expected_connection: [("FOO","Bar"),("ONE","two")].into_iter().map(|(k,v)|{(k.to_string(),v.to_string())}).collect()
expected_connection: [("foo","Bar"),("one","two")].into_iter().map(|(k,v)|{(k.to_string(),v.to_string())}).collect()
},
Test {
sql:"COPY catalog0.schema0.tbl TO 'tbl_file.parquet' WITH (FORMAT = 'parquet') CONNECTION (FOO='Bar', ONE='two')",
expected_connection: [("FOO","Bar"),("ONE","two")].into_iter().map(|(k,v)|{(k.to_string(),v.to_string())}).collect()
expected_connection: [("foo","Bar"),("one","two")].into_iter().map(|(k,v)|{(k.to_string(),v.to_string())}).collect()
},
];

View File

@@ -85,7 +85,7 @@ impl<'a> ParserContext<'a> {
.into_iter()
.filter_map(|option| {
if let Some(v) = parse_option_string(option.value) {
Some((option.name.value.to_uppercase(), v))
Some((option.name.value.to_lowercase(), v))
} else {
None
}
@@ -803,8 +803,8 @@ mod tests {
sql: "CREATE EXTERNAL TABLE city with(location='/var/data/city.csv',format='csv');",
expected_table_name: "city",
expected_options: HashMap::from([
("LOCATION".to_string(), "/var/data/city.csv".to_string()),
("FORMAT".to_string(), "csv".to_string()),
("location".to_string(), "/var/data/city.csv".to_string()),
("format".to_string(), "csv".to_string()),
]),
expected_engine: IMMUTABLE_FILE_ENGINE,
expected_if_not_exist: false,
@@ -813,8 +813,8 @@ mod tests {
sql: "CREATE EXTERNAL TABLE IF NOT EXISTS city ENGINE=foo with(location='/var/data/city.csv',format='csv');",
expected_table_name: "city",
expected_options: HashMap::from([
("LOCATION".to_string(), "/var/data/city.csv".to_string()),
("FORMAT".to_string(), "csv".to_string()),
("location".to_string(), "/var/data/city.csv".to_string()),
("format".to_string(), "csv".to_string()),
]),
expected_engine: "foo",
expected_if_not_exist: true,
@@ -848,8 +848,8 @@ mod tests {
) with(location='/var/data/city.csv',format='csv');";
let options = HashMap::from([
("LOCATION".to_string(), "/var/data/city.csv".to_string()),
("FORMAT".to_string(), "csv".to_string()),
("location".to_string(), "/var/data/city.csv".to_string()),
("format".to_string(), "csv".to_string()),
]);
let stmts = ParserContext::create_with_dialect(sql, &GenericDialect {}).unwrap();

View File

@@ -15,7 +15,6 @@
use std::collections::HashMap;
use sqlparser::ast::ObjectName;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CopyTable {
To(CopyTableArgument),
@@ -33,16 +32,16 @@ pub struct CopyTableArgument {
#[cfg(test)]
impl CopyTableArgument {
const FORMAT: &str = "FORMAT";
pub fn format(&self) -> Option<String> {
self.with
.get(Self::FORMAT)
.get(common_datasource::file_format::FORMAT_TYPE)
.cloned()
.or_else(|| Some("PARQUET".to_string()))
}
pub fn pattern(&self) -> Option<String> {
self.with.get("PATTERN").cloned()
self.with
.get(common_datasource::file_format::FILE_PATTERN)
.cloned()
}
}

View File

@@ -198,8 +198,7 @@ pub struct CreateExternalTable {
pub columns: Vec<ColumnDef>,
pub constraints: Vec<TableConstraint>,
/// Table options in `WITH`.
/// All keys are uppercase.
/// TODO(weny): unify the key's case styling.
/// All keys are lowercase.
pub options: HashMap<String, String>,
pub if_not_exists: bool,
pub engine: String,