Skip to content

Commit bb782d0

Browse files
committed
chore(cubestore): Upgrade DF: Treat unquoted schema/table names case sensitively as before
1 parent 14833a7 commit bb782d0

File tree

2 files changed

+30
-27
lines changed

2 files changed

+30
-27
lines changed

rust/cubestore/cubestore/src/sql/mod.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ impl SqlServiceImpl {
266266
multi_index: None,
267267
columns: columns
268268
.iter()
269-
.map(|c| fully_qualified_or_lower(&c))
269+
.map(|c| quoted_value_or_lower(&c))
270270
.collect(),
271271
index_type: IndexType::Regular, //TODO realize aggregate index here too
272272
},
@@ -291,13 +291,13 @@ impl SqlServiceImpl {
291291
for column in columns {
292292
let c = if let Some(item) = table_columns
293293
.iter()
294-
.find(|voc| *voc.get_name() == fully_qualified_or_lower(&column))
294+
.find(|voc| *voc.get_name() == quoted_value_or_lower(&column))
295295
{
296296
item
297297
} else {
298298
return Err(CubeError::user(format!(
299299
"Column {} is not present in table {}.{}.",
300-
fully_qualified_or_lower(&column),
300+
quoted_value_or_lower(&column),
301301
schema_name,
302302
table_name
303303
)));
@@ -502,14 +502,18 @@ pub fn boolean_prop(credentials: &Vec<SqlOption>, prop_name: &str) -> Option<boo
502502
})
503503
}
504504

