-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IGNITE-22717 SQL Calcite: User defined SQL views #11467
Conversation
0eec8ce
to
30fc18d
Compare
53f74e6
to
b6d5f2b
Compare
igniteSchemas.forEach(newCalciteSchema::add); | ||
newCalciteSchema.add(QueryUtils.DFLT_SCHEMA, new IgniteSchema(QueryUtils.DFLT_SCHEMA)); | ||
|
||
for (IgniteSchema schema : igniteSchemas.values()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like similar to the previous: igniteSchemas.values().forEach(sch->sch.register(newCalciteSchema));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a matter of taste. sch->sch.register(newCalciteSchema)
creates one additional object on each call for lambda.
...c/main/java/org/apache/ignite/internal/processors/query/calcite/schema/SchemaHolderImpl.java
Show resolved
Hide resolved
...e/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/PlannerTest.java
Outdated
Show resolved
Hide resolved
...ain/java/org/apache/ignite/internal/processors/query/schema/management/SchemaDescriptor.java
Outdated
Show resolved
Hide resolved
...ain/java/org/apache/ignite/internal/processors/query/schema/management/SchemaDescriptor.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
/** | ||
* Drop view. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same: descriptor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We drop view by descriptor.
new StatisticsTarget(schemaName, typeDesc.tableName(), cols.toArray(EMPTY_STRINGS)) | ||
), | ||
false | ||
mgmtBusyExecutor.execute(() -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can a related statistic survive for long if the executor is busy for long by an active statistics collection tasks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I think it's not so critical. If column doesn't exists, statistics for this column will no hurt anyone.
- Statistics update is done via the same executor (but statistics update after table creation or modification is more critical than statistics delete).
.../main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java
Outdated
Show resolved
Hide resolved
modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java
Outdated
Show resolved
Hide resolved
...core/src/main/java/org/apache/ignite/internal/managers/encryption/GridEncryptionManager.java
Outdated
Show resolved
Hide resolved
...rg/apache/ignite/internal/processors/metastorage/persistence/DistributedMetaStorageImpl.java
Outdated
Show resolved
Hide resolved
...les/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/RootQuery.java
Outdated
Show resolved
Hide resolved
@@ -451,6 +454,9 @@ public void onCacheDestroyed(String cacheName, boolean rmvIdx, boolean clearIdx) | |||
if (schema.decrementUsageCount()) { | |||
schemas.remove(schemaName); | |||
|
|||
if (destroy) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We just removed local schema and called onSchemaDropped()
. Why do we keep cluster schema if cache was only stopped? Looks wierd.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't get this comment.
We drop views on cache destroy, on cache stop we shouldn't drop the views.
# Conflicts: # modules/core/src/main/java/org/apache/ignite/internal/processors/cluster/GridClusterStateProcessor.java # modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java
...va/org/apache/ignite/internal/processors/subscription/GridInternalSubscriptionProcessor.java
Outdated
Show resolved
Hide resolved
...e/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/IgniteSchema.java
Outdated
Show resolved
Hide resolved
...e/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/IgniteSchema.java
Outdated
Show resolved
Hide resolved
@@ -41,6 +41,9 @@ public class IgniteSchema extends AbstractSchema { | |||
/** */ | |||
private final Multimap<String, Function> funcMap = Multimaps.synchronizedMultimap(HashMultimap.create()); | |||
|
|||
/** */ | |||
private final Map<String, String> viewMap = new ConcurrentHashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the tables and the functions we store interfaces like Function
or IgniteTable
. For views a string/sql/request instead. Could we similary keep something like TableMacro
. If I'm right, function register
would not be required in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TableMacro requires schamaPlus. We don't have a schemaPlus until register method, so we can't use table macro here.
|
||
while (true) { | ||
if (F.isEmpty(origin) || cnt++ >= 100) | ||
return typeFactory.getResultClass(type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An exception may be like "Unsupported views depth"? Should we limit this threshold somewhere at a view creation? Like MAX_VIEW_DEPTH = 10?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have a check for recursive views, I'm not sure we should limit count of inner views.
I think this case will never happens (since we prohibit recursive views), but this condition is just for our own peace of mind.
I've indroduced new variable MAX_VIEW_DEPTH instead of hardcoded value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the threshold is reached? A wrong type? A type coercion or a cast error? Do we have a test for it? I tried MAX_VIEW_DEPTH == 1, MAX_VIEW_DEPTH == 0. All the related tests seem to work.
...c/test/java/org/apache/ignite/internal/processors/query/calcite/sql/SqlCustomParserTest.java
Show resolved
Hide resolved
...pache/ignite/internal/processors/query/calcite/integration/AuthorizationIntegrationTest.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override protected void beforeTestsStarted() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to override this method, since we need to control grids lifecycle in each test
...va/org/apache/ignite/internal/processors/query/calcite/integration/ViewsIntegrationTest.java
Outdated
Show resolved
Hide resolved
...va/org/apache/ignite/internal/processors/query/calcite/integration/ViewsIntegrationTest.java
Show resolved
Hide resolved
client.destroyCache("CACHE1"); | ||
|
||
assertViewsCount("PUBLIC", "MY_VIEW", 1); | ||
assertViewsCount("CACHE1", "MY_VIEW", 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we remove a schema when it contains a view which requests an existing tabe/cache? There a VIEW which calls existing public.my_table
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have dedicated schema management procedures, except cache create/destroy. When schema is dropped (force by cache destroy) - it's assumed that schema objects is dropped too.
initGrids(3); | ||
initTable(3); | ||
|
||
assertThrows("CREATE VIEW my_schema.my_view AS SELECT * FROM public.my_table", IgniteSQLException.class, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's check full message or at least a part from it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are different messages for calcite and H2 engines, so only common part is checked here
* Tests views information distribution on node join. | ||
*/ | ||
@Test | ||
public void testNodeJoin() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if only non-baseline node left? Will a view exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Distributed metastorage is stored on non-baseline nodes too (AFAIK)
...org/apache/ignite/internal/processors/query/calcite/planner/UserDefinedViewsPlannerTest.java
Show resolved
Hide resolved
...e/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaSqlViewManager.java
Outdated
Show resolved
Hide resolved
|
||
/** */ | ||
public void clearSchemaViews(String schemaName) { | ||
if (!U.isLocalNodeCoordinator(ctx.discovery())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use !U.isLocalNodeCoordinator(ctx.discovery())
outside
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disagree here.
SchemaSqlViewManager - it's a global manager, it's his responsibility to control global views state.
SchemaManager it's a local-node manager and shouldn't know about ways, how SchemaSqlViewManager store the views.
...e/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaSqlViewManager.java
Outdated
Show resolved
Hide resolved
modules/core/src/test/java/org/apache/ignite/internal/sql/SqlParserViewSelfTest.java
Outdated
Show resolved
Hide resolved
modules/core/src/test/java/org/apache/ignite/internal/sql/SqlParserViewSelfTest.java
Outdated
Show resolved
Hide resolved
modules/core/src/main/java/org/apache/ignite/internal/sql/command/SqlDropViewCommand.java
Show resolved
Hide resolved
.../main/java/org/apache/ignite/internal/processors/query/schema/management/ViewDescriptor.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/apache/ignite/internal/processors/query/schema/management/SchemaManager.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/apache/ignite/internal/processors/query/schema/management/SchemaManager.java
Outdated
Show resolved
Hide resolved
...c/main/java/org/apache/ignite/internal/processors/query/schema/management/SchemaManager.java
Outdated
Show resolved
Hide resolved
...alcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/util/TypeUtils.java
Outdated
Show resolved
Hide resolved
...org/apache/ignite/internal/processors/query/calcite/planner/UserDefinedViewsPlannerTest.java
Outdated
Show resolved
Hide resolved
# Conflicts: # modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/sql/generated/IgniteSqlParserImpl.java
|
Thank you for submitting the pull request to the Apache Ignite.
In order to streamline the review of the contribution
we ask you to ensure the following steps have been taken:
The Contribution Checklist
The description explains WHAT and WHY was made instead of HOW.
The following pattern must be used:
IGNITE-XXXX Change summary
whereXXXX
- number of JIRA issue.(see the Maintainers list)
the
green visa
attached to the JIRA ticket (see TC.Bot: Check PR)Notes
If you need any help, please email [email protected] or ask anу advice on http://asf.slack.com #ignite channel.