-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20fb7d8
commit 7569071
Showing
5 changed files
with
158 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
24 changes: 24 additions & 0 deletions
24
presto-main/src/main/java/io/prestosql/operator/aggregation/state/BooleanDistinctState.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,24 @@ | ||
/* | ||
* 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.prestosql.operator.aggregation.state; | ||
|
||
import io.prestosql.spi.function.AccumulatorState; | ||
|
||
public interface BooleanDistinctState | ||
extends AccumulatorState | ||
{ | ||
byte getByte(); | ||
|
||
void setByte(byte value); | ||
} |
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
90 changes: 90 additions & 0 deletions
90
.../src/test/java/io/prestosql/operator/aggregation/TestApproximateCountDistinctBoolean.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,90 @@ | ||
/* | ||
* 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.prestosql.operator.aggregation; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableSet; | ||
import com.google.common.primitives.Booleans; | ||
import io.prestosql.metadata.Signature; | ||
import io.prestosql.spi.type.Type; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
import static io.prestosql.metadata.FunctionKind.AGGREGATE; | ||
import static io.prestosql.spi.type.BigintType.BIGINT; | ||
import static io.prestosql.spi.type.BooleanType.BOOLEAN; | ||
import static io.prestosql.spi.type.DoubleType.DOUBLE; | ||
|
||
public class TestApproximateCountDistinctBoolean | ||
extends AbstractTestApproximateCountDistinct | ||
{ | ||
@Override | ||
public InternalAggregationFunction getAggregationFunction() | ||
{ | ||
return metadata.getFunctionRegistry().getAggregateFunctionImplementation( | ||
new Signature("approx_distinct", AGGREGATE, BIGINT.getTypeSignature(), BOOLEAN.getTypeSignature(), DOUBLE.getTypeSignature())); | ||
} | ||
|
||
@Override | ||
public Type getValueType() | ||
{ | ||
return BOOLEAN; | ||
} | ||
|
||
@Override | ||
public Object randomValue() | ||
{ | ||
return ThreadLocalRandom.current().nextBoolean(); | ||
} | ||
|
||
@DataProvider(name = "inputSequences") | ||
public Object[][] inputSequences() | ||
{ | ||
return new Object[][] { | ||
{true}, | ||
{false}, | ||
{true, false}, | ||
{true, true, true}, | ||
{false, false, false}, | ||
{true, false, true, false}, | ||
}; | ||
} | ||
|
||
@Test(dataProvider = "inputSequences") | ||
public void testNonEmptyInputs(boolean... inputSequence) | ||
{ | ||
List<Boolean> values = Booleans.asList(inputSequence); | ||
assertCount(values, 0, distinctCount(values)); | ||
} | ||
|
||
@Test | ||
public void testNoInput() | ||
{ | ||
assertCount(ImmutableList.of(), 0, 0); | ||
} | ||
|
||
private long distinctCount(List<Boolean> inputSequence) | ||
{ | ||
return ImmutableSet.copyOf(inputSequence).size(); | ||
} | ||
|
||
@Override | ||
protected int getUniqueValuesCount() | ||
{ | ||
return 2; | ||
} | ||
} |