Skip to content

Commit 1fa060c

Browse files
pauldheinrichsmcheshkov
authored andcommitted
fix(cubesql) Formatting
1 parent 2547d6d commit 1fa060c

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
@@ -16215,27 +16215,52 @@ LIMIT {{ limit }}{% endif %}"#.to_string(),
1621516215
#[tokio::test]
1621616216
async fn test_format_function() -> Result<(), CubeError> {
1621716217
// Test: Basic usage with a single identifier
16218-
let result = execute_query("SELECT format('%I', 'column_name') AS formatted_identifier".to_string(), DatabaseProtocol::PostgreSQL).await?;
16218+
let result = execute_query(
16219+
"SELECT format('%I', 'column_name') AS formatted_identifier".to_string(),
16220+
DatabaseProtocol::PostgreSQL,
16221+
)
16222+
.await?;
1621916223
insta::assert_snapshot!("formatted_identifier", result);
1622016224

1622116225
// Test: Using multiple identifiers
16222-
let result = execute_query("SELECT format('%I, %I', 'table_name', 'column_name') AS formatted_identifiers".to_string(), DatabaseProtocol::PostgreSQL).await?;
16226+
let result = execute_query(
16227+
"SELECT format('%I, %I', 'table_name', 'column_name') AS formatted_identifiers"
16228+
.to_string(),
16229+
DatabaseProtocol::PostgreSQL,
16230+
)
16231+
.await?;
1622316232
insta::assert_snapshot!("formatted_identifiers", result);
1622416233

1622516234
// Test: Unsupported format specifier
16226-
let result = execute_query("SELECT format('%X', 'value') AS unsupported_specifier".to_string(), DatabaseProtocol::PostgreSQL).await;
16235+
let result = execute_query(
16236+
"SELECT format('%X', 'value') AS unsupported_specifier".to_string(),
16237+
DatabaseProtocol::PostgreSQL,
16238+
)
16239+
.await;
1622716240
assert!(result.is_err());
1622816241

1622916242
// Test: Format string ending with %
16230-
let result = execute_query("SELECT format('%', 'value') AS invalid_format".to_string(), DatabaseProtocol::PostgreSQL).await;
16243+
let result = execute_query(
16244+
"SELECT format('%', 'value') AS invalid_format".to_string(),
16245+
DatabaseProtocol::PostgreSQL,
16246+
)
16247+
.await;
1623116248
assert!(result.is_err());
1623216249

1623316250
// Test: Quoting necessary for special characters
16234-
let result = execute_query("SELECT format('%I', 'column-name') AS quoted_identifier".to_string(), DatabaseProtocol::PostgreSQL).await?;
16251+
let result = execute_query(
16252+
"SELECT format('%I', 'column-name') AS quoted_identifier".to_string(),
16253+
DatabaseProtocol::PostgreSQL,
16254+
)
16255+
.await?;
1623516256
insta::assert_snapshot!("quoted_identifier", result);
1623616257

1623716258
// Test: Quoting necessary for reserved keywords
16238-
let result = execute_query("SELECT format('%I', 'select') AS quoted_keyword".to_string(), DatabaseProtocol::PostgreSQL).await?;
16259+
let result = execute_query(
16260+
"SELECT format('%I', 'select') AS quoted_keyword".to_string(),
16261+
DatabaseProtocol::PostgreSQL,
16262+
)
16263+
.await?;
1623916264
insta::assert_snapshot!("quoted_keyword", result);
1624016265

1624116266
Ok(())

0 commit comments

Comments
 (0)