This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PPL] Support Count aggregator and OR operator (#493)
* [PPL] Support Count aggregator and OR operator * address comments
- Loading branch information
Showing
12 changed files
with
302 additions
and
41 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
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
69 changes: 69 additions & 0 deletions
69
...ava/com/amazon/opendistroforelasticsearch/sql/expression/aggregation/CountAggregator.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,69 @@ | ||
/* | ||
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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 com.amazon.opendistroforelasticsearch.sql.expression.aggregation; | ||
|
||
import static com.amazon.opendistroforelasticsearch.sql.utils.ExpressionUtils.format; | ||
|
||
import com.amazon.opendistroforelasticsearch.sql.data.model.ExprType; | ||
import com.amazon.opendistroforelasticsearch.sql.data.model.ExprValue; | ||
import com.amazon.opendistroforelasticsearch.sql.data.model.ExprValueUtils; | ||
import com.amazon.opendistroforelasticsearch.sql.expression.Expression; | ||
import com.amazon.opendistroforelasticsearch.sql.expression.aggregation.CountAggregator.CountState; | ||
import com.amazon.opendistroforelasticsearch.sql.expression.function.BuiltinFunctionName; | ||
import com.amazon.opendistroforelasticsearch.sql.storage.bindingtuple.BindingTuple; | ||
import java.util.List; | ||
import java.util.Locale; | ||
|
||
public class CountAggregator extends Aggregator<CountState> { | ||
|
||
public CountAggregator(List<Expression> arguments, ExprType returnType) { | ||
super(BuiltinFunctionName.COUNT.getName(), arguments, returnType); | ||
} | ||
|
||
@Override | ||
public CountAggregator.CountState create() { | ||
return new CountState(); | ||
} | ||
|
||
@Override | ||
public CountState iterate(BindingTuple tuple, CountState state) { | ||
Expression expression = getArguments().get(0); | ||
ExprValue value = expression.valueOf(tuple); | ||
if (!(value.isNull() || value.isMissing())) { | ||
state.count++; | ||
} | ||
return state; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format(Locale.ROOT, "count(%s)", format(getArguments())); | ||
} | ||
|
||
/** Count State. */ | ||
protected class CountState implements AggregationState { | ||
private int count; | ||
|
||
public CountState() { | ||
this.count = 0; | ||
} | ||
|
||
@Override | ||
public ExprValue result() { | ||
return ExprValueUtils.integerValue(count); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.