Example usage for org.joda.time Interval getStartMillis

List of usage examples for org.joda.time Interval getStartMillis

Introduction

In this page you can find the example usage for org.joda.time Interval getStartMillis.

Prototype

public long getStartMillis() 

Source Link

Document

Gets the start of this time interval which is inclusive.

Usage

From source file:io.druid.segment.realtime.plumber.Sink.java

License:Apache License

public Sink(Interval interval, DataSchema schema, RealtimeTuningConfig config, String version) {
    this.schema = schema;
    this.config = config;
    this.interval = interval;
    this.version = version;

    makeNewCurrIndex(interval.getStartMillis(), schema);
}

From source file:io.druid.segment.realtime.plumber.Sink.java

License:Apache License

public Sink(Interval interval, DataSchema schema, RealtimeTuningConfig config, String version,
        List<FireHydrant> hydrants) {
    this.schema = schema;
    this.config = config;
    this.interval = interval;
    this.version = version;

    int maxCount = -1;
    for (int i = 0; i < hydrants.size(); ++i) {
        final FireHydrant hydrant = hydrants.get(i);
        if (hydrant.getCount() <= maxCount) {
            throw new ISE("hydrant[%s] not the right count[%s]", hydrant, i);
        }//from  w w w  .  j ava2s.  c  o  m
        maxCount = hydrant.getCount();
    }
    this.hydrants.addAll(hydrants);

    makeNewCurrIndex(interval.getStartMillis(), schema);
}

From source file:io.druid.server.coordinator.rules.PeriodLoadRule.java

License:Apache License

@Override
public boolean appliesTo(Interval interval, DateTime referenceTimestamp) {
    final Interval currInterval = new Interval(period, referenceTimestamp);
    return currInterval.overlaps(interval) && interval.getStartMillis() >= currInterval.getStartMillis();
}

From source file:io.druid.server.coordinator.rules.Rules.java

License:Apache License

public static boolean eligibleForLoad(Period period, Interval interval, DateTime referenceTimestamp) {
    final Interval currInterval = new Interval(period, referenceTimestamp);
    return currInterval.overlaps(interval) && interval.getStartMillis() >= currInterval.getStartMillis();
}

From source file:io.druid.sql.calcite.expression.Expressions.java

License:Apache License

/**
 * Translates to a simple leaf filter, meaning one that hits just a single column and is not an expression filter.
 *///from  ww  w. j  a va2s.  c o m
