Skip to content

Commit ac35e83

Browse files
committed
Introduce DdlBatchAware annotation
1 parent 35c688c commit ac35e83

19 files changed

+114
-36
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.internal.sql.engine.exec.fsm;
19+
20+
import static java.lang.annotation.ElementType.TYPE;
21+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
22+
23+
import java.lang.annotation.Retention;
24+
import java.lang.annotation.Target;
25+
26+
/**
27+
* Annotation that defines how multi-statement handler executes DDL statement.
28+
*
29+
* <p>DDL statements of the same {@link DdlBatchGroup} can be executed in together within the same batch except {@link DdlBatchGroup#OTHER}.
30+
* Statements marked as {@link DdlBatchGroup#OTHER} can be executed only separately, this is the default behavior.
31+
*/
32+
@Target({TYPE})
33+
@Retention(RUNTIME)
34+
public @interface DdlBatchAware {
35+
/** Returns DDL batch group. */
36+
DdlBatchGroup group() default DdlBatchGroup.OTHER;
37+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.ignite.internal.sql.engine.exec.fsm;
19+
20+
/**
21+
* Groups fpr batching compatible DDL operations.
22+
*
23+
* @see DdlBatchAware
24+
*/
25+
public enum DdlBatchGroup {
26+
/** Group for CREATE operations. */
27+
CREATE,
28+
/** Group for DROP operations. */
29+
DROP,
30+
/** Group for other operations. */
31+
OTHER;
32+
}

modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/fsm/DdlBatchingHelper.java

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package org.apache.ignite.internal.sql.engine.exec.fsm;
1919

20-
import org.apache.calcite.sql.SqlKind;
2120
import org.apache.calcite.sql.SqlNode;
2221

2322
/**
@@ -26,42 +25,18 @@
2625
class DdlBatchingHelper {
2726
/** Returns {@code true} if commands (represented by AST trees) can be executed together, {@code false} otherwise. */
2827
static boolean isCompatible(SqlNode node1, SqlNode node2) {
29-
DdlCommandType kind1 = getCommandType(node1);
30-
DdlCommandType kind2 = getCommandType(node2);
28+
DdlBatchGroup kind1 = getCommandType(node1);
29+
DdlBatchGroup kind2 = getCommandType(node2);
3130

32-
return kind1 == kind2 && kind1 != DdlCommandType.OTHER;
31+
return kind1 == kind2 && kind1 != DdlBatchGroup.OTHER;
3332
}
3433

3534
/** Returns command kind. */
36-
private static DdlCommandType getCommandType(SqlNode node) {
37-
SqlKind kind = node.getKind();
35+
private static DdlBatchGroup getCommandType(SqlNode node) {
36+
DdlBatchAware batchAwareAnnotation = node.getClass().getDeclaredAnnotation(DdlBatchAware.class);
3837

39-
switch (kind) {
40-
case CREATE_SCHEMA:
41-
case CREATE_TABLE:
42-
case CREATE_SEQUENCE:
43-
case CREATE_INDEX:
44-
return DdlCommandType.CREATE;
38+
assert batchAwareAnnotation != null : "Batching behaviour wasn't specified for " + node.getClass();
4539

46-
case DROP_SCHEMA:
47-
case DROP_TABLE:
48-
case DROP_INDEX:
49-
case DROP_SEQUENCE:
50-
return DdlCommandType.DROP;
51-
52-
case OTHER_DDL:
53-
default:
54-
return DdlCommandType.OTHER;
55-
}
56-
}
57-
58-
/** DDL command kind. */
59-
private enum DdlCommandType {
60-
/** Create command. */
61-
CREATE,
62-
/** Drop command. */
63-
DROP,
64-
/** Any other DDL command (ALTER command, zone commands, and others). */
65-
OTHER
40+
return batchAwareAnnotation.group();
6641
}
6742
}

modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/exec/fsm/QueryExecutor.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,6 @@ static class ParsedResultWithNextCursorFuture {
623623
this.parsedQuery = parsedQuery;
624624
this.nextCursorFuture = nextCursorFuture;
625625
}
626-
627-
public ParsedResult parsedQuery() {
628-
return parsedQuery;
629-
}
630626
}
631627

632628
@Override

modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/sql/IgniteSqlAlterColumn.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
import org.apache.calcite.sql.SqlWriter;
2828
import org.apache.calcite.sql.parser.SqlParserPos;
2929
import org.apache.calcite.util.ImmutableNullableList;
30+
import org.apache.ignite.internal.sql.engine.exec.fsm.DdlBatchAware;
3031
import org.jetbrains.annotations.Nullable;
3132

3233
/**
3334
* Parse tree for {@code ALTER TABLE ... ALTER COLUMN} statement.
3435
*/
36+
@DdlBatchAware
3537
public class IgniteSqlAlterColumn extends IgniteAbstractSqlAlterTable {
3638

3739
/** ALTER TABLE .. ALTER COLUMN operator. */

modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/sql/IgniteSqlAlterTableAddColumn.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
import org.apache.calcite.sql.SqlWriter;
2929
import org.apache.calcite.sql.parser.SqlParserPos;
3030
import org.apache.calcite.util.ImmutableNullableList;
31+
import org.apache.ignite.internal.sql.engine.exec.fsm.DdlBatchAware;
3132
import org.checkerframework.checker.nullness.qual.Nullable;
3233

3334
/**
3435
* Parse tree for {@code ALTER TABLE ... ADD COLUMN} statement.
3536
*/
37+
@DdlBatchAware
3638
public class IgniteSqlAlterTableAddColumn extends IgniteAbstractSqlAlterTable {
3739

3840
/** ALTER TABLE ... ADD COLUMN operator. */

modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/sql/IgniteSqlAlterTableDropColumn.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
import org.apache.calcite.sql.SqlWriter;
2929
import org.apache.calcite.sql.parser.SqlParserPos;
3030
import org.apache.calcite.util.ImmutableNullableList;
31+
import org.apache.ignite.internal.sql.engine.exec.fsm.DdlBatchAware;
3132
import org.checkerframework.checker.nullness.qual.Nullable;
3233

3334
/**
3435
* Parse tree for {@code ALTER TABLE ... DROP COLUMN} statement.
3536
*/
37+
@DdlBatchAware
3638
public class IgniteSqlAlterTableDropColumn extends IgniteAbstractSqlAlterTable {
3739

3840
/** ALTER TABLE operator. */

modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/sql/IgniteSqlAlterTableSetProperties.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
import org.apache.calcite.sql.SqlWriter;
2929
import org.apache.calcite.sql.parser.SqlParserPos;
3030
import org.apache.calcite.util.ImmutableNullableList;
31+
import org.apache.ignite.internal.sql.engine.exec.fsm.DdlBatchAware;
3132
import org.checkerframework.checker.nullness.qual.Nullable;
3233

3334
/**
3435
* Parse tree for {@code ALTER TABLE ... SET} statement.
3536
*/
37+
@DdlBatchAware
3638
public class IgniteSqlAlterTableSetProperties extends IgniteAbstractSqlAlterTable {
3739

3840
/** ALTER TABLE ... SET operator. */

modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/sql/IgniteSqlAlterZoneRenameTo.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
import org.apache.calcite.sql.SqlWriter;
2828
import org.apache.calcite.sql.parser.SqlParserPos;
2929
import org.apache.calcite.util.ImmutableNullableList;
30+
import org.apache.ignite.internal.sql.engine.exec.fsm.DdlBatchAware;
3031
import org.checkerframework.checker.nullness.qual.Nullable;
3132

3233
/**
3334
* Parse tree for {@code ALTER ZONE RENAME TO} statement.
3435
*/
36+
@DdlBatchAware
3537
public class IgniteSqlAlterZoneRenameTo extends IgniteAbstractSqlAlterZone {
3638

3739
/** ALTER ZONE RENAME TO operator. */

modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/sql/IgniteSqlAlterZoneSet.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
import org.apache.calcite.sql.SqlWriter;
2929
import org.apache.calcite.sql.parser.SqlParserPos;
3030
import org.apache.calcite.util.ImmutableNullableList;
31+
import org.apache.ignite.internal.sql.engine.exec.fsm.DdlBatchAware;
3132
import org.checkerframework.checker.nullness.qual.Nullable;
3233

3334
/**
3435
* Parse tree for {@code ALTER ZONE SET} statement.
3536
*/
37+
@DdlBatchAware
3638
public class IgniteSqlAlterZoneSet extends IgniteAbstractSqlAlterZone {
3739

3840
/** ALTER ZONE SET operator. */

0 commit comments

Comments
 (0)