Search in sources :

Example 1 with BucketExtractionFn

use of io.druid.query.extraction.BucketExtractionFn in project druid by druid-io.

the class VirtualColumnsTest method testMakeSelectors.

@Test
public void testMakeSelectors() {
    final VirtualColumns virtualColumns = makeVirtualColumns();
    final ObjectColumnSelector objectSelector = virtualColumns.makeObjectColumnSelector("expr", null);
    final DimensionSelector dimensionSelector = virtualColumns.makeDimensionSelector(new DefaultDimensionSpec("expr", "x"), null);
    final DimensionSelector extractionDimensionSelector = virtualColumns.makeDimensionSelector(new ExtractionDimensionSpec("expr", "x", new BucketExtractionFn(1.0, 0.5)), null);
    final FloatColumnSelector floatSelector = virtualColumns.makeFloatColumnSelector("expr", null);
    final LongColumnSelector longSelector = virtualColumns.makeLongColumnSelector("expr", null);
    Assert.assertEquals(1L, objectSelector.get());
    Assert.assertEquals("1", dimensionSelector.lookupName(dimensionSelector.getRow().get(0)));
    Assert.assertEquals("0.5", extractionDimensionSelector.lookupName(extractionDimensionSelector.getRow().get(0)));
    Assert.assertEquals(1.0f, floatSelector.get(), 0.0f);
    Assert.assertEquals(1L, longSelector.get());
}
Also used : DimensionSelector(io.druid.segment.DimensionSelector) BucketExtractionFn(io.druid.query.extraction.BucketExtractionFn) TestLongColumnSelector(io.druid.segment.TestLongColumnSelector) LongColumnSelector(io.druid.segment.LongColumnSelector) TestFloatColumnSelector(io.druid.segment.TestFloatColumnSelector) FloatColumnSelector(io.druid.segment.FloatColumnSelector) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) VirtualColumns(io.druid.segment.VirtualColumns) ObjectColumnSelector(io.druid.segment.ObjectColumnSelector) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Example 2 with BucketExtractionFn

use of io.druid.query.extraction.BucketExtractionFn in project druid by druid-io.

the class FloorExtractionOperator method convert.

@Override
public RowExtraction convert(final DruidOperatorTable operatorTable, final PlannerContext plannerContext, final List<String> rowOrder, final RexNode expression) {
    final RexCall call = (RexCall) expression;
    final RexNode arg = call.getOperands().get(0);
    final RowExtraction rex = Expressions.toRowExtraction(operatorTable, plannerContext, rowOrder, arg);
    if (rex == null) {
        return null;
    } else if (call.getOperands().size() == 1) {
        // FLOOR(expr)
        return RowExtraction.of(rex.getColumn(), ExtractionFns.compose(new BucketExtractionFn(1.0, 0.0), rex.getExtractionFn()));
    } else if (call.getOperands().size() == 2) {
        // FLOOR(expr TO timeUnit)
        final RexLiteral flag = (RexLiteral) call.getOperands().get(1);
        final TimeUnitRange timeUnit = (TimeUnitRange) flag.getValue();
        return applyTimestampFloor(rex, TimeUnits.toQueryGranularity(timeUnit, plannerContext.getTimeZone()));
    } else {
        // WTF? FLOOR with 3 arguments?
        return null;
    }
}
Also used : RexCall(org.apache.calcite.rex.RexCall) RexLiteral(org.apache.calcite.rex.RexLiteral) BucketExtractionFn(io.druid.query.extraction.BucketExtractionFn) TimeUnitRange(org.apache.calcite.avatica.util.TimeUnitRange) RexNode(org.apache.calcite.rex.RexNode)

Example 3 with BucketExtractionFn

use of io.druid.query.extraction.BucketExtractionFn in project druid by druid-io.

the class ExpressionVirtualColumnTest method testDimensionSelectorWithExtraction.

@Test
public void testDimensionSelectorWithExtraction() {
    final DimensionSelector selector = XPLUSY.makeDimensionSelector(new ExtractionDimensionSpec("expr", "x", new BucketExtractionFn(1.0, 0.0)), COLUMN_SELECTOR_FACTORY);
    final ValueMatcher nullMatcher = selector.makeValueMatcher((String) null);
    final ValueMatcher fiveMatcher = selector.makeValueMatcher("5");
    final ValueMatcher nonNullMatcher = selector.makeValueMatcher(Predicates.<String>notNull());
    COLUMN_SELECTOR_FACTORY.setRow(ROW0);
    Assert.assertEquals(true, nullMatcher.matches());
    Assert.assertEquals(false, fiveMatcher.matches());
    Assert.assertEquals(false, nonNullMatcher.matches());
    Assert.assertEquals(null, selector.lookupName(selector.getRow().get(0)));
    COLUMN_SELECTOR_FACTORY.setRow(ROW1);
    Assert.assertEquals(true, nullMatcher.matches());
    Assert.assertEquals(false, fiveMatcher.matches());
    Assert.assertEquals(false, nonNullMatcher.matches());
    Assert.assertEquals(null, selector.lookupName(selector.getRow().get(0)));
    COLUMN_SELECTOR_FACTORY.setRow(ROW2);
    Assert.assertEquals(false, nullMatcher.matches());
    Assert.assertEquals(true, fiveMatcher.matches());
    Assert.assertEquals(true, nonNullMatcher.matches());
    Assert.assertEquals("5", selector.lookupName(selector.getRow().get(0)));
}
Also used : DimensionSelector(io.druid.segment.DimensionSelector) BucketExtractionFn(io.druid.query.extraction.BucketExtractionFn) ValueMatcher(io.druid.query.filter.ValueMatcher) ExtractionDimensionSpec(io.druid.query.dimension.ExtractionDimensionSpec) Test(org.junit.Test)

Aggregations

BucketExtractionFn (io.druid.query.extraction.BucketExtractionFn)3 ExtractionDimensionSpec (io.druid.query.dimension.ExtractionDimensionSpec)2 DimensionSelector (io.druid.segment.DimensionSelector)2 Test (org.junit.Test)2 DefaultDimensionSpec (io.druid.query.dimension.DefaultDimensionSpec)1 ValueMatcher (io.druid.query.filter.ValueMatcher)1 FloatColumnSelector (io.druid.segment.FloatColumnSelector)1 LongColumnSelector (io.druid.segment.LongColumnSelector)1 ObjectColumnSelector (io.druid.segment.ObjectColumnSelector)1 TestFloatColumnSelector (io.druid.segment.TestFloatColumnSelector)1 TestLongColumnSelector (io.druid.segment.TestLongColumnSelector)1 VirtualColumns (io.druid.segment.VirtualColumns)1 TimeUnitRange (org.apache.calcite.avatica.util.TimeUnitRange)1 RexCall (org.apache.calcite.rex.RexCall)1 RexLiteral (org.apache.calcite.rex.RexLiteral)1 RexNode (org.apache.calcite.rex.RexNode)1