Skip to content

Commit e7a91db

Browse files
pauldheinrichsmcheshkov
authored andcommitted
fix(cubesql) Formatting
1 parent 8f73512 commit e7a91db

File tree

2 files changed

+46
-23
lines changed

2 files changed

+46
-23
lines changed

rust/cubesql/cubesql/src/compile/engine/udf/common.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3174,9 +3174,10 @@ pub fn create_col_description_udf() -> ScalarUDF {
31743174

31753175
ScalarUDF::new(
31763176
"col_description",
3177-
&Signature::one_of(vec![
3178-
TypeSignature::Exact(vec![DataType::Utf8, DataType::Utf8]),
3179-
], Volatility::Immutable),
3177+
&Signature::one_of(
3178+
vec![TypeSignature::Exact(vec![DataType::Utf8, DataType::Utf8])],
3179+
Volatility::Immutable,
3180+
),
31803181
&return_type,
31813182
&fun,
31823183
)
@@ -3233,31 +3234,32 @@ pub fn create_format_udf() -> ScalarUDF {
32333234
let str_arr = downcast_string_arg!(arg, "arg", i32);
32343235
if str_arr.is_null(i) {
32353236
return Err(DataFusionError::Execution(
3236-
"NULL values cannot be formatted as identifiers".to_string(),
3237+
"NULL values cannot be formatted as identifiers"
3238+
.to_string(),
32373239
));
32383240
}
32393241
str_arr.value(i).to_string()
32403242
}
32413243
_ => {
32423244
// For other types, try to convert to string
32433245
let str_arr = cast(&arg, &DataType::Utf8)?;
3244-
let str_arr = str_arr
3245-
.as_any()
3246-
.downcast_ref::<StringArray>()
3247-
.unwrap();
3246+
let str_arr =
3247+
str_arr.as_any().downcast_ref::<StringArray>().unwrap();
32483248
if str_arr.is_null(i) {
32493249
return Err(DataFusionError::Execution(
3250-
"NULL values cannot be formatted as identifiers".to_string(),
3250+
"NULL values cannot be formatted as identifiers"
3251+
.to_string(),
32513252
));
32523253
}
32533254
str_arr.value(i).to_string()
32543255
}
32553256
};
32563257

32573258
// Quote identifier if necessary
3258-
let needs_quoting = !value.chars().all(|c| {
3259-
c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_'
3260-
}) || value.is_empty();
3259+
let needs_quoting = !value
3260+
.chars()
3261+
.all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_')
3262+
|| value.is_empty();
32613263

32623264
if needs_quoting {
32633265
result.push('"');
@@ -3296,16 +3298,12 @@ pub fn create_format_udf() -> ScalarUDF {
32963298

32973299
ScalarUDF::new(
32983300
"format",
3299-
&Signature::variadic(
3300-
vec![DataType::Utf8],
3301-
Volatility::Immutable,
3302-
),
3301+
&Signature::variadic(vec![DataType::Utf8], Volatility::Immutable),
33033302
&return_type,
33043303
&fun,
33053304
)
33063305
}
33073306

3308-
33093307
pub fn create_json_build_object_udf() -> ScalarUDF {
33103308
let fun = make_scalar_function(move |_args: &[ArrayRef]| {
33113309
// TODO: Implement

rust/cubesql/cubesql/src/compile/mod.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16355,27 +16355,52 @@ LIMIT {{ limit }}{% endif %}"#.to_string(),
1635516355
#[tokio::test]
1635616356
async fn test_format_function() -> Result<(), CubeError> {
1635716357
// Test: Basic usage with a single identifier
16358-
let result = execute_query("SELECT format('%I', 'column_name') AS formatted_identifier".to_string(), DatabaseProtocol::PostgreSQL).await?;
16358+
let result = execute_query(
16359+
"SELECT format('%I', 'column_name') AS formatted_identifier".to_string(),
16360+
DatabaseProtocol::PostgreSQL,
16361+
)
16362+
.await?;
1635916363
insta::assert_snapshot!("formatted_identifier", result);
1636016364

1636116365
// Test: Using multiple identifiers
16362-
let result = execute_query("SELECT format('%I, %I', 'table_name', 'column_name') AS formatted_identifiers".to_string(), DatabaseProtocol::PostgreSQL).await?;
16366+
let result = execute_query(
16367+
"SELECT format('%I, %I', 'table_name', 'column_name') AS formatted_identifiers"
16368+
.to_string(),
16369+
DatabaseProtocol::PostgreSQL,
16370+
)
16371+
.await?;
1636316372
insta::assert_snapshot!("formatted_identifiers", result);
1636416373

1636516374
// Test: Unsupported format specifier
16366-
let result = execute_query("SELECT format('%X', 'value') AS unsupported_specifier".to_string(), DatabaseProtocol::PostgreSQL).await;
16375+
let result = execute_query(
16376+
"SELECT format('%X', 'value') AS unsupported_specifier".to_string(),
16377+
DatabaseProtocol::PostgreSQL,
16378+
)
16379+
.await;
1636716380
assert!(result.is_err());
1636816381

1636916382
// Test: Format string ending with %
16370-
let result = execute_query("SELECT format('%', 'value') AS invalid_format".to_string(), DatabaseProtocol::PostgreSQL).await;
16383+
let result = execute_query(
16384+
"SELECT format('%', 'value') AS invalid_format".to_string(),
16385+
DatabaseProtocol::PostgreSQL,
16386+
)
16387+
.await;
1637116388
assert!(result.is_err());
1637216389

1637316390
// Test: Quoting necessary for special characters
16374-
let result = execute_query("SELECT format('%I', 'column-name') AS quoted_identifier".to_string(), DatabaseProtocol::PostgreSQL).await?;
16391+
let result = execute_query(
16392+
"SELECT format('%I', 'column-name') AS quoted_identifier".to_string(),
16393+
DatabaseProtocol::PostgreSQL,
16394+
)
16395+
.await?;
1637516396
insta::assert_snapshot!("quoted_identifier", result);
1637616397

1637716398
// Test: Quoting necessary for reserved keywords
16378-
let result = execute_query("SELECT format('%I', 'select') AS quoted_keyword".to_string(), DatabaseProtocol::PostgreSQL).await?;
16399+
let result = execute_query(
16400+
"SELECT format('%I', 'select') AS quoted_keyword".to_string(),
16401+
DatabaseProtocol::PostgreSQL,
16402+
)
16403+
.await?;
1637916404
insta::assert_snapshot!("quoted_keyword", result);
1638016405

1638116406
Ok(())

0 commit comments

Comments
 (0)