-
Notifications
You must be signed in to change notification settings - Fork 986
DRILL-8190: Fix mongo project pushdown for queries with joins #2652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * 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.drill.exec.store.enumerable; | ||
|
|
||
| import com.fasterxml.jackson.databind.DeserializationConfig; | ||
| import com.fasterxml.jackson.databind.JavaType; | ||
| import com.fasterxml.jackson.databind.jsontype.NamedType; | ||
| import com.fasterxml.jackson.databind.jsontype.TypeDeserializer; | ||
| import com.fasterxml.jackson.databind.jsontype.impl.StdTypeResolverBuilder; | ||
| import org.reflections.Reflections; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class DynamicTypeResolverBuilder extends StdTypeResolverBuilder { | ||
|
|
||
| @Override | ||
| public TypeDeserializer buildTypeDeserializer(DeserializationConfig config, | ||
| JavaType baseType, Collection<NamedType> subtypes) { | ||
|
|
||
| Reflections reflections = new Reflections("org.apache.drill.exec.store"); | ||
| @SuppressWarnings("unchecked") | ||
| Class<Object> rawClass = (Class<Object>) baseType.getRawClass(); | ||
| List<NamedType> dynamicSubtypes = reflections.getSubTypesOf(rawClass).stream() | ||
| .map(NamedType::new) | ||
| .collect(Collectors.toList()); | ||
| dynamicSubtypes.addAll(subtypes); | ||
|
|
||
| return super.buildTypeDeserializer(config, baseType, dynamicSubtypes); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,15 +18,22 @@ | |
| package org.apache.drill.exec.store.enumerable.plan; | ||
|
|
||
| import org.apache.calcite.plan.RelOptCluster; | ||
| import org.apache.calcite.plan.RelOptCost; | ||
| import org.apache.calcite.plan.RelOptPlanner; | ||
| import org.apache.calcite.plan.RelTraitSet; | ||
| import org.apache.calcite.rel.RelNode; | ||
| import org.apache.calcite.rel.SingleRel; | ||
| import org.apache.calcite.rel.metadata.RelMetadataQuery; | ||
| import org.apache.drill.common.logical.data.LogicalOperator; | ||
| import org.apache.drill.exec.planner.logical.DrillImplementor; | ||
| import org.apache.drill.exec.planner.logical.DrillRel; | ||
| import org.apache.drill.exec.util.Utilities; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.apache.drill.exec.planner.logical.DrillScanRel.STAR_COLUMN_COST; | ||
|
|
||
| /** | ||
| * The vertex simply holds the child nodes but contains its own traits. | ||
| * Used for completing Drill logical planning when child nodes have some specific traits. | ||
|
|
@@ -51,4 +58,15 @@ protected Object clone() { | |
| public LogicalOperator implement(DrillImplementor implementor) { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| @Override | ||
| public @Nullable RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) { | ||
| double rowCount = estimateRowCount(mq); | ||
| double columnCount = Utilities.isStarQuery(getRowType()) ? STAR_COLUMN_COST : getRowType().getFieldCount(); | ||
| double valueCount = rowCount * columnCount; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was it only queries with a pushed down join that were affected by there being no cost saving for adding a plugin projection?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think more queries were affected, but probably it was simpler to reproduce it on queries with joins. |
||
| // columns count is considered during cost calculation to make preferable plans | ||
| // with pushed plugin project operators since in the opposite case planner wouldn't consider | ||
| // a plan with additional plugin projection that reduces columns as better than a plan without it | ||
| return planner.getCostFactory().makeCost(rowCount, valueCount, 0).multiplyBy(0.1); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,7 +51,7 @@ public Aggregate copy(RelTraitSet traitSet, RelNode input, ImmutableBitSet group | |
|
|
||
| @Override | ||
| public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) { | ||
| return super.computeSelfCost(planner, mq).multiplyBy(0.1); | ||
| return super.computeLogicalAggCost(planner, mq).multiplyBy(0.1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these Plugin*Rel RelNodes used when operations are pushed down to storage plugins?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, they represent part of the pushed-down query, so it is possible to find out the most optimal query for both Drill and actual storage where the query is pushed down. |
||
| } | ||
|
|
||
| @Override | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did this new serde builder become necessary because of the changes made in this PR for pushing down projections to Mongo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, fixes for Mongo (in the java-exec module) helped to find out that serde for enumerable plugins is broken, so fixed it here.