github-advanced-security[bot] commented on code in PR #15626:
URL: https://github.com/apache/druid/pull/15626#discussion_r1442371868
##########
benchmarks/src/test/java/org/apache/druid/benchmark/query/SqlBenchmark.java:
##########
@@ -461,66 +479,112 @@
public void setup()
{
final GeneratorSchemaInfo schemaInfo =
GeneratorBasicSchemas.SCHEMA_MAP.get("basic");
-
- final DataSegment dataSegment = DataSegment.builder()
- .dataSource("foo")
-
.interval(schemaInfo.getDataInterval())
- .version("1")
- .shardSpec(new
LinearShardSpec(0))
- .size(0)
- .build();
-
- final PlannerConfig plannerConfig = new PlannerConfig();
-
+ final DataSegment dataSegment = schemaInfo.makeSegmentDescriptor("foo");
final SegmentGenerator segmentGenerator = closer.register(new
SegmentGenerator());
+
log.info("Starting benchmark setup using cacheDir[%s], rows[%,d].",
segmentGenerator.getCacheDir(), rowsPerSegment);
- StringEncodingStrategy encodingStrategy;
- if (stringEncoding.startsWith("front-coded")) {
- String[] split = stringEncoding.split("-");
- int bucketSize = Integer.parseInt(split[2]);
- encodingStrategy = new StringEncodingStrategy.FrontCoded(bucketSize,
FrontCodedIndexed.V1);
- } else {
- encodingStrategy = new StringEncodingStrategy.Utf8();
- }
+
final QueryableIndex index = segmentGenerator.generate(
dataSegment,
schemaInfo,
-
IndexSpec.builder().withStringDictionaryEncoding(encodingStrategy).build(),
+
IndexSpec.builder().withStringDictionaryEncoding(getStringEncodingStrategy()).build(),
Granularities.NONE,
rowsPerSegment
);
- final QueryRunnerFactoryConglomerate conglomerate =
QueryStackTests.createQueryRunnerFactoryConglomerate(closer);
+ final Pair<PlannerFactory, SqlEngine> sqlSystem = createSqlSystem(
+ ImmutableMap.of(dataSegment, index),
+ Collections.emptyMap(),
+ null,
+ closer
+ );
+
+ plannerFactory = sqlSystem.lhs;
+ engine = sqlSystem.rhs;
+ }
+
+ private StringEncodingStrategy getStringEncodingStrategy()
+ {
+ if (stringEncoding.startsWith("front-coded")) {
+ String[] split = stringEncoding.split("-");
+ int bucketSize = Integer.parseInt(split[2]);
Review Comment:
## Missing catch of NumberFormatException
Potential uncaught 'java.lang.NumberFormatException'.
[Show more
details](https://github.com/apache/druid/security/code-scanning/6410)
##########
sql/src/main/java/org/apache/druid/sql/calcite/rule/AggregatePullUpLookupRule.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.rule;
+
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.core.Aggregate;
+import org.apache.calcite.rel.core.Project;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.ImmutableBitSet;
+import org.apache.druid.query.lookup.LookupExtractor;
+import
org.apache.druid.sql.calcite.expression.builtin.QueryLookupOperatorConversion;
+import org.apache.druid.sql.calcite.planner.PlannerContext;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Rule that pulls {@link QueryLookupOperatorConversion#SQL_FUNCTION} up
through an {@link Aggregate}.
+ */
+public class AggregatePullUpLookupRule extends RelOptRule
+{
+ private final PlannerContext plannerContext;
+
+ public AggregatePullUpLookupRule(final PlannerContext plannerContext)
+ {
+ super(operand(Aggregate.class, operand(Project.class, any())));
Review Comment:
## Deprecated method or constructor invocation
Invoking [RelOptRule.operand](1) should be avoided because it has been
deprecated.
[Show more
details](https://github.com/apache/druid/security/code-scanning/6411)
##########
sql/src/main/java/org/apache/druid/sql/calcite/rule/ReverseLookupRule.java:
##########
@@ -0,0 +1,634 @@
+/*
+ * 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.rule;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.rel.core.Filter;
+import org.apache.calcite.rel.logical.LogicalFilter;
+import org.apache.calcite.rel.rules.SubstitutionRule;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexShuttle;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.type.SqlTypeFamily;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.druid.common.config.NullHandling;
+import org.apache.druid.java.util.common.ISE;
+import org.apache.druid.java.util.common.Pair;
+import org.apache.druid.query.QueryContext;
+import org.apache.druid.query.extraction.MapLookupExtractor;
+import org.apache.druid.query.filter.InDimFilter;
+import org.apache.druid.query.lookup.LookupExtractionFn;
+import org.apache.druid.query.lookup.LookupExtractor;
+import
org.apache.druid.sql.calcite.expression.builtin.MultiValueStringOperatorConversions;
+import
org.apache.druid.sql.calcite.expression.builtin.QueryLookupOperatorConversion;
+import
org.apache.druid.sql.calcite.expression.builtin.SearchOperatorConversion;
+import org.apache.druid.sql.calcite.filtration.CollectComparisons;
+import org.apache.druid.sql.calcite.planner.Calcites;
+import org.apache.druid.sql.calcite.planner.PlannerContext;
+import org.apache.druid.utils.CollectionUtils;
+
+import javax.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * Eliminates calls to {@link QueryLookupOperatorConversion#SQL_FUNCTION} by
doing reverse-lookups.
+ *
+ * Considers reversing {@link SqlStdOperatorTable#IS_NULL} and operators that
match
+ * {@link #isBinaryComparison(RexNode)}. However, reversal is not done in all
cases, such as when it would require
+ * embedding the entire lookup into the query, or when the number of keys
exceeds
+ * {@link QueryContext#getInSubQueryThreshold()}.
+ *
+ * The heart of the class, where the reversal actually happens, is
+ * {@link ReverseLookupShuttle.CollectReverseLookups#reverseLookup}. The rest
of the rule is mainly about grouping
+ * together as many LOOKUP calls as possible prior to attempting to reverse,
since reversing a lookup may require
+ * iteration of the lookup. We don't want to do that more often than necessary.
+ */
+public class ReverseLookupRule extends RelOptRule implements SubstitutionRule
+{
+ /**
+ * Context parameter for tests, to allow us to confirm that this rule
doesn't do too many calls to
+ * {@link InDimFilter#optimize}. This is important because certain lookup
implementations, most
+ * prominently {@link MapLookupExtractor}, do a full iteration of the map
for each call to
+ * {@link LookupExtractor#unapplyAll}, which may be called by {@link
InDimFilter#optimize}.
+ */
+ public static final String CTX_MAX_OPTIMIZE_COUNT =
"maxOptimizeCountForDruidReverseLookupRule";
+
+ /**
+ * Context parameter for tests, to allow us to force the case where we avoid
creating a bunch of ORs.
+ */
+ public static final String CTX_MAX_IN_SIZE =
"maxInSizeForDruidReverseLookupRule";
+
+ private final PlannerContext plannerContext;
+
+ public ReverseLookupRule(final PlannerContext plannerContext)
+ {
+ super(operand(LogicalFilter.class, any()));
Review Comment:
## Deprecated method or constructor invocation
Invoking [RelOptRule.operand](1) should be avoided because it has been
deprecated.
[Show more
details](https://github.com/apache/druid/security/code-scanning/6414)
##########
sql/src/main/java/org/apache/druid/sql/calcite/rule/ReverseLookupRule.java:
##########
@@ -0,0 +1,634 @@
+/*
+ * 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.rule;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.rel.core.Filter;
+import org.apache.calcite.rel.logical.LogicalFilter;
+import org.apache.calcite.rel.rules.SubstitutionRule;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexShuttle;
+import org.apache.calcite.rex.RexUtil;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.type.SqlTypeFamily;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.druid.common.config.NullHandling;
+import org.apache.druid.java.util.common.ISE;
+import org.apache.druid.java.util.common.Pair;
+import org.apache.druid.query.QueryContext;
+import org.apache.druid.query.extraction.MapLookupExtractor;
+import org.apache.druid.query.filter.InDimFilter;
+import org.apache.druid.query.lookup.LookupExtractionFn;
+import org.apache.druid.query.lookup.LookupExtractor;
+import
org.apache.druid.sql.calcite.expression.builtin.MultiValueStringOperatorConversions;
+import
org.apache.druid.sql.calcite.expression.builtin.QueryLookupOperatorConversion;
+import
org.apache.druid.sql.calcite.expression.builtin.SearchOperatorConversion;
+import org.apache.druid.sql.calcite.filtration.CollectComparisons;
+import org.apache.druid.sql.calcite.planner.Calcites;
+import org.apache.druid.sql.calcite.planner.PlannerContext;
+import org.apache.druid.utils.CollectionUtils;
+
+import javax.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * Eliminates calls to {@link QueryLookupOperatorConversion#SQL_FUNCTION} by
doing reverse-lookups.
+ *
+ * Considers reversing {@link SqlStdOperatorTable#IS_NULL} and operators that
match
+ * {@link #isBinaryComparison(RexNode)}. However, reversal is not done in all
cases, such as when it would require
+ * embedding the entire lookup into the query, or when the number of keys
exceeds
+ * {@link QueryContext#getInSubQueryThreshold()}.
+ *
+ * The heart of the class, where the reversal actually happens, is
+ * {@link ReverseLookupShuttle.CollectReverseLookups#reverseLookup}. The rest
of the rule is mainly about grouping
+ * together as many LOOKUP calls as possible prior to attempting to reverse,
since reversing a lookup may require
+ * iteration of the lookup. We don't want to do that more often than necessary.
+ */
+public class ReverseLookupRule extends RelOptRule implements SubstitutionRule
+{
+ /**
+ * Context parameter for tests, to allow us to confirm that this rule
doesn't do too many calls to
+ * {@link InDimFilter#optimize}. This is important because certain lookup
implementations, most
+ * prominently {@link MapLookupExtractor}, do a full iteration of the map
for each call to
+ * {@link LookupExtractor#unapplyAll}, which may be called by {@link
InDimFilter#optimize}.
+ */
+ public static final String CTX_MAX_OPTIMIZE_COUNT =
"maxOptimizeCountForDruidReverseLookupRule";
+
+ /**
+ * Context parameter for tests, to allow us to force the case where we avoid
creating a bunch of ORs.
+ */
+ public static final String CTX_MAX_IN_SIZE =
"maxInSizeForDruidReverseLookupRule";
+
+ private final PlannerContext plannerContext;
+
+ public ReverseLookupRule(final PlannerContext plannerContext)
+ {
+ super(operand(LogicalFilter.class, any()));
Review Comment:
## Deprecated method or constructor invocation
Invoking [RelOptRule.any](1) should be avoided because it has been
deprecated.
[Show more
details](https://github.com/apache/druid/security/code-scanning/6415)
##########
sql/src/main/java/org/apache/druid/sql/calcite/rule/AggregatePullUpLookupRule.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.rule;
+
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.core.Aggregate;
+import org.apache.calcite.rel.core.Project;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.ImmutableBitSet;
+import org.apache.druid.query.lookup.LookupExtractor;
+import
org.apache.druid.sql.calcite.expression.builtin.QueryLookupOperatorConversion;
+import org.apache.druid.sql.calcite.planner.PlannerContext;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Rule that pulls {@link QueryLookupOperatorConversion#SQL_FUNCTION} up
through an {@link Aggregate}.
+ */
+public class AggregatePullUpLookupRule extends RelOptRule
+{
+ private final PlannerContext plannerContext;
+
+ public AggregatePullUpLookupRule(final PlannerContext plannerContext)
+ {
+ super(operand(Aggregate.class, operand(Project.class, any())));
Review Comment:
## Deprecated method or constructor invocation
Invoking [RelOptRule.operand](1) should be avoided because it has been
deprecated.
[Show more
details](https://github.com/apache/druid/security/code-scanning/6412)
##########
sql/src/main/java/org/apache/druid/sql/calcite/rule/AggregatePullUpLookupRule.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.rule;
+
+import org.apache.calcite.plan.RelOptRule;
+import org.apache.calcite.plan.RelOptRuleCall;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.core.Aggregate;
+import org.apache.calcite.rel.core.Project;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexCall;
+import org.apache.calcite.rex.RexLiteral;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.ImmutableBitSet;
+import org.apache.druid.query.lookup.LookupExtractor;
+import
org.apache.druid.sql.calcite.expression.builtin.QueryLookupOperatorConversion;
+import org.apache.druid.sql.calcite.planner.PlannerContext;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Rule that pulls {@link QueryLookupOperatorConversion#SQL_FUNCTION} up
through an {@link Aggregate}.
+ */
+public class AggregatePullUpLookupRule extends RelOptRule
+{
+ private final PlannerContext plannerContext;
+
+ public AggregatePullUpLookupRule(final PlannerContext plannerContext)
+ {
+ super(operand(Aggregate.class, operand(Project.class, any())));
Review Comment:
## Deprecated method or constructor invocation
Invoking [RelOptRule.any](1) should be avoided because it has been
deprecated.
[Show more
details](https://github.com/apache/druid/security/code-scanning/6413)
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]