Skip to content

Commit 724f030

Browse files
committed
Fixes after review
1 parent e7a91db commit 724f030

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3088,8 +3088,9 @@ pub fn create_cube_regclass_cast_udf() -> ScalarUDF {
30883088
match PgType::get_all().iter().find(|e| e.typname == as_str) {
30893089
None => {
30903090
// If the type name contains a dot, it's a schema-qualified name
3091-
// and we should return return the approprate RegClass to be converted to OID
3091+
// and we should return the approprate RegClass to be converted to OID
30923092
// For now, we'll return 0 so metabase can sync without failing
3093+
// TODO actually read `pg_type`
30933094
if as_str.contains('.') {
30943095
builder.append_value(0)?;
30953096
} else {
@@ -3156,6 +3157,7 @@ pub fn create_pg_get_serial_sequence_udf() -> ScalarUDF {
31563157
}
31573158

31583159
// Return a NOOP for this so metabase can sync without failing
3160+
// See https://www.postgresql.org/docs/17/functions-info.html#FUNCTIONS-INFO-COMMENT here
31593161
// TODO: Implement this
31603162
pub fn create_col_description_udf() -> ScalarUDF {
31613163
let fun = make_scalar_function(move |args: &[ArrayRef]| {
@@ -3174,15 +3176,13 @@ pub fn create_col_description_udf() -> ScalarUDF {
31743176

31753177
ScalarUDF::new(
31763178
"col_description",
3177-
&Signature::one_of(
3178-
vec![TypeSignature::Exact(vec![DataType::Utf8, DataType::Utf8])],
3179-
Volatility::Immutable,
3180-
),
3179+
&Signature::exact(vec![DataType::UInt32, DataType::Int32], Volatility::Stable),
31813180
&return_type,
31823181
&fun,
31833182
)
31843183
}
31853184

3185+
// See https://www.postgresql.org/docs/17/functions-string.html#FUNCTIONS-STRING-FORMAT
31863186
pub fn create_format_udf() -> ScalarUDF {
31873187
let fun = make_scalar_function(move |args: &[ArrayRef]| {
31883188
// Ensure at least one argument is provided
@@ -3255,11 +3255,11 @@ pub fn create_format_udf() -> ScalarUDF {
32553255
}
32563256
};
32573257

3258-
// Quote identifier if necessary
3259-
let needs_quoting = !value
3260-
.chars()
3261-
.all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_')
3262-
|| value.is_empty();
3258+
// Quote any identifier for now
3259+
// That's a safety-first approach: it would quote too much, but every edge-case would be covered
3260+
// Like `1` or `1a` or `select`
3261+
// TODO Quote identifier only if necessary
3262+
let needs_quoting = true;
32633263

32643264
if needs_quoting {
32653265
result.push('"');
@@ -3298,6 +3298,10 @@ pub fn create_format_udf() -> ScalarUDF {
32983298

32993299
ScalarUDF::new(
33003300
"format",
3301+
// Actually, format should be variadic with types (Utf8, any*)
3302+
// But ATM DataFusion does not support those signatures
3303+
// And this would work through implicit casting to Utf8
3304+
// TODO migrate to proper custom signature once it's supported by DF
33013305
&Signature::variadic(vec![DataType::Utf8], Volatility::Immutable),
33023306
&return_type,
33033307
&fun,
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
---
22
source: cubesql/src/compile/mod.rs
33
expression: result
4+
snapshot_kind: text
45
---
56
+----------------------+
67
| formatted_identifier |
78
+----------------------+
8-
| column_name |
9+
| "column_name" |
910
+----------------------+

0 commit comments

Comments
 (0)