-
Notifications
You must be signed in to change notification settings - Fork 8
feat: support configuring distinct count agg function #143
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
60e3d64
271fe58
9aaa078
729ec2f
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,38 @@ | ||
| package org.hypertrace.core.query.service.pinot.converters; | ||
|
|
||
| import com.typesafe.config.Config; | ||
| import com.typesafe.config.ConfigFactory; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Value; | ||
|
|
||
| @Value | ||
| @AllArgsConstructor | ||
| public class PinotFunctionConverterConfig { | ||
|
|
||
| private static final String PERCENTILE_AGGREGATION_FUNCTION_CONFIG = "percentileAggFunction"; | ||
| private static final String DISTINCT_COUNT_AGGREGATION_FUNCTION_CONFIG = | ||
| "distinctCountAggFunction"; | ||
| private static final String DEFAULT_PERCENTILE_AGGREGATION_FUNCTION = "PERCENTILETDIGEST"; | ||
| private static final String DEFAULT_DISTINCT_COUNT_AGGREGATION_FUNCTION = "DISTINCTCOUNT"; | ||
|
|
||
| String percentileAggregationFunction; | ||
| String distinctCountAggregationFunction; | ||
|
|
||
| public PinotFunctionConverterConfig(Config config) { | ||
| if (config.hasPath(PERCENTILE_AGGREGATION_FUNCTION_CONFIG)) { | ||
| this.percentileAggregationFunction = config.getString(PERCENTILE_AGGREGATION_FUNCTION_CONFIG); | ||
| } else { | ||
| this.percentileAggregationFunction = DEFAULT_PERCENTILE_AGGREGATION_FUNCTION; | ||
| } | ||
| if (config.hasPath(DISTINCT_COUNT_AGGREGATION_FUNCTION_CONFIG)) { | ||
| this.distinctCountAggregationFunction = | ||
| config.getString(DISTINCT_COUNT_AGGREGATION_FUNCTION_CONFIG); | ||
| } else { | ||
| this.distinctCountAggregationFunction = DEFAULT_DISTINCT_COUNT_AGGREGATION_FUNCTION; | ||
| } | ||
| } | ||
|
|
||
| public PinotFunctionConverterConfig() { | ||
| this(ConfigFactory.empty()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,7 +104,7 @@ void acceptsCustomPercentileFunctions() { | |
|
|
||
| assertEquals( | ||
| expected, | ||
| new PinotFunctionConverter("CUSTOMPERCENTILE") | ||
| new PinotFunctionConverter(new PinotFunctionConverterConfig("CUSTOMPERCENTILE", null)) | ||
| .convert(mockingExecutionContext, percentileFunction, this.mockArgumentConverter)); | ||
| } | ||
|
|
||
|
|
@@ -211,7 +211,7 @@ void convertAvgRateFunction() { | |
| .thenReturn(Optional.of(Duration.ofSeconds(10))); | ||
|
|
||
| assertEquals( | ||
| "SUM(DIV(foo, 2.0))", | ||
| "SUM(foo / 2.0)", | ||
|
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. Just curious: Do we have any value level test that compares prior (SUM(DIV(foo, 2.0)) vs SUM(foo / 2.0, resulting in the same values?
Contributor
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. That would be testing pinot's functionality - that
Contributor
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.
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. |
||
| new PinotFunctionConverter() | ||
| .convert( | ||
| mockingExecutionContext, | ||
|
|
@@ -223,14 +223,37 @@ void convertAvgRateFunction() { | |
| .thenReturn(Optional.of(Duration.ofSeconds(20))); | ||
|
|
||
| assertEquals( | ||
| "SUM(DIV(foo, 4.0))", | ||
| "SUM(foo / 4.0)", | ||
| new PinotFunctionConverter() | ||
| .convert( | ||
| mockingExecutionContext, | ||
| buildFunction(QUERY_FUNCTION_AVGRATE, column1.toBuilder(), column2.toBuilder()), | ||
| this.mockArgumentConverter)); | ||
| } | ||
|
|
||
| @Test | ||
| void convertsDistinctCountFunction() { | ||
| Expression column = createColumnExpression("foo").build(); | ||
|
|
||
| when(this.mockArgumentConverter.apply(column)).thenReturn("foo"); | ||
|
|
||
| assertEquals( | ||
| "DISTINCTCOUNT(foo)", | ||
| new PinotFunctionConverter() | ||
| .convert( | ||
| mockingExecutionContext, | ||
| buildFunction(QUERY_FUNCTION_DISTINCTCOUNT, column.toBuilder()), | ||
| this.mockArgumentConverter)); | ||
|
|
||
| assertEquals( | ||
| "CUSTOM_DC(foo)", | ||
| new PinotFunctionConverter(new PinotFunctionConverterConfig(null, "CUSTOM_DC")) | ||
| .convert( | ||
| mockingExecutionContext, | ||
| buildFunction(QUERY_FUNCTION_DISTINCTCOUNT, column.toBuilder()), | ||
| this.mockArgumentConverter)); | ||
| } | ||
|
|
||
| @Test | ||
| void testIllegalDurationFormat() { | ||
| Expression column1 = createColumnExpression("foo").build(); | ||
|
|
||



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.
I think we should make DISTINCT_COUNT_HLL as the default.
Uh oh!
There was an error while loading. Please reload this page.
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.
I left it this way for backwards compatibility. Without any custom config it'll retain identical behavior as before, but it's easily changed.