use of org.apache.druid.java.util.common.HumanReadableBytes in project druid by druid-io.
the class ExpressionLambdaAggregatorFactoryTest method testDoubleType.
@Test
public void testDoubleType() {
ExpressionLambdaAggregatorFactory agg = new ExpressionLambdaAggregatorFactory("expr_agg_name", ImmutableSet.of("some_column", "some_other_column"), null, "0.0", null, null, false, false, "__acc + some_column + some_other_column", "__acc + expr_agg_name", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE);
Assert.assertEquals(ColumnType.DOUBLE, agg.getIntermediateType());
Assert.assertEquals(ColumnType.DOUBLE, agg.getCombiningFactory().getIntermediateType());
Assert.assertEquals(ColumnType.DOUBLE, agg.getResultType());
}
use of org.apache.druid.java.util.common.HumanReadableBytes in project druid by druid-io.
the class ExpressionLambdaAggregatorFactoryTest method testSerde.
@Test
public void testSerde() throws IOException {
ExpressionLambdaAggregatorFactory agg = new ExpressionLambdaAggregatorFactory("expr_agg_name", ImmutableSet.of("some_column", "some_other_column"), "customAccumulator", "0.0", "10.0", true, true, false, "customAccumulator + some_column + some_other_column", "customAccumulator + expr_agg_name", "if (o1 > o2, if (o1 == o2, 0, 1), -1)", "o + 100", new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE);
Assert.assertEquals(agg, MAPPER.readValue(MAPPER.writeValueAsBytes(agg), ExpressionLambdaAggregatorFactory.class));
}
use of org.apache.druid.java.util.common.HumanReadableBytes in project druid by druid-io.
the class ExpressionLambdaAggregatorFactoryTest method testResultArraySignature.
@Test
public void testResultArraySignature() {
final TimeseriesQuery query = Druids.newTimeseriesQueryBuilder().dataSource("dummy").intervals("2000/3000").granularity(Granularities.HOUR).aggregators(new ExpressionLambdaAggregatorFactory("string_expr", ImmutableSet.of("some_column", "some_other_column"), null, "''", "''", null, false, false, "concat(__acc, some_column, some_other_column)", "concat(__acc, string_expr)", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("double_expr", ImmutableSet.of("some_column", "some_other_column"), null, "0.0", null, null, false, false, "__acc + some_column + some_other_column", "__acc + double_expr", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("long_expr", ImmutableSet.of("some_column", "some_other_column"), null, "0", null, null, false, false, "__acc + some_column + some_other_column", "__acc + long_expr", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("string_array_expr", ImmutableSet.of("some_column", "some_other_column"), null, "ARRAY<STRING>[]", "ARRAY<STRING>[]", null, true, false, "array_set_add(__acc, concat(some_column, some_other_column))", "array_set_add_all(__acc, string_array_expr)", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("double_array_expr", ImmutableSet.of("some_column", "some_other_column_expr"), null, "0.0", "ARRAY<DOUBLE>[]", null, false, false, "__acc + some_column + some_other_column", "array_set_add(__acc, double_array)", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("long_array_expr", ImmutableSet.of("some_column", "some_other_column"), null, "0", "ARRAY<LONG>[]", null, false, false, "__acc + some_column + some_other_column", "array_set_add(__acc, long_array_expr)", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("string_array_expr_finalized", ImmutableSet.of("some_column", "some_other_column"), null, "''", "ARRAY<STRING>[]", null, false, false, "concat(__acc, some_column, some_other_column)", "array_set_add(__acc, string_array_expr)", null, "array_to_string(o, ';')", new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("double_array_expr_finalized", ImmutableSet.of("some_column", "some_other_column_expr"), null, "0.0", "ARRAY<DOUBLE>[]", null, false, false, "__acc + some_column + some_other_column", "array_set_add(__acc, double_array)", null, "array_to_string(o, ';')", new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("long_array_expr_finalized", ImmutableSet.of("some_column", "some_other_column"), null, "0", "ARRAY<LONG>[]", null, false, false, "__acc + some_column + some_other_column", "array_set_add(__acc, long_array_expr)", null, "fold((x, acc) -> x + acc, o, 0)", new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("complex_expr", ImmutableSet.of("some_column"), null, "hyper_unique()", null, null, false, false, "hyper_unique_add(some_column, __acc)", "hyper_unique_add(__acc, expr_agg_name)", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE), new ExpressionLambdaAggregatorFactory("complex_expr_finalized", ImmutableSet.of("some_column"), null, "hyper_unique()", null, null, false, false, "hyper_unique_add(some_column, __acc)", "hyper_unique_add(__acc, expr_agg_name)", null, "hyper_unique_estimate(o)", new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE)).postAggregators(new FieldAccessPostAggregator("string-array-expr-access", "string_array_expr_finalized"), new FinalizingFieldAccessPostAggregator("string-array-expr-finalize", "string_array_expr_finalized"), new FieldAccessPostAggregator("double-array-expr-access", "double_array_expr_finalized"), new FinalizingFieldAccessPostAggregator("double-array-expr-finalize", "double_array_expr_finalized"), new FieldAccessPostAggregator("long-array-expr-access", "long_array_expr_finalized"), new FinalizingFieldAccessPostAggregator("long-array-expr-finalize", "long_array_expr_finalized"), new FieldAccessPostAggregator("complex-expr-access", "complex_expr_finalized"), new FinalizingFieldAccessPostAggregator("complex-expr-finalize", "complex_expr_finalized")).build();
Assert.assertEquals(RowSignature.builder().addTimeColumn().add("string_expr", ColumnType.STRING).add("double_expr", ColumnType.DOUBLE).add("long_expr", ColumnType.LONG).add("string_array_expr", ColumnType.STRING_ARRAY).add("double_array_expr", null).add("long_array_expr", null).add("string_array_expr_finalized", ColumnType.STRING).add("double_array_expr_finalized", null).add("long_array_expr_finalized", ColumnType.LONG).add("complex_expr", HyperUniquesAggregatorFactory.TYPE).add("complex_expr_finalized", null).add("string-array-expr-access", ColumnType.STRING).add("string-array-expr-finalize", ColumnType.STRING).add("double-array-expr-access", ColumnType.DOUBLE).add("double-array-expr-finalize", ColumnType.STRING).add("long-array-expr-access", ColumnType.LONG).add("long-array-expr-finalize", ColumnType.LONG).add("complex-expr-access", HyperUniquesAggregatorFactory.TYPE).add("complex-expr-finalize", ColumnType.DOUBLE).build(), new TimeseriesQueryQueryToolChest().resultArraySignature(query));
}
use of org.apache.druid.java.util.common.HumanReadableBytes in project druid by druid-io.
the class ExpressionLambdaAggregatorFactoryTest method testLongType.
@Test
public void testLongType() {
ExpressionLambdaAggregatorFactory agg = new ExpressionLambdaAggregatorFactory("expr_agg_name", ImmutableSet.of("some_column", "some_other_column"), null, "0", null, null, false, false, "__acc + some_column + some_other_column", "__acc + expr_agg_name", null, null, new HumanReadableBytes(2048), TestExprMacroTable.INSTANCE);
Assert.assertEquals(ColumnType.LONG, agg.getIntermediateType());
Assert.assertEquals(ColumnType.LONG, agg.getCombiningFactory().getIntermediateType());
Assert.assertEquals(ColumnType.LONG, agg.getResultType());
}
use of org.apache.druid.java.util.common.HumanReadableBytes in project druid by druid-io.
the class CalciteArraysQueryTest method testArrayAggGroupByArrayAggFromSubquery.
@Test
public void testArrayAggGroupByArrayAggFromSubquery() throws Exception {
cannotVectorize();
testQuery("SELECT dim2, arr, COUNT(*) FROM (SELECT dim2, ARRAY_AGG(DISTINCT dim1) as arr FROM foo WHERE dim1 is not null GROUP BY 1 LIMIT 5) GROUP BY 1,2", QUERY_CONTEXT_NO_STRINGIFY_ARRAY, ImmutableList.of(GroupByQuery.builder().setDataSource(new TopNQuery(new TableDataSource(CalciteTests.DATASOURCE1), null, new DefaultDimensionSpec("dim2", "d0", ColumnType.STRING), new DimensionTopNMetricSpec(null, StringComparators.LEXICOGRAPHIC), 5, querySegmentSpec(Filtration.eternity()), new NotDimFilter(new SelectorDimFilter("dim1", null, null)), Granularities.ALL, aggregators(new ExpressionLambdaAggregatorFactory("a0", ImmutableSet.of("dim1"), "__acc", "ARRAY<STRING>[]", "ARRAY<STRING>[]", true, true, false, "array_set_add(\"__acc\", \"dim1\")", "array_set_add_all(\"__acc\", \"a0\")", null, null, new HumanReadableBytes(1024), ExprMacroTable.nil())), null, QUERY_CONTEXT_NO_STRINGIFY_ARRAY)).setInterval(querySegmentSpec(Filtration.eternity())).setGranularity(Granularities.ALL).setDimFilter(null).setGranularity(Granularities.ALL).setDimensions(dimensions(new DefaultDimensionSpec("d0", "_d0", ColumnType.STRING), new DefaultDimensionSpec("a0", "_d1", ColumnType.STRING_ARRAY))).setAggregatorSpecs(aggregators(new CountAggregatorFactory("_a0"))).setContext(QUERY_CONTEXT_NO_STRINGIFY_ARRAY).build()), useDefault ? ImmutableList.of(new Object[] { "", ImmutableList.of("10.1", "2", "abc"), 1L }, new Object[] { "a", ImmutableList.of("1"), 1L }, new Object[] { "abc", ImmutableList.of("def"), 1L }) : ImmutableList.of(new Object[] { null, ImmutableList.of("10.1", "abc"), 1L }, new Object[] { "", ImmutableList.of("2"), 1L }, new Object[] { "a", ImmutableList.of("", "1"), 1L }, new Object[] { "abc", ImmutableList.of("def"), 1L }));
}
Aggregations