fix(influxdb): merge compat query series and quote explicit columns
This commit is contained in:
4 files changed
+170
-33
No files matched your search
@@ -608,14 +608,21 @@ pub(super) fn build_select_columns(
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
}
|
||||
if !matches!(database_type, Some(DatabaseType::Hive | DatabaseType::Kyuubi | DatabaseType::Impala)) {
|
||||
if !matches!(
|
||||
database_type,
|
||||
Some(DatabaseType::Hive | DatabaseType::Kyuubi | DatabaseType::Impala | DatabaseType::InfluxDb)
|
||||
) {
|
||||
return "*".to_string();
|
||||
}
|
||||
columns
|
||||
.iter()
|
||||
.map(|column| {
|
||||
let ident = quote_table_identifier(database_type, column);
|
||||
format!("{ident} AS {ident}")
|
||||
if database_type == Some(DatabaseType::Hive) {
|
||||
format!("{ident} AS {ident}")
|
||||
} else {
|
||||
ident
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
@@ -770,6 +777,22 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn influxdb_table_select_quotes_explicit_columns() {
|
||||
// InfluxQL needs double-quoted identifiers and only permits ORDER BY on
|
||||
// the time column; explicit column lists must not fall back to "*".
|
||||
assert_eq!(
|
||||
build_table_data_select_sql(TableDataSelectSqlOptions {
|
||||
database_type: Some(DatabaseType::InfluxDb),
|
||||
database: Some("monitor".to_string()),
|
||||
table_name: "cpu".to_string(),
|
||||
columns: vec!["time".to_string(), "host".to_string(), "value".to_string()],
|
||||
..Default::default()
|
||||
}),
|
||||
"SELECT \"time\", \"host\", \"value\" FROM \"cpu\" ORDER BY time DESC LIMIT 100;"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn databricks_table_select_uses_backtick_identifiers() {
|
||||
assert_eq!(
|
||||
|
||||
@@ -492,7 +492,7 @@ fn builds_table_data_where_and_schema_queries() {
|
||||
include_row_id: false,
|
||||
..Default::default()
|
||||
}),
|
||||
"SELECT `id` AS `id`, `name` AS `name` FROM `dbx_demo`.`connection_test` ORDER BY 1 LIMIT 2 OFFSET 1;"
|
||||
"SELECT `id`, `name` FROM `dbx_demo`.`connection_test` ORDER BY 1 LIMIT 2 OFFSET 1;"
|
||||
);
|
||||
assert_eq!(
|
||||
build_table_data_select_sql(TableDataSelectSqlOptions {
|
||||
|
||||
Reference in new issue
Block a user