このドキュメントは、spec/apache-calcite-Parser.js が出力する AST の最小仕様をまとめたものです。
現状は実装の読みやすさ優先の軽量ノード構成です。
- すべてのノードは
typeフィールドを持つ - 省略可能要素は
nullまたは未設定 - リストは配列で表現
SqlStmtListstatements: ステートメント配列
SqlStmtEofstmt
SqlExpressionEofexpr
SqlSelecthints:TableHints | nullstream:booleansetQuantifier:"ALL" | "DISTINCT" | nullselectItems:AddSelectItem[]from:FromClause | nullwhere:Where | nullgroupBy:GroupBy | nullhaving:Having | nullwindow:Window | nullqualify:Qualify | null
QueryOrExprwithList,leaf,setOps
OrderedQueryOrExprquery,orderByLimitOpt
FromClausefirst:TableRefjoins: (JoinTable|CommaJoin|ApplyJoin)[]
JoinTablenatural:booleanjoinType:string(e.g."JOIN","LEFT JOIN")table:TableRefcondition:On | Using | null
CommaJointable
Whereexpr
GroupByset:"DISTINCT" | "ALL" | nulllist:GroupingElementList
Havingexpr
Windowitems:AddWindowSpec[]
Qualifyexpr
OrderBylist:OrderItemList
LimitClausevalue,offset
OffsetClausevalue,rows
FetchClausemode,value,rows
TableRefbase,pivot,unpivot,matchRecognize,alias,columns,tablesample
TableNamename:CompoundTableIdentifier
Subqueryquery:OrderedQueryOrExpr
Unnestitems:Expression[]withOrdinality:boolean
TableFunctionCallcall:NamedRoutineCall
Pivotaggs:AddPivotAgg[]axis:SimpleIdentifierOrListvalues:AddPivotValue[]
Unpivotnulls:"INCLUDE" | "EXCLUDE" | nullcolumns:SimpleIdentifierOrListaxis:SimpleIdentifierOrListvalues:AddUnpivotValue[]
MatchRecognizepartitionBy,orderBy,measures,rowsPerMatch,afterMatchSkippattern,anchorStart,anchorEnd,within,subsets,define
Expression2b(内部表現)prefixes,base,extensions
BinaryExpressionoperator,left,right
Literalvalue
StringLiteralvalue
NumericLiteralvalue
Identifiername
CompoundIdentifierparts
NamedFunctionCallname,args,orderBy,withinGroup,nullTreatment,filter,over
BuiltinFunctionCallkindごとにフィールドが異なる(各関数ノード参照)
MatchRecognizeFunctionCall
SqlInsert/SqlDelete/SqlUpdate/SqlMergeSqlSetOption/SqlAlter/SqlExplain/SqlDescribe
{
"type": "SqlStmtList",
"statements": [
{
"type": "SqlSelect",
"selectItems": [
{ "type": "AddSelectItem", "expr": { "type": "SelectExpression", "star": true } }
],
"from": {
"type": "FromClause",
"first": { "type": "TableRef", "base": { "type": "TableName", "name": { "type": "CompoundTableIdentifier" } } },
"joins": []
}
}
]
}Expression*系の正規化BuiltinFunctionCallの各関数ノードの仕様を追加- テストで AST 形を固定