Skip to content

Commit 8271fb5

Browse files
IGNITE-15424 Move query schema management infrastructure to the core module - Fixes #10200.
Signed-off-by: Aleksey Plekhanov <plehanov.alex@gmail.com> (cherry picked from commit 7b17327)
1 parent 00842a7 commit 8271fb5

113 files changed

Lines changed: 4640 additions & 4519 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/_docs/SQL/sql-calcite.adoc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ CAUTION: The Calcite-based query engine is currently in beta status.
2626

2727
To use a Calcite-based engine, please make sure that the Calcite module libraries are in a classpath.
2828

29-
CAUTION: Currently, a part of the `ignite-indexing` module functionality is reused, this means the `ignite-indexing` module also has to be present at classpath.
30-
3129
=== Standalone Mode
3230

3331
When starting a standalone node, move `optional/ignite-calcite` folder to the `libs` folder before running `ignite.{sh|bat}` script. In this case, the content of the module folder is added to the classpath.

modules/calcite/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@
5555
</dependency>
5656

5757
<!--
58-
At now the new calcite engine reuses some logic
59-
and doesn't work without "old" indexing module.
58+
Indexing is required for cross-engines tests.
6059
-->
6160
<dependency>
6261
<groupId>${project.groupId}</groupId>
6362
<artifactId>ignite-indexing</artifactId>
63+
<scope>test</scope>
6464
</dependency>
6565

6666
<dependency>

modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessor.java

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@ public class CalciteQueryProcessor extends GridProcessorAdapter implements Query
194194
/** */
195195
private final QueryRegistry qryReg;
196196

197+
/** */
198+
private volatile boolean started;
199+
197200
/**
198201
* @param ctx Kernal context.
199202
*/
@@ -283,7 +286,7 @@ public PrepareServiceImpl prepareService() {
283286
}
284287