private static DimFilter toSimpleLeafFilter(final PlannerContext plannerContext,
        final RowSignature rowSignature, final RexNode rexNode) {
    final SqlKind kind = rexNode.getKind();

    if (kind == SqlKind.IS_TRUE || kind == SqlKind.IS_NOT_FALSE) {
        return toSimpleLeafFilter(plannerContext, rowSignature,
                Iterables.getOnlyElement(((RexCall) rexNode).getOperands()));
    } else if (kind == SqlKind.IS_FALSE || kind == SqlKind.IS_NOT_TRUE) {
        return new NotDimFilter(toSimpleLeafFilter(plannerContext, rowSignature,
                Iterables.getOnlyElement(((RexCall) rexNode).getOperands())));
    } else if (kind == SqlKind.IS_NULL || kind == SqlKind.IS_NOT_NULL) {
        final RexNode operand = Iterables.getOnlyElement(((RexCall) rexNode).getOperands());

        // operand must be translatable to a SimpleExtraction to be simple-filterable
        final DruidExpression druidExpression = toDruidExpression(plannerContext, rowSignature, operand);
        if (druidExpression == null || !druidExpression.isSimpleExtraction()) {
            return null;
        }

        final BoundDimFilter equalFilter = Bounds.equalTo(new BoundRefKey(
                druidExpression.getSimpleExtraction().getColumn(),
                druidExpression.getSimpleExtraction().getExtractionFn(), StringComparators.LEXICOGRAPHIC), "");

        return kind == SqlKind.IS_NOT_NULL ? new NotDimFilter(equalFilter) : equalFilter;
    } else if (kind == SqlKind.EQUALS || kind == SqlKind.NOT_EQUALS || kind == SqlKind.GREATER_THAN
            || kind == SqlKind.GREATER_THAN_OR_EQUAL || kind == SqlKind.LESS_THAN
            || kind == SqlKind.LESS_THAN_OR_EQUAL) {
        final List<RexNode> operands = ((RexCall) rexNode).getOperands();
        Preconditions.checkState(operands.size() == 2, "WTF?! Expected 2 operands, got[%,d]", operands.size());
        boolean flip = false;
        RexNode lhs = operands.get(0);
        RexNode rhs = operands.get(1);

        if (lhs.getKind() == SqlKind.LITERAL && rhs.getKind() != SqlKind.LITERAL) {
            // swap lhs, rhs
            RexNode x = lhs;
            lhs = rhs;
            rhs = x;
            flip = true;
        }

        // rhs must be a literal
        if (rhs.getKind() != SqlKind.LITERAL) {
            return null;
        }

        // lhs must be translatable to a SimpleExtraction to be simple-filterable
        final DruidExpression lhsExpression = toDruidExpression(plannerContext, rowSignature, lhs);
        if (lhsExpression == null || !lhsExpression.isSimpleExtraction()) {
            return null;
        }

        final String column = lhsExpression.getSimpleExtraction().getColumn();
        final ExtractionFn extractionFn = lhsExpression.getSimpleExtraction().getExtractionFn();

        if (column.equals(Column.TIME_COLUMN_NAME) && extractionFn instanceof TimeFormatExtractionFn) {
            // Check if we can strip the extractionFn and convert the filter to a direct filter on __time.
            // This allows potential conversion to query-level "intervals" later on, which is ideal for Druid queries.

            final Granularity granularity = ExtractionFns.toQueryGranularity(extractionFn);
            if (granularity != null) {
                // lhs is FLOOR(__time TO granularity); rhs must be a timestamp
                final long rhsMillis = Calcites.calciteDateTimeLiteralToJoda(rhs, plannerContext.getTimeZone())
                        .getMillis();
                final Interval rhsInterval = granularity.bucket(new DateTime(rhsMillis));

                // Is rhs aligned on granularity boundaries?
                final boolean rhsAligned = rhsInterval.getStartMillis() == rhsMillis;

                // Create a BoundRefKey that strips the extractionFn and compares __time as a number.
                final BoundRefKey boundRefKey = new BoundRefKey(column, null, StringComparators.NUMERIC);

                if (kind == SqlKind.EQUALS) {
                    return rhsAligned ? Bounds.interval(boundRefKey, rhsInterval) : Filtration.matchNothing();
                } else if (kind == SqlKind.NOT_EQUALS) {
                    return rhsAligned ? new NotDimFilter(Bounds.interval(boundRefKey, rhsInterval))
                            : Filtration.matchEverything();
                } else if ((!flip && kind == SqlKind.GREATER_THAN) || (flip && kind == SqlKind.LESS_THAN)) {
                    return Bounds.greaterThanOrEqualTo(boundRefKey, String.valueOf(rhsInterval.getEndMillis()));
                } else if ((!flip && kind == SqlKind.GREATER_THAN_OR_EQUAL)
                        || (flip && kind == SqlKind.LESS_THAN_OR_EQUAL)) {
                    return rhsAligned
                            ? Bounds.greaterThanOrEqualTo(boundRefKey,
                                    String.valueOf(rhsInterval.getStartMillis()))
                            : Bounds.greaterThanOrEqualTo(boundRefKey,
                                    String.valueOf(rhsInterval.getEndMillis()));
                } else if ((!flip && kind == SqlKind.LESS_THAN) || (flip && kind == SqlKind.GREATER_THAN)) {
                    return rhsAligned
                            ? Bounds.lessThan(boundRefKey, String.valueOf(rhsInterval.getStartMillis()))
                            : Bounds.lessThan(boundRefKey, String.valueOf(rhsInterval.getEndMillis()));
                } else if ((!flip && kind == SqlKind.LESS_THAN_OR_EQUAL)
                        || (flip && kind == SqlKind.GREATER_THAN_OR_EQUAL)) {
                    return Bounds.lessThan(boundRefKey, String.valueOf(rhsInterval.getEndMillis()));
                } else {
                    throw new IllegalStateException("WTF?! Shouldn't have got here...");
                }
            }
        }

        final String val;
        final RexLiteral rhsLiteral = (RexLiteral) rhs;
        if (SqlTypeName.NUMERIC_TYPES.contains(rhsLiteral.getTypeName())) {
            val = String.valueOf(RexLiteral.value(rhsLiteral));
        } else if (SqlTypeName.CHAR_TYPES.contains(rhsLiteral.getTypeName())) {
            val = String.valueOf(RexLiteral.stringValue(rhsLiteral));
        } else if (SqlTypeName.TIMESTAMP == rhsLiteral.getTypeName()
                || SqlTypeName.DATE == rhsLiteral.getTypeName()) {
            val = String.valueOf(Calcites.calciteDateTimeLiteralToJoda(rhsLiteral, plannerContext.getTimeZone())
                    .getMillis());
        } else {
            // Don't know how to filter on this kind of literal.
            return null;
        }

        // Numeric lhs needs a numeric comparison.
        final StringComparator comparator = Calcites
                .getStringComparatorForSqlTypeName(lhs.getType().getSqlTypeName());
        final BoundRefKey boundRefKey = new BoundRefKey(column, extractionFn, comparator);
        final DimFilter filter;

        // Always use BoundDimFilters, to simplify filter optimization later (it helps to remember the comparator).
        if (kind == SqlKind.EQUALS) {
            filter = Bounds.equalTo(boundRefKey, val);
        } else if (kind == SqlKind.NOT_EQUALS) {
            filter = new NotDimFilter(Bounds.equalTo(boundRefKey, val));
        } else if ((!flip && kind == SqlKind.GREATER_THAN) || (flip && kind == SqlKind.LESS_THAN)) {
            filter = Bounds.greaterThan(boundRefKey, val);
        } else if ((!flip && kind == SqlKind.GREATER_THAN_OR_EQUAL)
                || (flip && kind == SqlKind.LESS_THAN_OR_EQUAL)) {
            filter = Bounds.greaterThanOrEqualTo(boundRefKey, val);
        } else if ((!flip && kind == SqlKind.LESS_THAN) || (flip && kind == SqlKind.GREATER_THAN)) {
            filter = Bounds.lessThan(boundRefKey, val);
        } else if ((!flip && kind == SqlKind.LESS_THAN_OR_EQUAL)
                || (flip && kind == SqlKind.GREATER_THAN_OR_EQUAL)) {
            filter = Bounds.lessThanOrEqualTo(boundRefKey, val);
        } else {
            throw new IllegalStateException("WTF?! Shouldn't have got here...");
        }

        return filter;
    } else if (kind == SqlKind.LIKE) {
        final List<RexNode> operands = ((RexCall) rexNode).getOperands();
        final DruidExpression druidExpression = toDruidExpression(plannerContext, rowSignature,
                operands.get(0));
        if (druidExpression == null || !druidExpression.isSimpleExtraction()) {
            return null;
        }
        return new LikeDimFilter(druidExpression.getSimpleExtraction().getColumn(),
                RexLiteral.stringValue(operands.get(1)),
                operands.size() > 2 ? RexLiteral.stringValue(operands.get(2)) : null,
                druidExpression.getSimpleExtraction().getExtractionFn());
    } else {
        return null;
    }
}

