Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bindings/python/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ impl PyDataField {
}

fn field_type(&self) -> String {
// TODO(#284 follow-up): mirror Java DataType.asSQLString() once
// a Display impl is added to paimon::spec::DataType.
format!("{:?}", self.inner.data_type())
// Java `DataField.type().asSQLString()`, which is what
// `Display for DataType` renders.
self.inner.data_type().to_string()
}

fn is_nullable(&self) -> bool {
Expand Down
13 changes: 10 additions & 3 deletions crates/paimon/src/spec/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,8 +1119,10 @@ impl DataField {
}
}

/// Quote an identifier the way Java `EncodingUtils.escapeIdentifier` does: wrap it
/// in backticks and double any backtick it contains.
pub fn escape_identifier(identifier: &str) -> String {
identifier.replace('"', "\"\"")
format!("`{}`", identifier.replace('`', "``"))
}

pub fn escape_single_quotes(text: &str) -> String {
Expand Down Expand Up @@ -2386,8 +2388,13 @@ mod tests {

#[test]
fn test_escape_identifier() {
let escaped_identifier = escape_identifier("\"identifier\"");
assert_eq!(escaped_identifier, "\"\"identifier\"\"");
// Java doubles backticks and wraps in backticks; a double quote is not
// special (`EncodingUtils.escapeIdentifier`).
assert_eq!(escape_identifier("id"), "`id`");
assert_eq!(escape_identifier("a`b"), "`a``b`");
assert_eq!(escape_identifier("\"identifier\""), "`\"identifier\"`");
assert_eq!(escape_identifier("two words"), "`two words`");
assert_eq!(escape_identifier(""), "``");
}

#[test]
Expand Down
Loading
Loading