clintropolis commented on a change in pull request #6974: sql support for dynamic parameters URL: https://github.com/apache/druid/pull/6974#discussion_r380424679
########## File path: sql/src/test/java/org/apache/druid/sql/calcite/CalciteParameterQueryTest.java ########## @@ -0,0 +1,616 @@ +/* + * 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.druid.sql.calcite; + +import com.google.common.collect.ImmutableList; +import org.apache.calcite.avatica.SqlType; +import org.apache.druid.common.config.NullHandling; +import org.apache.druid.java.util.common.DateTimes; +import org.apache.druid.java.util.common.Intervals; +import org.apache.druid.java.util.common.granularity.Granularities; +import org.apache.druid.query.Druids; +import org.apache.druid.query.aggregation.CountAggregatorFactory; +import org.apache.druid.query.aggregation.DoubleSumAggregatorFactory; +import org.apache.druid.query.aggregation.FilteredAggregatorFactory; +import org.apache.druid.query.dimension.DefaultDimensionSpec; +import org.apache.druid.query.groupby.GroupByQuery; +import org.apache.druid.query.ordering.StringComparators; +import org.apache.druid.query.scan.ScanQuery; +import org.apache.druid.segment.column.ValueType; +import org.apache.druid.sql.calcite.filtration.Filtration; +import org.apache.druid.sql.calcite.util.CalciteTests; +import org.apache.druid.sql.http.SqlParameter; +import org.junit.Test; + +/** + * This class has copied a subset of the tests in {@link CalciteQueryTest} and replaced various parts of queries with + * dynamic parameters. It is NOT important that this file remains in sync with {@link CalciteQueryTest}, the tests + * were merely chosen to produce a selection of parameter types and positions within query expressions and have been + * renamed to reflect this + */ +public class CalciteParameterQueryTest extends BaseCalciteQueryTest +{ + private final boolean useDefault = NullHandling.replaceWithDefault(); Review comment: Hmm, thanks for asking as the current implementation wasn't accepting null valued parameters because a year ago when I made this branch we didn't really publicly acknowledge that null could exist, and it had a precondition check that value was not in fact null. I've adjusted this to accept null parameters. However, since there is no null equivalence in sql, it doesn't really seem to be all that useful, and in all cases I could think of you need a different expression to be able to explicitly use a null parameter, making using a parameter to pass null basically pointless afaict unless I'm missing some obvious case. Additionally, calcite seems to fail to parse stuff like: ``` SELECT COUNT(*) FROM table WHERE column IS ?``` producing an error of the form: ```org.apache.calcite.sql.parser.SqlParseException: Encountered "IS ?" at line 3, column 10.1``` I did add a couple of contrived examples, one using coalesce that optimizes out the parameter if it is null since coalesce returns first non-null, and a bloom filter test which is optimized out because it ends up being a constant, just to test the path of a null parameter getting fed into things. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