505-
pub fn fully_qualified_or_lower(ident: &Ident) -> String {
505+
pub fn quoted_value_or_lower(ident: &Ident) -> String {
506506
if ident.quote_style.is_some() {
507507
ident.value.to_string()
508508
} else {
509509
ident.value.to_lowercase()
510510
}
511511
}
512512

513+
pub fn quoted_value_or_retain_case(ident: &Ident) -> String {
514+
ident.value.to_string()
515+
}
516+
513517
#[derive(Debug)]
514518
pub struct MySqlDialectWithBackTicks {}
515519

@@ -683,7 +687,7 @@ impl SqlService for SqlServiceImpl {
683687
Some(&vec![metrics::format_tag("command", "create_schema")]),
684688
);
685689

686-
let name = fully_qualified_or_lower(&schema_name.0[0]);
690+
let name = quoted_value_or_retain_case(&schema_name.0[0]);
687691
let res = self.create_schema(name, if_not_exists).await?;
688692
Ok(Arc::new(DataFrame::from(vec![res])))
689693
}
@@ -715,8 +719,8 @@ impl SqlService for SqlServiceImpl {
715719
name
716720
)));
717721
}
718-
let schema_name = &fully_qualified_or_lower(&nv[0]);
719-
let table_name = &fully_qualified_or_lower(&nv[1]);
722+
let schema_name = &quoted_value_or_retain_case(&nv[0]);
723+
let table_name = &quoted_value_or_retain_case(&nv[1]);
720724
let mut import_format = with_options
721725
.iter()
722726
.find(|&opt| opt.name.value == "input_format")
@@ -888,8 +892,8 @@ impl SqlService for SqlServiceImpl {
888892
table_name
889893
)));
890894
}
891-
let schema_name = &fully_qualified_or_lower(&table_name.0[0]);
892-
let table_name = &fully_qualified_or_lower(&table_name.0[1]);
895+
let schema_name = &quoted_value_or_retain_case(&table_name.0[0]);
896+
let table_name = &quoted_value_or_retain_case(&table_name.0[1]);
893897
let name = name.ok_or(CubeError::user(format!(
894898
"Index name is not defined during index creation for {}.{}",
895899
schema_name, table_name
@@ -959,7 +963,7 @@ impl SqlService for SqlServiceImpl {
959963
};
960964
let source = self
961965
.db
962-
.create_or_update_source(fully_qualified_or_lower(&name), creds?)
966+
.create_or_update_source(quoted_value_or_lower(&name), creds?)
963967
.await?;
964968
Ok(Arc::new(DataFrame::from(vec![source])))
965969
} else {
@@ -1057,8 +1061,8 @@ impl SqlService for SqlServiceImpl {
10571061
if nv.len() != 2 {
10581062
return Err(CubeError::user(format!("Schema's name should be present in query (boo.table1). Your query was '{}'", query)));
10591063
}
1060-
let schema_name = &fully_qualified_or_lower(&nv[0]);
1061-
let table_name = &fully_qualified_or_lower(&nv[1]);
1064+
let schema_name = &quoted_value_or_retain_case(&nv[0]);
1065+
let table_name = &quoted_value_or_retain_case(&nv[1]);
10621066

10631067
self.insert_data(schema_name.clone(), table_name.clone(), &columns, data)
10641068
.await?;

rust/cubestore/cubestore/src/sql/table_creator.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ use crate::metastore::{
1212
};
1313
use crate::metastore::{Column, ColumnType, MetaStore};
1414
use crate::sql::cache::SqlResultCache;
15-
use crate::sql::fully_qualified_or_lower;
15+
use crate::sql::{quoted_value_or_lower, quoted_value_or_retain_case};
1616
use crate::sql::parser::{CubeStoreParser, PartitionedIndexRef};
1717
use crate::telemetry::incoming_traffic_agent_event;
1818
use crate::CubeError;
1919
use async_trait::async_trait;
2020
use chrono::{DateTime, Utc};
2121
use futures::future::join_all;
2222
use sqlparser::ast::*;
23-
use std::mem::take;
2423

2524
#[async_trait]
2625

@@ -293,12 +292,12 @@ impl TableCreator {
293292
if let Some(mut p) = partitioned_index {
294293
let part_index_name = match p.name.0.as_mut_slice() {
295294
&mut [ref schema, ref mut name] => {
296-
if fully_qualified_or_lower(&schema) != schema_name {
295+
if quoted_value_or_retain_case(&schema) != schema_name {
297296
return Err(CubeError::user(format!("CREATE TABLE in schema '{}' cannot reference PARTITIONED INDEX from schema '{}'", schema_name, schema)));
298297
}
299-
take(&mut fully_qualified_or_lower(&name))
298+
quoted_value_or_retain_case(&name)
300299
}
301-
&mut [ref mut name] => take(&mut fully_qualified_or_lower(&name)),
300+
&mut [ref mut name] => quoted_value_or_retain_case(&name),
302301
_ => {
303302
return Err(CubeError::user(format!(
304303
"PARTITIONED INDEX must consist of 1 or 2 identifiers, got '{}'",
@@ -308,8 +307,8 @@ impl TableCreator {
308307
};
309308

310309
let mut columns = Vec::new();
311-
for mut c in p.columns {
312-
columns.push(take(&mut fully_qualified_or_lower(&c)));
310+
for c in p.columns {
311+
columns.push(quoted_value_or_lower(&c));
313312
}
314313

315314
indexes_to_create.push(IndexDef {
@@ -339,7 +338,7 @@ impl TableCreator {
339338
.iter()
340339
.map(|c| {
341340
if let Expr::Identifier(ident) = &c.expr {
342-
Ok(fully_qualified_or_lower(&ident))
341+
Ok(quoted_value_or_lower(&ident))
343342
} else {
344343
Err(CubeError::internal(format!(
345344
"Unexpected column expression: {:?}",
@@ -401,13 +400,13 @@ impl TableCreator {
401400
None,
402401
stream_offset,
403402
unique_key
404-
.map(|keys| keys.iter().map(|c| fully_qualified_or_lower(&c)).collect()),
403+
.map(|keys| keys.iter().map(|c| quoted_value_or_lower(&c)).collect()),
405404
aggregates.map(|keys| {
406405
keys.iter()
407406
.map(|c| {
408407
(
409-
fully_qualified_or_lower(&c.0),
410-
fully_qualified_or_lower(&c.1),
408+
quoted_value_or_lower(&c.0),
409+
quoted_value_or_lower(&c.1),
411410
)
412411
})
413412
.collect()
@@ -487,13 +486,13 @@ impl TableCreator {
487486
select_statement,
488487
source_columns,
489488
stream_offset,
490-
unique_key.map(|keys| keys.iter().map(|c| fully_qualified_or_lower(&c)).collect()),
489+
unique_key.map(|keys| keys.iter().map(|c| quoted_value_or_lower(&c)).collect()),
491490
aggregates.map(|keys| {
492491
keys.iter()
493492
.map(|c| {
494493
(
495-
fully_qualified_or_lower(&c.0),
496-
fully_qualified_or_lower(&c.1),
494+
quoted_value_or_lower(&c.0),
495+
quoted_value_or_lower(&c.1),
497496
)
498497
})
499498
.collect()
@@ -579,7 +578,7 @@ pub fn convert_columns_type(columns: &Vec<ColumnDef>) -> Result<Vec<Column>, Cub
579578

580579
for (i, col) in columns.iter().enumerate() {
581580
let cube_col = Column::new(
582-
fully_qualified_or_lower(&col.name),
581+
quoted_value_or_lower(&col.name),
583582
match &col.data_type {
584583
DataType::Date
585584
| DataType::Time(_, _)

0 commit comments

Comments
 (0)