You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "alex-plekhanov (via GitHub)" <gi...@apache.org> on 2024/08/07 15:51:59 UTC
[PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
alex-plekhanov opened a new pull request, #11467:
URL: https://github.com/apache/ignite/pull/11467
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
- [ ] There is a single JIRA ticket related to the pull request.
- [ ] The web-link to the pull request is attached to the JIRA ticket.
- [ ] The JIRA ticket has the _Patch Available_ state.
- [ ] The pull request body describes changes that have been made.
The description explains _WHAT_ and _WHY_ was made instead of _HOW_.
- [ ] The pull request title is treated as the final commit message.
The following pattern must be used: `IGNITE-XXXX Change summary` where `XXXX` - number of JIRA issue.
- [ ] A reviewer has been mentioned through the JIRA comments
(see [the Maintainers list](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute#HowtoContribute-ReviewProcessandMaintainers))
- [ ] The pull request has been checked by the Teamcity Bot and
the `green visa` attached to the JIRA ticket (see [TC.Bot: Check PR](https://mtcga.gridgain.com/prs.html))
### Notes
- [How to Contribute](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute)
- [Coding abbreviation rules](https://cwiki.apache.org/confluence/display/IGNITE/Abbreviation+Rules)
- [Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines)
- [Apache Ignite Teamcity Bot](https://cwiki.apache.org/confluence/display/IGNITE/Apache+Ignite+Teamcity+Bot)
If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com _#ignite_ channel.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1714163314
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/PlannerTest.java:
##########
@@ -780,105 +772,29 @@ public void testMergeFilters() throws Exception {
*/
@Test
public void testJoinPushExpressionRule() throws Exception {
- IgniteTypeFactory f = new IgniteTypeFactory(IgniteTypeSystem.INSTANCE);
Review Comment:
Can we make this refactoring in another ticket?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1713921237
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/SchemaHolderImpl.java:
##########
@@ -387,8 +408,11 @@ private void rebuild() {
SchemaPlus newCalciteSchema = Frameworks.createRootSchema(false);
newCalciteSchema.add("UUID", typeFactory -> ((IgniteTypeFactory)typeFactory).createCustomType(UUID.class));
newCalciteSchema.add("OTHER", typeFactory -> ((IgniteTypeFactory)typeFactory).createCustomType(Object.class));
- newCalciteSchema.add("PUBLIC", new IgniteSchema("PUBLIC"));
- igniteSchemas.forEach(newCalciteSchema::add);
+ newCalciteSchema.add(QueryUtils.DFLT_SCHEMA, new IgniteSchema(QueryUtils.DFLT_SCHEMA));
Review Comment:
Suggestion: let's add a line break before adding dfl. schema and after `SchemaPlus newCalciteSchema = Frameworks.createRootSchema(false);`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1734943429
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/ViewsIntegrationTest.java:
##########
@@ -0,0 +1,432 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.integration;
+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.calcite.CalciteQueryEngineConfiguration;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.SqlConfiguration;
+import org.apache.ignite.indexing.IndexingQueryEngineConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.util.typedef.G;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/** */
+@RunWith(Parameterized.class)
+public class ViewsIntegrationTest extends AbstractBasicIntegrationTest {
+ /** */
+ private boolean persistenceEnabled;
+
+ /** */
+ private String[] predefinedSchemas;
+
+ /** */
+ @Parameterized.Parameter
+ public String engine;
+
+ /** */
+ @Parameterized.Parameters(name = "Query engine={0}")
+ public static Iterable<Object> params() {
+ return Arrays.asList(CalciteQueryEngineConfiguration.ENGINE_NAME, IndexingQueryEngineConfiguration.ENGINE_NAME);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ return super.getConfiguration(igniteInstanceName)
+ .setSqlConfiguration(new SqlConfiguration()
+ .setSqlSchemas(predefinedSchemas)
+ .setQueryEnginesConfiguration(engine.equals(CalciteQueryEngineConfiguration.ENGINE_NAME) ?
+ new CalciteQueryEngineConfiguration() : new IndexingQueryEngineConfiguration()))
+ .setDataStorageConfiguration(new DataStorageConfiguration()
+ .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+ .setPersistenceEnabled(persistenceEnabled)));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ stopAllGrids();
+
+ cleanPersistenceDir();
+ }
+
+ /**
+ * Creates and drops view.
+ */
+ @Test
+ public void testCreateDrop() throws Exception {
+ initGrids(3);
+ initTable(3);
+
+ sql("create or replace view my_view as select * from my_table");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+
+ assertRowsCount(3, "select * from my_view");
+ assertRowsCount(3, "select t.id, val_int, * from my_view t");
+
+ sql("drop view my_view");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 0);
+ }
+
+ /**
+ * Tests views on different schemas.
+ */
+ @Test
+ public void testDifferentSchemas() throws Exception {
+ initGrids(3);
+ initTable(5);
+
+ IgniteCache<?, ?> cache1 = client.getOrCreateCache(new CacheConfiguration<>("CACHE1")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ IgniteCache<?, ?> cache2 = client.getOrCreateCache(new CacheConfiguration<>("CACHE2")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ IgniteCache<?, ?> cache3 = client.getOrCreateCache(new CacheConfiguration<>("CACHE3")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
Review Comment:
linebreak
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1735061839
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaSqlViewManager.java:
##########
@@ -0,0 +1,222 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema;
+
+import java.io.Serializable;
+import java.util.Objects;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport;
+import org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage;
+import org.apache.ignite.internal.processors.metastorage.DistributedMetastorageLifecycleListener;
+import org.apache.ignite.internal.processors.metastorage.ReadableDistributedMetaStorage;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.plugin.security.SecurityPermission;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Global schema SQL view manager.
+ */
+public class SchemaSqlViewManager implements IgniteChangeGlobalStateSupport {
+ /** Distributed metastorage key prefix. */
+ private static final String SQL_VIEW_KEY_PREFIX = DistributedMetaStorage.IGNITE_INTERNAL_KEY_PREFIX + "sql.view.";
+
+ /** Kernal context. */
+ private final GridKernalContext ctx;
+
+ /** */
+ private volatile DistributedMetaStorage metastorage;
+
+ /** Logger. */
+ private final IgniteLogger log;
+
+ /**
+ * Constructor.
+ *
+ * @param ctx Context.
Review Comment:
Minor: Kernal context
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1735150614
##########
modules/core/src/main/java/org/apache/ignite/internal/sql/command/SqlDropViewCommand.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.sql.command;
+
+import org.apache.ignite.internal.sql.SqlLexer;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+import static org.apache.ignite.internal.sql.SqlKeyword.IF;
+import static org.apache.ignite.internal.sql.SqlParserUtils.parseIfExists;
+import static org.apache.ignite.internal.sql.SqlParserUtils.parseQualifiedIdentifier;
+
+/**
+ * DROP VIEW command.
+ */
+public class SqlDropViewCommand implements SqlCommand {
+ /** Schema name. */
+ private String schemaName;
+
+ /** View name. */
+ private String viewName;
+
+ /** IF EXISTS flag. */
+ private boolean ifExists;
+
+ /**
+ * Default constructor.
+ */
+ public SqlDropViewCommand() {
+ }
Review Comment:
// No-op.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1715431128
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/IgniteSchema.java:
##########
@@ -88,4 +91,33 @@ public void removeTable(String tblName) {
public void addFunction(String name, Function func) {
funcMap.put(name, func);
}
+
+ /**
+ * @param name View name.
+ * @param sql View sql.
+ */
+ public void addView(String name, String sql) {
+ viewMap.put(name, sql);
+ }
+
+ /**
+ * @param name View name.
+ */
+ public void removeView(String name) {
+ viewMap.remove(name);
+ }
+
+ /**
+ * Registers current {@code IgniteSchema} in parent {@code schema}.
+ *
+ * @param schema Parent schema.
+ * @return Registered schema.
+ */
+ public SchemaPlus register(SchemaPlus schema) {
+ SchemaPlus schemaPlus = schema.add(schemaName, this);
+
+ viewMap.forEach((name, sql) -> schemaPlus.add(name, new ViewTableMacroImpl(sql, schemaPlus)));
Review Comment:
Why only the views?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1716915328
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/RootQuery.java:
##########
@@ -142,16 +139,10 @@ public RootQuery(
FrameworkConfig frameworkCfg = qryCtx != null ? qryCtx.unwrap(FrameworkConfig.class) : null;
- if (frameworkCfg == null)
Review Comment:
This change is unclear. We still have static `static final FrameworkConfig FRAMEWORK_CONFIG`. In general, the idea to make it non-statis, configurable look good. But do we need this in current ticket?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1716858439
##########
modules/core/src/main/java/org/apache/ignite/internal/managers/encryption/GridEncryptionManager.java:
##########
@@ -311,6 +311,8 @@ public GridEncryptionManager(GridKernalContext ctx) {
}
});
+ ctx.internalSubscriptionProcessor().registerGlobalStateListener(this);
Review Comment:
Why changed? Can we move it into another ticket?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1735126817
##########
modules/core/src/test/java/org/apache/ignite/internal/sql/SqlParserViewSelfTest.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.sql;
+
+import org.apache.ignite.internal.sql.command.SqlCreateViewCommand;
+import org.apache.ignite.internal.sql.command.SqlDropViewCommand;
+import org.junit.Test;
+
+/**
+ * Tests for SQL parser: CREATE VIEW.
+ */
+public class SqlParserViewSelfTest extends SqlParserAbstractSelfTest {
+ /**
+ * Tests for CREATE VIEW command.
+ */
+ @Test
+ public void testCreateView() {
+ parseValidateCreate("CREATE VIEW test AS SELECT * FROM test2",
+ null, "TEST", "SELECT * FROM test2", false);
+
+ parseValidateCreate("CREATE OR REPLACE VIEW test AS SELECT * FROM test2",
+ null, "TEST", "SELECT * FROM test2", true);
+
+ parseValidateCreate("CREATE VIEW test.test AS SELECT * FROM test2",
+ "TEST", "TEST", "SELECT * FROM test2", false);
+
+ parseValidateCreate("CREATE VIEW \"test\" AS SELECT * FROM test2",
+ null, "test", "SELECT * FROM test2", false);
+
+ parseValidateCreate("CREATE VIEW \"test\".\"test\" AS SELECT * FROM test2",
+ "test", "test", "SELECT * FROM test2", false);
+
+ parseValidateCreate("CREATE VIEW \"te.st\".\"te.st\" AS SELECT * FROM test2",
+ "te.st", "te.st", "SELECT * FROM test2", false);
+
+ parseValidateCreate("CREATE VIEW test.\"test\" AS SELECT * FROM test2",
+ "TEST", "test", "SELECT * FROM test2", false);
+
+ parseValidateCreate("CREATE VIEW test AS SELECT * FROM test2;",
+ null, "TEST", "SELECT * FROM test2", false);
+
+ parseValidateCreate("CREATE VIEW test AS SELECT * FROM test2 ;",
+ null, "TEST", "SELECT * FROM test2", false);
+
+ parseValidateCreate("CREATE VIEW test AS SELECT * FROM test2; SELECT * FROM test",
+ null, "TEST", "SELECT * FROM test2", false);
+
+ assertParseError(null, "CREATE VIEW test.test.test AS SELECT * FROM test2",
+ "Unexpected token: \".\" (expected: \"AS\")");
+
+ assertParseError(null, "CREATE VIEW test AS UNEXPECTED",
+ "Unexpected token: \"UNEXPECTED\" (expected: \"SELECT\")");
+
+ assertParseError(null, "CREATE VIEW test AS \"SELECT * FROM test2\"",
+ "Unexpected token: \"SELECT * FROM test2\" (expected: \"SELECT\")");
+
+ assertParseError(null, "CREATE OR REPLACE INDEX test",
+ "Unexpected token: \"INDEX\" (expected: \"VIEW\")");
+
+ assertParseError(null, "CREATE OR DROP VIEW test AS SELECT * FROM test2",
+ "Unexpected token: \"DROP\" (expected: \"REPLACE\")");
+ }
+
+ /**
+ * Tests for DROP VIEW command.
Review Comment:
'Test' or remove 'for'
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1735232528
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/management/SchemaManager.java:
##########
@@ -1087,6 +1146,29 @@ public Collection<TableDescriptor> tablesForCache(String cacheName) {
}
}
+ /**
+ * Find view by its identifier.
+ *
+ * @param schemaName Schema name.
+ * @param viewName View name.
+ * @return View or {@code null} if none found.
+ */
+ @Nullable public ViewDescriptor view(String schemaName, String viewName) {
Review Comment:
private?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #11467:
URL: https://github.com/apache/ignite/pull/11467#issuecomment-2275087591
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) **Quality Gate failed**
Failed conditions
 [13 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) (required ≤ 1)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarLint](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1734855287
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/sql/SqlCustomParserTest.java:
##########
@@ -687,6 +690,78 @@ public void dropUser() throws Exception {
assertParserThrows("drop user test with password 'asd'", SqlParseException.class);
}
+ /**
+ * Tests that CREATE OR REPLACE is not allowed for CREATE TABLE/INDEX/USER.
+ */
+ @Test
+ public void invalidCreateOrReplace() {
+ assertParserThrows("create or replace table my_table(id int, val varchar)", SqlParseException.class,
+ "Unsupported clause 'REPLACE'");
+
+ assertParserThrows("create or replace index my_index on my_table(id)", SqlParseException.class,
+ "Unsupported clause 'REPLACE'");
+
+ assertParserThrows("create or replace user test with password 'asd'", SqlParseException.class,
+ "Unsupported clause 'REPLACE'");
+ }
+
+ /**
+ * Create view.
+ */
+ @Test
+ public void createView() throws SqlParseException {
+ SqlCreateView createView = parse("create view my_view as select * from my_table");
+
+ assertThat(createView.name.names, is(ImmutableList.of("MY_VIEW")));
+ assertThat(createView.getReplace(), is(false));
+ assertThat(createView.query, instanceOf(SqlSelect.class));
+ assertThat(((SqlSelect)createView.query).getFrom().toString(), is("MY_TABLE"));
Review Comment:
We could also check `query.hints` and make a test for it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1734794720
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/util/TypeUtils.java:
##########
@@ -236,20 +237,36 @@ public static RelDataType getResultType(IgniteTypeFactory typeFactory, RelOptSch
* @param origin Column origin.
* @return Result type.
*/
- private static Type getResultClass(IgniteTypeFactory typeFactory, RelOptSchema schema, RelDataType type,
- @Nullable List<String> origin) {
- if (F.isEmpty(origin))
- return typeFactory.getResultClass(type);
+ private static Type getResultClass(
+ IgniteTypeFactory typeFactory,
+ RelOptSchema schema,
+ RelDataType type,
+ @Nullable List<String> origin
+ ) {
+ int cnt = 0; // Counter to protect from infinite recursion.
+
+ while (true) {
+ if (F.isEmpty(origin) || cnt++ >= 100)
+ return typeFactory.getResultClass(type);
Review Comment:
An exception may be like "Unsupported views depth"? Should we limit this threshold somewhere at a view creation? Like MAX_VIEW_DEPTH = 10?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #11467:
URL: https://github.com/apache/ignite/pull/11467#issuecomment-2275171649
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) **Quality Gate failed**
Failed conditions
 [13 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) (required ≤ 1)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarLint](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1716859626
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/metastorage/persistence/DistributedMetaStorageImpl.java:
##########
@@ -279,6 +279,8 @@ public DistributedMetaStorageImpl(GridKernalContext ctx) {
DistributedMetaStorageUpdateAckMessage.class,
this::onAckMessage
);
+
+ ctx.internalSubscriptionProcessor().registerGlobalStateListener(this);
Review Comment:
Why changed? Can we move it into another ticket?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1717182826
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/management/SchemaManager.java:
##########
@@ -451,6 +454,9 @@ public void onCacheDestroyed(String cacheName, boolean rmvIdx, boolean clearIdx)
if (schema.decrementUsageCount()) {
schemas.remove(schemaName);
+ if (destroy)
Review Comment:
We just removed local schema. Why do we keep cluster schema if cache was only stopped? Also `if (!U.isLocalNodeCoordinator(ctx.discovery()))` might be moved outside.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1715072089
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/management/SchemaDescriptor.java:
##########
@@ -121,6 +124,37 @@ public void drop(TableDescriptor tbl) {
typeToTbl.remove(new QueryTypeNameKey(tbl.cacheInfo().name(), tbl.type().name()));
}
+ /**
+ * @return Views.
Review Comment:
View descriptors?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1715072739
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/management/SchemaDescriptor.java:
##########
@@ -121,6 +124,37 @@ public void drop(TableDescriptor tbl) {
typeToTbl.remove(new QueryTypeNameKey(tbl.cacheInfo().name(), tbl.type().name()));
}
+ /**
+ * @return Views.
+ */
+ public Collection<ViewDescriptor> views() {
+ return views.values();
+ }
+
+ /**
+ * @param viewName View name.
+ * @return View.
Review Comment:
View descriptor?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1734976510
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/ViewsIntegrationTest.java:
##########
@@ -0,0 +1,432 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.integration;
+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.calcite.CalciteQueryEngineConfiguration;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.SqlConfiguration;
+import org.apache.ignite.indexing.IndexingQueryEngineConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.util.typedef.G;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/** */
+@RunWith(Parameterized.class)
+public class ViewsIntegrationTest extends AbstractBasicIntegrationTest {
+ /** */
+ private boolean persistenceEnabled;
+
+ /** */
+ private String[] predefinedSchemas;
+
+ /** */
+ @Parameterized.Parameter
+ public String engine;
+
+ /** */
+ @Parameterized.Parameters(name = "Query engine={0}")
+ public static Iterable<Object> params() {
+ return Arrays.asList(CalciteQueryEngineConfiguration.ENGINE_NAME, IndexingQueryEngineConfiguration.ENGINE_NAME);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ return super.getConfiguration(igniteInstanceName)
+ .setSqlConfiguration(new SqlConfiguration()
+ .setSqlSchemas(predefinedSchemas)
+ .setQueryEnginesConfiguration(engine.equals(CalciteQueryEngineConfiguration.ENGINE_NAME) ?
+ new CalciteQueryEngineConfiguration() : new IndexingQueryEngineConfiguration()))
+ .setDataStorageConfiguration(new DataStorageConfiguration()
+ .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+ .setPersistenceEnabled(persistenceEnabled)));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ stopAllGrids();
+
+ cleanPersistenceDir();
+ }
+
+ /**
+ * Creates and drops view.
+ */
+ @Test
+ public void testCreateDrop() throws Exception {
+ initGrids(3);
+ initTable(3);
+
+ sql("create or replace view my_view as select * from my_table");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+
+ assertRowsCount(3, "select * from my_view");
+ assertRowsCount(3, "select t.id, val_int, * from my_view t");
+
+ sql("drop view my_view");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 0);
+ }
+
+ /**
+ * Tests views on different schemas.
+ */
+ @Test
+ public void testDifferentSchemas() throws Exception {
+ initGrids(3);
+ initTable(5);
+
+ IgniteCache<?, ?> cache1 = client.getOrCreateCache(new CacheConfiguration<>("CACHE1")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ IgniteCache<?, ?> cache2 = client.getOrCreateCache(new CacheConfiguration<>("CACHE2")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ IgniteCache<?, ?> cache3 = client.getOrCreateCache(new CacheConfiguration<>("CACHE3")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+ IgniteCache<?, ?> cache4 = client.getOrCreateCache(new CacheConfiguration<>("CACHE4")
+ .setIndexedTypes(Integer.class, String.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+
+ sql("create or replace view my_view as select * from my_table");
+ sql("create or replace view cache1.my_view as select * from public.my_table where id < 4");
+ sql("create or replace view cache2.my_view as select * from cache1.my_view where id < 3");
+ sql("create or replace view my_schema.my_view1 as select * from public.my_table where id < 2");
+ sql("create or replace view my_schema.my_view2 as select * from my_view1 where id < 1");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 1);
+ assertViewsCount("CACHE2", "MY_VIEW", 1);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW1", 1);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW2", 1);
+
+ assertRowsCount(5, "select * from my_view");
+ assertRowsCount(4, "select * from cache1.my_view");
+ assertRowsCount(3, "select * from cache2.my_view");
+ assertRowsCount(2, "select * from my_schema.my_view1");
+ assertRowsCount(1, "select * from my_schema.my_view2");
+
+ // PUBLIC.MY_VIEW
+ assertEquals(5, cache1.query(new SqlFieldsQuery("select * from public.my_view")).getAll().size());
+ assertEquals(5, cache1.query(new SqlFieldsQuery("select * from my_view").setSchema("PUBLIC")).getAll().size());
+ // CACHE1.MY_VIEW
+ assertEquals(4, cache1.query(new SqlFieldsQuery("select * from my_view")).getAll().size());
+ assertEquals(4, cache2.query(new SqlFieldsQuery("select * from cache1.my_view")).getAll().size());
+ // CACHE2.MY_VIEW
+ assertEquals(3, cache2.query(new SqlFieldsQuery("select * from my_view")).getAll().size());
+ assertEquals(3, cache1.query(new SqlFieldsQuery("select * from my_view").setSchema("CACHE2")).getAll().size());
+ // MY_SCHEMA.MY_VIEW1
+ assertEquals(2, cache3.query(new SqlFieldsQuery("select * from my_view1")).getAll().size());
+ assertEquals(2, cache4.query(new SqlFieldsQuery("select * from my_view1")).getAll().size());
+ // MY_SCHEMA.MY_VIEW2
+ assertEquals(1, cache3.query(new SqlFieldsQuery("select * from my_view2")).getAll().size());
+ assertEquals(1, cache4.query(new SqlFieldsQuery("select * from my_view2")).getAll().size());
+ }
+
+ /**
+ * Tests views drop on schema drop.
+ */
+ @Test
+ public void testSchemaCleaning() throws Exception {
+ initGrids(3);
+ initTable(5);
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE1")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE2")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("PUBLIC")
+ );
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE3")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE4")
+ .setIndexedTypes(Integer.class, String.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+
+ sql("create or replace view my_view as select * from my_table");
+ sql("create or replace view cache1.my_view as select * from public.my_table");
+ sql("create or replace view my_schema.my_view as select * from public.my_table");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 1);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 1);
+
+ client.destroyCache("CACHE1");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 0);
Review Comment:
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`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1734458825
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/IgniteSchema.java:
##########
@@ -88,4 +91,33 @@ public void removeTable(String tblName) {
public void addFunction(String name, Function func) {
funcMap.put(name, func);
}
+
+ /**
+ * @param name View name.
+ * @param sql View sql.
+ */
+ public void addView(String name, String sql) {
+ viewMap.put(name, sql);
+ }
+
+ /**
+ * @param name View name.
+ */
+ public void removeView(String name) {
+ viewMap.remove(name);
+ }
+
+ /**
+ * Registers current {@code IgniteSchema} in parent {@code schema}.
+ *
+ * @param schema Parent schema.
+ * @return Registered schema.
+ */
+ public SchemaPlus register(SchemaPlus schema) {
Review Comment:
Everything is about 'schema'. Current one is a schema (IgniteSchema), register into a schema, return new schema. My suggestion is fix the namings like: `schema` -> `parent`, 'schemaPlus' -> 'newSchema'.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #11467:
URL: https://github.com/apache/ignite/pull/11467#issuecomment-2275061747
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) **Quality Gate failed**
Failed conditions
 [13 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) (required ≤ 1)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarLint](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #11467:
URL: https://github.com/apache/ignite/pull/11467#issuecomment-2274267101
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) **Quality Gate failed**
Failed conditions
 [13 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) (required ≤ 1)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarLint](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "alex-plekhanov (via GitHub)" <gi...@apache.org>.
alex-plekhanov commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1744196063
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/ViewsIntegrationTest.java:
##########
@@ -0,0 +1,432 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.integration;
+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.calcite.CalciteQueryEngineConfiguration;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.SqlConfiguration;
+import org.apache.ignite.indexing.IndexingQueryEngineConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.util.typedef.G;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/** */
+@RunWith(Parameterized.class)
+public class ViewsIntegrationTest extends AbstractBasicIntegrationTest {
+ /** */
+ private boolean persistenceEnabled;
+
+ /** */
+ private String[] predefinedSchemas;
+
+ /** */
+ @Parameterized.Parameter
+ public String engine;
+
+ /** */
+ @Parameterized.Parameters(name = "Query engine={0}")
+ public static Iterable<Object> params() {
+ return Arrays.asList(CalciteQueryEngineConfiguration.ENGINE_NAME, IndexingQueryEngineConfiguration.ENGINE_NAME);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ return super.getConfiguration(igniteInstanceName)
+ .setSqlConfiguration(new SqlConfiguration()
+ .setSqlSchemas(predefinedSchemas)
+ .setQueryEnginesConfiguration(engine.equals(CalciteQueryEngineConfiguration.ENGINE_NAME) ?
+ new CalciteQueryEngineConfiguration() : new IndexingQueryEngineConfiguration()))
+ .setDataStorageConfiguration(new DataStorageConfiguration()
+ .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+ .setPersistenceEnabled(persistenceEnabled)));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
Review Comment:
We need to override this method, since we need to control grids lifecycle in each test
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #11467:
URL: https://github.com/apache/ignite/pull/11467#issuecomment-2329655986
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) **Quality Gate failed**
Failed conditions
 [5 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) (required ≤ 1)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarLint](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1717135381
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/management/SchemaManager.java:
##########
@@ -413,13 +416,13 @@ private static void validateTypeDescriptor(GridQueryTypeDescriptor type) throws
}
/**
- * Handle cache destroy.
+ * Handle cache stop.
*
* @param cacheName Cache name.
- * @param rmvIdx Whether to remove indexes.
+ * @param destroy Destroy cache.
* @param clearIdx Whether to clear the index.
*/
- public void onCacheDestroyed(String cacheName, boolean rmvIdx, boolean clearIdx) {
+ public void onCacheStopped(String cacheName, boolean destroy, boolean clearIdx) {
Review Comment:
If we do an additional related refactoring ticket, this and similar renamings might be moved there too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1734981236
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/ViewsIntegrationTest.java:
##########
@@ -0,0 +1,432 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.integration;
+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.calcite.CalciteQueryEngineConfiguration;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.SqlConfiguration;
+import org.apache.ignite.indexing.IndexingQueryEngineConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.util.typedef.G;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/** */
+@RunWith(Parameterized.class)
+public class ViewsIntegrationTest extends AbstractBasicIntegrationTest {
+ /** */
+ private boolean persistenceEnabled;
+
+ /** */
+ private String[] predefinedSchemas;
+
+ /** */
+ @Parameterized.Parameter
+ public String engine;
+
+ /** */
+ @Parameterized.Parameters(name = "Query engine={0}")
+ public static Iterable<Object> params() {
+ return Arrays.asList(CalciteQueryEngineConfiguration.ENGINE_NAME, IndexingQueryEngineConfiguration.ENGINE_NAME);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ return super.getConfiguration(igniteInstanceName)
+ .setSqlConfiguration(new SqlConfiguration()
+ .setSqlSchemas(predefinedSchemas)
+ .setQueryEnginesConfiguration(engine.equals(CalciteQueryEngineConfiguration.ENGINE_NAME) ?
+ new CalciteQueryEngineConfiguration() : new IndexingQueryEngineConfiguration()))
+ .setDataStorageConfiguration(new DataStorageConfiguration()
+ .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+ .setPersistenceEnabled(persistenceEnabled)));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ stopAllGrids();
+
+ cleanPersistenceDir();
+ }
+
+ /**
+ * Creates and drops view.
+ */
+ @Test
+ public void testCreateDrop() throws Exception {
+ initGrids(3);
+ initTable(3);
+
+ sql("create or replace view my_view as select * from my_table");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+
+ assertRowsCount(3, "select * from my_view");
+ assertRowsCount(3, "select t.id, val_int, * from my_view t");
+
+ sql("drop view my_view");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 0);
+ }
+
+ /**
+ * Tests views on different schemas.
+ */
+ @Test
+ public void testDifferentSchemas() throws Exception {
+ initGrids(3);
+ initTable(5);
+
+ IgniteCache<?, ?> cache1 = client.getOrCreateCache(new CacheConfiguration<>("CACHE1")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ IgniteCache<?, ?> cache2 = client.getOrCreateCache(new CacheConfiguration<>("CACHE2")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ IgniteCache<?, ?> cache3 = client.getOrCreateCache(new CacheConfiguration<>("CACHE3")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+ IgniteCache<?, ?> cache4 = client.getOrCreateCache(new CacheConfiguration<>("CACHE4")
+ .setIndexedTypes(Integer.class, String.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+
+ sql("create or replace view my_view as select * from my_table");
+ sql("create or replace view cache1.my_view as select * from public.my_table where id < 4");
+ sql("create or replace view cache2.my_view as select * from cache1.my_view where id < 3");
+ sql("create or replace view my_schema.my_view1 as select * from public.my_table where id < 2");
+ sql("create or replace view my_schema.my_view2 as select * from my_view1 where id < 1");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 1);
+ assertViewsCount("CACHE2", "MY_VIEW", 1);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW1", 1);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW2", 1);
+
+ assertRowsCount(5, "select * from my_view");
+ assertRowsCount(4, "select * from cache1.my_view");
+ assertRowsCount(3, "select * from cache2.my_view");
+ assertRowsCount(2, "select * from my_schema.my_view1");
+ assertRowsCount(1, "select * from my_schema.my_view2");
+
+ // PUBLIC.MY_VIEW
+ assertEquals(5, cache1.query(new SqlFieldsQuery("select * from public.my_view")).getAll().size());
+ assertEquals(5, cache1.query(new SqlFieldsQuery("select * from my_view").setSchema("PUBLIC")).getAll().size());
+ // CACHE1.MY_VIEW
+ assertEquals(4, cache1.query(new SqlFieldsQuery("select * from my_view")).getAll().size());
+ assertEquals(4, cache2.query(new SqlFieldsQuery("select * from cache1.my_view")).getAll().size());
+ // CACHE2.MY_VIEW
+ assertEquals(3, cache2.query(new SqlFieldsQuery("select * from my_view")).getAll().size());
+ assertEquals(3, cache1.query(new SqlFieldsQuery("select * from my_view").setSchema("CACHE2")).getAll().size());
+ // MY_SCHEMA.MY_VIEW1
+ assertEquals(2, cache3.query(new SqlFieldsQuery("select * from my_view1")).getAll().size());
+ assertEquals(2, cache4.query(new SqlFieldsQuery("select * from my_view1")).getAll().size());
+ // MY_SCHEMA.MY_VIEW2
+ assertEquals(1, cache3.query(new SqlFieldsQuery("select * from my_view2")).getAll().size());
+ assertEquals(1, cache4.query(new SqlFieldsQuery("select * from my_view2")).getAll().size());
+ }
+
+ /**
+ * Tests views drop on schema drop.
+ */
+ @Test
+ public void testSchemaCleaning() throws Exception {
+ initGrids(3);
+ initTable(5);
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE1")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE2")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("PUBLIC")
+ );
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE3")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE4")
+ .setIndexedTypes(Integer.class, String.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+
+ sql("create or replace view my_view as select * from my_table");
+ sql("create or replace view cache1.my_view as select * from public.my_table");
+ sql("create or replace view my_schema.my_view as select * from public.my_table");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 1);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 1);
+
+ client.destroyCache("CACHE1");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 0);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 1);
+
+ client.destroyCache("CACHE2");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 0);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 1);
+
+ client.destroyCache("CACHE3");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 0);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 1);
+
+ client.destroyCache("CACHE4");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 0);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 0);
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE1")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE3")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 0);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 0);
+ }
+
+ /**
+ * Tests views on not existing schema.
+ */
+ @Test
+ public void testNotExistingSchema() throws Exception {
+ initGrids(3);
+ initTable(3);
+
+ assertThrows("CREATE VIEW my_schema.my_view AS SELECT * FROM public.my_table", IgniteSQLException.class,
Review Comment:
Let's check full message or at least a part from it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1735028779
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/UserDefinedViewsPlannerTest.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.calcite.planner;
+
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.util.ImmutableBitSet;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.processors.query.calcite.schema.IgniteSchema;
+import org.apache.ignite.internal.processors.query.calcite.trait.IgniteDistributions;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.junit.Test;
+
+import static org.apache.calcite.sql.type.SqlTypeName.INTEGER;
+
+/**
+ * User defined views test.
+ */
+public class UserDefinedViewsPlannerTest extends AbstractPlannerTest {
Review Comment:
We could alse check plan with hints in view. The hints should work.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "alex-plekhanov (via GitHub)" <gi...@apache.org>.
alex-plekhanov commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1743939484
##########
docs/_docs/sql-reference/ddl.adoc:
##########
@@ -472,6 +472,66 @@ DROP INDEX idx_person_name;
----
+== CREATE VIEW
+
+Creates an user definded SQL view
Review Comment:
Fixed
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/SchemaHolderImpl.java:
##########
@@ -387,8 +408,11 @@ private void rebuild() {
SchemaPlus newCalciteSchema = Frameworks.createRootSchema(false);
newCalciteSchema.add("UUID", typeFactory -> ((IgniteTypeFactory)typeFactory).createCustomType(UUID.class));
newCalciteSchema.add("OTHER", typeFactory -> ((IgniteTypeFactory)typeFactory).createCustomType(Object.class));
- newCalciteSchema.add("PUBLIC", new IgniteSchema("PUBLIC"));
- igniteSchemas.forEach(newCalciteSchema::add);
+ newCalciteSchema.add(QueryUtils.DFLT_SCHEMA, new IgniteSchema(QueryUtils.DFLT_SCHEMA));
+
+ for (IgniteSchema schema : igniteSchemas.values())
Review Comment:
It's a matter of taste. `sch->sch.register(newCalciteSchema)` creates one additional object on each call for lambda.
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/management/SchemaDescriptor.java:
##########
@@ -121,6 +124,37 @@ public void drop(TableDescriptor tbl) {
typeToTbl.remove(new QueryTypeNameKey(tbl.cacheInfo().name(), tbl.type().name()));
}
+ /**
+ * @return Views.
+ */
+ public Collection<ViewDescriptor> views() {
+ return views.values();
+ }
+
+ /**
+ * @param viewName View name.
+ * @return View.
+ */
+ public ViewDescriptor viewByName(String viewName) {
+ return views.get(viewName);
+ }
+
+ /**
+ * @param view View descriptor.
+ */
+ public void add(ViewDescriptor view) {
+ views.put(view.name(), view);
+ }
+
+ /**
+ * Drop view.
Review Comment:
We drop view by descriptor.
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/SchemaHolderImpl.java:
##########
@@ -387,8 +408,11 @@ private void rebuild() {
SchemaPlus newCalciteSchema = Frameworks.createRootSchema(false);
newCalciteSchema.add("UUID", typeFactory -> ((IgniteTypeFactory)typeFactory).createCustomType(UUID.class));
newCalciteSchema.add("OTHER", typeFactory -> ((IgniteTypeFactory)typeFactory).createCustomType(Object.class));
- newCalciteSchema.add("PUBLIC", new IgniteSchema("PUBLIC"));
- igniteSchemas.forEach(newCalciteSchema::add);
+ newCalciteSchema.add(QueryUtils.DFLT_SCHEMA, new IgniteSchema(QueryUtils.DFLT_SCHEMA));
Review Comment:
Fixed
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/UserDefinedViewsPlannerTest.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.calcite.planner;
+
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.util.ImmutableBitSet;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.processors.query.calcite.schema.IgniteSchema;
+import org.apache.ignite.internal.processors.query.calcite.trait.IgniteDistributions;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.junit.Test;
+
+import static org.apache.calcite.sql.type.SqlTypeName.INTEGER;
+
+/**
+ * User defined views test.
+ */
+public class UserDefinedViewsPlannerTest extends AbstractPlannerTest {
Review Comment:
Fixed
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaSqlViewManager.java:
##########
@@ -0,0 +1,222 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema;
+
+import java.io.Serializable;
+import java.util.Objects;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport;
+import org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage;
+import org.apache.ignite.internal.processors.metastorage.DistributedMetastorageLifecycleListener;
+import org.apache.ignite.internal.processors.metastorage.ReadableDistributedMetaStorage;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.plugin.security.SecurityPermission;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Global schema SQL view manager.
+ */
+public class SchemaSqlViewManager implements IgniteChangeGlobalStateSupport {
+ /** Distributed metastorage key prefix. */
+ private static final String SQL_VIEW_KEY_PREFIX = DistributedMetaStorage.IGNITE_INTERNAL_KEY_PREFIX + "sql.view.";
+
+ /** Kernal context. */
+ private final GridKernalContext ctx;
+
+ /** */
+ private volatile DistributedMetaStorage metastorage;
+
+ /** Logger. */
+ private final IgniteLogger log;
+
+ /**
+ * Constructor.
+ *
+ * @param ctx Context.
+ */
+ public SchemaSqlViewManager(GridKernalContext ctx) {
+ this.ctx = ctx;
+
+ log = ctx.log(SchemaSqlViewManager.class);
+ }
+
+ /** */
+ public void start() {
+ ctx.internalSubscriptionProcessor().registerDistributedMetastorageListener(new DistributedMetastorageLifecycleListener() {
+ @Override public void onReadyForRead(ReadableDistributedMetaStorage metastorage) {
+ metastorage.listen(key -> key.startsWith(SQL_VIEW_KEY_PREFIX),
+ SchemaSqlViewManager.this::processMetastorageUpdate);
+ }
+
+ @Override public void onReadyForWrite(DistributedMetaStorage metastorage) {
+ SchemaSqlViewManager.this.metastorage = metastorage;
+ }
+ });
+
+ ctx.internalSubscriptionProcessor().registerGlobalStateListener(this);
+ }
+
+ /** */
+ public void createView(String schemaName, String viewName, String viewSql, boolean replace) throws IgniteCheckedException {
+ ctx.security().authorize(SecurityPermission.SQL_VIEW_CREATE);
+
+ if (!ctx.query().schemaManager().schemaNames().contains(schemaName))
+ throw new SchemaOperationException(SchemaOperationException.CODE_SCHEMA_NOT_FOUND, schemaName);
+
+ String key = makeKey(schemaName, viewName);
+
+ Serializable oldVal;
+ Serializable newVal = new SqlView(schemaName, viewName, viewSql);
+
+ do {
+ oldVal = metastorage.read(key);
+
+ if (oldVal != null && !replace)
+ throw new SchemaOperationException(SchemaOperationException.CODE_VIEW_EXISTS, viewName);
+ }
+ while (!metastorage.compareAndSet(key, oldVal, newVal));
+ }
+
+ /** */
+ public void dropView(String schemaName, String viewName, boolean ifExists) throws IgniteCheckedException {
+ ctx.security().authorize(SecurityPermission.SQL_VIEW_DROP);
+
+ String key = makeKey(schemaName, viewName);
+
+ Serializable oldVal;
+
+ do {
+ oldVal = metastorage.read(key);
+
+ if (oldVal == null) {
+ if (!ifExists)
+ throw new SchemaOperationException(SchemaOperationException.CODE_VIEW_NOT_FOUND, viewName);
+ else
+ return;
+ }
+ }
+ while (!metastorage.compareAndRemove(key, oldVal));
+ }
+
+ /** */
+ public void clearSchemaViews(String schemaName) {
+ if (!U.isLocalNodeCoordinator(ctx.discovery()))
+ return;
+
+ try {
+ metastorage.iterate(makeKey(schemaName, null), (k, v) -> {
+ try {
+ metastorage.removeAsync(k);
+ }
+ catch (IgniteCheckedException e) {
+ log.warning("Failed to remove SQL views from metastorage [key=" + k + ']', e);
+ }
+ });
+ }
+ catch (IgniteCheckedException e) {
+ log.warning("Failed to get views list from metastorage", e);
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override public void onActivate(GridKernalContext kctx) throws IgniteCheckedException {
+ metastorage.iterate(SQL_VIEW_KEY_PREFIX, (k, v) -> processMetastorageUpdate(k, null, v));
+ }
+
+ /** {@inheritDoc} */
+ @Override public void onDeActivate(GridKernalContext kctx) {
+ // No-op.
+ }
+
+ /** */
+ private void processMetastorageUpdate(String key, @Nullable Serializable oldVal, @Nullable Serializable newVal) {
+ assert key.startsWith(SQL_VIEW_KEY_PREFIX) : "Invalid key: " + key;
+ assert oldVal == null || oldVal instanceof SqlView : "Invalid old value: " + oldVal;
+ assert newVal == null || newVal instanceof SqlView : "Invalid new value: " + newVal;
+ assert oldVal != null || newVal != null;
+
+ String schemaName = newVal == null ? ((SqlView)oldVal).schemaName : ((SqlView)newVal).schemaName;
+ String viewName = newVal == null ? ((SqlView)oldVal).viewName : ((SqlView)newVal).viewName;
+
+ // Register in local manager.
+ if (newVal == null)
+ ctx.query().schemaManager().dropView(schemaName, viewName);
+ else
+ ctx.query().schemaManager().createView(schemaName, viewName, ((SqlView)newVal).viewSql);
+ }
+
+ /** */
+ private static String makeKey(String schemaName, @Nullable String viewName) {
+ return SQL_VIEW_KEY_PREFIX + escape(schemaName) + '.' + (viewName == null ? "" : escape(viewName));
+ }
+
+ /** */
+ private static String escape(String name) {
+ return name.replace("\\", "\\\\").replace(".", "\\.");
+ }
+
+ /** */
+ private static class SqlView implements Serializable {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** */
+ private final String schemaName;
+
+ /** */
+ private final String viewName;
+
+ /** */
+ private final String viewSql;
+
+ /** */
+ public SqlView(String schemaName, String viewName, String viewSql) {
Review Comment:
Fixed
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/management/ViewDescriptor.java:
##########
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema.management;
+
+/**
+ * Local database view object.
+ */
+public class ViewDescriptor {
+ /** View name. */
+ private final String name;
+
+ /** View SQL. */
+ private final String sql;
+
+ /** View description. */
+ private final String desc;
+
+ /**
+ * @param name View name.
+ * @param sql View SQL.
+ * @param desc View description.
+ */
+ public ViewDescriptor(String name, String sql, String desc) {
Review Comment:
Fixed
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/management/SchemaDescriptor.java:
##########
@@ -121,6 +124,37 @@ public void drop(TableDescriptor tbl) {
typeToTbl.remove(new QueryTypeNameKey(tbl.cacheInfo().name(), tbl.type().name()));
}
+ /**
+ * @return Views.
Review Comment:
Fixed
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/management/SchemaDescriptor.java:
##########
@@ -121,6 +124,37 @@ public void drop(TableDescriptor tbl) {
typeToTbl.remove(new QueryTypeNameKey(tbl.cacheInfo().name(), tbl.type().name()));
}
+ /**
+ * @return Views.
+ */
+ public Collection<ViewDescriptor> views() {
+ return views.values();
+ }
+
+ /**
+ * @param viewName View name.
+ * @return View.
Review Comment:
Fixed
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/subscription/GridInternalSubscriptionProcessor.java:
##########
@@ -59,6 +59,9 @@ public class GridInternalSubscriptionProcessor extends GridProcessorAdapter {
/** */
private final List<IgniteChangeGlobalStateSupport> globalStateListeners = new ArrayList<>();
+ /** */
+ private final List<IgniteChangeGlobalStateSupport> globalStateListeners = new ArrayList<>();
Review Comment:
Fixed.
I am surprized, how java allows this.
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/IgniteSchema.java:
##########
@@ -88,4 +91,33 @@ public void removeTable(String tblName) {
public void addFunction(String name, Function func) {
funcMap.put(name, func);
}
+
+ /**
+ * @param name View name.
+ * @param sql View sql.
+ */
+ public void addView(String name, String sql) {
+ viewMap.put(name, sql);
+ }
+
+ /**
+ * @param name View name.
+ */
+ public void removeView(String name) {
+ viewMap.remove(name);
+ }
+
+ /**
+ * Registers current {@code IgniteSchema} in parent {@code schema}.
+ *
+ * @param schema Parent schema.
+ * @return Registered schema.
+ */
+ public SchemaPlus register(SchemaPlus schema) {
Review Comment:
Fixed
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/management/SchemaManager.java:
##########
@@ -451,6 +454,9 @@ public void onCacheDestroyed(String cacheName, boolean rmvIdx, boolean clearIdx)
if (schema.decrementUsageCount()) {
schemas.remove(schemaName);
+ if (destroy)
Review Comment:
I didn't get this comment.
We drop views on cache destroy, on cache stop we shouldn't drop the views.
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/IgniteSchema.java:
##########
@@ -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<>();
Review Comment:
TableMacro requires schamaPlus. We don't have a schemaPlus until register method, so we can't use table macro here.
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaSqlViewManager.java:
##########
@@ -0,0 +1,222 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema;
+
+import java.io.Serializable;
+import java.util.Objects;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport;
+import org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage;
+import org.apache.ignite.internal.processors.metastorage.DistributedMetastorageLifecycleListener;
+import org.apache.ignite.internal.processors.metastorage.ReadableDistributedMetaStorage;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.plugin.security.SecurityPermission;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Global schema SQL view manager.
+ */
+public class SchemaSqlViewManager implements IgniteChangeGlobalStateSupport {
+ /** Distributed metastorage key prefix. */
+ private static final String SQL_VIEW_KEY_PREFIX = DistributedMetaStorage.IGNITE_INTERNAL_KEY_PREFIX + "sql.view.";
+
+ /** Kernal context. */
+ private final GridKernalContext ctx;
+
+ /** */
+ private volatile DistributedMetaStorage metastorage;
+
+ /** Logger. */
+ private final IgniteLogger log;
+
+ /**
+ * Constructor.
+ *
+ * @param ctx Context.
Review Comment:
Fixed
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaSqlViewManager.java:
##########
@@ -0,0 +1,222 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema;
+
+import java.io.Serializable;
+import java.util.Objects;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport;
+import org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage;
+import org.apache.ignite.internal.processors.metastorage.DistributedMetastorageLifecycleListener;
+import org.apache.ignite.internal.processors.metastorage.ReadableDistributedMetaStorage;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.plugin.security.SecurityPermission;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Global schema SQL view manager.
+ */
+public class SchemaSqlViewManager implements IgniteChangeGlobalStateSupport {
+ /** Distributed metastorage key prefix. */
+ private static final String SQL_VIEW_KEY_PREFIX = DistributedMetaStorage.IGNITE_INTERNAL_KEY_PREFIX + "sql.view.";
+
+ /** Kernal context. */
+ private final GridKernalContext ctx;
+
+ /** */
+ private volatile DistributedMetaStorage metastorage;
+
+ /** Logger. */
+ private final IgniteLogger log;
+
+ /**
+ * Constructor.
+ *
+ * @param ctx Context.
+ */
+ public SchemaSqlViewManager(GridKernalContext ctx) {
+ this.ctx = ctx;
+
+ log = ctx.log(SchemaSqlViewManager.class);
+ }
+
+ /** */
+ public void start() {
+ ctx.internalSubscriptionProcessor().registerDistributedMetastorageListener(new DistributedMetastorageLifecycleListener() {
+ @Override public void onReadyForRead(ReadableDistributedMetaStorage metastorage) {
+ metastorage.listen(key -> key.startsWith(SQL_VIEW_KEY_PREFIX),
+ SchemaSqlViewManager.this::processMetastorageUpdate);
+ }
+
+ @Override public void onReadyForWrite(DistributedMetaStorage metastorage) {
+ SchemaSqlViewManager.this.metastorage = metastorage;
+ }
+ });
+
+ ctx.internalSubscriptionProcessor().registerGlobalStateListener(this);
+ }
+
+ /** */
+ public void createView(String schemaName, String viewName, String viewSql, boolean replace) throws IgniteCheckedException {
+ ctx.security().authorize(SecurityPermission.SQL_VIEW_CREATE);
+
+ if (!ctx.query().schemaManager().schemaNames().contains(schemaName))
+ throw new SchemaOperationException(SchemaOperationException.CODE_SCHEMA_NOT_FOUND, schemaName);
+
+ String key = makeKey(schemaName, viewName);
+
+ Serializable oldVal;
+ Serializable newVal = new SqlView(schemaName, viewName, viewSql);
+
+ do {
+ oldVal = metastorage.read(key);
+
+ if (oldVal != null && !replace)
+ throw new SchemaOperationException(SchemaOperationException.CODE_VIEW_EXISTS, viewName);
+ }
+ while (!metastorage.compareAndSet(key, oldVal, newVal));
+ }
+
+ /** */
+ public void dropView(String schemaName, String viewName, boolean ifExists) throws IgniteCheckedException {
+ ctx.security().authorize(SecurityPermission.SQL_VIEW_DROP);
+
+ String key = makeKey(schemaName, viewName);
+
+ Serializable oldVal;
+
+ do {
+ oldVal = metastorage.read(key);
+
+ if (oldVal == null) {
+ if (!ifExists)
+ throw new SchemaOperationException(SchemaOperationException.CODE_VIEW_NOT_FOUND, viewName);
+ else
+ return;
+ }
+ }
+ while (!metastorage.compareAndRemove(key, oldVal));
+ }
+
+ /** */
+ public void clearSchemaViews(String schemaName) {
+ if (!U.isLocalNodeCoordinator(ctx.discovery()))
Review Comment:
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.
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/IgniteSchema.java:
##########
@@ -88,4 +91,33 @@ public void removeTable(String tblName) {
public void addFunction(String name, Function func) {
funcMap.put(name, func);
}
+
+ /**
+ * @param name View name.
+ * @param sql View sql.
+ */
+ public void addView(String name, String sql) {
+ viewMap.put(name, sql);
+ }
+
+ /**
+ * @param name View name.
+ */
+ public void removeView(String name) {
+ viewMap.remove(name);
+ }
+
+ /**
+ * Registers current {@code IgniteSchema} in parent {@code schema}.
Review Comment:
Fixed
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/sql/SqlCustomParserTest.java:
##########
@@ -687,6 +690,78 @@ public void dropUser() throws Exception {
assertParserThrows("drop user test with password 'asd'", SqlParseException.class);
}
+ /**
+ * Tests that CREATE OR REPLACE is not allowed for CREATE TABLE/INDEX/USER.
+ */
+ @Test
+ public void invalidCreateOrReplace() {
+ assertParserThrows("create or replace table my_table(id int, val varchar)", SqlParseException.class,
+ "Unsupported clause 'REPLACE'");
+
+ assertParserThrows("create or replace index my_index on my_table(id)", SqlParseException.class,
+ "Unsupported clause 'REPLACE'");
+
+ assertParserThrows("create or replace user test with password 'asd'", SqlParseException.class,
+ "Unsupported clause 'REPLACE'");
+ }
+
+ /**
+ * Create view.
+ */
+ @Test
+ public void createView() throws SqlParseException {
+ SqlCreateView createView = parse("create view my_view as select * from my_table");
+
+ assertThat(createView.name.names, is(ImmutableList.of("MY_VIEW")));
+ assertThat(createView.getReplace(), is(false));
+ assertThat(createView.query, instanceOf(SqlSelect.class));
+ assertThat(((SqlSelect)createView.query).getFrom().toString(), is("MY_TABLE"));
Review Comment:
FIxed
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/AuthorizationIntegrationTest.java:
##########
@@ -95,12 +107,14 @@ public class AuthorizationIntegrationTest extends AbstractSecurityTest {
/** {@inheritDoc} */
@Override protected TestSecurityData[] securityData() {
return new TestSecurityData[] {
- new TestSecurityData(LOGIN, PWD, clientPermissions, null)
+ new TestSecurityData(LOGIN, PWD, clientPermissions(), null)
};
}
- /** {@inheritDoc} */
- @Override protected void beforeTestsStarted() throws Exception {
+ /** */
Review Comment:
Fixed
##########
modules/core/src/test/java/org/apache/ignite/internal/sql/SqlParserViewSelfTest.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.sql;
+
+import org.apache.ignite.internal.sql.command.SqlCreateViewCommand;
+import org.apache.ignite.internal.sql.command.SqlDropViewCommand;
+import org.junit.Test;
+
+/**
+ * Tests for SQL parser: CREATE VIEW.
+ */
+public class SqlParserViewSelfTest extends SqlParserAbstractSelfTest {
+ /**
+ * Tests for CREATE VIEW command.
Review Comment:
Fixed
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/management/SchemaManager.java:
##########
@@ -285,6 +286,8 @@ public void createSystemView(String schema, SystemView<?> view) {
try {
createSchema(schema, true);
+ schema(schema).add(new ViewDescriptor(MetricUtils.toSqlName(view.name()), "SYSTEM", view.description()));
Review Comment:
Fixed
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/util/TypeUtils.java:
##########
@@ -236,20 +237,36 @@ public static RelDataType getResultType(IgniteTypeFactory typeFactory, RelOptSch
* @param origin Column origin.
* @return Result type.
*/
- private static Type getResultClass(IgniteTypeFactory typeFactory, RelOptSchema schema, RelDataType type,
- @Nullable List<String> origin) {
- if (F.isEmpty(origin))
- return typeFactory.getResultClass(type);
+ private static Type getResultClass(
+ IgniteTypeFactory typeFactory,
+ RelOptSchema schema,
+ RelDataType type,
+ @Nullable List<String> origin
+ ) {
+ int cnt = 0; // Counter to protect from infinite recursion.
+
+ while (true) {
+ if (F.isEmpty(origin) || cnt++ >= 100)
+ return typeFactory.getResultClass(type);
Review Comment:
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.
##########
modules/core/src/main/java/org/apache/ignite/internal/sql/command/SqlDropViewCommand.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.sql.command;
+
+import org.apache.ignite.internal.sql.SqlLexer;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+import static org.apache.ignite.internal.sql.SqlKeyword.IF;
+import static org.apache.ignite.internal.sql.SqlParserUtils.parseIfExists;
+import static org.apache.ignite.internal.sql.SqlParserUtils.parseQualifiedIdentifier;
+
+/**
+ * DROP VIEW command.
+ */
+public class SqlDropViewCommand implements SqlCommand {
+ /** Schema name. */
+ private String schemaName;
+
+ /** View name. */
+ private String viewName;
+
+ /** IF EXISTS flag. */
+ private boolean ifExists;
+
+ /**
+ * Default constructor.
+ */
+ public SqlDropViewCommand() {
+ }
Review Comment:
Fixed
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/stat/IgniteStatisticsConfigurationManager.java:
##########
@@ -165,11 +165,13 @@ public class IgniteStatisticsConfigurationManager {
assert !F.isEmpty(cols);
// Drop statistics after columns dropped.
- dropStatistics(
- Collections.singletonList(
- new StatisticsTarget(schemaName, typeDesc.tableName(), cols.toArray(EMPTY_STRINGS))
- ),
- false
+ mgmtBusyExecutor.execute(() ->
Review Comment:
1. I think it's not so critical. If column doesn't exists, statistics for this column will no hurt anyone.
2. Statistics update is done via the same executor (but statistics update after table creation or modification is more critical than statistics delete).
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/management/SchemaManager.java:
##########
@@ -1087,6 +1146,29 @@ public Collection<TableDescriptor> tablesForCache(String cacheName) {
}
}
+ /**
+ * Find view by its identifier.
+ *
+ * @param schemaName Schema name.
+ * @param viewName View name.
+ * @return View or {@code null} if none found.
+ */
+ @Nullable public ViewDescriptor view(String schemaName, String viewName) {
+ lock.readLock().lock();
Review Comment:
Fixed
##########
modules/core/src/test/java/org/apache/ignite/internal/sql/SqlParserViewSelfTest.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.sql;
+
+import org.apache.ignite.internal.sql.command.SqlCreateViewCommand;
+import org.apache.ignite.internal.sql.command.SqlDropViewCommand;
+import org.junit.Test;
+
+/**
+ * Tests for SQL parser: CREATE VIEW.
+ */
+public class SqlParserViewSelfTest extends SqlParserAbstractSelfTest {
+ /**
+ * Tests for CREATE VIEW command.
+ */
+ @Test
+ public void testCreateView() {
+ parseValidateCreate("CREATE VIEW test AS SELECT * FROM test2",
+ null, "TEST", "SELECT * FROM test2", false);
+
+ parseValidateCreate("CREATE OR REPLACE VIEW test AS SELECT * FROM test2",
+ null, "TEST", "SELECT * FROM test2", true);
+
+ parseValidateCreate("CREATE VIEW test.test AS SELECT * FROM test2",
+ "TEST", "TEST", "SELECT * FROM test2", false);
+
+ parseValidateCreate("CREATE VIEW \"test\" AS SELECT * FROM test2",
+ null, "test", "SELECT * FROM test2", false);
+
+ parseValidateCreate("CREATE VIEW \"test\".\"test\" AS SELECT * FROM test2",
+ "test", "test", "SELECT * FROM test2", false);
+
+ parseValidateCreate("CREATE VIEW \"te.st\".\"te.st\" AS SELECT * FROM test2",
+ "te.st", "te.st", "SELECT * FROM test2", false);
+
+ parseValidateCreate("CREATE VIEW test.\"test\" AS SELECT * FROM test2",
+ "TEST", "test", "SELECT * FROM test2", false);
+
+ parseValidateCreate("CREATE VIEW test AS SELECT * FROM test2;",
+ null, "TEST", "SELECT * FROM test2", false);
+
+ parseValidateCreate("CREATE VIEW test AS SELECT * FROM test2 ;",
+ null, "TEST", "SELECT * FROM test2", false);
+
+ parseValidateCreate("CREATE VIEW test AS SELECT * FROM test2; SELECT * FROM test",
+ null, "TEST", "SELECT * FROM test2", false);
+
+ assertParseError(null, "CREATE VIEW test.test.test AS SELECT * FROM test2",
+ "Unexpected token: \".\" (expected: \"AS\")");
+
+ assertParseError(null, "CREATE VIEW test AS UNEXPECTED",
+ "Unexpected token: \"UNEXPECTED\" (expected: \"SELECT\")");
+
+ assertParseError(null, "CREATE VIEW test AS \"SELECT * FROM test2\"",
+ "Unexpected token: \"SELECT * FROM test2\" (expected: \"SELECT\")");
+
+ assertParseError(null, "CREATE OR REPLACE INDEX test",
+ "Unexpected token: \"INDEX\" (expected: \"VIEW\")");
+
+ assertParseError(null, "CREATE OR DROP VIEW test AS SELECT * FROM test2",
+ "Unexpected token: \"DROP\" (expected: \"REPLACE\")");
+ }
+
+ /**
+ * Tests for DROP VIEW command.
Review Comment:
Fixed
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/management/SchemaManager.java:
##########
@@ -1087,6 +1146,29 @@ public Collection<TableDescriptor> tablesForCache(String cacheName) {
}
}
+ /**
+ * Find view by its identifier.
+ *
+ * @param schemaName Schema name.
+ * @param viewName View name.
+ * @return View or {@code null} if none found.
+ */
+ @Nullable public ViewDescriptor view(String schemaName, String viewName) {
Review Comment:
Fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "asfgit (via GitHub)" <gi...@apache.org>.
asfgit closed pull request #11467: IGNITE-22717 SQL Calcite: User defined SQL views
URL: https://github.com/apache/ignite/pull/11467
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1770617107
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/UserDefinedViewsPlannerTest.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.calcite.planner;
+
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.util.ImmutableBitSet;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.processors.query.calcite.schema.IgniteSchema;
+import org.apache.ignite.internal.processors.query.calcite.trait.IgniteDistributions;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.junit.Test;
+
+import static org.apache.calcite.sql.type.SqlTypeName.INTEGER;
+
+/**
+ * User defined views test.
+ */
+public class UserDefinedViewsPlannerTest extends AbstractPlannerTest {
+ /**
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testSimpleView() throws Exception {
+ IgniteSchema schema = createSchema(
+ createTable("T1", IgniteDistributions.single(), "C1", INTEGER, "C2", INTEGER, "C3", INTEGER),
+ createTable("T2", IgniteDistributions.single(), "C1", INTEGER, "C2", INTEGER, "C3", INTEGER)
+ );
+
+ String viewSql = "SELECT T1.C1 AS C1_1, T1.C2 AS C1_2, T2.C1 AS C2_1, T2.C2 AS C2_2 FROM T1 JOIN T2 ON (T1.C3 = T2.C3)";
+
+ schema.addView("V1", viewSql);
+
+ String sql = "select * from v1 where c1_1 = 1 AND c2_2 = 2";
+
+ assertPlan(sql, schema, hasChildThat(isInstanceOf(Join.class)
+ .and(hasChildThat(isTableScan("T1")
+ .and(t -> "=($t0, 1)".equals(t.condition().toString()))))
+ .and(hasChildThat(isTableScan("T2")
+ .and(t -> "=($t1, 2)".equals(t.condition().toString()))))
+ ));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testViewOnView() throws Exception {
+ IgniteSchema schema = createSchema(
+ createTable("T1", IgniteDistributions.single(), "C1", INTEGER, "C2", INTEGER, "C3", INTEGER)
+ );
+
+ schema.addView("V1", "SELECT C1, C2 FROM T1");
+ schema.addView("V2", "SELECT C1 FROM V1");
+
+ assertPlan("select * from v2", schema, isTableScan("T1")
+ .and(t -> t.requiredColumns().equals(ImmutableBitSet.of(0))));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testViewHint() throws Exception {
+ IgniteSchema schema = createSchema(
+ createTable("T1", IgniteDistributions.single(), "C1", INTEGER, "C2", INTEGER, "C3", INTEGER)
+ .addIndex("IDX_1", 0)
+ .addIndex("IDX_2", 1)
+ );
+
+ schema.addView("V1", "SELECT /*+ FORCE_INDEX(IDX_1) */ C1, C2 FROM T1");
+ schema.addView("V2", "SELECT /*+ FORCE_INDEX(IDX_2) */ C1, C2 FROM T1");
+
+ assertPlan("SELECT * FROM v1 WHERE c1 = ? AND c2 = ?", schema, isIndexScan("T1", "IDX_1"));
+ assertPlan("SELECT * FROM v2 WHERE c1 = ? AND c2 = ?", schema, isIndexScan("T1", "IDX_2"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testRecursiveView() throws Exception {
Review Comment:
Minor: no need of `throws Exception`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1770620874
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/util/TypeUtils.java:
##########
@@ -236,20 +237,36 @@ public static RelDataType getResultType(IgniteTypeFactory typeFactory, RelOptSch
* @param origin Column origin.
* @return Result type.
*/
- private static Type getResultClass(IgniteTypeFactory typeFactory, RelOptSchema schema, RelDataType type,
- @Nullable List<String> origin) {
- if (F.isEmpty(origin))
- return typeFactory.getResultClass(type);
+ private static Type getResultClass(
+ IgniteTypeFactory typeFactory,
+ RelOptSchema schema,
+ RelDataType type,
+ @Nullable List<String> origin
+ ) {
+ int cnt = 0; // Counter to protect from infinite recursion.
+
+ while (true) {
+ if (F.isEmpty(origin) || cnt++ >= 100)
+ return typeFactory.getResultClass(type);
Review Comment:
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1734985168
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/ViewsIntegrationTest.java:
##########
@@ -0,0 +1,432 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.integration;
+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.calcite.CalciteQueryEngineConfiguration;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.SqlConfiguration;
+import org.apache.ignite.indexing.IndexingQueryEngineConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.util.typedef.G;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/** */
+@RunWith(Parameterized.class)
+public class ViewsIntegrationTest extends AbstractBasicIntegrationTest {
+ /** */
+ private boolean persistenceEnabled;
+
+ /** */
+ private String[] predefinedSchemas;
+
+ /** */
+ @Parameterized.Parameter
+ public String engine;
+
+ /** */
+ @Parameterized.Parameters(name = "Query engine={0}")
+ public static Iterable<Object> params() {
+ return Arrays.asList(CalciteQueryEngineConfiguration.ENGINE_NAME, IndexingQueryEngineConfiguration.ENGINE_NAME);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ return super.getConfiguration(igniteInstanceName)
+ .setSqlConfiguration(new SqlConfiguration()
+ .setSqlSchemas(predefinedSchemas)
+ .setQueryEnginesConfiguration(engine.equals(CalciteQueryEngineConfiguration.ENGINE_NAME) ?
+ new CalciteQueryEngineConfiguration() : new IndexingQueryEngineConfiguration()))
+ .setDataStorageConfiguration(new DataStorageConfiguration()
+ .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+ .setPersistenceEnabled(persistenceEnabled)));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ stopAllGrids();
+
+ cleanPersistenceDir();
+ }
+
+ /**
+ * Creates and drops view.
+ */
+ @Test
+ public void testCreateDrop() throws Exception {
+ initGrids(3);
+ initTable(3);
+
+ sql("create or replace view my_view as select * from my_table");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+
+ assertRowsCount(3, "select * from my_view");
+ assertRowsCount(3, "select t.id, val_int, * from my_view t");
+
+ sql("drop view my_view");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 0);
+ }
+
+ /**
+ * Tests views on different schemas.
+ */
+ @Test
+ public void testDifferentSchemas() throws Exception {
+ initGrids(3);
+ initTable(5);
+
+ IgniteCache<?, ?> cache1 = client.getOrCreateCache(new CacheConfiguration<>("CACHE1")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ IgniteCache<?, ?> cache2 = client.getOrCreateCache(new CacheConfiguration<>("CACHE2")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ IgniteCache<?, ?> cache3 = client.getOrCreateCache(new CacheConfiguration<>("CACHE3")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+ IgniteCache<?, ?> cache4 = client.getOrCreateCache(new CacheConfiguration<>("CACHE4")
+ .setIndexedTypes(Integer.class, String.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+
+ sql("create or replace view my_view as select * from my_table");
+ sql("create or replace view cache1.my_view as select * from public.my_table where id < 4");
+ sql("create or replace view cache2.my_view as select * from cache1.my_view where id < 3");
+ sql("create or replace view my_schema.my_view1 as select * from public.my_table where id < 2");
+ sql("create or replace view my_schema.my_view2 as select * from my_view1 where id < 1");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 1);
+ assertViewsCount("CACHE2", "MY_VIEW", 1);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW1", 1);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW2", 1);
+
+ assertRowsCount(5, "select * from my_view");
+ assertRowsCount(4, "select * from cache1.my_view");
+ assertRowsCount(3, "select * from cache2.my_view");
+ assertRowsCount(2, "select * from my_schema.my_view1");
+ assertRowsCount(1, "select * from my_schema.my_view2");
+
+ // PUBLIC.MY_VIEW
+ assertEquals(5, cache1.query(new SqlFieldsQuery("select * from public.my_view")).getAll().size());
+ assertEquals(5, cache1.query(new SqlFieldsQuery("select * from my_view").setSchema("PUBLIC")).getAll().size());
+ // CACHE1.MY_VIEW
+ assertEquals(4, cache1.query(new SqlFieldsQuery("select * from my_view")).getAll().size());
+ assertEquals(4, cache2.query(new SqlFieldsQuery("select * from cache1.my_view")).getAll().size());
+ // CACHE2.MY_VIEW
+ assertEquals(3, cache2.query(new SqlFieldsQuery("select * from my_view")).getAll().size());
+ assertEquals(3, cache1.query(new SqlFieldsQuery("select * from my_view").setSchema("CACHE2")).getAll().size());
+ // MY_SCHEMA.MY_VIEW1
+ assertEquals(2, cache3.query(new SqlFieldsQuery("select * from my_view1")).getAll().size());
+ assertEquals(2, cache4.query(new SqlFieldsQuery("select * from my_view1")).getAll().size());
+ // MY_SCHEMA.MY_VIEW2
+ assertEquals(1, cache3.query(new SqlFieldsQuery("select * from my_view2")).getAll().size());
+ assertEquals(1, cache4.query(new SqlFieldsQuery("select * from my_view2")).getAll().size());
+ }
+
+ /**
+ * Tests views drop on schema drop.
+ */
+ @Test
+ public void testSchemaCleaning() throws Exception {
+ initGrids(3);
+ initTable(5);
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE1")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE2")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("PUBLIC")
+ );
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE3")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE4")
+ .setIndexedTypes(Integer.class, String.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+
+ sql("create or replace view my_view as select * from my_table");
+ sql("create or replace view cache1.my_view as select * from public.my_table");
+ sql("create or replace view my_schema.my_view as select * from public.my_table");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 1);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 1);
+
+ client.destroyCache("CACHE1");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 0);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 1);
+
+ client.destroyCache("CACHE2");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 0);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 1);
+
+ client.destroyCache("CACHE3");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 0);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 1);
+
+ client.destroyCache("CACHE4");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 0);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 0);
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE1")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE3")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 0);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 0);
+ }
+
+ /**
+ * Tests views on not existing schema.
+ */
+ @Test
+ public void testNotExistingSchema() throws Exception {
+ initGrids(3);
+ initTable(3);
+
+ assertThrows("CREATE VIEW my_schema.my_view AS SELECT * FROM public.my_table", IgniteSQLException.class,
+ "MY_SCHEMA");
+ }
+
+ /**
+ * Tests view after in-memory grid restart.
+ */
+ @Test
+ public void testInMemory() throws Exception {
+ initGrids(3);
+ initTable(3);
+
+ sql("create or replace view my_view as select * from my_table");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+
+ stopAllGrids();
+
+ initGrids(3);
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 0);
+ }
+
+ /**
+ * Tests view after persistent grid restart.
+ */
+ @Test
+ public void testPersistance() throws Exception {
+ persistenceEnabled = true;
+
+ initGrids(3);
+ initTable(3);
+
+ sql("create or replace view my_view as select * from my_table");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+
+ stopAllGrids();
+
+ initGrids(3);
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ }
+
+ /**
+ * Tests views information distribution on node join.
+ */
+ @Test
+ public void testNodeJoin() throws Exception {
Review Comment:
What if only non-baseline node left? Will a view exist?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1734453562
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/IgniteSchema.java:
##########
@@ -88,4 +91,33 @@ public void removeTable(String tblName) {
public void addFunction(String name, Function func) {
funcMap.put(name, func);
}
+
+ /**
+ * @param name View name.
+ * @param sql View sql.
+ */
+ public void addView(String name, String sql) {
+ viewMap.put(name, sql);
+ }
+
+ /**
+ * @param name View name.
+ */
+ public void removeView(String name) {
+ viewMap.remove(name);
+ }
+
+ /**
+ * Registers current {@code IgniteSchema} in parent {@code schema}.
Review Comment:
Let's emphasize that parent schema is a SchemaPlus: `{@code schema}` -> `{@code SchemaPlus}`
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/IgniteSchema.java:
##########
@@ -88,4 +91,33 @@ public void removeTable(String tblName) {
public void addFunction(String name, Function func) {
funcMap.put(name, func);
}
+
+ /**
+ * @param name View name.
+ * @param sql View sql.
+ */
+ public void addView(String name, String sql) {
+ viewMap.put(name, sql);
+ }
+
+ /**
+ * @param name View name.
+ */
+ public void removeView(String name) {
+ viewMap.remove(name);
+ }
+
+ /**
+ * Registers current {@code IgniteSchema} in parent {@code schema}.
+ *
+ * @param schema Parent schema.
+ * @return Registered schema.
+ */
+ public SchemaPlus register(SchemaPlus schema) {
+ SchemaPlus schemaPlus = schema.add(schemaName, this);
+
+ viewMap.forEach((name, sql) -> schemaPlus.add(name, new ViewTableMacroImpl(sql, schemaPlus)));
Review Comment:
Why only the views?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1734942966
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/ViewsIntegrationTest.java:
##########
@@ -0,0 +1,432 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.integration;
+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.calcite.CalciteQueryEngineConfiguration;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.SqlConfiguration;
+import org.apache.ignite.indexing.IndexingQueryEngineConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.util.typedef.G;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/** */
+@RunWith(Parameterized.class)
+public class ViewsIntegrationTest extends AbstractBasicIntegrationTest {
+ /** */
+ private boolean persistenceEnabled;
+
+ /** */
+ private String[] predefinedSchemas;
+
+ /** */
+ @Parameterized.Parameter
+ public String engine;
+
+ /** */
+ @Parameterized.Parameters(name = "Query engine={0}")
+ public static Iterable<Object> params() {
+ return Arrays.asList(CalciteQueryEngineConfiguration.ENGINE_NAME, IndexingQueryEngineConfiguration.ENGINE_NAME);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ return super.getConfiguration(igniteInstanceName)
+ .setSqlConfiguration(new SqlConfiguration()
+ .setSqlSchemas(predefinedSchemas)
+ .setQueryEnginesConfiguration(engine.equals(CalciteQueryEngineConfiguration.ENGINE_NAME) ?
+ new CalciteQueryEngineConfiguration() : new IndexingQueryEngineConfiguration()))
+ .setDataStorageConfiguration(new DataStorageConfiguration()
+ .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+ .setPersistenceEnabled(persistenceEnabled)));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ stopAllGrids();
+
+ cleanPersistenceDir();
+ }
+
+ /**
+ * Creates and drops view.
+ */
+ @Test
+ public void testCreateDrop() throws Exception {
+ initGrids(3);
+ initTable(3);
+
+ sql("create or replace view my_view as select * from my_table");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+
+ assertRowsCount(3, "select * from my_view");
+ assertRowsCount(3, "select t.id, val_int, * from my_view t");
+
+ sql("drop view my_view");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 0);
+ }
+
+ /**
+ * Tests views on different schemas.
+ */
+ @Test
+ public void testDifferentSchemas() throws Exception {
+ initGrids(3);
+ initTable(5);
+
+ IgniteCache<?, ?> cache1 = client.getOrCreateCache(new CacheConfiguration<>("CACHE1")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ IgniteCache<?, ?> cache2 = client.getOrCreateCache(new CacheConfiguration<>("CACHE2")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ IgniteCache<?, ?> cache3 = client.getOrCreateCache(new CacheConfiguration<>("CACHE3")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+ IgniteCache<?, ?> cache4 = client.getOrCreateCache(new CacheConfiguration<>("CACHE4")
Review Comment:
linebreak
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/ViewsIntegrationTest.java:
##########
@@ -0,0 +1,432 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.integration;
+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.calcite.CalciteQueryEngineConfiguration;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.SqlConfiguration;
+import org.apache.ignite.indexing.IndexingQueryEngineConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.util.typedef.G;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/** */
+@RunWith(Parameterized.class)
+public class ViewsIntegrationTest extends AbstractBasicIntegrationTest {
+ /** */
+ private boolean persistenceEnabled;
+
+ /** */
+ private String[] predefinedSchemas;
+
+ /** */
+ @Parameterized.Parameter
+ public String engine;
+
+ /** */
+ @Parameterized.Parameters(name = "Query engine={0}")
+ public static Iterable<Object> params() {
+ return Arrays.asList(CalciteQueryEngineConfiguration.ENGINE_NAME, IndexingQueryEngineConfiguration.ENGINE_NAME);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ return super.getConfiguration(igniteInstanceName)
+ .setSqlConfiguration(new SqlConfiguration()
+ .setSqlSchemas(predefinedSchemas)
+ .setQueryEnginesConfiguration(engine.equals(CalciteQueryEngineConfiguration.ENGINE_NAME) ?
+ new CalciteQueryEngineConfiguration() : new IndexingQueryEngineConfiguration()))
+ .setDataStorageConfiguration(new DataStorageConfiguration()
+ .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+ .setPersistenceEnabled(persistenceEnabled)));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ stopAllGrids();
+
+ cleanPersistenceDir();
+ }
+
+ /**
+ * Creates and drops view.
+ */
+ @Test
+ public void testCreateDrop() throws Exception {
+ initGrids(3);
+ initTable(3);
+
+ sql("create or replace view my_view as select * from my_table");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+
+ assertRowsCount(3, "select * from my_view");
+ assertRowsCount(3, "select t.id, val_int, * from my_view t");
+
+ sql("drop view my_view");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 0);
+ }
+
+ /**
+ * Tests views on different schemas.
+ */
+ @Test
+ public void testDifferentSchemas() throws Exception {
+ initGrids(3);
+ initTable(5);
+
+ IgniteCache<?, ?> cache1 = client.getOrCreateCache(new CacheConfiguration<>("CACHE1")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ IgniteCache<?, ?> cache2 = client.getOrCreateCache(new CacheConfiguration<>("CACHE2")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ IgniteCache<?, ?> cache3 = client.getOrCreateCache(new CacheConfiguration<>("CACHE3")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+ IgniteCache<?, ?> cache4 = client.getOrCreateCache(new CacheConfiguration<>("CACHE4")
Review Comment:
linebreak
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1715151511
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/stat/IgniteStatisticsConfigurationManager.java:
##########
@@ -165,11 +165,13 @@ public class IgniteStatisticsConfigurationManager {
assert !F.isEmpty(cols);
// Drop statistics after columns dropped.
- dropStatistics(
- Collections.singletonList(
- new StatisticsTarget(schemaName, typeDesc.tableName(), cols.toArray(EMPTY_STRINGS))
- ),
- false
+ mgmtBusyExecutor.execute(() ->
Review Comment:
Can a related statistic survive for long if the executor is busy for long by an active statistics collection tasks?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1715073978
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/management/SchemaDescriptor.java:
##########
@@ -121,6 +124,37 @@ public void drop(TableDescriptor tbl) {
typeToTbl.remove(new QueryTypeNameKey(tbl.cacheInfo().name(), tbl.type().name()));
}
+ /**
+ * @return Views.
+ */
+ public Collection<ViewDescriptor> views() {
+ return views.values();
+ }
+
+ /**
+ * @param viewName View name.
+ * @return View.
+ */
+ public ViewDescriptor viewByName(String viewName) {
+ return views.get(viewName);
+ }
+
+ /**
+ * @param view View descriptor.
+ */
+ public void add(ViewDescriptor view) {
+ views.put(view.name(), view);
+ }
+
+ /**
+ * Drop view.
Review Comment:
Same: descriptor?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1713918857
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/SchemaHolderImpl.java:
##########
@@ -387,8 +408,11 @@ private void rebuild() {
SchemaPlus newCalciteSchema = Frameworks.createRootSchema(false);
newCalciteSchema.add("UUID", typeFactory -> ((IgniteTypeFactory)typeFactory).createCustomType(UUID.class));
newCalciteSchema.add("OTHER", typeFactory -> ((IgniteTypeFactory)typeFactory).createCustomType(Object.class));
- newCalciteSchema.add("PUBLIC", new IgniteSchema("PUBLIC"));
- igniteSchemas.forEach(newCalciteSchema::add);
+ newCalciteSchema.add(QueryUtils.DFLT_SCHEMA, new IgniteSchema(QueryUtils.DFLT_SCHEMA));
+
+ for (IgniteSchema schema : igniteSchemas.values())
Review Comment:
I like similar to the previous: `igniteSchemas.values().forEach(sch->sch.register(newCalciteSchema));`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #11467:
URL: https://github.com/apache/ignite/pull/11467#issuecomment-2275296532
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) **Quality Gate failed**
Failed conditions
 [13 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) (required ≤ 1)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarLint](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #11467:
URL: https://github.com/apache/ignite/pull/11467#issuecomment-2371974744
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) **Quality Gate failed**
Failed conditions
 [13 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) (required ≤ 1)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarLint](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #11467:
URL: https://github.com/apache/ignite/pull/11467#issuecomment-2273811048
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) **Quality Gate failed**
Failed conditions
 [15 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) (required ≤ 1)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarLint](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1717182826
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/management/SchemaManager.java:
##########
@@ -451,6 +454,9 @@ public void onCacheDestroyed(String cacheName, boolean rmvIdx, boolean clearIdx)
if (schema.decrementUsageCount()) {
schemas.remove(schemaName);
+ if (destroy)
Review Comment:
We just removed local schema and called `onSchemaDropped()`. Why do we keep cluster schema if cache was only stopped? Looks wierd. Also `if (!U.isLocalNodeCoordinator(ctx.discovery()))` might be moved outside.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1734938446
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/ViewsIntegrationTest.java:
##########
@@ -0,0 +1,432 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.integration;
+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.calcite.CalciteQueryEngineConfiguration;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.SqlConfiguration;
+import org.apache.ignite.indexing.IndexingQueryEngineConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.util.typedef.G;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/** */
+@RunWith(Parameterized.class)
+public class ViewsIntegrationTest extends AbstractBasicIntegrationTest {
+ /** */
+ private boolean persistenceEnabled;
+
+ /** */
+ private String[] predefinedSchemas;
+
+ /** */
+ @Parameterized.Parameter
+ public String engine;
+
+ /** */
+ @Parameterized.Parameters(name = "Query engine={0}")
+ public static Iterable<Object> params() {
+ return Arrays.asList(CalciteQueryEngineConfiguration.ENGINE_NAME, IndexingQueryEngineConfiguration.ENGINE_NAME);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ return super.getConfiguration(igniteInstanceName)
+ .setSqlConfiguration(new SqlConfiguration()
+ .setSqlSchemas(predefinedSchemas)
+ .setQueryEnginesConfiguration(engine.equals(CalciteQueryEngineConfiguration.ENGINE_NAME) ?
+ new CalciteQueryEngineConfiguration() : new IndexingQueryEngineConfiguration()))
+ .setDataStorageConfiguration(new DataStorageConfiguration()
+ .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+ .setPersistenceEnabled(persistenceEnabled)));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
Review Comment:
Let's remove this method
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1735290588
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/management/SchemaManager.java:
##########
@@ -285,6 +286,8 @@ public void createSystemView(String schema, SystemView<?> view) {
try {
createSchema(schema, true);
+ schema(schema).add(new ViewDescriptor(MetricUtils.toSqlName(view.name()), "SYSTEM", view.description()));
Review Comment:
Let's keep the SQL for system views empty
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1735196989
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/management/ViewDescriptor.java:
##########
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema.management;
+
+/**
+ * Local database view object.
+ */
+public class ViewDescriptor {
+ /** View name. */
+ private final String name;
+
+ /** View SQL. */
+ private final String sql;
+
+ /** View description. */
+ private final String desc;
+
+ /**
+ * @param name View name.
+ * @param sql View SQL.
+ * @param desc View description.
+ */
+ public ViewDescriptor(String name, String sql, String desc) {
Review Comment:
Could be package-level
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1735231291
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/management/SchemaManager.java:
##########
@@ -1087,6 +1146,29 @@ public Collection<TableDescriptor> tablesForCache(String cacheName) {
}
}
+ /**
+ * Find view by its identifier.
+ *
+ * @param schemaName Schema name.
+ * @param viewName View name.
+ * @return View or {@code null} if none found.
+ */
+ @Nullable public ViewDescriptor view(String schemaName, String viewName) {
+ lock.readLock().lock();
Review Comment:
Used only under a write lock
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "alex-plekhanov (via GitHub)" <gi...@apache.org>.
alex-plekhanov commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1744192701
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/RootQuery.java:
##########
@@ -142,16 +139,10 @@ public RootQuery(
FrameworkConfig frameworkCfg = qryCtx != null ? qryCtx.unwrap(FrameworkConfig.class) : null;
- if (frameworkCfg == null)
Review Comment:
Fixed by another ticket
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1713450464
##########
docs/_docs/sql-reference/ddl.adoc:
##########
@@ -472,6 +472,66 @@ DROP INDEX idx_person_name;
----
+== CREATE VIEW
+
+Creates an user definded SQL view
Review Comment:
Dot at the end.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "alex-plekhanov (via GitHub)" <gi...@apache.org>.
alex-plekhanov commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1771696789
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/UserDefinedViewsPlannerTest.java:
##########
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.calcite.planner;
+
+import org.apache.calcite.rel.core.Join;
+import org.apache.calcite.util.ImmutableBitSet;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.processors.query.calcite.schema.IgniteSchema;
+import org.apache.ignite.internal.processors.query.calcite.trait.IgniteDistributions;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.junit.Test;
+
+import static org.apache.calcite.sql.type.SqlTypeName.INTEGER;
+
+/**
+ * User defined views test.
+ */
+public class UserDefinedViewsPlannerTest extends AbstractPlannerTest {
+ /**
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testSimpleView() throws Exception {
+ IgniteSchema schema = createSchema(
+ createTable("T1", IgniteDistributions.single(), "C1", INTEGER, "C2", INTEGER, "C3", INTEGER),
+ createTable("T2", IgniteDistributions.single(), "C1", INTEGER, "C2", INTEGER, "C3", INTEGER)
+ );
+
+ String viewSql = "SELECT T1.C1 AS C1_1, T1.C2 AS C1_2, T2.C1 AS C2_1, T2.C2 AS C2_2 FROM T1 JOIN T2 ON (T1.C3 = T2.C3)";
+
+ schema.addView("V1", viewSql);
+
+ String sql = "select * from v1 where c1_1 = 1 AND c2_2 = 2";
+
+ assertPlan(sql, schema, hasChildThat(isInstanceOf(Join.class)
+ .and(hasChildThat(isTableScan("T1")
+ .and(t -> "=($t0, 1)".equals(t.condition().toString()))))
+ .and(hasChildThat(isTableScan("T2")
+ .and(t -> "=($t1, 2)".equals(t.condition().toString()))))
+ ));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testViewOnView() throws Exception {
+ IgniteSchema schema = createSchema(
+ createTable("T1", IgniteDistributions.single(), "C1", INTEGER, "C2", INTEGER, "C3", INTEGER)
+ );
+
+ schema.addView("V1", "SELECT C1, C2 FROM T1");
+ schema.addView("V2", "SELECT C1 FROM V1");
+
+ assertPlan("select * from v2", schema, isTableScan("T1")
+ .and(t -> t.requiredColumns().equals(ImmutableBitSet.of(0))));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testViewHint() throws Exception {
+ IgniteSchema schema = createSchema(
+ createTable("T1", IgniteDistributions.single(), "C1", INTEGER, "C2", INTEGER, "C3", INTEGER)
+ .addIndex("IDX_1", 0)
+ .addIndex("IDX_2", 1)
+ );
+
+ schema.addView("V1", "SELECT /*+ FORCE_INDEX(IDX_1) */ C1, C2 FROM T1");
+ schema.addView("V2", "SELECT /*+ FORCE_INDEX(IDX_2) */ C1, C2 FROM T1");
+
+ assertPlan("SELECT * FROM v1 WHERE c1 = ? AND c2 = ?", schema, isIndexScan("T1", "IDX_1"));
+ assertPlan("SELECT * FROM v2 WHERE c1 = ? AND c2 = ?", schema, isIndexScan("T1", "IDX_2"));
+ }
+
+ /**
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testRecursiveView() throws Exception {
Review Comment:
Fixed
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/util/TypeUtils.java:
##########
@@ -236,20 +237,38 @@ public static RelDataType getResultType(IgniteTypeFactory typeFactory, RelOptSch
* @param origin Column origin.
* @return Result type.
*/
- private static Type getResultClass(IgniteTypeFactory typeFactory, RelOptSchema schema, RelDataType type,
- @Nullable List<String> origin) {
- if (F.isEmpty(origin))
- return typeFactory.getResultClass(type);
+ private static Type getResultClass(
+ IgniteTypeFactory typeFactory,
+ RelOptSchema schema,
+ RelDataType type,
+ @Nullable List<String> origin
+ ) {
+ int MAX_VIEW_DEPTH = 100;
Review Comment:
Fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1735127174
##########
modules/core/src/test/java/org/apache/ignite/internal/sql/SqlParserViewSelfTest.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.sql;
+
+import org.apache.ignite.internal.sql.command.SqlCreateViewCommand;
+import org.apache.ignite.internal.sql.command.SqlDropViewCommand;
+import org.junit.Test;
+
+/**
+ * Tests for SQL parser: CREATE VIEW.
+ */
+public class SqlParserViewSelfTest extends SqlParserAbstractSelfTest {
+ /**
+ * Tests for CREATE VIEW command.
Review Comment:
'Test' or remove 'for'
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1735080602
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/SchemaSqlViewManager.java:
##########
@@ -0,0 +1,222 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.query.schema;
+
+import java.io.Serializable;
+import java.util.Objects;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupport;
+import org.apache.ignite.internal.processors.metastorage.DistributedMetaStorage;
+import org.apache.ignite.internal.processors.metastorage.DistributedMetastorageLifecycleListener;
+import org.apache.ignite.internal.processors.metastorage.ReadableDistributedMetaStorage;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.plugin.security.SecurityPermission;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Global schema SQL view manager.
+ */
+public class SchemaSqlViewManager implements IgniteChangeGlobalStateSupport {
+ /** Distributed metastorage key prefix. */
+ private static final String SQL_VIEW_KEY_PREFIX = DistributedMetaStorage.IGNITE_INTERNAL_KEY_PREFIX + "sql.view.";
+
+ /** Kernal context. */
+ private final GridKernalContext ctx;
+
+ /** */
+ private volatile DistributedMetaStorage metastorage;
+
+ /** Logger. */
+ private final IgniteLogger log;
+
+ /**
+ * Constructor.
+ *
+ * @param ctx Context.
+ */
+ public SchemaSqlViewManager(GridKernalContext ctx) {
+ this.ctx = ctx;
+
+ log = ctx.log(SchemaSqlViewManager.class);
+ }
+
+ /** */
+ public void start() {
+ ctx.internalSubscriptionProcessor().registerDistributedMetastorageListener(new DistributedMetastorageLifecycleListener() {
+ @Override public void onReadyForRead(ReadableDistributedMetaStorage metastorage) {
+ metastorage.listen(key -> key.startsWith(SQL_VIEW_KEY_PREFIX),
+ SchemaSqlViewManager.this::processMetastorageUpdate);
+ }
+
+ @Override public void onReadyForWrite(DistributedMetaStorage metastorage) {
+ SchemaSqlViewManager.this.metastorage = metastorage;
+ }
+ });
+
+ ctx.internalSubscriptionProcessor().registerGlobalStateListener(this);
+ }
+
+ /** */
+ public void createView(String schemaName, String viewName, String viewSql, boolean replace) throws IgniteCheckedException {
+ ctx.security().authorize(SecurityPermission.SQL_VIEW_CREATE);
+
+ if (!ctx.query().schemaManager().schemaNames().contains(schemaName))
+ throw new SchemaOperationException(SchemaOperationException.CODE_SCHEMA_NOT_FOUND, schemaName);
+
+ String key = makeKey(schemaName, viewName);
+
+ Serializable oldVal;
+ Serializable newVal = new SqlView(schemaName, viewName, viewSql);
+
+ do {
+ oldVal = metastorage.read(key);
+
+ if (oldVal != null && !replace)
+ throw new SchemaOperationException(SchemaOperationException.CODE_VIEW_EXISTS, viewName);
+ }
+ while (!metastorage.compareAndSet(key, oldVal, newVal));
+ }
+
+ /** */
+ public void dropView(String schemaName, String viewName, boolean ifExists) throws IgniteCheckedException {
+ ctx.security().authorize(SecurityPermission.SQL_VIEW_DROP);
+
+ String key = makeKey(schemaName, viewName);
+
+ Serializable oldVal;
+
+ do {
+ oldVal = metastorage.read(key);
+
+ if (oldVal == null) {
+ if (!ifExists)
+ throw new SchemaOperationException(SchemaOperationException.CODE_VIEW_NOT_FOUND, viewName);
+ else
+ return;
+ }
+ }
+ while (!metastorage.compareAndRemove(key, oldVal));
+ }
+
+ /** */
+ public void clearSchemaViews(String schemaName) {
+ if (!U.isLocalNodeCoordinator(ctx.discovery()))
Review Comment:
Let's use `!U.isLocalNodeCoordinator(ctx.discovery())` outside
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "alex-plekhanov (via GitHub)" <gi...@apache.org>.
alex-plekhanov commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1744211615
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/ViewsIntegrationTest.java:
##########
@@ -0,0 +1,432 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.integration;
+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.calcite.CalciteQueryEngineConfiguration;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.SqlConfiguration;
+import org.apache.ignite.indexing.IndexingQueryEngineConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.util.typedef.G;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/** */
+@RunWith(Parameterized.class)
+public class ViewsIntegrationTest extends AbstractBasicIntegrationTest {
+ /** */
+ private boolean persistenceEnabled;
+
+ /** */
+ private String[] predefinedSchemas;
+
+ /** */
+ @Parameterized.Parameter
+ public String engine;
+
+ /** */
+ @Parameterized.Parameters(name = "Query engine={0}")
+ public static Iterable<Object> params() {
+ return Arrays.asList(CalciteQueryEngineConfiguration.ENGINE_NAME, IndexingQueryEngineConfiguration.ENGINE_NAME);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ return super.getConfiguration(igniteInstanceName)
+ .setSqlConfiguration(new SqlConfiguration()
+ .setSqlSchemas(predefinedSchemas)
+ .setQueryEnginesConfiguration(engine.equals(CalciteQueryEngineConfiguration.ENGINE_NAME) ?
+ new CalciteQueryEngineConfiguration() : new IndexingQueryEngineConfiguration()))
+ .setDataStorageConfiguration(new DataStorageConfiguration()
+ .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+ .setPersistenceEnabled(persistenceEnabled)));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ stopAllGrids();
+
+ cleanPersistenceDir();
+ }
+
+ /**
+ * Creates and drops view.
Review Comment:
Fixed
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/ViewsIntegrationTest.java:
##########
@@ -0,0 +1,432 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.integration;
+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.calcite.CalciteQueryEngineConfiguration;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.SqlConfiguration;
+import org.apache.ignite.indexing.IndexingQueryEngineConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.util.typedef.G;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/** */
+@RunWith(Parameterized.class)
+public class ViewsIntegrationTest extends AbstractBasicIntegrationTest {
+ /** */
+ private boolean persistenceEnabled;
+
+ /** */
+ private String[] predefinedSchemas;
+
+ /** */
+ @Parameterized.Parameter
+ public String engine;
+
+ /** */
+ @Parameterized.Parameters(name = "Query engine={0}")
+ public static Iterable<Object> params() {
+ return Arrays.asList(CalciteQueryEngineConfiguration.ENGINE_NAME, IndexingQueryEngineConfiguration.ENGINE_NAME);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ return super.getConfiguration(igniteInstanceName)
+ .setSqlConfiguration(new SqlConfiguration()
+ .setSqlSchemas(predefinedSchemas)
+ .setQueryEnginesConfiguration(engine.equals(CalciteQueryEngineConfiguration.ENGINE_NAME) ?
+ new CalciteQueryEngineConfiguration() : new IndexingQueryEngineConfiguration()))
+ .setDataStorageConfiguration(new DataStorageConfiguration()
+ .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+ .setPersistenceEnabled(persistenceEnabled)));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ stopAllGrids();
+
+ cleanPersistenceDir();
+ }
+
+ /**
+ * Creates and drops view.
+ */
+ @Test
+ public void testCreateDrop() throws Exception {
+ initGrids(3);
+ initTable(3);
+
+ sql("create or replace view my_view as select * from my_table");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+
+ assertRowsCount(3, "select * from my_view");
+ assertRowsCount(3, "select t.id, val_int, * from my_view t");
+
+ sql("drop view my_view");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 0);
+ }
+
+ /**
+ * Tests views on different schemas.
+ */
+ @Test
+ public void testDifferentSchemas() throws Exception {
+ initGrids(3);
+ initTable(5);
+
+ IgniteCache<?, ?> cache1 = client.getOrCreateCache(new CacheConfiguration<>("CACHE1")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ IgniteCache<?, ?> cache2 = client.getOrCreateCache(new CacheConfiguration<>("CACHE2")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ IgniteCache<?, ?> cache3 = client.getOrCreateCache(new CacheConfiguration<>("CACHE3")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
Review Comment:
Fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #11467:
URL: https://github.com/apache/ignite/pull/11467#issuecomment-2329687907
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) **Quality Gate failed**
Failed conditions
 [5 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) (required ≤ 1)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarLint](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1716803847
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java:
##########
@@ -259,6 +259,7 @@ public DataStructuresProcessor(GridKernalContext ctx) {
/** {@inheritDoc} */
@Override public void start() {
ctx.event().addLocalEventListener(lsnr, EVT_NODE_LEFT, EVT_NODE_FAILED);
+ ctx.internalSubscriptionProcessor().registerGlobalStateListener(this);
Review Comment:
Why changed? Can be moved to another ticket?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #11467:
URL: https://github.com/apache/ignite/pull/11467#issuecomment-2275683835
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) **Quality Gate failed**
Failed conditions
 [11 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) (required ≤ 1)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarLint](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #11467:
URL: https://github.com/apache/ignite/pull/11467#issuecomment-2276242027
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) **Quality Gate failed**
Failed conditions
 [4 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) (required ≤ 1)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarLint](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1770616732
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/util/TypeUtils.java:
##########
@@ -236,20 +237,38 @@ public static RelDataType getResultType(IgniteTypeFactory typeFactory, RelOptSch
* @param origin Column origin.
* @return Result type.
*/
- private static Type getResultClass(IgniteTypeFactory typeFactory, RelOptSchema schema, RelDataType type,
- @Nullable List<String> origin) {
- if (F.isEmpty(origin))
- return typeFactory.getResultClass(type);
+ private static Type getResultClass(
+ IgniteTypeFactory typeFactory,
+ RelOptSchema schema,
+ RelDataType type,
+ @Nullable List<String> origin
+ ) {
+ int MAX_VIEW_DEPTH = 100;
Review Comment:
`maxViewDepth`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #11467:
URL: https://github.com/apache/ignite/pull/11467#issuecomment-2368696873
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) **Quality Gate failed**
Failed conditions
 [13 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) (required ≤ 1)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarLint](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "sonarcloud[bot] (via GitHub)" <gi...@apache.org>.
sonarcloud[bot] commented on PR #11467:
URL: https://github.com/apache/ignite/pull/11467#issuecomment-2273898774
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) **Quality Gate failed**
Failed conditions
 [13 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467) (required ≤ 1)
[See analysis details on SonarCloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=11467)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarLint](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1734328418
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/subscription/GridInternalSubscriptionProcessor.java:
##########
@@ -59,6 +59,9 @@ public class GridInternalSubscriptionProcessor extends GridProcessorAdapter {
/** */
private final List<IgniteChangeGlobalStateSupport> globalStateListeners = new ArrayList<>();
+ /** */
+ private final List<IgniteChangeGlobalStateSupport> globalStateListeners = new ArrayList<>();
Review Comment:
duplicate
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1734489121
##########
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/IgniteSchema.java:
##########
@@ -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<>();
Review Comment:
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1734928903
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/AuthorizationIntegrationTest.java:
##########
@@ -95,12 +107,14 @@ public class AuthorizationIntegrationTest extends AbstractSecurityTest {
/** {@inheritDoc} */
@Override protected TestSecurityData[] securityData() {
return new TestSecurityData[] {
- new TestSecurityData(LOGIN, PWD, clientPermissions, null)
+ new TestSecurityData(LOGIN, PWD, clientPermissions(), null)
};
}
- /** {@inheritDoc} */
- @Override protected void beforeTestsStarted() throws Exception {
+ /** */
Review Comment:
Let's keep '{@inheritDoc} '
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "alex-plekhanov (via GitHub)" <gi...@apache.org>.
alex-plekhanov commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1744209585
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/ViewsIntegrationTest.java:
##########
@@ -0,0 +1,432 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.integration;
+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.calcite.CalciteQueryEngineConfiguration;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.SqlConfiguration;
+import org.apache.ignite.indexing.IndexingQueryEngineConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.util.typedef.G;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/** */
+@RunWith(Parameterized.class)
+public class ViewsIntegrationTest extends AbstractBasicIntegrationTest {
+ /** */
+ private boolean persistenceEnabled;
+
+ /** */
+ private String[] predefinedSchemas;
+
+ /** */
+ @Parameterized.Parameter
+ public String engine;
+
+ /** */
+ @Parameterized.Parameters(name = "Query engine={0}")
+ public static Iterable<Object> params() {
+ return Arrays.asList(CalciteQueryEngineConfiguration.ENGINE_NAME, IndexingQueryEngineConfiguration.ENGINE_NAME);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ return super.getConfiguration(igniteInstanceName)
+ .setSqlConfiguration(new SqlConfiguration()
+ .setSqlSchemas(predefinedSchemas)
+ .setQueryEnginesConfiguration(engine.equals(CalciteQueryEngineConfiguration.ENGINE_NAME) ?
+ new CalciteQueryEngineConfiguration() : new IndexingQueryEngineConfiguration()))
+ .setDataStorageConfiguration(new DataStorageConfiguration()
+ .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+ .setPersistenceEnabled(persistenceEnabled)));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ stopAllGrids();
+
+ cleanPersistenceDir();
+ }
+
+ /**
+ * Creates and drops view.
+ */
+ @Test
+ public void testCreateDrop() throws Exception {
+ initGrids(3);
+ initTable(3);
+
+ sql("create or replace view my_view as select * from my_table");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+
+ assertRowsCount(3, "select * from my_view");
+ assertRowsCount(3, "select t.id, val_int, * from my_view t");
+
+ sql("drop view my_view");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 0);
+ }
+
+ /**
+ * Tests views on different schemas.
+ */
+ @Test
+ public void testDifferentSchemas() throws Exception {
+ initGrids(3);
+ initTable(5);
+
+ IgniteCache<?, ?> cache1 = client.getOrCreateCache(new CacheConfiguration<>("CACHE1")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ IgniteCache<?, ?> cache2 = client.getOrCreateCache(new CacheConfiguration<>("CACHE2")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ IgniteCache<?, ?> cache3 = client.getOrCreateCache(new CacheConfiguration<>("CACHE3")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+ IgniteCache<?, ?> cache4 = client.getOrCreateCache(new CacheConfiguration<>("CACHE4")
+ .setIndexedTypes(Integer.class, String.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+
+ sql("create or replace view my_view as select * from my_table");
+ sql("create or replace view cache1.my_view as select * from public.my_table where id < 4");
+ sql("create or replace view cache2.my_view as select * from cache1.my_view where id < 3");
+ sql("create or replace view my_schema.my_view1 as select * from public.my_table where id < 2");
+ sql("create or replace view my_schema.my_view2 as select * from my_view1 where id < 1");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 1);
+ assertViewsCount("CACHE2", "MY_VIEW", 1);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW1", 1);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW2", 1);
+
+ assertRowsCount(5, "select * from my_view");
+ assertRowsCount(4, "select * from cache1.my_view");
+ assertRowsCount(3, "select * from cache2.my_view");
+ assertRowsCount(2, "select * from my_schema.my_view1");
+ assertRowsCount(1, "select * from my_schema.my_view2");
+
+ // PUBLIC.MY_VIEW
+ assertEquals(5, cache1.query(new SqlFieldsQuery("select * from public.my_view")).getAll().size());
+ assertEquals(5, cache1.query(new SqlFieldsQuery("select * from my_view").setSchema("PUBLIC")).getAll().size());
+ // CACHE1.MY_VIEW
+ assertEquals(4, cache1.query(new SqlFieldsQuery("select * from my_view")).getAll().size());
+ assertEquals(4, cache2.query(new SqlFieldsQuery("select * from cache1.my_view")).getAll().size());
+ // CACHE2.MY_VIEW
+ assertEquals(3, cache2.query(new SqlFieldsQuery("select * from my_view")).getAll().size());
+ assertEquals(3, cache1.query(new SqlFieldsQuery("select * from my_view").setSchema("CACHE2")).getAll().size());
+ // MY_SCHEMA.MY_VIEW1
+ assertEquals(2, cache3.query(new SqlFieldsQuery("select * from my_view1")).getAll().size());
+ assertEquals(2, cache4.query(new SqlFieldsQuery("select * from my_view1")).getAll().size());
+ // MY_SCHEMA.MY_VIEW2
+ assertEquals(1, cache3.query(new SqlFieldsQuery("select * from my_view2")).getAll().size());
+ assertEquals(1, cache4.query(new SqlFieldsQuery("select * from my_view2")).getAll().size());
+ }
+
+ /**
+ * Tests views drop on schema drop.
+ */
+ @Test
+ public void testSchemaCleaning() throws Exception {
+ initGrids(3);
+ initTable(5);
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE1")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE2")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("PUBLIC")
+ );
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE3")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE4")
+ .setIndexedTypes(Integer.class, String.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+
+ sql("create or replace view my_view as select * from my_table");
+ sql("create or replace view cache1.my_view as select * from public.my_table");
+ sql("create or replace view my_schema.my_view as select * from public.my_table");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 1);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 1);
+
+ client.destroyCache("CACHE1");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 0);
Review Comment:
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.
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/ViewsIntegrationTest.java:
##########
@@ -0,0 +1,432 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.integration;
+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.calcite.CalciteQueryEngineConfiguration;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.SqlConfiguration;
+import org.apache.ignite.indexing.IndexingQueryEngineConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.util.typedef.G;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/** */
+@RunWith(Parameterized.class)
+public class ViewsIntegrationTest extends AbstractBasicIntegrationTest {
+ /** */
+ private boolean persistenceEnabled;
+
+ /** */
+ private String[] predefinedSchemas;
+
+ /** */
+ @Parameterized.Parameter
+ public String engine;
+
+ /** */
+ @Parameterized.Parameters(name = "Query engine={0}")
+ public static Iterable<Object> params() {
+ return Arrays.asList(CalciteQueryEngineConfiguration.ENGINE_NAME, IndexingQueryEngineConfiguration.ENGINE_NAME);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ return super.getConfiguration(igniteInstanceName)
+ .setSqlConfiguration(new SqlConfiguration()
+ .setSqlSchemas(predefinedSchemas)
+ .setQueryEnginesConfiguration(engine.equals(CalciteQueryEngineConfiguration.ENGINE_NAME) ?
+ new CalciteQueryEngineConfiguration() : new IndexingQueryEngineConfiguration()))
+ .setDataStorageConfiguration(new DataStorageConfiguration()
+ .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+ .setPersistenceEnabled(persistenceEnabled)));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ stopAllGrids();
+
+ cleanPersistenceDir();
+ }
+
+ /**
+ * Creates and drops view.
+ */
+ @Test
+ public void testCreateDrop() throws Exception {
+ initGrids(3);
+ initTable(3);
+
+ sql("create or replace view my_view as select * from my_table");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+
+ assertRowsCount(3, "select * from my_view");
+ assertRowsCount(3, "select t.id, val_int, * from my_view t");
+
+ sql("drop view my_view");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 0);
+ }
+
+ /**
+ * Tests views on different schemas.
+ */
+ @Test
+ public void testDifferentSchemas() throws Exception {
+ initGrids(3);
+ initTable(5);
+
+ IgniteCache<?, ?> cache1 = client.getOrCreateCache(new CacheConfiguration<>("CACHE1")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ IgniteCache<?, ?> cache2 = client.getOrCreateCache(new CacheConfiguration<>("CACHE2")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ IgniteCache<?, ?> cache3 = client.getOrCreateCache(new CacheConfiguration<>("CACHE3")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+ IgniteCache<?, ?> cache4 = client.getOrCreateCache(new CacheConfiguration<>("CACHE4")
+ .setIndexedTypes(Integer.class, String.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+
+ sql("create or replace view my_view as select * from my_table");
+ sql("create or replace view cache1.my_view as select * from public.my_table where id < 4");
+ sql("create or replace view cache2.my_view as select * from cache1.my_view where id < 3");
+ sql("create or replace view my_schema.my_view1 as select * from public.my_table where id < 2");
+ sql("create or replace view my_schema.my_view2 as select * from my_view1 where id < 1");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 1);
+ assertViewsCount("CACHE2", "MY_VIEW", 1);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW1", 1);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW2", 1);
+
+ assertRowsCount(5, "select * from my_view");
+ assertRowsCount(4, "select * from cache1.my_view");
+ assertRowsCount(3, "select * from cache2.my_view");
+ assertRowsCount(2, "select * from my_schema.my_view1");
+ assertRowsCount(1, "select * from my_schema.my_view2");
+
+ // PUBLIC.MY_VIEW
+ assertEquals(5, cache1.query(new SqlFieldsQuery("select * from public.my_view")).getAll().size());
+ assertEquals(5, cache1.query(new SqlFieldsQuery("select * from my_view").setSchema("PUBLIC")).getAll().size());
+ // CACHE1.MY_VIEW
+ assertEquals(4, cache1.query(new SqlFieldsQuery("select * from my_view")).getAll().size());
+ assertEquals(4, cache2.query(new SqlFieldsQuery("select * from cache1.my_view")).getAll().size());
+ // CACHE2.MY_VIEW
+ assertEquals(3, cache2.query(new SqlFieldsQuery("select * from my_view")).getAll().size());
+ assertEquals(3, cache1.query(new SqlFieldsQuery("select * from my_view").setSchema("CACHE2")).getAll().size());
+ // MY_SCHEMA.MY_VIEW1
+ assertEquals(2, cache3.query(new SqlFieldsQuery("select * from my_view1")).getAll().size());
+ assertEquals(2, cache4.query(new SqlFieldsQuery("select * from my_view1")).getAll().size());
+ // MY_SCHEMA.MY_VIEW2
+ assertEquals(1, cache3.query(new SqlFieldsQuery("select * from my_view2")).getAll().size());
+ assertEquals(1, cache4.query(new SqlFieldsQuery("select * from my_view2")).getAll().size());
+ }
+
+ /**
+ * Tests views drop on schema drop.
+ */
+ @Test
+ public void testSchemaCleaning() throws Exception {
+ initGrids(3);
+ initTable(5);
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE1")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE2")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("PUBLIC")
+ );
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE3")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE4")
+ .setIndexedTypes(Integer.class, String.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+
+ sql("create or replace view my_view as select * from my_table");
+ sql("create or replace view cache1.my_view as select * from public.my_table");
+ sql("create or replace view my_schema.my_view as select * from public.my_table");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 1);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 1);
+
+ client.destroyCache("CACHE1");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 0);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 1);
+
+ client.destroyCache("CACHE2");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 0);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 1);
+
+ client.destroyCache("CACHE3");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 0);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 1);
+
+ client.destroyCache("CACHE4");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 0);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 0);
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE1")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE3")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 0);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 0);
+ }
+
+ /**
+ * Tests views on not existing schema.
+ */
+ @Test
+ public void testNotExistingSchema() throws Exception {
+ initGrids(3);
+ initTable(3);
+
+ assertThrows("CREATE VIEW my_schema.my_view AS SELECT * FROM public.my_table", IgniteSQLException.class,
Review Comment:
There are different messages for calcite and H2 engines, so only common part is checked here
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/ViewsIntegrationTest.java:
##########
@@ -0,0 +1,432 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.integration;
+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.calcite.CalciteQueryEngineConfiguration;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.SqlConfiguration;
+import org.apache.ignite.indexing.IndexingQueryEngineConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.util.typedef.G;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/** */
+@RunWith(Parameterized.class)
+public class ViewsIntegrationTest extends AbstractBasicIntegrationTest {
+ /** */
+ private boolean persistenceEnabled;
+
+ /** */
+ private String[] predefinedSchemas;
+
+ /** */
+ @Parameterized.Parameter
+ public String engine;
+
+ /** */
+ @Parameterized.Parameters(name = "Query engine={0}")
+ public static Iterable<Object> params() {
+ return Arrays.asList(CalciteQueryEngineConfiguration.ENGINE_NAME, IndexingQueryEngineConfiguration.ENGINE_NAME);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ return super.getConfiguration(igniteInstanceName)
+ .setSqlConfiguration(new SqlConfiguration()
+ .setSqlSchemas(predefinedSchemas)
+ .setQueryEnginesConfiguration(engine.equals(CalciteQueryEngineConfiguration.ENGINE_NAME) ?
+ new CalciteQueryEngineConfiguration() : new IndexingQueryEngineConfiguration()))
+ .setDataStorageConfiguration(new DataStorageConfiguration()
+ .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+ .setPersistenceEnabled(persistenceEnabled)));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ stopAllGrids();
+
+ cleanPersistenceDir();
+ }
+
+ /**
+ * Creates and drops view.
+ */
+ @Test
+ public void testCreateDrop() throws Exception {
+ initGrids(3);
+ initTable(3);
+
+ sql("create or replace view my_view as select * from my_table");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+
+ assertRowsCount(3, "select * from my_view");
+ assertRowsCount(3, "select t.id, val_int, * from my_view t");
+
+ sql("drop view my_view");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 0);
+ }
+
+ /**
+ * Tests views on different schemas.
+ */
+ @Test
+ public void testDifferentSchemas() throws Exception {
+ initGrids(3);
+ initTable(5);
+
+ IgniteCache<?, ?> cache1 = client.getOrCreateCache(new CacheConfiguration<>("CACHE1")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ IgniteCache<?, ?> cache2 = client.getOrCreateCache(new CacheConfiguration<>("CACHE2")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ IgniteCache<?, ?> cache3 = client.getOrCreateCache(new CacheConfiguration<>("CACHE3")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+ IgniteCache<?, ?> cache4 = client.getOrCreateCache(new CacheConfiguration<>("CACHE4")
+ .setIndexedTypes(Integer.class, String.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+
+ sql("create or replace view my_view as select * from my_table");
+ sql("create or replace view cache1.my_view as select * from public.my_table where id < 4");
+ sql("create or replace view cache2.my_view as select * from cache1.my_view where id < 3");
+ sql("create or replace view my_schema.my_view1 as select * from public.my_table where id < 2");
+ sql("create or replace view my_schema.my_view2 as select * from my_view1 where id < 1");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 1);
+ assertViewsCount("CACHE2", "MY_VIEW", 1);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW1", 1);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW2", 1);
+
+ assertRowsCount(5, "select * from my_view");
+ assertRowsCount(4, "select * from cache1.my_view");
+ assertRowsCount(3, "select * from cache2.my_view");
+ assertRowsCount(2, "select * from my_schema.my_view1");
+ assertRowsCount(1, "select * from my_schema.my_view2");
+
+ // PUBLIC.MY_VIEW
+ assertEquals(5, cache1.query(new SqlFieldsQuery("select * from public.my_view")).getAll().size());
+ assertEquals(5, cache1.query(new SqlFieldsQuery("select * from my_view").setSchema("PUBLIC")).getAll().size());
+ // CACHE1.MY_VIEW
+ assertEquals(4, cache1.query(new SqlFieldsQuery("select * from my_view")).getAll().size());
+ assertEquals(4, cache2.query(new SqlFieldsQuery("select * from cache1.my_view")).getAll().size());
+ // CACHE2.MY_VIEW
+ assertEquals(3, cache2.query(new SqlFieldsQuery("select * from my_view")).getAll().size());
+ assertEquals(3, cache1.query(new SqlFieldsQuery("select * from my_view").setSchema("CACHE2")).getAll().size());
+ // MY_SCHEMA.MY_VIEW1
+ assertEquals(2, cache3.query(new SqlFieldsQuery("select * from my_view1")).getAll().size());
+ assertEquals(2, cache4.query(new SqlFieldsQuery("select * from my_view1")).getAll().size());
+ // MY_SCHEMA.MY_VIEW2
+ assertEquals(1, cache3.query(new SqlFieldsQuery("select * from my_view2")).getAll().size());
+ assertEquals(1, cache4.query(new SqlFieldsQuery("select * from my_view2")).getAll().size());
+ }
+
+ /**
+ * Tests views drop on schema drop.
+ */
+ @Test
+ public void testSchemaCleaning() throws Exception {
+ initGrids(3);
+ initTable(5);
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE1")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE2")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("PUBLIC")
+ );
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE3")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE4")
+ .setIndexedTypes(Integer.class, String.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+
+ sql("create or replace view my_view as select * from my_table");
+ sql("create or replace view cache1.my_view as select * from public.my_table");
+ sql("create or replace view my_schema.my_view as select * from public.my_table");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 1);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 1);
+
+ client.destroyCache("CACHE1");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 0);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 1);
+
+ client.destroyCache("CACHE2");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 0);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 1);
+
+ client.destroyCache("CACHE3");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 0);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 1);
+
+ client.destroyCache("CACHE4");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 0);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 0);
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE1")
+ .setIndexedTypes(Integer.class, Integer.class));
+
+ client.getOrCreateCache(new CacheConfiguration<>("CACHE3")
+ .setIndexedTypes(Integer.class, Integer.class)
+ .setSqlSchema("MY_SCHEMA")
+ );
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ assertViewsCount("CACHE1", "MY_VIEW", 0);
+ assertViewsCount("MY_SCHEMA", "MY_VIEW", 0);
+ }
+
+ /**
+ * Tests views on not existing schema.
+ */
+ @Test
+ public void testNotExistingSchema() throws Exception {
+ initGrids(3);
+ initTable(3);
+
+ assertThrows("CREATE VIEW my_schema.my_view AS SELECT * FROM public.my_table", IgniteSQLException.class,
+ "MY_SCHEMA");
+ }
+
+ /**
+ * Tests view after in-memory grid restart.
+ */
+ @Test
+ public void testInMemory() throws Exception {
+ initGrids(3);
+ initTable(3);
+
+ sql("create or replace view my_view as select * from my_table");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+
+ stopAllGrids();
+
+ initGrids(3);
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 0);
+ }
+
+ /**
+ * Tests view after persistent grid restart.
+ */
+ @Test
+ public void testPersistance() throws Exception {
+ persistenceEnabled = true;
+
+ initGrids(3);
+ initTable(3);
+
+ sql("create or replace view my_view as select * from my_table");
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+
+ stopAllGrids();
+
+ initGrids(3);
+
+ assertViewsCount("PUBLIC", "MY_VIEW", 1);
+ }
+
+ /**
+ * Tests views information distribution on node join.
+ */
+ @Test
+ public void testNodeJoin() throws Exception {
Review Comment:
Distributed metastorage is stored on non-baseline nodes too (AFAIK)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1734941028
##########
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/ViewsIntegrationTest.java:
##########
@@ -0,0 +1,432 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ignite.internal.processors.query.calcite.integration;
+
+import java.util.Arrays;
+import java.util.List;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.calcite.CalciteQueryEngineConfiguration;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.SqlConfiguration;
+import org.apache.ignite.indexing.IndexingQueryEngineConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.util.typedef.G;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/** */
+@RunWith(Parameterized.class)
+public class ViewsIntegrationTest extends AbstractBasicIntegrationTest {
+ /** */
+ private boolean persistenceEnabled;
+
+ /** */
+ private String[] predefinedSchemas;
+
+ /** */
+ @Parameterized.Parameter
+ public String engine;
+
+ /** */
+ @Parameterized.Parameters(name = "Query engine={0}")
+ public static Iterable<Object> params() {
+ return Arrays.asList(CalciteQueryEngineConfiguration.ENGINE_NAME, IndexingQueryEngineConfiguration.ENGINE_NAME);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ return super.getConfiguration(igniteInstanceName)
+ .setSqlConfiguration(new SqlConfiguration()
+ .setSqlSchemas(predefinedSchemas)
+ .setQueryEnginesConfiguration(engine.equals(CalciteQueryEngineConfiguration.ENGINE_NAME) ?
+ new CalciteQueryEngineConfiguration() : new IndexingQueryEngineConfiguration()))
+ .setDataStorageConfiguration(new DataStorageConfiguration()
+ .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+ .setPersistenceEnabled(persistenceEnabled)));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ // No-op.
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ super.afterTest();
+
+ stopAllGrids();
+
+ cleanPersistenceDir();
+ }
+
+ /**
+ * Creates and drops view.
Review Comment:
Let's use common 'Tests' or 'Tests that'
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1717135381
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/management/SchemaManager.java:
##########
@@ -413,13 +416,13 @@ private static void validateTypeDescriptor(GridQueryTypeDescriptor type) throws
}
/**
- * Handle cache destroy.
+ * Handle cache stop.
*
* @param cacheName Cache name.
- * @param rmvIdx Whether to remove indexes.
+ * @param destroy Destroy cache.
* @param clearIdx Whether to clear the index.
*/
- public void onCacheDestroyed(String cacheName, boolean rmvIdx, boolean clearIdx) {
+ public void onCacheStopped(String cacheName, boolean destroy, boolean clearIdx) {
Review Comment:
If we do an additional related refactoring ticket, this and similar renamings might be moved there too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1716857760
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/task/GridTaskProcessor.java:
##########
@@ -200,6 +200,8 @@ public GridTaskProcessor(GridKernalContext ctx) {
ctx.io().addMessageListener(TOPIC_TASK_CANCEL, new TaskCancelMessageListener());
ctx.io().addMessageListener(TOPIC_TASK, new JobMessageListener(true));
+ ctx.internalSubscriptionProcessor().registerGlobalStateListener(this);
Review Comment:
Why changed? Can we move it into another ticket?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-22717 SQL Calcite: User defined SQL views [ignite]
Posted by "Vladsz83 (via GitHub)" <gi...@apache.org>.
Vladsz83 commented on code in PR #11467:
URL: https://github.com/apache/ignite/pull/11467#discussion_r1717182826
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/management/SchemaManager.java:
##########
@@ -451,6 +454,9 @@ public void onCacheDestroyed(String cacheName, boolean rmvIdx, boolean clearIdx)
if (schema.decrementUsageCount()) {
schemas.remove(schemaName);
+ if (destroy)
Review Comment:
We just removed local schema and called `onSchemaDropped()`. Why do we keep cluster schema if cache was only stopped? Looks wierd.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org