Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ static void updateSketch(final HllSketch sketch, final Object value)
for (String v : list) {
sketch.update(v.toCharArray());
}
} else if (value instanceof String[]) {
// noinspection unchecked
String[] list = (String[]) value;
for (String v : list) {
sketch.update(v.toCharArray());
}
} else if (value instanceof char[]) {
sketch.update((char[]) value);
} else if (value instanceof byte[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.apache.druid.java.util.common.granularity.Granularities;
import org.apache.druid.java.util.common.guava.Sequence;
import org.apache.druid.math.expr.ExprMacroTable;
import org.apache.druid.query.aggregation.AggregationTestHelper;
import org.apache.druid.query.groupby.GroupByQueryConfig;
import org.apache.druid.query.groupby.GroupByQueryRunnerTest;
import org.apache.druid.query.groupby.ResultRow;
import org.apache.druid.segment.transform.ExpressionTransform;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -42,6 +45,7 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@RunWith(Parameterized.class)
public class HllSketchAggregatorTest
Expand Down Expand Up @@ -112,6 +116,34 @@ public void buildSketchesAtIngestionTime() throws Exception
Assert.assertEquals(200, (double) row.get(0), 0.1);
}

@Test
public void buildSketchesAtIngestionTimeMultiValueWithTransformations() throws Exception
{
Sequence<ResultRow> seq = helper.createIndexAndRunQueryOnSegment(
new File(this.getClass().getClassLoader().getResource("hll/hll_raw.tsv").getFile()),
buildParserJson(
Collections.singletonList("dim"),
Arrays.asList("timestamp", "dim", "multiDim", "id"),
ImmutableList.of(
new ExpressionTransform(
"multiDimAppended",
"array_append(multiDim, '15')",
ExprMacroTable.nil()
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clintropolis yes, I guess you're right.

However I am still not able to make this test pass. Is there a simple way to run these tests?

Or maybe the issue is evident right away? I haven't found any test with transformations, I suppose this test implementation is flawed.

)
)
),
buildAggregatorJson("HLLSketchBuild", "multiDimAppended", !ROUND),
0, // minTimestamp
Granularities.NONE,
200, // maxRowCount
buildGroupByQueryJson("HLLSketchMerge", "sketch", !ROUND)
);
List<ResultRow> results = seq.toList();
Assert.assertEquals(1, results.size());
ResultRow row = results.get(0);
Assert.assertEquals(15, (double) row.get(0), 0.1);
}

@Test
public void buildSketchesAtQueryTime() throws Exception
{
Expand Down Expand Up @@ -221,6 +253,48 @@ private static String buildParserJson(List<String> dimensions, List<String> colu
return toJson(object);
}

private static String buildParserJson(
List<String> dimensions,
List<String> columns,
List<ExpressionTransform> transforms
)
{
List<Map<String, String>> transformsObjects = transforms.stream().map(transform ->
ImmutableMap.of(
"type", "expression",
"name", transform.getName(),
"expression", transform.getExpression()
)
).collect(Collectors.toList());

Map<String, Object> transformsObject = ImmutableMap.of(
"transforms", transformsObjects
);

Map<String, Object> timestampSpec = ImmutableMap.of(
"column", "timestamp",
"format", "yyyyMMdd"
);
Map<String, Object> dimensionsSpec = ImmutableMap.of(
"dimensions", dimensions,
"dimensionExclusions", Collections.emptyList(),
"spatialDimensions", Collections.emptyList()
);
Map<String, Object> parseSpec = ImmutableMap.of(
"format", "tsv",
"timestampSpec", timestampSpec,
"dimensionsSpec", dimensionsSpec,
"columns", columns,
"listDelimiter", ","
);
Map<String, Object> object = ImmutableMap.of(
"type", "string",
"parseSpec", parseSpec,
"transformSpec", transformsObject
);
return toJson(object);
}

private static String toJson(Object object)
{
final String json;
Expand Down