From source file:io.druid.sql.calcite.filtration.Bounds.java

License:Apache License

public static BoundDimFilter interval(final BoundRefKey boundRefKey, final Interval interval) {
    if (!boundRefKey.getComparator().equals(StringComparators.NUMERIC)) {
        // Interval comparison only works with NUMERIC comparator.
        throw new ISE("Comparator must be NUMERIC but was[%s]", boundRefKey.getComparator());
    }//  ww w  . ja v  a2s  .  com

    return new BoundDimFilter(boundRefKey.getDimension(), String.valueOf(interval.getStartMillis()),
            String.valueOf(interval.getEndMillis()), false, true, null, boundRefKey.getExtractionFn(),
            boundRefKey.getComparator());
}

From source file:io.druid.sql.calcite.filtration.RangeSets.java

License:Apache License

public static RangeSet<Long> fromIntervals(final Iterable<Interval> intervals) {
    final RangeSet<Long> retVal = TreeRangeSet.create();
    for (Interval interval : intervals) {
        retVal.add(Range.closedOpen(interval.getStartMillis(), interval.getEndMillis()));
    }/*  ww w  .  j av  a 2s .c o m*/
    return retVal;
}

From source file:net.sourceforge.fenixedu.util.date.IntervalTools.java

License:Open Source License

@Deprecated
public static YearMonthDay getStartYMD(Interval interval) {
    long startTime = interval.getStartMillis();
    return startTime == Long.MIN_VALUE ? null : new YearMonthDay(startTime);
}

From source file:net.sourceforge.fenixedu.util.date.IntervalTools.java

License:Open Source License

public static LocalDate getStartLocalDate(Interval interval) {
    long startTime = interval.getStartMillis();
    return startTime == Long.MIN_VALUE ? null : new LocalDate(startTime);
}

From source file:net.sourceforge.fenixedu.util.date.IntervalTools.java

License:Open Source License

@Deprecated
public static Interval intervalWithEnd(Interval originalInterval, YearMonthDay day) {
    long millis = day.toDateMidnight().toDateTime().withTime(23, 59, 59, 999).getMillis();
    return new Interval(originalInterval.getStartMillis(), millis);
}