This is an automated email from the ASF dual-hosted git repository. agoncharuk pushed a commit to branch sql-calcite in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/sql-calcite by this push: new 2b26b33 IGNITE-13729 Fix type casts for aggregates causing 'Not a boolean expression' error - Fixes #8738. 2b26b33 is described below commit 2b26b335140533c35ddc0cf883ae265fae94b3b8 Author: korlov42 <kor...@gridgain.com> AuthorDate: Mon Feb 8 17:30:47 2021 +0300 IGNITE-13729 Fix type casts for aggregates causing 'Not a boolean expression' error - Fixes #8738. --- .../query/calcite/exec/exp/agg/Accumulators.java | 7 +- .../calcite/exec/exp/agg/AccumulatorsFactory.java | 3 +- .../query/calcite/AggregatesIntegrationTest.java | 130 +++++++++++++++++++++ .../query/calcite/CalciteQueryProcessorTest.java | 3 +- .../ignite/testsuites/IgniteCalciteTestSuite.java | 4 +- 5 files changed, 141 insertions(+), 6 deletions(-) diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/Accumulators.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/Accumulators.java index f458fee..afb0ea3 100644 --- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/Accumulators.java +++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/Accumulators.java @@ -281,7 +281,10 @@ public class Accumulators { /** {@inheritDoc} */ @Override public void add(Object... args) { - cnt++; + assert F.isEmpty(args) || args.length == 1; + + if (F.isEmpty(args) || args[0] != null) + cnt++; } /** {@inheritDoc} */ @@ -297,7 +300,7 @@ public class Accumulators { /** {@inheritDoc} */ @Override public List<RelDataType> argumentTypes(IgniteTypeFactory typeFactory) { - return F.asList(typeFactory.createTypeWithNullability(typeFactory.createSqlType(BIGINT), false)); + return F.asList(typeFactory.createTypeWithNullability(typeFactory.createSqlType(ANY), false)); } /** {@inheritDoc} */ diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/AccumulatorsFactory.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/AccumulatorsFactory.java index 09344e6..7cd8ece 100644 --- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/AccumulatorsFactory.java +++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/agg/AccumulatorsFactory.java @@ -29,6 +29,7 @@ import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableList; import com.google.common.primitives.Primitives; import org.apache.calcite.DataContext; +import org.apache.calcite.adapter.enumerable.EnumUtils; import org.apache.calcite.adapter.enumerable.JavaRowFormat; import org.apache.calcite.adapter.enumerable.PhysTypeImpl; import org.apache.calcite.adapter.enumerable.RexToLixTranslator; @@ -112,7 +113,7 @@ public class AccumulatorsFactory<Row> implements Supplier<List<AccumulatorWrappe RexToLixTranslator.InputGetter getter = new RexToLixTranslator.InputGetterImpl( ImmutableList.of( - Pair.of(in_, + Pair.of(EnumUtils.convert(in_, Object.class, typeFactory.getJavaClass(from)), PhysTypeImpl.of(typeFactory, rowType, JavaRowFormat.SCALAR, false)))); diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/AggregatesIntegrationTest.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/AggregatesIntegrationTest.java new file mode 100644 index 0000000..019d7f0 --- /dev/null +++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/AggregatesIntegrationTest.java @@ -0,0 +1,130 @@ +/* + * 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; + +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.QueryEntity; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.processors.query.QueryEngine; +import org.apache.ignite.internal.processors.query.calcite.util.Commons; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.G; +import org.apache.ignite.testframework.junits.WithSystemProperty; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Test; + +/** + * + */ +@WithSystemProperty(key = "calcite.debug", value = "false") +public class AggregatesIntegrationTest extends GridCommonAbstractTest { + /** */ + private static IgniteEx client; + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + startGrids(3); + + client = startClientGrid(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() { + for (Ignite ign : G.allGrids()) { + for (String cacheName : ign.cacheNames()) + ign.destroyCache(cacheName); + + CalciteQueryProcessor qryProc = (CalciteQueryProcessor)Commons.lookupComponent( + ((IgniteEx)ign).context(), QueryEngine.class); + + qryProc.queryPlanCache().clear(); + } + } + + /** */ + @Test + public void countOfNonNumericField() throws InterruptedException { + IgniteCache<Integer, Employer> person = client.getOrCreateCache(new CacheConfiguration<Integer, Employer>() + .setName("person") + .setSqlSchema("PUBLIC") + .setQueryEntities(F.asList(new QueryEntity(Integer.class, Employer.class).setTableName("person"))) + .setBackups(2) + ); + + int idx = 0; + person.put(idx++, new Employer("Igor", 10d)); + person.put(idx++, new Employer(null, 15d)); + person.put(idx++, new Employer("Ilya", 15d)); + person.put(idx++, new Employer("Roma", 10d)); + + assertQuery("select count(name) from person").returns(3L).check(); + assertQuery("select count(*) from person").returns(4L).check(); + assertQuery("select count(1) from person").returns(4L).check(); + + assertQuery("select count(case when name like 'R%' then 1 else null end) from person").returns(1L).check(); + assertQuery("select count(case when name not like 'I%' then 1 else null end) from person").returns(1L).check(); + + assertQuery("select count(name) from person where salary > 10").returns(1L).check(); + assertQuery("select count(*) from person where salary > 10").returns(2L).check(); + assertQuery("select count(1) from person where salary > 10").returns(2L).check(); + + assertQuery("select salary, count(name) from person group by salary order by salary") + .returns(10d, 2L) + .returns(15d, 1L) + .check(); + + assertQuery("select salary, count(*) from person group by salary order by salary") + .returns(10d, 2L) + .returns(15d, 2L) + .check(); + + assertQuery("select salary, count(1) from person group by salary order by salary") + .returns(10d, 2L) + .returns(15d, 2L) + .check(); + } + + /** */ + private QueryChecker assertQuery(String qry) { + return new QueryChecker(qry) { + @Override protected QueryEngine getEngine() { + return Commons.lookupComponent(client.context(), QueryEngine.class); + } + }; + } + + /** */ + public static class Employer { + /** */ + @QuerySqlField + public String name; + + /** */ + @QuerySqlField + public Double salary; + + /** */ + public Employer(String name, Double salary) { + this.name = name; + this.salary = salary; + } + } +} diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessorTest.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessorTest.java index a68d6e3..b92c4e0 100644 --- a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessorTest.java +++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/CalciteQueryProcessorTest.java @@ -472,12 +472,11 @@ public class CalciteQueryProcessorTest extends GridCommonAbstractTest { /** */ @Test - @Ignore("https://issues.apache.org/jira/browse/IGNITE-13729") public void testNotExistsConditionWithSubquery() throws Exception { populateTables(); List<List<?>> rows = sql( - "EXPLAIN PLAN FOR SELECT name FROM Orders o WHERE NOT EXISTS (" + + "SELECT name FROM Orders o WHERE NOT EXISTS (" + " SELECT 1" + " FROM Account a" + " WHERE o.name = a.name)"); diff --git a/modules/calcite/src/test/java/org/apache/ignite/testsuites/IgniteCalciteTestSuite.java b/modules/calcite/src/test/java/org/apache/ignite/testsuites/IgniteCalciteTestSuite.java index c5a9b63..0b83ac8 100644 --- a/modules/calcite/src/test/java/org/apache/ignite/testsuites/IgniteCalciteTestSuite.java +++ b/modules/calcite/src/test/java/org/apache/ignite/testsuites/IgniteCalciteTestSuite.java @@ -17,6 +17,7 @@ package org.apache.ignite.testsuites; +import org.apache.ignite.internal.processors.query.calcite.AggregatesIntegrationTest; import org.apache.ignite.internal.processors.query.calcite.CalciteBasicSecondaryIndexIntegrationTest; import org.apache.ignite.internal.processors.query.calcite.CalciteErrorHandlilngIntegrationTest; import org.apache.ignite.internal.processors.query.calcite.CalciteQueryProcessorTest; @@ -52,7 +53,8 @@ import org.junit.runners.Suite; QueryCheckerTest.class, DateTimeTest.class, LimitOffsetTest.class, - SqlFieldsQueryUsageTest.class + SqlFieldsQueryUsageTest.class, + AggregatesIntegrationTest.class }) public class IgniteCalciteTestSuite { }