-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Distinct Count Pushdown in Pinot
- Loading branch information
1 parent
a1feed2
commit 8723d41
Showing
7 changed files
with
249 additions
and
6 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
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
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
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
...o-pinot/src/main/java/io/trino/plugin/pinot/query/aggregation/ImplementCountDistinct.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 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 io.trino.plugin.pinot.query.aggregation; | ||
|
||
import io.trino.matching.Capture; | ||
import io.trino.matching.Captures; | ||
import io.trino.matching.Pattern; | ||
import io.trino.plugin.base.expression.AggregateFunctionRule; | ||
import io.trino.plugin.pinot.PinotColumnHandle; | ||
import io.trino.spi.connector.AggregateFunction; | ||
import io.trino.spi.expression.Variable; | ||
|
||
import java.util.Optional; | ||
|
||
import static com.google.common.base.Verify.verify; | ||
import static io.trino.matching.Capture.newCapture; | ||
import static io.trino.plugin.base.expression.AggregateFunctionPatterns.basicAggregation; | ||
import static io.trino.plugin.base.expression.AggregateFunctionPatterns.functionName; | ||
import static io.trino.plugin.base.expression.AggregateFunctionPatterns.outputType; | ||
import static io.trino.plugin.base.expression.AggregateFunctionPatterns.singleInput; | ||
import static io.trino.plugin.base.expression.AggregateFunctionPatterns.variable; | ||
import static io.trino.plugin.pinot.PinotSessionProperties.isCountDistinctPushdownEnabled; | ||
import static io.trino.spi.type.BigintType.BIGINT; | ||
import static java.lang.String.format; | ||
|
||
public class ImplementCountDistinct | ||
implements AggregateFunctionRule | ||
{ | ||
private static final Capture<Variable> INPUT = newCapture(); | ||
|
||
@Override | ||
public Pattern<AggregateFunction> getPattern() | ||
{ | ||
return basicAggregation() | ||
.with(functionName().equalTo("count")) | ||
.with(outputType().equalTo(BIGINT)) | ||
.with(singleInput().matching(variable().capturedAs(INPUT))); | ||
} | ||
|
||
@Override | ||
public Optional<PinotColumnHandle> rewrite(AggregateFunction aggregateFunction, Captures captures, RewriteContext context) | ||
{ | ||
if (!isCountDistinctPushdownEnabled(context.getSession())) { | ||
return Optional.empty(); | ||
} | ||
Variable input = captures.get(INPUT); | ||
verify(aggregateFunction.getOutputType() == BIGINT); | ||
return Optional.of(new PinotColumnHandle(format("distinctcount(%s)", context.getIdentifierQuote().apply(input.getName())), aggregateFunction.getOutputType(), false)); | ||
} | ||
} |
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
Oops, something went wrong.