-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CALCITE-4882] Introduce new Lambda-based Metadata framework
- Introduce a Lambda-based RelMetadataQuery creator for AOT environments - Add new microbenchmark for metadata retrieval on a five-way-join - Fix incorrect results for disabled test JdbcTest.testJoinFiveWay() - Add support for multiple RelMetadataQuery test versions. - Update jmh-gradle-plugin version.
- Loading branch information
Showing
20 changed files
with
2,488 additions
and
331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
core/src/main/java/org/apache/calcite/rel/metadata/lambda/CachingLambdaProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* 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.calcite.rel.metadata.lambda; | ||
|
||
import org.apache.calcite.rel.RelNode; | ||
|
||
import com.google.common.cache.CacheBuilder; | ||
import com.google.common.cache.CacheLoader; | ||
import com.google.common.cache.LoadingCache; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
import javax.annotation.concurrent.ThreadSafe; | ||
|
||
/** | ||
* A LambdaProvider that maintains a cache for each RelNode class/Lambda class combination, | ||
* delegating to an underlying LambdaProvider to do actual work. | ||
*/ | ||
@ThreadSafe | ||
class CachingLambdaProvider implements LambdaProvider { | ||
|
||
private final LambdaProvider provider; | ||
private final LoadingCache<Class<? extends RelNode>, LoadingCache<Class, Object>> cache; | ||
|
||
CachingLambdaProvider(final LambdaProvider provider) { | ||
this.provider = provider; | ||
this.cache = CacheBuilder.newBuilder() | ||
.build(new CacheLoader<Class, LoadingCache<Class, Object>>() { | ||
@Override public LoadingCache<Class, Object> load(final Class relNodeClazz) | ||
throws Exception { | ||
return CacheBuilder.<Class, Object>newBuilder().build( | ||
new CacheLoader<Class, Object>() { | ||
@Override public Object load(final Class lambdaClazz) throws Exception { | ||
return provider.get((Class<? extends RelNode>) relNodeClazz, lambdaClazz); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
public <R extends RelNode, T extends MetadataLambda> List<T> get( | ||
Class<R> relNodeClazz, | ||
Class<T> lambdaClazz) throws ExecutionException { | ||
return (List<T>) cache.get(relNodeClazz).get(lambdaClazz); | ||
} | ||
|
||
} |
82 changes: 82 additions & 0 deletions
82
core/src/main/java/org/apache/calcite/rel/metadata/lambda/CanonicalizingIRMQ.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* 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.calcite.rel.metadata.lambda; | ||
|
||
import org.apache.calcite.plan.RelOptPredicateList; | ||
import org.apache.calcite.rel.RelDistribution; | ||
import org.apache.calcite.rel.RelDistributions; | ||
import org.apache.calcite.rel.RelNode; | ||
import org.apache.calcite.rel.metadata.RelMdUtil; | ||
import org.apache.calcite.rex.RexNode; | ||
import org.apache.calcite.sql.SqlExplainLevel; | ||
import org.apache.calcite.util.ImmutableBitSet; | ||
|
||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
import static org.apache.calcite.linq4j.Nullness.castNonNull; | ||
|
||
/** | ||
* Canonicalizes methods from null to other standard outputs. | ||
*/ | ||
class CanonicalizingIRMQ extends DelegatingIRMQ { | ||
CanonicalizingIRMQ(IRelMetadataQuery delegate) { | ||
super(delegate); | ||
} | ||
|
||
@Override public @Nullable RelDistribution distribution(final RelNode rel) { | ||
RelDistribution distribution = super.distribution(rel); | ||
if (distribution == null) { | ||
return RelDistributions.ANY; | ||
} | ||
return distribution; | ||
} | ||
|
||
public Double getRowCount(RelNode rel) { | ||
return RelMdUtil.validateResult(castNonNull(super.getRowCount(rel))); | ||
} | ||
|
||
public @Nullable Double getPopulationSize(RelNode rel, ImmutableBitSet groupKey) { | ||
return RelMdUtil.validateResult(super.getPopulationSize(rel, groupKey)); | ||
} | ||
|
||
public @Nullable Double getPercentageOriginalRows(RelNode rel) { | ||
Double result = super.getPercentageOriginalRows(rel); | ||
return RelMdUtil.validatePercentage(result); | ||
} | ||
|
||
public @Nullable Double getSelectivity(RelNode rel, @Nullable RexNode predicate) { | ||
return RelMdUtil.validatePercentage(super.getSelectivity(rel, predicate)); | ||
} | ||
|
||
public @Nullable Double getDistinctRowCount( | ||
RelNode rel, | ||
ImmutableBitSet groupKey, | ||
@Nullable RexNode predicate) { | ||
return RelMdUtil.validateResult(super.getDistinctRowCount(rel, groupKey, predicate)); | ||
} | ||
|
||
public RelOptPredicateList getPulledUpPredicates(RelNode rel) { | ||
RelOptPredicateList result = super.getPulledUpPredicates(rel); | ||
return result != null ? result : RelOptPredicateList.EMPTY; | ||
} | ||
|
||
public Boolean isVisibleInExplain(RelNode rel, | ||
SqlExplainLevel explainLevel) { | ||
Boolean b = super.isVisibleInExplain(rel, explainLevel); | ||
return b == null || b; | ||
} | ||
} |
Oops, something went wrong.