Search in sources :

Example 11 with RowSignature

use of org.apache.druid.segment.column.RowSignature in project druid by druid-io.

the class DruidOuterQueryRel method toDruidQuery.

@Override
public DruidQuery toDruidQuery(final boolean finalizeAggregations) {
    // Must finalize aggregations on subqueries.
    final DruidQuery subQuery = ((DruidRel) sourceRel).toDruidQuery(true);
    final RowSignature sourceRowSignature = subQuery.getOutputRowSignature();
    return partialQuery.build(new QueryDataSource(subQuery.getQuery()), sourceRowSignature, getPlannerContext(), getCluster().getRexBuilder(), finalizeAggregations);
}
Also used : QueryDataSource(org.apache.druid.query.QueryDataSource) RowSignature(org.apache.druid.segment.column.RowSignature)

Example 12 with RowSignature

use of org.apache.druid.segment.column.RowSignature in project druid by druid-io.

the class ExpressionPostAggregatorTest method testNilOutputType.

@Test
public void testNilOutputType() {
    ExpressionPostAggregator postAgg = new ExpressionPostAggregator("p0", "x + y", null, TestExprMacroTable.INSTANCE);
    RowSignature signature = RowSignature.builder().build();
    // columns not existing in the output signature means they don't exist, so the output is also null
    Assert.assertNull(postAgg.getType(signature));
}
Also used : RowSignature(org.apache.druid.segment.column.RowSignature) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 13 with RowSignature

use of org.apache.druid.segment.column.RowSignature in project druid by druid-io.

the class ExpressionPostAggregatorTest method testOutputTypeAndCompute.

@Test
public void testOutputTypeAndCompute() {
    ExpressionPostAggregator postAgg = new ExpressionPostAggregator("p0", "x + y", null, TestExprMacroTable.INSTANCE);
    RowSignature signature = RowSignature.builder().add("x", ColumnType.LONG).add("y", ColumnType.DOUBLE).build();
    SettableObjectBinding binding = new SettableObjectBinding().withBinding("x", 2L).withBinding("y", 3.0);
    Assert.assertEquals(ColumnType.DOUBLE, postAgg.getType(signature));
    Assert.assertEquals(5.0, postAgg.compute(binding.asMap()));
}
Also used : RowSignature(org.apache.druid.segment.column.RowSignature) SettableObjectBinding(org.apache.druid.math.expr.SettableObjectBinding) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 14 with RowSignature

use of org.apache.druid.segment.column.RowSignature in project druid by druid-io.

the class FieldAccessPostAggregatorTest method testGetTypeBeforeDecorate.

@Test
public void testGetTypeBeforeDecorate() {
    FieldAccessPostAggregator postAgg = new FieldAccessPostAggregator("name", "column");
    RowSignature signature = RowSignature.builder().add("column", ColumnType.LONG).build();
    Assert.assertEquals(ColumnType.LONG, postAgg.getType(signature));
}
Also used : RowSignature(org.apache.druid.segment.column.RowSignature) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 15 with RowSignature

use of org.apache.druid.segment.column.RowSignature in project druid by druid-io.

the class DruidSchemaTest method testSegmentMetadataColumnType.

@Test
public void testSegmentMetadataColumnType() {
    RowSignature signature = DruidSchema.analysisToRowSignature(new SegmentAnalysis("id", ImmutableList.of(Intervals.utc(1L, 2L)), ImmutableMap.of("a", new ColumnAnalysis(ColumnType.STRING, ColumnType.STRING.asTypeString(), false, true, 1234, 26, "a", "z", null), "count", new ColumnAnalysis(ColumnType.LONG, ColumnType.LONG.asTypeString(), false, true, 1234, 26, "a", "z", null)), 1234, 100, null, null, null, null));
    Assert.assertEquals(RowSignature.builder().add("a", ColumnType.STRING).add("count", ColumnType.LONG).build(), signature);
}
Also used : ColumnAnalysis(org.apache.druid.query.metadata.metadata.ColumnAnalysis) SegmentAnalysis(org.apache.druid.query.metadata.metadata.SegmentAnalysis) RowSignature(org.apache.druid.segment.column.RowSignature) Test(org.junit.Test)

Aggregations

RowSignature (org.apache.druid.segment.column.RowSignature)46 ColumnType (org.apache.druid.segment.column.ColumnType)17 List (java.util.List)14 Test (org.junit.Test)13 Collectors (java.util.stream.Collectors)12 Nullable (javax.annotation.Nullable)11 PlannerContext (org.apache.druid.sql.calcite.planner.PlannerContext)11 DruidExpression (org.apache.druid.sql.calcite.expression.DruidExpression)10 Expressions (org.apache.druid.sql.calcite.expression.Expressions)10 Project (org.apache.calcite.rel.core.Project)9 RexLiteral (org.apache.calcite.rex.RexLiteral)9 RexNode (org.apache.calcite.rex.RexNode)9 SqlKind (org.apache.calcite.sql.SqlKind)9 ISE (org.apache.druid.java.util.common.ISE)9 Aggregation (org.apache.druid.sql.calcite.aggregation.Aggregation)9 ArrayList (java.util.ArrayList)8 StringUtils (org.apache.druid.java.util.common.StringUtils)8 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)8 ImmutableList (com.google.common.collect.ImmutableList)6 ImmutableSet (com.google.common.collect.ImmutableSet)6