Skip to content

feat(plsql): fill CREATE TABLE grammar gaps against Oracle 19c spec#66

Merged
h3n4l merged 2 commits intomainfrom
h3n4l/plsql-create-table-grammar-gaps
Apr 17, 2026
Merged

feat(plsql): fill CREATE TABLE grammar gaps against Oracle 19c spec#66
h3n4l merged 2 commits intomainfrom
h3n4l/plsql-create-table-grammar-gaps

Conversation

@h3n4l
Copy link
Copy Markdown
Member

@h3n4l h3n4l commented Apr 17, 2026

Summary

Systematic pass against Oracle 19c CREATE TABLE reference to close gaps in plsql/PlSqlParser.g4. Directly unblocks BYT-9302PARTITION BY RANGE (...) INTERVAL (NUMTODSINTERVAL(...)) (PARTITION p0 VALUES LESS THAN (DATE '2026-01-01')) failed to parse.

Changes are grouped into four tiers by priority and scope.

Tier 1 — partition value clauses accept full expressions (root cause of BYT-9302)

Oracle spec says VALUES LESS THAN ( expr | MAXVALUE ) and VALUES ( { expr | NULL } | DEFAULT ). The grammar previously restricted both to the narrow literal rule (CHAR_STRING | string_function | numeric | MAXVALUE), which excluded DATE '...', TIMESTAMP '...', arithmetic, NULL, and multi-column tuple form.

  • range_values_clause(expression | MAXVALUE)
  • list_values_clause(expression | NULL) plus tuple form ((1,2),(3,4)) for multi-column LIST

Tier 2 — structural keywords and blockchain flexibility

  • CREATE TABLE IF NOT EXISTS
  • list_partitions / composite_list_partitions / subpartition_by_list: accept multi-column partition keys and optional AUTOMATIC
  • blockchain_table_clauses: NO DROP / NO DELETE clauses now optional (only the hash clause is required)
  • blockchain_row_retention_clause: accept DAYS IDLE (in addition to DAYS AFTER INSERT)
  • blockchain_hash_and_data_format_clause: accept arbitrary CHAR_STRING or DELIMITED_ID for algorithm and version (removed the hardcoded SHA2_512_Q / V1_Q lexer tokens that forced a specific literal spelling)

Tier 3 — missing top-level partition strategies (12.2+/19c)

  • PARTITION BY CONSISTENT HASH (...) PARTITIONS AUTO [SUBPARTITION BY {RANGE|LIST} (...) SUBPARTITIONS AUTO]
  • PARTITION BY PARTITIONSET {RANGE|LIST} (...) with range_partitionset_desc and list_partitionset_desc
  • New PARTITIONSET lexer token

Tier 4 — completeness

  • range_subpartition_desc / list_subpartition_desc / individual_hash_subparts: accept optional read_only_clause and indexing_clause
  • column_definition: accept optional annotations_clause (Oracle 23c)

Test plan

  • make build (regenerates Go parser) — no new ANTLR warnings
  • go test ./plsql/... green (all pre-existing example SQL fixtures pass)
  • go test ./... green across all 20 engine parsers
  • New fixture plsql/examples/create_table_grammar_gaps.sql covers every scenario above and is exercised by the existing TestPLSQLParser harness
  • Verified end-to-end against bytebase/bytebase via a temporary replace directive: the 11 previously failing ParsePLSQL cases (DATE/TIMESTAMP range bounds, arithmetic bounds, NULL in LIST, multi-column LIST, AUTOMATIC, IF NOT EXISTS, CONSISTENT HASH, PARTITIONSET, blockchain DAYS IDLE) now all parse

🤖 Generated with Claude Code

Systematic pass comparing the PL/SQL grammar against the Oracle 19c
CREATE TABLE reference. Directly unblocks the reported failure on
CREATE TABLE ... PARTITION BY RANGE ... INTERVAL (NUMTODSINTERVAL(...))
(... VALUES LESS THAN (DATE '...'))

Tier 1 — partition value clauses accept full expressions:
- range_values_clause: literal-only -> (expression | MAXVALUE)
- list_values_clause: broadened to (expression | NULL) and tuple form
  for multi-column LIST partitioning; kept DEFAULT

Tier 2 — structural keywords and blockchain flexibility:
- CREATE TABLE IF NOT EXISTS
- list_partitions / composite_list_partitions / subpartition_by_list:
  accept multi-column partition keys and optional AUTOMATIC
- blockchain_table_clauses: NO DROP / NO DELETE clauses now optional
- blockchain_row_retention_clause: accept 'DAYS IDLE' form
- blockchain_hash_and_data_format_clause: accept arbitrary CHAR_STRING
  or DELIMITED_ID for hash algorithm and version (removed the
  hardcoded SHA2_512_Q / V1_Q lexer tokens)

