Skip to content

Fix #10: double-quote reserved-word field names in read_json_auto STRUCT type#13

Open
piotrszul wants to merge 1 commit into
masterfrom
fix/10_quote-struct-identifiers
Open

Fix #10: double-quote reserved-word field names in read_json_auto STRUCT type#13
piotrszul wants to merge 1 commit into
masterfrom
fix/10_quote-struct-identifiers

Conversation

@piotrszul

Copy link
Copy Markdown
Collaborator

Fixes #10.

Problem

pathsToSchema (src/ddb-sql-builder.js) emitted FHIR field names unquoted in the read_json_auto columns STRUCT type string. When a field name is a DuckDB reserved word — e.g. end from the FHIR Period type — the generated spec is unparseable:

columns = { period: 'STRUCT(start JSON, end JSON)' }
-> Invalid Input Error: Value "STRUCT(start JSON, end JSON)" can not be converted to a DuckDB Type.

Fix

Always double-quote the identifier in both emitted forms (root key and struct member):

return isInRoot ? `"${node.value}": '${sqlType}'` : `"${node.value}" ${sqlType}`

Always-quoting is safe for all names and avoids maintaining a reserved-word list (the issue's recommended direction). Verified in DuckDB 1.5.2 that quoting normal identifiers is harmless, that quoting works for both the root key and struct members, and that the previously-failing Encounter period.start/period.end view now executes and returns rows instead of aborting.

Tests

  • Added a reserved-word (end) regression test in tests/schema.test.js.
  • Updated existing schema expectations to the quoted output.
  • All 192 tests pass (bun test), including the e2e tests that run real read_json_auto queries.

Note: the secondary schema-coverage observation in #10 (Period fields falling back to JSON instead of VARCHAR) is the R4-schema bug fixed separately in #11 — the two compose cleanly. This PR is purely the quoting fix.

… spec

pathsToSchema emitted FHIR field names unquoted in the read_json_auto
`columns` STRUCT type string. When a field name is a DuckDB reserved
word — e.g. `end` from the FHIR Period type — the generated type spec
(`STRUCT(start JSON, end JSON)`) is unparseable and DuckDB aborts with
"can not be converted to a DuckDB Type".

Always double-quote the identifier (both the root key and struct member
names). This is safe for all names and avoids maintaining a reserved-word
list. Verified in DuckDB 1.5.2 that quoting normal identifiers is
harmless and that the previously-failing Encounter period.start/period.end
view now executes and returns rows.

- src/ddb-sql-builder.js: quote node.value in both emitted forms.
- tests/schema.test.js: add a reserved-word ("end") regression test and
  update existing expectations to the quoted output.

All 192 tests pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unquoted reserved-word field names in read_json_auto columns STRUCT type (e.g. Period.end) -> 'can not be converted to a DuckDB Type'

1 participant