285288
/** {@inheritDoc} */
286-
@Override public void start() {
289+
@Override public void onKernalStart(boolean active) {
287290
onStart(ctx,
288291
executionSvc,
289292
mailboxRegistry,
@@ -296,22 +299,28 @@ public PrepareServiceImpl prepareService() {
296299
exchangeSvc,
297300
qryReg
298301
);
302+
303+
started = true;
299304
}
300305

301306
/** {@inheritDoc} */
302-
@Override public void stop(boolean cancel) {
303-
onStop(
304-
qryReg,
305-
executionSvc,
306-
mailboxRegistry,
307-
partSvc,
308-
schemaHolder,
309-
msgSvc,
310-
taskExecutor,
311-
mappingSvc,
312-
qryPlanCache,
313-
exchangeSvc
314-
);
307+
@Override public void onKernalStop(boolean cancel) {
308+
if (started) {
309+
started = false;
310+
311+
onStop(
312+
qryReg,
313+
executionSvc,
314+
mailboxRegistry,
315+
partSvc,
316+
schemaHolder,
317+
msgSvc,
318+
taskExecutor,
319+
mappingSvc,
320+
qryPlanCache,
321+
exchangeSvc
322+
);
323+
}
315324
}
316325

317326
/** {@inheritDoc} */

modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/ExecutionServiceImpl.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public class ExecutionServiceImpl<Row> extends AbstractService implements Execut
152152
private final RowHandler<Row> handler;
153153

154154
/** */
155-
private final DdlCommandHandler ddlCmdHnd;
155+
private DdlCommandHandler ddlCmdHnd;
156156

157157
/**
158158
* @param ctx Kernal.
@@ -162,10 +162,6 @@ public ExecutionServiceImpl(GridKernalContext ctx, RowHandler<Row> handler) {
162162
this.handler = handler;
163163

164164
discoLsnr = (e, c) -> onNodeLeft(e.eventNode().id());
165-
166-
ddlCmdHnd = new DdlCommandHandler(
167-
ctx::query, ctx.cache(), ctx.security(), () -> schemaHolder().schema(null)
168-
);
169165
}
170166

171167
/**
@@ -384,6 +380,8 @@ public void queryRegistry(QueryRegistry qryReg) {
384380
queryRegistry(proc.queryRegistry());
385381
prepareService(proc.prepareService());
386382

383+
ddlCmdHnd = new DdlCommandHandler(ctx.query(), ctx.cache(), ctx.security(), () -> schemaHolder().schema(null));
384+
387385
init();
388386
}
389387

modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/ddl/DdlCommandHandler.java

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import org.apache.ignite.internal.processors.cache.GridCacheProcessor;
3939
import org.apache.ignite.internal.processors.cache.query.IgniteQueryErrorCode;
4040
import org.apache.ignite.internal.processors.query.GridQueryProcessor;
41-
import org.apache.ignite.internal.processors.query.GridQuerySchemaManager;
4241
import org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor;
4342
import org.apache.ignite.internal.processors.query.IgniteSQLException;
4443
import org.apache.ignite.internal.processors.query.QueryEntityEx;
@@ -56,6 +55,8 @@
5655
import org.apache.ignite.internal.processors.query.calcite.type.IgniteTypeFactory;
5756
import org.apache.ignite.internal.processors.query.calcite.util.Commons;
5857
import org.apache.ignite.internal.processors.query.schema.SchemaOperationException;
58+
import org.apache.ignite.internal.processors.query.schema.management.SchemaManager;
59+
import org.apache.ignite.internal.processors.query.schema.management.TableDescriptor;
5960
import org.apache.ignite.internal.processors.security.IgniteSecurity;
6061
import org.apache.ignite.internal.util.typedef.F;
6162
import org.apache.ignite.lang.IgniteUuid;
@@ -67,10 +68,10 @@
6768
/** */
6869
public class DdlCommandHandler {
6970
/** */
70-
private final Supplier<GridQueryProcessor> qryProcessorSupp;
71+
private final GridQueryProcessor qryProc;
7172

7273
/** */
73-
private final GridCacheProcessor cacheProcessor;
74+
private final GridCacheProcessor cacheProc;
7475

7576
/** */
7677
private final IgniteSecurity security;
@@ -82,17 +83,17 @@ public class DdlCommandHandler {
8283
private final NativeCommandHandler nativeCmdHnd;
8384

8485
/** */
85-
private final GridQuerySchemaManager schemaMgr;
86+
private final SchemaManager schemaMgr;
8687

8788
/** */
88-
public DdlCommandHandler(Supplier<GridQueryProcessor> qryProcessorSupp, GridCacheProcessor cacheProcessor,
89+
public DdlCommandHandler(GridQueryProcessor qryProc, GridCacheProcessor cacheProc,
8990
IgniteSecurity security, Supplier<SchemaPlus> schemaSupp) {
90-
this.qryProcessorSupp = qryProcessorSupp;
91-
this.cacheProcessor = cacheProcessor;
91+
this.qryProc = qryProc;
92+
this.cacheProc = cacheProc;
9293
this.security = security;
9394
this.schemaSupp = schemaSupp;
94-
schemaMgr = new SchemaManager(schemaSupp);
95-
nativeCmdHnd = new NativeCommandHandler(cacheProcessor.context().kernalContext(), schemaMgr);
95+
schemaMgr = qryProc.schemaManager();
96+
nativeCmdHnd = new NativeCommandHandler(cacheProc.context().kernalContext());
9697
}
9798

9899
/** */
@@ -143,13 +144,13 @@ private void handle0(CreateTableCommand cmd) throws IgniteCheckedException {
143144
ccfg.setSqlSchema(cmd.schemaName());
144145

145146
SchemaOperationException err =
146-
QueryUtils.checkQueryEntityConflicts(ccfg, cacheProcessor.cacheDescriptors().values());
147+
QueryUtils.checkQueryEntityConflicts(ccfg, cacheProc.cacheDescriptors().values());
147148

148149
if (err != null)
149150
throw convert(err);
150151

151-
if (!F.isEmpty(cmd.cacheName()) && cacheProcessor.cacheDescriptor(cmd.cacheName()) != null) {
152-
qryProcessorSupp.get().dynamicAddQueryEntity(
152+
if (!F.isEmpty(cmd.cacheName()) && cacheProc.cacheDescriptor(cmd.cacheName()) != null) {
153+
qryProc.dynamicAddQueryEntity(
153154
cmd.cacheName(),
154155
cmd.schemaName(),
155156
e,
@@ -158,7 +159,7 @@ private void handle0(CreateTableCommand cmd) throws IgniteCheckedException {
158159
).get();
159160
}
160161
else {
161-
qryProcessorSupp.get().dynamicTableCreate(
162+
qryProc.dynamicTableCreate(
162163
cmd.schemaName(),
163164
e,
164165
cmd.templateName(),
@@ -195,20 +196,22 @@ private void handle0(DropTableCommand cmd) throws IgniteCheckedException {
195196

196197
security.authorize(cacheName, SecurityPermission.CACHE_DESTROY);
197198

198-
qryProcessorSupp.get().dynamicTableDrop(cacheName, cmd.tableName(), cmd.ifExists());
199+
qryProc.dynamicTableDrop(cacheName, cmd.tableName(), cmd.ifExists());
199200
}
200201

201202
/** */
202203
private void handle0(AlterTableAddCommand cmd) throws IgniteCheckedException {
203204
isDdlOnSchemaSupported(cmd.schemaName());
204205

205-
GridQueryTypeDescriptor typeDesc = schemaMgr.typeDescriptorForTable(cmd.schemaName(), cmd.tableName());
206+
TableDescriptor tblDesc = schemaMgr.table(cmd.schemaName(), cmd.tableName());
206207

207-
if (typeDesc == null) {
208+
if (tblDesc == null) {
208209
if (!cmd.ifTableExists())
209210
throw new SchemaOperationException(SchemaOperationException.CODE_TABLE_NOT_FOUND, cmd.tableName());
210211
}
211212
else {
213+
GridQueryTypeDescriptor typeDesc = tblDesc.type();
214+
212215
if (QueryUtils.isSqlType(typeDesc.valueClass())) {
213216
throw new SchemaOperationException("Cannot add column(s) because table was created " +
214217
"with WRAP_VALUE=false option.");
@@ -243,14 +246,14 @@ private void handle0(AlterTableAddCommand cmd) throws IgniteCheckedException {
243246
}
244247

245248
if (!F.isEmpty(cols)) {
246-
GridCacheContextInfo<?, ?> ctxInfo = schemaMgr.cacheInfoForTable(cmd.schemaName(), cmd.tableName());
249+
GridCacheContextInfo<?, ?> ctxInfo = tblDesc.cacheInfo();
247250

248251
assert ctxInfo != null;
249252

250253
if (!allFieldsNullable)
251254
QueryUtils.checkNotNullAllowed(ctxInfo.config());
252255

253-
qryProcessorSupp.get().dynamicColumnAdd(ctxInfo.name(), cmd.schemaName(),
256+
qryProc.dynamicColumnAdd(ctxInfo.name(), cmd.schemaName(),
254257
typeDesc.tableName(), cols, cmd.ifTableExists(), cmd.ifColumnNotExists()).get();
255258
}
256259
}
@@ -260,14 +263,15 @@ private void handle0(AlterTableAddCommand cmd) throws IgniteCheckedException {
260263
private void handle0(AlterTableDropCommand cmd) throws IgniteCheckedException {
261264
isDdlOnSchemaSupported(cmd.schemaName());
262265

263-
GridQueryTypeDescriptor typeDesc = schemaMgr.typeDescriptorForTable(cmd.schemaName(), cmd.tableName());
266+
TableDescriptor tblDesc = schemaMgr.table(cmd.schemaName(), cmd.tableName());
264267

265-
if (typeDesc == null) {
268+
if (tblDesc == null) {
266269
if (!cmd.ifTableExists())
267270
throw new SchemaOperationException(SchemaOperationException.CODE_TABLE_NOT_FOUND, cmd.tableName());
268271
}
269272
else {
270-
GridCacheContextInfo<?, ?> ctxInfo = schemaMgr.cacheInfoForTable(cmd.schemaName(), cmd.tableName());
273+
GridQueryTypeDescriptor typeDesc = tblDesc.type();
274+
GridCacheContextInfo<?, ?> ctxInfo = tblDesc.cacheInfo();
271275

272276
GridCacheContext<?, ?> cctx = ctxInfo.cacheContext();
273277

@@ -302,7 +306,7 @@ private void handle0(AlterTableDropCommand cmd) throws IgniteCheckedException {
302306
}
303307

304308
if (!F.isEmpty(cols)) {
305-
qryProcessorSupp.get().dynamicColumnRemove(ctxInfo.name(), cmd.schemaName(),
309+
qryProc.dynamicColumnRemove(ctxInfo.name(), cmd.schemaName(),
306310
typeDesc.tableName(), cols, cmd.ifTableExists(), cmd.ifColumnExists()).get();
307311
}
308312
}

modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/ddl/NativeCommandHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.UUID;
2222
import org.apache.ignite.cache.query.FieldsQueryCursor;
2323
import org.apache.ignite.internal.GridKernalContext;
24-
import org.apache.ignite.internal.processors.query.GridQuerySchemaManager;
2524
import org.apache.ignite.internal.processors.query.calcite.prepare.ddl.NativeCommandWrapper;
2625
import org.apache.ignite.internal.sql.SqlCommandProcessor;
2726

@@ -35,8 +34,8 @@ public class NativeCommandHandler {
3534
/**
3635
* @param ctx Context.
3736
*/
38-
public NativeCommandHandler(GridKernalContext ctx, GridQuerySchemaManager schemaMgr) {
39-
proc = new SqlCommandProcessor(ctx, schemaMgr);
37+
public NativeCommandHandler(GridKernalContext ctx) {
38+
proc = new SqlCommandProcessor(ctx);
4039
}
4140

4241
/**

modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/ddl/SchemaManager.java

Lines changed: 0 additions & 85 deletions
This file was deleted.

0 commit comments

Comments
 (0)