fix(python): render field types as SQL strings, not Rust Debug - #786
fix(python): render field types as SQL strings, not Rust Debug#786jackylee-ch wants to merge 3 commits into
Conversation
| write!( | ||
| f, | ||
| "{} {}", | ||
| crate::spec::escape_identifier(field.name()), |
There was a problem hiding this comment.
[P2] Quote ROW field names with Java's identifier syntax
This helper does not implement Java EncodingUtils.escapeIdentifier: the Rust function only doubles " characters and does not add delimiters, while Java returns a backtick-wrapped identifier and doubles embedded backticks. Consequently this renders even id as ROW<id INT> instead of Java's backtick-wrapped id; names containing spaces or reserved words become ambiguous, and a name containing a backtick is not escaped at all. That also means the new Python field_type() contract is not the claimed Java asSQLString() for nested rows.
Please use a ROW-specific helper that wraps the name in backticks and replaces each embedded backtick with two backticks (or deliberately align the existing helper if all its callers need Java syntax), and update the tests to cover a normal name, a reserved/space-containing name, and an embedded backtick.
|
Right — |
PyDataField.field_type()returns RustDebugoutput — a column declaredVARCHAR(10)reads back asVarchar(VarCharType { length: 10, nullable: true }).The in-place
TODO(#284 follow-up)names the cause:DataTypehas no enum-levelDisplay, so there was nothing to call.Only 10 of the 23 variants carried a leaf
Display. This adds the other ninescalars and the four constructed types, then the dispatch. The constructed formats
fill Java's
FORMATwith the children's own SQL strings (ARRAY<%s>,MAP<%s, %s>,MULTISET<%s>,ROW<%s>), so a child'sNOT NULLsits inside thebrackets and the outer one after them.
ROWrenders fields likeDataField.asSQLString: the escaped name, the type, thenCOMMENT '...'. So a nested row readsROW<`id` INT, `name` VARCHAR(10)>.spec::escape_identifierwas not Java'sEncodingUtils.escapeIdentifier— it onlydoubled
"and added no delimiter — so it is aligned here rather than workedaround. It had no production caller before this PR (
Display for DataFieldwasnever written), and its test pinned the wrong shape.
The dispatch also retires
VectorType::element_sql_name, a private table of sevenprimitive names with
unreachable!()for the rest.cargo test -p pypaimon_rustcannot link libpython here, so the binding iscompile-checked locally and its behaviour left to
integration (python). Therendering is covered by unit tests in
paimon.