Skip to content

Commit

Permalink
[fix][dingo-calcite] Resolve the issue of inconsistency between the n…
Browse files Browse the repository at this point in the history
…umber of copies in meta records and the actual number of copies
  • Loading branch information
guojn1 committed Feb 21, 2025
1 parent 565ca7f commit 18b86a2
Show file tree
Hide file tree
Showing 24 changed files with 271 additions and 131 deletions.
11 changes: 8 additions & 3 deletions dingo-calcite/src/main/codegen/includes/AlterTable.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ SqlAlterTable SqlAlterTable(Span s, String scope): {
alterTable = addColumn(s, scope, id)
|
alterTable = addConstraint(s, scope, id)
|
alterTable = foreign(s, id)
|
<FULLTEXT> alterTable = addIndexByMode(s, scope, id, "fulltext")
|
Expand Down Expand Up @@ -242,7 +244,8 @@ SqlAlterTable addIndex(Span s, String scope, SqlIdentifier id): {
[<SCALAR>] columnList = indexColumns()
)
(
<WITH> withColumnList = ParenthesizedSimpleIdentifierList()
LOOKAHEAD(2)
<WITH> (withColumnList = ParenthesizedSimpleIdentifierList() | <PARSER> { strIdent(); })
|
<ENGINE> <EQ> engine = dingoIdentifier() { if (engine.equalsIgnoreCase("innodb")) { engine = "TXN_LSM";} }
|
Expand Down Expand Up @@ -288,7 +291,8 @@ SqlAlterTable addUniqueIndex(Span s, String scope, SqlIdentifier id): {
{ index = getNextToken().image; }
[<SCALAR>] columnList = indexColumns()
(
<WITH> withColumnList = ParenthesizedSimpleIdentifierList()
LOOKAHEAD(2)
<WITH> (withColumnList = ParenthesizedSimpleIdentifierList() | <PARSER> { strIdent(); })
|
<ENGINE> <EQ> engine = dingoIdentifier() { if (engine.equalsIgnoreCase("innodb")) { engine = "TXN_LSM";} }
|
Expand Down Expand Up @@ -334,7 +338,8 @@ SqlAlterTable addIndexByMode(Span s, String scope, SqlIdentifier id, String mode
{ index = getNextToken().image; }
columnList = indexColumns()
(
<WITH> withColumnList = ParenthesizedSimpleIdentifierList()
LOOKAHEAD(2)
<WITH> (withColumnList = ParenthesizedSimpleIdentifierList() | <PARSER> { strIdent(); })
|
<ENGINE> <EQ> engine = dingoIdentifier() { if (engine.equalsIgnoreCase("innodb")) { engine = "TXN_LSM";} }
|
Expand Down
1 change: 1 addition & 0 deletions dingo-calcite/src/main/codegen/includes/Show.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ SqlShow SqlShowTable(Span s): {
} {
<TABLE>
(
LOOKAHEAD(2)
<STATUS> [ <FROM> (<QUOTED_STRING> | <IDENTIFIER>) { schema = token.image.toUpperCase(); } ]
[ <LIKE> <QUOTED_STRING> { pattern = token.image.toUpperCase().replace("'", ""); } ]
{
Expand Down
10 changes: 4 additions & 6 deletions dingo-calcite/src/main/codegen/includes/parserImpls.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ void TableElement(List<SqlNode> list) :
|
<REFERENCES> refTable = CompoundIdentifier() refColumnList = ParenthesizedSimpleIdentifierList()
[<MATCH>(<FULL>|<PARTIAL>|<SIMPLE>)]
( <ON> (
( LOOKAHEAD(2) <ON> (
<UPDATE> updateRefOpt = referenceOpt()
|
<DELETE> deleteRefOpt = referenceOpt()
Expand All @@ -226,7 +226,7 @@ void TableElement(List<SqlNode> list) :
}
)
|
[ <CONSTRAINT> { s.add(this); } [name = SimpleIdentifier()] ]
[ LOOKAHEAD(2) <CONSTRAINT> { s.add(this); } [name = SimpleIdentifier()] ]
(
<CHECK> { s.add(this); } <LPAREN>
e = Expression(ExprContext.ACCEPT_SUB_QUERY) <RPAREN> [<NOT>] (<ENFORCED>|<NULL>|{ String t = "";}){
Expand All @@ -247,7 +247,7 @@ void TableElement(List<SqlNode> list) :
{ indexType = "text"; }
columnList = ParenthesizedSimpleIdentifierList()
)
( <WITH> withColumnList = ParenthesizedSimpleIdentifierList()
( <WITH> (withColumnList = ParenthesizedSimpleIdentifierList() | <PARSER> { strIdent();})
|
<ENGINE> <EQ> { engine = getNextToken().image; if (engine.equalsIgnoreCase("innodb")) { engine = "TXN_LSM";} }
|
Expand Down Expand Up @@ -403,7 +403,7 @@ ColumnOption parseColumnOption(): {
|
<REFERENCES> refTable = CompoundIdentifier() refColumnList = ParenthesizedSimpleIdentifierList()
[<MATCH>(<FULL>|<PARTIAL>|<SIMPLE>)]
( <ON> (
( LOOKAHEAD(2) <ON> (
<UPDATE> updateRefOpt = referenceOpt()
|
<DELETE> deleteRefOpt = referenceOpt()
Expand Down Expand Up @@ -915,8 +915,6 @@ Properties indexOption(): {
|
indexType = indexTypeName() { prop.put("indexType", indexType);}
|
<WITH> <PARSER> { prop.put("parser", strIdent()); }
|
<COMMENT> { prop.put("comment", strIdent());}
|
<VISIBLE> { prop.put("visible", "true"); }
Expand Down
98 changes: 57 additions & 41 deletions dingo-calcite/src/main/codegen/templates/Parser.jj
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,7 @@ void AddArg0(List<SqlNode> list, ExprContext exprContext) :
LOOKAHEAD(3)
e = TableParam()
|
LOOKAHEAD(2)
e = PartitionedQueryOrQueryOrExpr(firstExprContext)
|
e = TableFunctionCall()
Expand Down Expand Up @@ -1107,6 +1108,7 @@ void AddArg(List<SqlNode> list, ExprContext exprContext) :
|
e = Expression(exprContext)
|
LOOKAHEAD(2)
e = TableParam()
|
e = TableFunctionCall()
Expand Down Expand Up @@ -1412,9 +1414,9 @@ SqlNode SqlSelect() :
( groupBy = GroupBy() | { groupBy = null; } )
( having = Having() | { having = null; } )
( windowDecls = Window() | { windowDecls = null; } )
[ exportOptions = exportOptions() ]
[ <FOR> <UPDATE> { forUpdate=true; }]
[ <AS> <OF> { flashbackQuery = true; }
[ LOOKAHEAD(2) exportOptions = exportOptions() ]
[ LOOKAHEAD(2) <FOR> <UPDATE> { forUpdate=true; }]
[ LOOKAHEAD(2) <AS> <OF> { flashbackQuery = true; }
(
<TIMESTAMP> <QUOTED_STRING> { flashBackStr = token.image.replace("'", ""); }
|
Expand Down Expand Up @@ -1490,8 +1492,8 @@ SqlNode SqlTraceSelect() :
( windowDecls = Window() | { windowDecls = null; } )
( orderBy = OrderBy(true) | { orderBy = null; } )
[ LimitClause(s, offsetFetch) ]
[ exportOptions = exportOptions() ]
[ <FOR> <UPDATE> { forUpdate=true; }]
[ LOOKAHEAD(2) exportOptions = exportOptions() ]
[ LOOKAHEAD(2) <FOR> <UPDATE> { forUpdate=true; }]
|
E() {
fromClause = null;
Expand Down Expand Up @@ -1542,15 +1544,12 @@ ExportOptions exportOptions(): {
]
[
<LINES>
[ <STARTING> <BY> [<QUOTED_STRING> { lineStarting = getSpecialBytes(token.image); }]
( <STARTING> <BY> [<QUOTED_STRING> { lineStarting = getSpecialBytes(token.image); }]
[<BINARY_STRING_LITERAL> { lineStarting = getSpecialHexBytes(token.image); }]
]
[ <TERMINATED> <BY> [<QUOTED_STRING> { lineTerminated = getSpecialBytes(token.image); } ]
|
<TERMINATED> <BY> [<QUOTED_STRING> { lineTerminated = getSpecialBytes(token.image); } ]
[<BINARY_STRING_LITERAL> { lineTerminated = getSpecialHexBytes(token.image); }]
]
[ <STARTING> <BY> [<QUOTED_STRING> { lineStarting = getSpecialBytes(token.image); }]
[<BINARY_STRING_LITERAL> { lineStarting = getSpecialHexBytes(token.image); }]
]
)*
]
[ <STARTTS> (<UNSIGNED_INTEGER_LITERAL> | <DECIMAL_NUMERIC_LITERAL>) { startTs = Long.parseLong(token.image); }]
{
Expand Down Expand Up @@ -2447,7 +2446,7 @@ SqlNode TableRef3(ExprContext exprContext, boolean lateral) :
( tableRef = TableHints(tableName) | { tableRef = tableName; } )
[ tableRef = ExtendTable(tableRef) ]
tableRef = Over(tableRef)
[ tableRef = Snapshot(tableRef) ]
[ LOOKAHEAD(2) tableRef = Snapshot(tableRef) ]
[ tableRef = MatchRecognize(tableRef) ]
|
LOOKAHEAD(2)
Expand All @@ -2460,6 +2459,7 @@ SqlNode TableRef3(ExprContext exprContext, boolean lateral) :
<UNNEST> { s = span(); }
args = ParenthesizedQueryOrCommaList(ExprContext.ACCEPT_SUB_QUERY)
[
LOOKAHEAD(2)
<WITH> <ORDINALITY> {
unnestOp = SqlStdOperatorTable.UNNEST_WITH_ORDINALITY;
}
Expand All @@ -2485,7 +2485,7 @@ SqlNode TableRef3(ExprContext exprContext, boolean lateral) :
tableRef = Unpivot(tableRef)
]
[
[ <AS> ]
[ LOOKAHEAD(2) <AS> ]
(
alias = SimpleIdentifier()
|
Expand Down Expand Up @@ -3771,6 +3771,7 @@ SqlNode LeafQueryOrExpr(ExprContext exprContext) :
SqlNode e;
}
{
LOOKAHEAD(2)
e = LeafQuery(exprContext) { return e; }
|
e = Expression(exprContext) { return e; }
Expand Down Expand Up @@ -4342,6 +4343,7 @@ SqlNode AtomicRowExpression() :
LOOKAHEAD( [<SPECIFIC>] FunctionName() <LPAREN>)
e = NamedFunctionCall()
|
LOOKAHEAD(2)
e = ContextVariable()
|
e = CompoundIdentifier()
Expand Down Expand Up @@ -4435,7 +4437,8 @@ SqlSetOption SqlSetOption(Span s, String scope) :
<SET> {
s.add(this);
}
[
(
LOOKAHEAD(2)
<PASSWORD> <FOR>
( <QUOTED_STRING> | <IDENTIFIER> )
{ user = token.image; }
Expand All @@ -4448,14 +4451,18 @@ SqlSetOption SqlSetOption(Span s, String scope) :
{
return new SqlSetPassword(s.end(this), user, host, password);
}
]
|
(
[ <COMMA> ]
[ <GLOBAL> { scope = "SYSTEM"; } ]
[ <SESSION> { scope = "SESSION"; } ]
[ <EXECUTOR> { scope = "EXECUTOR"; } ]
[ <AT_SPLIT> { scope = "USER"; } ]
[ <AT_SPLIT_2> { scope = "GLOBAL"; } ]
LOOKAHEAD(2)<GLOBAL> { scope = "SYSTEM"; }
|
LOOKAHEAD(2)<SESSION> { scope = "SESSION"; }
|
<EXECUTOR> { scope = "EXECUTOR"; }
|
<AT_SPLIT> { scope = "USER"; }
|
<AT_SPLIT_2> { scope = "GLOBAL"; }
|
name = CompoundIdentifier()
(
<UTF8> {
Expand All @@ -4468,13 +4475,17 @@ SqlSetOption SqlSetOption(Span s, String scope) :
return new SqlSetOption(s.end(this), scope, name, val);
}
|
(<QUOTED_STRING> <COLLATE> <QUOTED_STRING>
|
<QUOTED_STRING> <COLLATE> <QUOTED_STRING>
|
<ISOLATION> <LEVEL>
[<READ> [<MINUS>] [ <COMMITTED> { val = new SqlIdentifier("read-committed", s.end(this)); } ] [<UNCOMMITTED> { val = new SqlIdentifier("read-uncommitted", s.end(this)); }] ]
[<REPEATABLE> [<MINUS>] <READ> { val = new SqlIdentifier("repeatable-read", s.end(this)); } ]
[<SERIALIZABLE> { val = new SqlIdentifier(token.image, s.end(this)); }]
){
(
<READ> [<MINUS>] ( <COMMITTED> { val = new SqlIdentifier("read-committed", s.end(this)); } | <UNCOMMITTED> { val = new SqlIdentifier("read-uncommitted", s.end(this)); })
|
<REPEATABLE> [<MINUS>] <READ> { val = new SqlIdentifier("repeatable-read", s.end(this)); }
|
<SERIALIZABLE> { val = new SqlIdentifier(token.image, s.end(this)); }
)
{
if (name.names.size() != 1 || !name.names.get(0).equalsIgnoreCase("transaction")) {
throw new RuntimeException("Syntax error");
}
Expand All @@ -4485,7 +4496,7 @@ SqlSetOption SqlSetOption(Span s, String scope) :
return new SqlSetOption(s.end(this), scope, name, val);
}
|
<READ> [<WRITE> { val = new SqlIdentifier("off", s.end(this)); }]{
<READ> {
name = new SqlIdentifier("transaction_read_only", name.getParserPosition());
if (val == null) {
val = new SqlIdentifier("on", s.end(this));
Expand Down Expand Up @@ -4513,8 +4524,10 @@ SqlSetOption SqlSetOption(Span s, String scope) :
val = new SqlIdentifier(token.image.toUpperCase(Locale.ROOT), getPos());
}
)
[ <COMMA> ]
)
)*
)
{
if (scope == null) {
scope = "session";
Expand Down Expand Up @@ -5417,17 +5430,17 @@ SqlIntervalQualifier TimeUnitOrName() : {
{
LOOKAHEAD(2)
<NANOSECOND> { return new SqlIntervalQualifier(TimeUnit.NANOSECOND, null, getPos()); }
| <MICROSECOND> { return new SqlIntervalQualifier(TimeUnit.MICROSECOND, null, getPos()); }
| <MILLISECOND> { return new SqlIntervalQualifier(TimeUnit.MILLISECOND, null, getPos()); }
| LOOKAHEAD(2) <MICROSECOND> { return new SqlIntervalQualifier(TimeUnit.MICROSECOND, null, getPos()); }
| LOOKAHEAD(2) <MILLISECOND> { return new SqlIntervalQualifier(TimeUnit.MILLISECOND, null, getPos()); }
| <SECOND> { return new SqlIntervalQualifier(TimeUnit.SECOND, null, getPos()); }
| <MINUTE> { return new SqlIntervalQualifier(TimeUnit.MINUTE, null, getPos()); }
| <HOUR> { return new SqlIntervalQualifier(TimeUnit.HOUR, null, getPos()); }
| <DAY> { return new SqlIntervalQualifier(TimeUnit.DAY, null, getPos()); }
| <DOW> { return new SqlIntervalQualifier(TimeUnit.DOW, null, getPos()); }
| <DOY> { return new SqlIntervalQualifier(TimeUnit.DOY, null, getPos()); }
| <ISODOW> { return new SqlIntervalQualifier(TimeUnit.ISODOW, null, getPos()); }
| <ISOYEAR> { return new SqlIntervalQualifier(TimeUnit.ISOYEAR, null, getPos()); }
| <WEEK> { span = span(); }
| LOOKAHEAD(2) <DOW> { return new SqlIntervalQualifier(TimeUnit.DOW, null, getPos()); }
| LOOKAHEAD(2) <DOY> { return new SqlIntervalQualifier(TimeUnit.DOY, null, getPos()); }
| LOOKAHEAD(2) <ISODOW> { return new SqlIntervalQualifier(TimeUnit.ISODOW, null, getPos()); }
| LOOKAHEAD(2) <ISOYEAR> { return new SqlIntervalQualifier(TimeUnit.ISOYEAR, null, getPos()); }
| LOOKAHEAD(2) <WEEK> { span = span(); }
(
LOOKAHEAD(2)
<LPAREN> w = weekdayName() <RPAREN> {
Expand All @@ -5437,12 +5450,12 @@ SqlIntervalQualifier TimeUnitOrName() : {
{ return new SqlIntervalQualifier(TimeUnit.WEEK, null, getPos()); }
)
| <MONTH> { return new SqlIntervalQualifier(TimeUnit.MONTH, null, getPos()); }
| <QUARTER> { return new SqlIntervalQualifier(TimeUnit.QUARTER, null, getPos()); }
| LOOKAHEAD(2) <QUARTER> { return new SqlIntervalQualifier(TimeUnit.QUARTER, null, getPos()); }
| <YEAR> { return new SqlIntervalQualifier(TimeUnit.YEAR, null, getPos()); }
| <EPOCH> { return new SqlIntervalQualifier(TimeUnit.EPOCH, null, getPos()); }
| <DECADE> { return new SqlIntervalQualifier(TimeUnit.DECADE, null, getPos()); }
| <CENTURY> { return new SqlIntervalQualifier(TimeUnit.CENTURY, null, getPos()); }
| <MILLENNIUM> { return new SqlIntervalQualifier(TimeUnit.MILLENNIUM, null, getPos()); }
| LOOKAHEAD(2) <EPOCH> { return new SqlIntervalQualifier(TimeUnit.EPOCH, null, getPos()); }
| LOOKAHEAD(2) <DECADE> { return new SqlIntervalQualifier(TimeUnit.DECADE, null, getPos()); }
| LOOKAHEAD(2) <CENTURY> { return new SqlIntervalQualifier(TimeUnit.CENTURY, null, getPos()); }
| LOOKAHEAD(2) <MILLENNIUM> { return new SqlIntervalQualifier(TimeUnit.MILLENNIUM, null, getPos()); }
| unitName = SimpleIdentifier() {
return new SqlIntervalQualifier(unitName.getSimple(),
unitName.getParserPosition());
Expand Down Expand Up @@ -7084,6 +7097,7 @@ SqlCall DateTruncFunctionCall() :
// the BigQuery variant, e.g. "DATE_TRUNC(d, YEAR)",
// and the Redshift variant, e.g. "DATE_TRUNC('year', DATE '2008-09-08')".
(
LOOKAHEAD(2)
unit = TimeUnitOrName() { args.add(unit); }
|
AddExpression(args, ExprContext.ACCEPT_SUB_QUERY)
Expand Down Expand Up @@ -7511,6 +7525,7 @@ SqlIdentifier FunctionName() :
}
{
(
LOOKAHEAD(2)
qualifiedName = CompoundIdentifier()
|
qualifiedName = ReservedFunctionName()
Expand Down Expand Up @@ -7703,6 +7718,7 @@ SqlNode JdbcFunctionCall() :
LOOKAHEAD(1)
( <INSERT> | <LEFT> | <RIGHT> | <TRUNCATE> ) { name = unquotedIdentifier(); }
|
LOOKAHEAD(2)
// For cases like {fn power(1,2)} and {fn lower('a')}
id = ReservedFunctionName() { name = id.getSimple(); }
|
Expand Down
Loading

0 comments on commit 18b86a2

Please sign in to comment.