Tier 3 — missing top-level partition strategies (12.2+/19c):
- PARTITION BY CONSISTENT HASH (... ) PARTITIONS AUTO [SUBPARTITION ...]
- PARTITION BY PARTITIONSET {RANGE|LIST} with range_partitionset_desc
  and list_partitionset_desc

Tier 4 — completeness:
- range_subpartition_desc / list_subpartition_desc / individual_hash_subparts:
  accept optional read_only_clause and indexing_clause
- column_definition: accept optional annotations_clause (Oracle 23c)

New regression fixture plsql/examples/create_table_grammar_gaps.sql
covers every scenario above. Full test suite (go test ./...) is green.
Copilot AI review requested due to automatic review settings April 17, 2026 07:28
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Oracle PL/SQL ANTLR grammar to better match Oracle 19c CREATE TABLE syntax, primarily expanding partitioning support (including expression-valued partition bounds) and adding missing partitioning variants that previously failed to parse (e.g., the BYT-9302 interval/range case).

Changes:

  • Broadened RANGE/LIST partition value clauses to accept full expressions and added additional partitioning strategies (CONSISTENT HASH, PARTITIONSET).
  • Added CREATE TABLE IF NOT EXISTS, enhanced LIST partition key support (multi-column + AUTOMATIC), and loosened blockchain table clause requirements.
  • Added a new SQL fixture file to exercise the newly-supported grammar forms via the existing PL/SQL parser test harness.

Reviewed changes

Copilot reviewed 7 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
plsql/PlSqlParser.g4 Core grammar updates for CREATE TABLE partitioning, blockchain clauses, and column annotations.
plsql/PlSqlLexer.g4 Adds PARTITIONSET token; removes hardcoded blockchain hash/version tokens.
plsql/examples/create_table_grammar_gaps.sql New regression fixtures covering the newly supported CREATE TABLE forms.
plsql/plsqlparser_listener.go Regenerated listener interface for new grammar productions.
plsql/plsqlparser_base_listener.go Regenerated base listener stubs for new grammar productions.
plsql/plsqlparser_visitor.go Regenerated visitor interface for new grammar productions.
plsql/plsqlparser_base_visitor.go Regenerated base visitor stubs for new grammar productions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plsql/PlSqlParser.g4 Outdated
Comment thread plsql/PlSqlParser.g4 Outdated
Comment thread plsql/PlSqlParser.g4
Address review feedback: the parenthesized-tuple alternative in
list_partition_value was unreachable because expression -> atom
already matches LEFT_PAREN expressions RIGHT_PAREN with identical
semantics. Remove the dedicated tuple layer and rely on expression
for tuple form in multi-column LIST partitioning — same parse
coverage with simpler AST shape. Comments on range_partition_value
and list_partition_value explain why their inner alternatives stay
(clarity of intended terminals).
@h3n4l h3n4l merged commit 57b6ef7 into main Apr 17, 2026
5 checks passed
@h3n4l h3n4l deleted the h3n4l/plsql-create-table-grammar-gaps branch April 17, 2026 07:51
h3n4l added a commit to bytebase/bytebase that referenced this pull request Apr 17, 2026
Bump github.com/bytebase/parser to pick up bytebase/parser#66, which
closes a batch of CREATE TABLE grammar gaps against the Oracle 19c
spec. Directly unblocks BYT-9302: PARTITION BY RANGE ... INTERVAL
(NUMTODSINTERVAL(...)) (... VALUES LESS THAN (DATE '...')) now parses.

Add the reported fixture as a regression test in TestPLSQLParser.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
h3n4l added a commit to bytebase/bytebase that referenced this pull request Apr 17, 2026
Bump github.com/bytebase/parser to pick up bytebase/parser#66, which
closes a batch of CREATE TABLE grammar gaps against the Oracle 19c
spec. Directly unblocks BYT-9302: PARTITION BY RANGE ... INTERVAL
(NUMTODSINTERVAL(...)) (... VALUES LESS THAN (DATE '...')) now parses.

Add the reported fixture as a regression test in TestPLSQLParser.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
h3n4l added a commit to bytebase/bytebase that referenced this pull request Apr 17, 2026
…#20042)

Bump github.com/bytebase/parser to pick up bytebase/parser#66, which
closes a batch of CREATE TABLE grammar gaps against the Oracle 19c
spec. Directly unblocks BYT-9302: PARTITION BY RANGE ... INTERVAL
(NUMTODSINTERVAL(...)) (... VALUES LESS THAN (DATE '...')) now parses.

Add the reported fixture as a regression test in TestPLSQLParser.

Co-authored-by: Claude Opus 4.7 (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.

3 participants