timoninmaxim commented on a change in pull request #8744: URL: https://github.com/apache/ignite/pull/8744#discussion_r663107316
########## File path: modules/indexing/src/test/java/org/apache/ignite/sqltests/CheckWarnJoinPartitionedTables.java ########## @@ -0,0 +1,408 @@ +/* + * 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.sqltests; + +import java.util.List; +import org.apache.ignite.Ignite; +import org.apache.ignite.cache.query.FieldsQueryCursor; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.testframework.ListeningTestLogger; +import org.apache.ignite.testframework.LogListener; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Test; + +/** Check that illegal joins of partitioned tables are warned. */ +public class CheckWarnJoinPartitionedTables extends GridCommonAbstractTest { + /** */ + private final ListeningTestLogger testLog = new ListeningTestLogger(log); + + /** */ + private Ignite crd; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + cfg.setGridLogger(testLog); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + crd = startGrid(); + } + + /** */ + @Test + public void joinSameTableWithPrimaryKey() { + execute(crd, new SqlFieldsQuery( + "CREATE TABLE A (ID INT PRIMARY KEY, TITLE VARCHAR);")); + + checkSameTableWithJoinType("LEFT JOIN"); + checkSameTableWithJoinType("RIGHT JOIN"); + checkSameTableWithJoinType("INNER JOIN"); + checkSameTableWithJoinType("JOIN"); + } + + /** */ + @Test + public void joinSameTableWithPrimaryAffinityKey() { + execute(crd, new SqlFieldsQuery( + "CREATE TABLE A (ID INT PRIMARY KEY, TITLE VARCHAR) with \"AFFINITY_KEY=ID\";")); + + checkSameTableWithJoinType("LEFT JOIN"); + checkSameTableWithJoinType("RIGHT JOIN"); + checkSameTableWithJoinType("INNER JOIN"); + checkSameTableWithJoinType("JOIN"); + } + + /** */ + private void checkSameTableWithJoinType(String joinType) { + checkLogListener(false, + "SELECT a1.* FROM A a1 " + joinType + " A a2 on a1.ID = a2.ID;"); + + checkLogListener(false, + "SELECT a1.* FROM A a1 " + joinType + " A a2 on a2.ID = a1.ID;"); + + checkLogListener(false, + "SELECT a1.* FROM A a1 " + joinType + " A a2 on a1.ID = a2._KEY;"); + + checkLogListener(false, + "SELECT a1.* FROM A a1 " + joinType + " A a2 on a1._KEY = a2.ID;"); + + checkLogListener(false, + "SELECT a1.* FROM A a1 " + joinType + " A a2 on a1._KEY = a2._KEY;"); + + checkLogListener(false, + "SELECT a1.* FROM A a1 " + joinType + " A a2 where a1.ID = a2.ID;"); + + checkLogListener(false, + "SELECT a1.* FROM A a1 " + joinType + " A a2 where a1.ID = a2._KEY;"); + + checkLogListener(false, + "SELECT a1.* FROM A a1 " + joinType + " A a2 on a1.ID = a2.ID AND a1.TITLE = a2.TITLE;"); + + checkLogListener(false, + "SELECT a1.* FROM A a1 " + joinType + " A a2 on a1.ID = a2.ID AND a1.TITLE != a2.TITLE;"); + + checkLogListener(false, + "SELECT a1.* FROM A a1 " + joinType + " A a2 on a1.ID = a2.ID AND (a1.TITLE = a2.TITLE OR a1.ID = a2.ID);"); + + checkLogListener(false, + "SELECT a1.* FROM A a1 " + joinType + " A a2 on (a1.TITLE = a2.TITLE OR a1.ID = a2.ID) AND a1.ID = a2.ID;"); + + checkLogListener(false, + "SELECT a1.* FROM A a1 " + joinType + " (select a2.ID from A a2) a3 on a1.ID = a3.ID;"); + + checkLogListener(false, + "SELECT a1.* FROM A a1 where a1.ID in (select a2.ID from A a2 " + joinType + " A a3 on a2.ID = a3.ID);"); + + checkLogListener(false, + "SELECT a1.* FROM A a1 " + joinType + " (select a2.ID from A a2 " + joinType + " A a3 on a2.ID = a3.ID) t" + + " on a1.ID = t.ID;"); + + // Ignite doesn't support this. + if (!joinType.contains("RIGHT")) Review comment: Yes, SQL engine write a message about unsupported clause. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
