public class OceanBaseSqlParser extends Object implements SqlParser
OceanBase is a multi-tenant database whose SQL surface depends on the
tenant kind. Each tenant is permanently MySQL-compatible, Oracle-compatible,
or the system (sys) tenant. This parser is a thin
SqlParser adapter that selects a delegate based on the
EOBTenantMode carried inside ParserContext (mirrored from
TGSqlParser.setOBTenantMode).
This class implements SqlParser directly rather than extending
AbstractSqlParser. The reason is that AbstractSqlParser.parse(gudusoft.gsqlparser.parser.ParserContext)
is final and the template method orchestrates state on the
subclass instance (sourcetokenlist, sqlstatements,
lexer, parserContext, etc.). Splitting that state across
an OceanBase wrapper plus a wrapped MySQL/Oracle delegate would be a
concurrency-unsafe nightmare and defeat the purpose of the abstract
template. By implementing the small SqlParser interface directly,
Phase 1 forwards the entire parse cycle to a single delegate as an atomic
unit, which is both simpler and easier to reason about.
The delegate's lexer/parser/AST machinery is reused as-is. AST nodes
built during delegation report dbvoceanbase as their vendor
because TGSqlParser.doDelegatedRawParse re-binds the
NodeFactory back-reference to the OceanBase-configured TGSqlParser after the vendor parser returns. This is
the same fixup mechanism existing delegated vendors rely on.
CREATE TENANT, ALTER SYSTEM, OB hint payloads,
OB partition syntax, tablegroups, outlines, or global indexes.
OB-specific syntax is added incrementally in Phase 4 after the
grammar forks land in Phases 2/3.TGSqlParser.setOBTenantMode(gudusoft.gsqlparser.EOBTenantMode). Boundary
detection of admin prefixes is handled by
TSqlCmdsOceanbase for statement splitting only.TGSqlParser instance — OceanBase
tenants are immutable in mode at creation time on the server side.Phase 2 — landed: EOBTenantMode.MYSQL and
EOBTenantMode.SYSTEM route to OceanBaseMysqlSqlParser
(the forked MySQL grammar).
Phase 3 — landed: EOBTenantMode.ORACLE routes to
OceanBaseOracleSqlParser (the forked Oracle dual grammar
with full PL/SQL support). The public contract of this class does
not change across these promotions.
SqlParser,
EOBTenantMode,
TGSqlParser.setOBTenantMode(gudusoft.gsqlparser.EOBTenantMode)| Constructor and Description |
|---|
OceanBaseSqlParser()
Construct an OceanBase parser.
|
| Modifier and Type | Method and Description |
|---|---|
SqlParseResult |
getrawsqlstatements(ParserContext context)
Extract raw SQL statements without full parsing.
|
EDbVendor |
getVendor()
Get the database vendor this parser handles.
|
SqlParseResult |
parse(ParserContext context)
Parse SQL from the given context.
|
SqlParseResult |
tokenize(ParserContext context)
Tokenize SQL without parsing or statement extraction.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitdoExtractRawStatementspublic OceanBaseSqlParser()
dbvoceanbase
but never actually used does not pay any allocation cost.public EDbVendor getVendor()
SqlParserpublic SqlParseResult parse(ParserContext context)
SqlParserThis method performs full parsing including:
All inputs come from the context parameter, all outputs go to the result. This ensures clean separation of concerns and thread-safety.
public SqlParseResult tokenize(ParserContext context)
SqlParserThis method performs only tokenization (lexical analysis):
The result contains tokens but NO statements. Use this when you only need the token stream (e.g., for syntax highlighting, token analysis).
For statement boundaries without full parsing, use SqlParser.getrawsqlstatements(ParserContext).
public SqlParseResult getrawsqlstatements(ParserContext context)
SqlParserThis method performs:
This is faster than SqlParser.parse(ParserContext) because it skips
detailed syntax checking and semantic analysis. The statements returned
have their tokens grouped correctly but no AST (parse tree) is built.
Use cases:
Equivalent to legacy API: TGSqlParser.getrawsqlstatements()
Default implementation: For parsers still in delegation phase,
this default implementation falls back to SqlParser.tokenize(ParserContext).
Parsers extending AbstractSqlParser override this with proper implementation.
getrawsqlstatements in interface SqlParsercontext - immutable context containing all parser inputs