List of usage examples for com.google.common.collect Range hasUpperBound
public boolean hasUpperBound()
From source file:org.pshdl.model.extensions.RangeExtension.java
protected Optional<Range<BigInteger>> _determineRange(final HDLShiftOp obj, final HDLEvaluationContext context) { HDLExpression _left = obj.getLeft(); final Optional<Range<BigInteger>> leftRange = this.determineRange(_left, context); boolean _isPresent = leftRange.isPresent(); boolean _not = (!_isPresent); if (_not) {//from ww w .j a v a 2 s . c o m return Optional.<Range<BigInteger>>absent(); } final Range<BigInteger> lrVal = leftRange.get(); boolean _or = false; boolean _hasLowerBound = lrVal.hasLowerBound(); boolean _not_1 = (!_hasLowerBound); if (_not_1) { _or = true; } else { boolean _hasUpperBound = lrVal.hasUpperBound(); boolean _not_2 = (!_hasUpperBound); _or = _not_2; } if (_or) { return Optional.<Range<BigInteger>>absent(); } HDLExpression _right = obj.getRight(); final Optional<Range<BigInteger>> rightRange = this.determineRange(_right, context); boolean _isPresent_1 = rightRange.isPresent(); boolean _not_3 = (!_isPresent_1); if (_not_3) { return Optional.<Range<BigInteger>>absent(); } final Range<BigInteger> rrVal = rightRange.get(); boolean _or_1 = false; boolean _hasLowerBound_1 = rrVal.hasLowerBound(); boolean _not_4 = (!_hasLowerBound_1); if (_not_4) { _or_1 = true; } else { boolean _hasUpperBound_1 = rrVal.hasUpperBound(); boolean _not_5 = (!_hasUpperBound_1); _or_1 = _not_5; } if (_or_1) { return Optional.<Range<BigInteger>>absent(); } HDLShiftOp.HDLShiftOpType _type = obj.getType(); if (_type != null) { switch (_type) { case SLL: BigInteger _lowerEndpoint = lrVal.lowerEndpoint(); BigInteger _lowerEndpoint_1 = rrVal.lowerEndpoint(); int _intValue = _lowerEndpoint_1.intValue(); final BigInteger ff = _lowerEndpoint.shiftLeft(_intValue); BigInteger _lowerEndpoint_2 = lrVal.lowerEndpoint(); BigInteger _upperEndpoint = rrVal.upperEndpoint(); int _intValue_1 = _upperEndpoint.intValue(); final BigInteger ft = _lowerEndpoint_2.shiftLeft(_intValue_1); BigInteger _upperEndpoint_1 = lrVal.upperEndpoint(); BigInteger _lowerEndpoint_3 = rrVal.lowerEndpoint(); int _intValue_2 = _lowerEndpoint_3.intValue(); final BigInteger tf = _upperEndpoint_1.shiftLeft(_intValue_2); BigInteger _upperEndpoint_2 = lrVal.upperEndpoint(); BigInteger _upperEndpoint_3 = rrVal.upperEndpoint(); int _intValue_3 = _upperEndpoint_3.intValue(); final BigInteger tt = _upperEndpoint_2.shiftLeft(_intValue_3); BigInteger _min = ff.min(ft); BigInteger _min_1 = _min.min(tf); BigInteger _min_2 = _min_1.min(tt); BigInteger _max = ff.max(ft); BigInteger _max_1 = _max.max(tf); BigInteger _max_2 = _max_1.max(tt); Range<BigInteger> _createRange = RangeTool.<BigInteger>createRange(_min_2, _max_2); return Optional.<Range<BigInteger>>of(_createRange); case SRA: BigInteger _lowerEndpoint_4 = lrVal.lowerEndpoint(); BigInteger _lowerEndpoint_5 = rrVal.lowerEndpoint(); int _intValue_4 = _lowerEndpoint_5.intValue(); final BigInteger ff_1 = _lowerEndpoint_4.shiftRight(_intValue_4); BigInteger _lowerEndpoint_6 = lrVal.lowerEndpoint(); BigInteger _upperEndpoint_4 = rrVal.upperEndpoint(); int _intValue_5 = _upperEndpoint_4.intValue(); final BigInteger ft_1 = _lowerEndpoint_6.shiftRight(_intValue_5); BigInteger _upperEndpoint_5 = lrVal.upperEndpoint(); BigInteger _lowerEndpoint_7 = rrVal.lowerEndpoint(); int _intValue_6 = _lowerEndpoint_7.intValue(); final BigInteger tf_1 = _upperEndpoint_5.shiftRight(_intValue_6); BigInteger _upperEndpoint_6 = lrVal.upperEndpoint(); BigInteger _upperEndpoint_7 = rrVal.upperEndpoint(); int _intValue_7 = _upperEndpoint_7.intValue(); final BigInteger tt_1 = _upperEndpoint_6.shiftRight(_intValue_7); BigInteger _min_3 = ff_1.min(ft_1); BigInteger _min_4 = _min_3.min(tf_1); BigInteger _min_5 = _min_4.min(tt_1); BigInteger _max_3 = ff_1.max(ft_1); BigInteger _max_4 = _max_3.max(tf_1); BigInteger _max_5 = _max_4.max(tt_1); Range<BigInteger> _createRange_1 = RangeTool.<BigInteger>createRange(_min_5, _max_5); return Optional.<Range<BigInteger>>of(_createRange_1); case SRL: BigInteger _lowerEndpoint_8 = lrVal.lowerEndpoint(); BigInteger _lowerEndpoint_9 = rrVal.lowerEndpoint(); final BigInteger ff_2 = RangeExtension.srl(_lowerEndpoint_8, _lowerEndpoint_9); BigInteger _lowerEndpoint_10 = lrVal.lowerEndpoint(); BigInteger _upperEndpoint_8 = rrVal.upperEndpoint(); final BigInteger ft_2 = RangeExtension.srl(_lowerEndpoint_10, _upperEndpoint_8); BigInteger _upperEndpoint_9 = lrVal.upperEndpoint(); BigInteger _lowerEndpoint_11 = rrVal.lowerEndpoint(); final BigInteger tf_2 = RangeExtension.srl(_upperEndpoint_9, _lowerEndpoint_11); BigInteger _upperEndpoint_10 = lrVal.upperEndpoint(); BigInteger _upperEndpoint_11 = rrVal.upperEndpoint(); final BigInteger tt_2 = RangeExtension.srl(_upperEndpoint_10, _upperEndpoint_11); BigInteger _min_6 = ff_2.min(ft_2); BigInteger _min_7 = _min_6.min(tf_2); BigInteger _min_8 = _min_7.min(tt_2); BigInteger _max_6 = ff_2.max(ft_2); BigInteger _max_7 = _max_6.max(tf_2); BigInteger _max_8 = _max_7.max(tt_2); Range<BigInteger> _createRange_2 = RangeTool.<BigInteger>createRange(_min_8, _max_8); return Optional.<Range<BigInteger>>of(_createRange_2); default: break; } } throw new RuntimeException("Incorrectly implemented obj op"); }
From source file:org.kiji.schema.impl.cassandra.CQLStatementCache.java
/** * Create a CQL statement for selecting the columns that make up the Entity ID from a Cassandra * Kiji Table.//from w w w .java 2s.c o m * * @param table The translated Cassandra table name. * @param tokenRange A range of tokens to scan. * @return a statement that will get the single column. */ public Statement createEntityIDScanStatement(final CassandraTableName table, final Range<Long> tokenRange) { // Retrieve the prepared statement from the cache // We can only use the 'DISTINCT' optimization if all entity ID components are part of the // partition key. CQL does not allow DISTINCT over non partition-key columns. final boolean useDistinct = mEntityIDClusteringColumns.isEmpty(); final Optional<BoundType> lowerBound = tokenRange.hasLowerBound() ? Optional.of(tokenRange.lowerBoundType()) : Optional.<BoundType>absent(); final Optional<BoundType> upperBound = tokenRange.hasUpperBound() ? Optional.of(tokenRange.upperBoundType()) : Optional.<BoundType>absent(); final EntityIDScanStatementKey key = new EntityIDScanStatementKey(table, lowerBound, upperBound, useDistinct); final PreparedStatement statement = mCache.getUnchecked(key); // Bind the parameters to the prepared statement // slots are for the min/max token final List<Object> values = Lists.newArrayListWithCapacity(2); if (tokenRange.hasLowerBound()) { values.add(tokenRange.lowerEndpoint()); } if (tokenRange.hasUpperBound()) { values.add(tokenRange.upperEndpoint()); } return statement.bind(values.toArray()).setFetchSize(ENTITY_ID_BATCH_SIZE); }
From source file:org.apache.kylin.common.util.RangeUtil.java
/** * remove from self the elements that exist in other * @return// w ww .j a va 2 s . co m */ public static <C extends Comparable<?>> List<Range<C>> remove(Range<C> self, Range<C> other) { // mimic the following logic in guava 18: // RangeSet<C> rangeSet = TreeRangeSet.create(); // rangeSet.add(self); // rangeSet.remove(other); // return Lists.newArrayList(rangeSet.asRanges()); if (other == null || !self.isConnected(other)) { return Collections.singletonList(self); } Range<C> share = self.intersection(other); if (share.isEmpty()) { return Collections.singletonList(self); } List<Range<C>> ret = Lists.newArrayList(); //see left part if (!self.hasLowerBound()) { if (share.hasLowerBound()) { if (share.lowerBoundType() == BoundType.CLOSED) { ret.add(Range.lessThan(share.lowerEndpoint())); } else { ret.add(Range.atMost(share.lowerEndpoint())); } } } else { if (self.lowerEndpoint() != share.lowerEndpoint()) { if (self.lowerBoundType() == BoundType.CLOSED) { if (share.lowerBoundType() == BoundType.CLOSED) { ret.add(Range.closedOpen(self.lowerEndpoint(), share.lowerEndpoint())); } else { ret.add(Range.closed(self.lowerEndpoint(), share.lowerEndpoint())); } } else { if (share.lowerBoundType() == BoundType.CLOSED) { ret.add(Range.open(self.lowerEndpoint(), share.lowerEndpoint())); } else { ret.add(Range.openClosed(self.lowerEndpoint(), share.lowerEndpoint())); } } } else { if (self.lowerBoundType() == BoundType.CLOSED && share.lowerBoundType() == BoundType.OPEN) { ret.add(Range.closed(self.lowerEndpoint(), share.lowerEndpoint())); } } } //see right part if (!self.hasUpperBound()) { if (share.hasUpperBound()) { if (share.upperBoundType() == BoundType.CLOSED) { ret.add(Range.greaterThan(share.upperEndpoint())); } else { ret.add(Range.atLeast(share.upperEndpoint())); } } } else { if (self.upperEndpoint() != share.upperEndpoint()) { if (self.upperBoundType() == BoundType.CLOSED) { if (share.upperBoundType() == BoundType.CLOSED) { ret.add(Range.openClosed(share.upperEndpoint(), self.upperEndpoint())); } else { ret.add(Range.closed(share.upperEndpoint(), self.upperEndpoint())); } } else { if (share.upperBoundType() == BoundType.CLOSED) { ret.add(Range.open(share.upperEndpoint(), self.upperEndpoint())); } else { ret.add(Range.closedOpen(share.upperEndpoint(), self.upperEndpoint())); } } } else { if (self.upperBoundType() == BoundType.CLOSED && share.upperBoundType() == BoundType.OPEN) { ret.add(Range.closed(self.upperEndpoint(), share.upperEndpoint())); } } } return ret; }
From source file:org.pshdl.model.extensions.RangeExtension.java
protected Optional<Range<BigInteger>> _determineRange(final HDLArithOp obj, final HDLEvaluationContext context) { HDLExpression _left = obj.getLeft(); final Optional<Range<BigInteger>> leftRange = this.determineRange(_left, context); boolean _isPresent = leftRange.isPresent(); boolean _not = (!_isPresent); if (_not) {/*from w w w . j av a2 s . c o m*/ return Optional.<Range<BigInteger>>absent(); } final Range<BigInteger> lrVal = leftRange.get(); boolean _or = false; boolean _hasLowerBound = lrVal.hasLowerBound(); boolean _not_1 = (!_hasLowerBound); if (_not_1) { _or = true; } else { boolean _hasUpperBound = lrVal.hasUpperBound(); boolean _not_2 = (!_hasUpperBound); _or = _not_2; } if (_or) { return Optional.<Range<BigInteger>>absent(); } HDLExpression _right = obj.getRight(); final Optional<Range<BigInteger>> rightRange = this.determineRange(_right, context); boolean _isPresent_1 = rightRange.isPresent(); boolean _not_3 = (!_isPresent_1); if (_not_3) { return Optional.<Range<BigInteger>>absent(); } final Range<BigInteger> rrVal = rightRange.get(); boolean _or_1 = false; boolean _hasLowerBound_1 = rrVal.hasLowerBound(); boolean _not_4 = (!_hasLowerBound_1); if (_not_4) { _or_1 = true; } else { boolean _hasUpperBound_1 = rrVal.hasUpperBound(); boolean _not_5 = (!_hasUpperBound_1); _or_1 = _not_5; } if (_or_1) { return Optional.<Range<BigInteger>>absent(); } HDLArithOp.HDLArithOpType _type = obj.getType(); if (_type != null) { switch (_type) { case PLUS: BigInteger _lowerEndpoint = lrVal.lowerEndpoint(); BigInteger _lowerEndpoint_1 = rrVal.lowerEndpoint(); BigInteger _add = _lowerEndpoint.add(_lowerEndpoint_1); BigInteger _upperEndpoint = lrVal.upperEndpoint(); BigInteger _upperEndpoint_1 = rrVal.upperEndpoint(); BigInteger _add_1 = _upperEndpoint.add(_upperEndpoint_1); Range<BigInteger> _createRange = RangeTool.<BigInteger>createRange(_add, _add_1); return Optional.<Range<BigInteger>>of(_createRange); case MINUS: BigInteger _lowerEndpoint_2 = lrVal.lowerEndpoint(); BigInteger _lowerEndpoint_3 = rrVal.lowerEndpoint(); BigInteger _subtract = _lowerEndpoint_2.subtract(_lowerEndpoint_3); BigInteger _upperEndpoint_2 = lrVal.upperEndpoint(); BigInteger _upperEndpoint_3 = rrVal.upperEndpoint(); BigInteger _subtract_1 = _upperEndpoint_2.subtract(_upperEndpoint_3); Range<BigInteger> _createRange_1 = RangeTool.<BigInteger>createRange(_subtract, _subtract_1); return Optional.<Range<BigInteger>>of(_createRange_1); case DIV: boolean _or_2 = false; BigInteger _lowerEndpoint_4 = rrVal.lowerEndpoint(); boolean _equals = _lowerEndpoint_4.equals(BigInteger.ZERO); if (_equals) { _or_2 = true; } else { BigInteger _upperEndpoint_4 = rrVal.upperEndpoint(); boolean _equals_1 = _upperEndpoint_4.equals(BigInteger.ZERO); _or_2 = _equals_1; } if (_or_2) { obj.<IHDLObject>addMeta(ProblemDescription.SOURCE, obj); obj.<ProblemDescription>addMeta(ProblemDescription.DESCRIPTION, ProblemDescription.ZERO_DIVIDE); return Optional.<Range<BigInteger>>absent(); } boolean _or_3 = false; BigInteger _lowerEndpoint_5 = rrVal.lowerEndpoint(); int _signum = _lowerEndpoint_5.signum(); BigInteger _upperEndpoint_5 = rrVal.upperEndpoint(); int _signum_1 = _upperEndpoint_5.signum(); int _multiply = (_signum * _signum_1); boolean _lessThan = (_multiply < 0); if (_lessThan) { _or_3 = true; } else { BigInteger _upperEndpoint_6 = rrVal.upperEndpoint(); int _signum_2 = _upperEndpoint_6.signum(); boolean _equals_2 = (_signum_2 == 0); _or_3 = _equals_2; } if (_or_3) { obj.<IHDLObject>addMeta(ProblemDescription.SOURCE, obj); obj.<ProblemDescription>addMeta(ProblemDescription.DESCRIPTION, ProblemDescription.POSSIBLY_ZERO_DIVIDE); } BigInteger _lowerEndpoint_6 = rrVal.lowerEndpoint(); BigDecimal _bigDecimal = new BigDecimal(_lowerEndpoint_6); BigDecimal _divide = BigDecimal.ONE.divide(_bigDecimal); BigInteger _upperEndpoint_7 = rrVal.upperEndpoint(); BigDecimal _bigDecimal_1 = new BigDecimal(_upperEndpoint_7); BigDecimal _divide_1 = BigDecimal.ONE.divide(_bigDecimal_1); final Range<BigDecimal> mulRange = RangeTool.<BigDecimal>createRange(_divide, _divide_1); BigInteger _lowerEndpoint_7 = lrVal.lowerEndpoint(); BigDecimal _bigDecimal_2 = new BigDecimal(_lowerEndpoint_7); BigDecimal _lowerEndpoint_8 = mulRange.lowerEndpoint(); final BigDecimal ff = _bigDecimal_2.multiply(_lowerEndpoint_8); BigInteger _lowerEndpoint_9 = lrVal.lowerEndpoint(); BigDecimal _bigDecimal_3 = new BigDecimal(_lowerEndpoint_9); BigDecimal _upperEndpoint_8 = mulRange.upperEndpoint(); final BigDecimal ft = _bigDecimal_3.multiply(_upperEndpoint_8); BigInteger _upperEndpoint_9 = lrVal.upperEndpoint(); BigDecimal _bigDecimal_4 = new BigDecimal(_upperEndpoint_9); BigDecimal _lowerEndpoint_10 = mulRange.lowerEndpoint(); final BigDecimal tf = _bigDecimal_4.multiply(_lowerEndpoint_10); BigInteger _upperEndpoint_10 = lrVal.upperEndpoint(); BigDecimal _bigDecimal_5 = new BigDecimal(_upperEndpoint_10); BigDecimal _upperEndpoint_11 = mulRange.upperEndpoint(); final BigDecimal tt = _bigDecimal_5.multiply(_upperEndpoint_11); BigDecimal _min = ff.min(ft); BigDecimal _min_1 = _min.min(tf); BigDecimal _min_2 = _min_1.min(tt); BigInteger _bigInteger = _min_2.toBigInteger(); BigDecimal _max = ff.max(ft); BigDecimal _max_1 = _max.max(tf); BigDecimal _max_2 = _max_1.max(tt); BigInteger _bigInteger_1 = _max_2.toBigInteger(); Range<BigInteger> _createRange_2 = RangeTool.<BigInteger>createRange(_bigInteger, _bigInteger_1); return Optional.<Range<BigInteger>>of(_createRange_2); case MUL: BigInteger _lowerEndpoint_11 = lrVal.lowerEndpoint(); BigInteger _lowerEndpoint_12 = rrVal.lowerEndpoint(); final BigInteger ff_1 = _lowerEndpoint_11.multiply(_lowerEndpoint_12); BigInteger _lowerEndpoint_13 = lrVal.lowerEndpoint(); BigInteger _upperEndpoint_12 = rrVal.upperEndpoint(); final BigInteger ft_1 = _lowerEndpoint_13.multiply(_upperEndpoint_12); BigInteger _upperEndpoint_13 = lrVal.upperEndpoint(); BigInteger _lowerEndpoint_14 = rrVal.lowerEndpoint(); final BigInteger tf_1 = _upperEndpoint_13.multiply(_lowerEndpoint_14); BigInteger _upperEndpoint_14 = lrVal.upperEndpoint(); BigInteger _upperEndpoint_15 = rrVal.upperEndpoint(); final BigInteger tt_1 = _upperEndpoint_14.multiply(_upperEndpoint_15); BigInteger _min_3 = ff_1.min(ft_1); BigInteger _min_4 = _min_3.min(tf_1); BigInteger _min_5 = _min_4.min(tt_1); BigInteger _max_3 = ff_1.max(ft_1); BigInteger _max_4 = _max_3.max(tf_1); BigInteger _max_5 = _max_4.max(tt_1); Range<BigInteger> _createRange_3 = RangeTool.<BigInteger>createRange(_min_5, _max_5); return Optional.<Range<BigInteger>>of(_createRange_3); case MOD: final BigInteger rle = rrVal.lowerEndpoint(); final BigInteger leftBound = rle.min(BigInteger.ZERO); BigInteger _upperEndpoint_16 = rrVal.upperEndpoint(); final BigInteger rue = _upperEndpoint_16.subtract(BigInteger.ONE); final BigInteger rightBound = rue.max(BigInteger.ZERO); Range<BigInteger> _createRange_4 = RangeTool.<BigInteger>createRange(leftBound, rightBound); return Optional.<Range<BigInteger>>of(_createRange_4); case POW: BigInteger _lowerEndpoint_15 = lrVal.lowerEndpoint(); BigInteger _lowerEndpoint_16 = rrVal.lowerEndpoint(); int _intValue = _lowerEndpoint_16.intValue(); final BigInteger ff_2 = _lowerEndpoint_15.pow(_intValue); BigInteger _lowerEndpoint_17 = lrVal.lowerEndpoint(); BigInteger _upperEndpoint_17 = rrVal.upperEndpoint(); int _intValue_1 = _upperEndpoint_17.intValue(); final BigInteger ft_2 = _lowerEndpoint_17.pow(_intValue_1); BigInteger _upperEndpoint_18 = lrVal.upperEndpoint(); BigInteger _lowerEndpoint_18 = rrVal.lowerEndpoint(); int _intValue_2 = _lowerEndpoint_18.intValue(); final BigInteger tf_2 = _upperEndpoint_18.pow(_intValue_2); BigInteger _upperEndpoint_19 = lrVal.upperEndpoint(); BigInteger _upperEndpoint_20 = rrVal.upperEndpoint(); int _intValue_3 = _upperEndpoint_20.intValue(); final BigInteger tt_2 = _upperEndpoint_19.pow(_intValue_3); BigInteger _min_6 = ff_2.min(ft_2); BigInteger _min_7 = _min_6.min(tf_2); BigInteger _min_8 = _min_7.min(tt_2); BigInteger _max_6 = ff_2.max(ft_2); BigInteger _max_7 = _max_6.max(tf_2); BigInteger _max_8 = _max_7.max(tt_2); Range<BigInteger> _createRange_5 = RangeTool.<BigInteger>createRange(_min_8, _max_8); return Optional.<Range<BigInteger>>of(_createRange_5); default: break; } } throw new RuntimeException("Incorrectly implemented obj op"); }
From source file:com.pingcap.tikv.predicates.ScanBuilder.java
private List<KeyRange> buildIndexScanKeyRange(TiTableInfo table, TiIndexInfo index, List<IndexRange> indexRanges) { requireNonNull(table, "Table cannot be null to encoding keyRange"); requireNonNull(index, "Index cannot be null to encoding keyRange"); requireNonNull(index, "indexRanges cannot be null to encoding keyRange"); List<KeyRange> ranges = new ArrayList<>(indexRanges.size()); for (IndexRange ir : indexRanges) { CodecDataOutput cdo = new CodecDataOutput(); List<Object> values = ir.getAccessPoints(); List<DataType> types = ir.getTypes(); for (int i = 0; i < values.size(); i++) { Object v = values.get(i); DataType t = types.get(i);/* www .j a va 2 s . c o m*/ t.encode(cdo, DataType.EncodeType.KEY, v); } byte[] pointsData = cdo.toBytes(); cdo.reset(); Range r = ir.getRange(); byte[] lPointKey; byte[] uPointKey; byte[] lKey; byte[] uKey; if (r == null) { lPointKey = pointsData; uPointKey = KeyUtils.prefixNext(lPointKey.clone()); lKey = new byte[0]; uKey = new byte[0]; } else { lPointKey = pointsData; uPointKey = pointsData; DataType type = ir.getRangeType(); if (!r.hasLowerBound()) { // -INF type.encodeMinValue(cdo); lKey = cdo.toBytes(); } else { Object lb = r.lowerEndpoint(); type.encode(cdo, DataType.EncodeType.KEY, lb); lKey = cdo.toBytes(); if (r.lowerBoundType().equals(BoundType.OPEN)) { lKey = KeyUtils.prefixNext(lKey); } } cdo.reset(); if (!r.hasUpperBound()) { // INF type.encodeMaxValue(cdo); uKey = cdo.toBytes(); } else { Object ub = r.upperEndpoint(); type.encode(cdo, DataType.EncodeType.KEY, ub); uKey = cdo.toBytes(); if (r.upperBoundType().equals(BoundType.CLOSED)) { uKey = KeyUtils.prefixNext(lKey); } } cdo.reset(); } TableCodec.writeIndexSeekKey(cdo, table.getId(), index.getId(), lPointKey, lKey); ByteString lbsKey = ByteString.copyFrom(cdo.toBytes()); cdo.reset(); TableCodec.writeIndexSeekKey(cdo, table.getId(), index.getId(), uPointKey, uKey); ByteString ubsKey = ByteString.copyFrom(cdo.toBytes()); ranges.add(KeyRange.newBuilder().setStart(lbsKey).setEnd(ubsKey).build()); } if (ranges.isEmpty()) { ranges.add(INDEX_FULL_RANGE); } return ranges; }
From source file:com.pingcap.tikv.predicates.ScanBuilder.java
private List<KeyRange> buildTableScanKeyRange(TiTableInfo table, List<IndexRange> indexRanges) { requireNonNull(table, "Table cannot be null to encoding keyRange"); requireNonNull(indexRanges, "indexRanges cannot be null to encoding keyRange"); List<KeyRange> ranges = new ArrayList<>(indexRanges.size()); for (IndexRange ir : indexRanges) { ByteString startKey;//from w w w. j a v a 2 s . co m ByteString endKey; if (ir.hasAccessPoints()) { checkArgument(!ir.hasRange(), "Table scan must have one and only one access condition / point"); Object v = ir.getAccessPoints().get(0); checkArgument(v instanceof Long, "Table scan key range must be long value"); DataType type = ir.getTypes().get(0); checkArgument(type instanceof IntegerType, "Table scan key range must be long value"); startKey = TableCodec.encodeRowKeyWithHandle(table.getId(), (long) v); endKey = ByteString.copyFrom(KeyUtils.prefixNext(startKey.toByteArray())); } else if (ir.hasRange()) { checkArgument(!ir.hasAccessPoints(), "Table scan must have one and only one access condition / point"); Range r = ir.getRange(); DataType type = ir.getRangeType(); checkArgument(type instanceof IntegerType, "Table scan key range must be long value"); if (!r.hasLowerBound()) { // -INF // TODO: Domain and encoding should be further encapsulated startKey = TableCodec.encodeRowKeyWithHandle(table.getId(), Long.MIN_VALUE); } else { // Comparision with null should be filtered since it yields unknown always Object lb = r.lowerEndpoint(); checkArgument(lb instanceof Long, "Table scan key range must be long value"); long lVal = (long) lb; if (r.lowerBoundType().equals(BoundType.OPEN)) { // TODO: Need push back? if (lVal != Long.MAX_VALUE) { lVal++; } } startKey = TableCodec.encodeRowKeyWithHandle(table.getId(), lVal); } if (!r.hasUpperBound()) { // INF endKey = TableCodec.encodeRowKeyWithHandle(table.getId(), Long.MAX_VALUE); } else { Object ub = r.upperEndpoint(); checkArgument(ub instanceof Long, "Table scan key range must be long value"); long lVal = (long) ub; if (r.upperBoundType().equals(BoundType.CLOSED)) { if (lVal != Long.MAX_VALUE) { lVal++; } } endKey = TableCodec.encodeRowKeyWithHandle(table.getId(), lVal); } } else { throw new TiClientInternalException("Empty access conditions"); } ranges.add(KeyRange.newBuilder().setStart(startKey).setEnd(endKey).build()); } if (ranges.isEmpty()) { ByteString startKey = TableCodec.encodeRowKeyWithHandle(table.getId(), Long.MIN_VALUE); ByteString endKey = TableCodec.encodeRowKeyWithHandle(table.getId(), Long.MAX_VALUE); ranges.add(KeyRange.newBuilder().setStart(startKey).setEnd(endKey).build()); } return ranges; }
From source file:org.apache.calcite.rex.RexSimplify.java
private static RexNode processRange(RexBuilder rexBuilder, List<RexNode> terms, Map<String, Pair<Range, List<RexNode>>> rangeTerms, RexNode term, RexNode ref, RexLiteral constant, SqlKind comparison) {/*from www. j a v a 2 s . c o m*/ final Comparable v0 = constant.getValue(); Pair<Range, List<RexNode>> p = rangeTerms.get(ref.toString()); if (p == null) { Range r; switch (comparison) { case EQUALS: r = Range.singleton(v0); break; case LESS_THAN: r = Range.lessThan(v0); break; case LESS_THAN_OR_EQUAL: r = Range.atMost(v0); break; case GREATER_THAN: r = Range.greaterThan(v0); break; case GREATER_THAN_OR_EQUAL: r = Range.atLeast(v0); break; default: throw new AssertionError(); } rangeTerms.put(ref.toString(), new Pair(r, ImmutableList.of(term))); } else { // Exists boolean removeUpperBound = false; boolean removeLowerBound = false; Range r = p.left; switch (comparison) { case EQUALS: if (!r.contains(v0)) { // Range is empty, not satisfiable return rexBuilder.makeLiteral(false); } rangeTerms.put(ref.toString(), new Pair(Range.singleton(v0), ImmutableList.of(term))); // remove terms.removeAll(p.right); break; case LESS_THAN: { int comparisonResult = 0; if (r.hasUpperBound()) { comparisonResult = v0.compareTo(r.upperEndpoint()); } if (comparisonResult <= 0) { // 1) No upper bound, or // 2) We need to open the upper bound, or // 3) New upper bound is lower than old upper bound if (r.hasLowerBound()) { if (v0.compareTo(r.lowerEndpoint()) < 0) { // Range is empty, not satisfiable return rexBuilder.makeLiteral(false); } // a <= x < b OR a < x < b r = Range.range(r.lowerEndpoint(), r.lowerBoundType(), v0, BoundType.OPEN); } else { // x < b r = Range.lessThan(v0); } if (r.isEmpty()) { // Range is empty, not satisfiable return rexBuilder.makeLiteral(false); } // remove prev upper bound removeUpperBound = true; } else { // Remove this term as it is contained in current upper bound terms.remove(term); } break; } case LESS_THAN_OR_EQUAL: { int comparisonResult = -1; if (r.hasUpperBound()) { comparisonResult = v0.compareTo(r.upperEndpoint()); } if (comparisonResult < 0) { // 1) No upper bound, or // 2) New upper bound is lower than old upper bound if (r.hasLowerBound()) { if (v0.compareTo(r.lowerEndpoint()) < 0) { // Range is empty, not satisfiable return rexBuilder.makeLiteral(false); } // a <= x <= b OR a < x <= b r = Range.range(r.lowerEndpoint(), r.lowerBoundType(), v0, BoundType.CLOSED); } else { // x <= b r = Range.atMost(v0); } if (r.isEmpty()) { // Range is empty, not satisfiable return rexBuilder.makeLiteral(false); } // remove prev upper bound removeUpperBound = true; } else { // Remove this term as it is contained in current upper bound terms.remove(term); } break; } case GREATER_THAN: { int comparisonResult = 0; if (r.hasLowerBound()) { comparisonResult = v0.compareTo(r.lowerEndpoint()); } if (comparisonResult >= 0) { // 1) No lower bound, or // 2) We need to open the lower bound, or // 3) New lower bound is greater than old lower bound if (r.hasUpperBound()) { if (v0.compareTo(r.upperEndpoint()) > 0) { // Range is empty, not satisfiable return rexBuilder.makeLiteral(false); } // a < x <= b OR a < x < b r = Range.range(v0, BoundType.OPEN, r.upperEndpoint(), r.upperBoundType()); } else { // x > a r = Range.greaterThan(v0); } if (r.isEmpty()) { // Range is empty, not satisfiable return rexBuilder.makeLiteral(false); } // remove prev lower bound removeLowerBound = true; } else { // Remove this term as it is contained in current lower bound terms.remove(term); } break; } case GREATER_THAN_OR_EQUAL: { int comparisonResult = 1; if (r.hasLowerBound()) { comparisonResult = v0.compareTo(r.lowerEndpoint()); } if (comparisonResult > 0) { // 1) No lower bound, or // 2) New lower bound is greater than old lower bound if (r.hasUpperBound()) { if (v0.compareTo(r.upperEndpoint()) > 0) { // Range is empty, not satisfiable return rexBuilder.makeLiteral(false); } // a <= x <= b OR a <= x < b r = Range.range(v0, BoundType.CLOSED, r.upperEndpoint(), r.upperBoundType()); } else { // x >= a r = Range.atLeast(v0); } if (r.isEmpty()) { // Range is empty, not satisfiable return rexBuilder.makeLiteral(false); } // remove prev lower bound removeLowerBound = true; } else { // Remove this term as it is contained in current lower bound terms.remove(term); } break; } default: throw new AssertionError(); } if (removeUpperBound) { ImmutableList.Builder<RexNode> newBounds = ImmutableList.builder(); for (RexNode e : p.right) { if (e.isA(SqlKind.LESS_THAN) || e.isA(SqlKind.LESS_THAN_OR_EQUAL)) { terms.remove(e); } else { newBounds.add(e); } } newBounds.add(term); rangeTerms.put(ref.toString(), new Pair(r, newBounds.build())); } else if (removeLowerBound) { ImmutableList.Builder<RexNode> newBounds = ImmutableList.builder(); for (RexNode e : p.right) { if (e.isA(SqlKind.GREATER_THAN) || e.isA(SqlKind.GREATER_THAN_OR_EQUAL)) { terms.remove(e); } else { newBounds.add(e); } } newBounds.add(term); rangeTerms.put(ref.toString(), new Pair(r, newBounds.build())); } } // Default return null; }
From source file:org.apache.kylin.storage.hbase.ii.coprocessor.endpoint.IIEndpoint.java
private Scan prepareScan(IIProtos.IIRequest request, HRegion region) throws IOException { Scan scan = new Scan(); scan.addColumn(IIDesc.HBASE_FAMILY_BYTES, IIDesc.HBASE_QUALIFIER_BYTES); scan.addColumn(IIDesc.HBASE_FAMILY_BYTES, IIDesc.HBASE_DICTIONARY_BYTES); if (request.hasTsRange()) { Range<Long> tsRange = (Range<Long>) SerializationUtils .deserialize(HBaseZeroCopyByteString.zeroCopyGetBytes(request.getTsRange())); byte[] regionStartKey = region.getStartKey(); if (!ArrayUtils.isEmpty(regionStartKey)) { shard = BytesUtil.readUnsigned(regionStartKey, 0, IIKeyValueCodec.SHARD_LEN); } else {//from w ww. j a va2 s. com shard = 0; } logger.info("Start key of the region is: " + BytesUtil.toReadableText(regionStartKey) + ", making shard to be :" + shard); if (tsRange.hasLowerBound()) { //differentiate GT and GTE seems not very beneficial Preconditions.checkArgument(shard != -1, "Shard is -1!"); long tsStart = tsRange.lowerEndpoint(); logger.info("ts start is " + tsStart); byte[] idealStartKey = new byte[IIKeyValueCodec.SHARD_LEN + IIKeyValueCodec.TIMEPART_LEN]; BytesUtil.writeUnsigned(shard, idealStartKey, 0, IIKeyValueCodec.SHARD_LEN); BytesUtil.writeLong(tsStart, idealStartKey, IIKeyValueCodec.SHARD_LEN, IIKeyValueCodec.TIMEPART_LEN); logger.info("ideaStartKey is(readable) :" + BytesUtil.toReadableText(idealStartKey)); Result result = region.getClosestRowBefore(idealStartKey, IIDesc.HBASE_FAMILY_BYTES); if (result != null) { byte[] actualStartKey = Arrays.copyOf(result.getRow(), IIKeyValueCodec.SHARD_LEN + IIKeyValueCodec.TIMEPART_LEN); scan.setStartRow(actualStartKey); logger.info("The start key is set to " + BytesUtil.toReadableText(actualStartKey)); } else { logger.info("There is no key before ideaStartKey so ignore tsStart"); } } if (tsRange.hasUpperBound()) { //differentiate LT and LTE seems not very beneficial Preconditions.checkArgument(shard != -1, "Shard is -1"); long tsEnd = tsRange.upperEndpoint(); logger.info("ts end is " + tsEnd); byte[] actualEndKey = new byte[IIKeyValueCodec.SHARD_LEN + IIKeyValueCodec.TIMEPART_LEN]; BytesUtil.writeUnsigned(shard, actualEndKey, 0, IIKeyValueCodec.SHARD_LEN); BytesUtil.writeLong(tsEnd + 1, actualEndKey, IIKeyValueCodec.SHARD_LEN, IIKeyValueCodec.TIMEPART_LEN);//notice +1 here scan.setStopRow(actualEndKey); logger.info("The stop key is set to " + BytesUtil.toReadableText(actualEndKey)); } } return scan; }
From source file:net.sourceforge.ganttproject.task.algorithm.SchedulerImpl.java
private void schedule(Node node) { Logger logger = GPLogger.getLogger(this); GPLogger.debug(logger, "Scheduling node %s", node); Range<Date> startRange = Range.all(); Range<Date> endRange = Range.all(); Range<Date> weakStartRange = Range.all(); Range<Date> weakEndRange = Range.all(); List<Date> subtaskRanges = Lists.newArrayList(); List<DependencyEdge> incoming = node.getIncoming(); GPLogger.debug(logger, ".. #incoming edges=%d", incoming.size()); for (DependencyEdge edge : incoming) { if (!edge.refresh()) { continue; }/*from w w w .ja v a 2s . c om*/ if (edge instanceof ImplicitSubSuperTaskDependency) { subtaskRanges.add(edge.getStartRange().upperEndpoint()); subtaskRanges.add(edge.getEndRange().lowerEndpoint()); } else { if (edge.isWeak()) { weakStartRange = weakStartRange.intersection(edge.getStartRange()); weakEndRange = weakEndRange.intersection(edge.getEndRange()); } else { startRange = startRange.intersection(edge.getStartRange()); endRange = endRange.intersection(edge.getEndRange()); } } if (startRange.isEmpty() || endRange.isEmpty()) { GPLogger.logToLogger("both start and end ranges were calculated as empty for task=" + node.getTask() + ". Skipping it"); } } GPLogger.debug(logger, "..Ranges: start=%s end=%s weakStart=%s weakEnd=%s", startRange, endRange, weakStartRange, weakEndRange); Range<Date> subtasksSpan = subtaskRanges.isEmpty() ? Range.closed(node.getTask().getStart().getTime(), node.getTask().getEnd().getTime()) : Range.encloseAll(subtaskRanges); Range<Date> subtreeStartUpwards = subtasksSpan .span(Range.downTo(node.getTask().getStart().getTime(), BoundType.CLOSED)); Range<Date> subtreeEndDownwards = subtasksSpan .span(Range.upTo(node.getTask().getEnd().getTime(), BoundType.CLOSED)); GPLogger.debug(logger, "..Subtasks span=%s", subtasksSpan); if (!startRange.equals(Range.all())) { startRange = startRange.intersection(weakStartRange); } else if (!weakStartRange.equals(Range.all())) { startRange = weakStartRange.intersection(subtreeStartUpwards); } if (!endRange.equals(Range.all())) { endRange = endRange.intersection(weakEndRange); } else if (!weakEndRange.equals(Range.all())) { endRange = weakEndRange.intersection(subtreeEndDownwards); } if (node.getTask().getThirdDateConstraint() == TaskImpl.EARLIESTBEGIN && node.getTask().getThird() != null) { startRange = startRange .intersection(Range.downTo(node.getTask().getThird().getTime(), BoundType.CLOSED)); GPLogger.debug(logger, ".. applying earliest start=%s. Now start range=%s", node.getTask().getThird(), startRange); } if (!subtaskRanges.isEmpty()) { startRange = startRange.intersection(subtasksSpan); endRange = endRange.intersection(subtasksSpan); } GPLogger.debug(logger, ".. finally, start range=%s", startRange); if (startRange.hasLowerBound()) { modifyTaskStart(node.getTask(), startRange.lowerEndpoint()); } if (endRange.hasUpperBound()) { GPCalendarCalc cal = node.getTask().getManager().getCalendar(); Date endDate = endRange.upperEndpoint(); TimeUnit timeUnit = node.getTask().getDuration().getTimeUnit(); if (DayMask.WORKING == (cal.getDayMask(endDate) & DayMask.WORKING)) { // in case if calculated end date falls on first day after holidays (say, on Monday) // we'll want to modify it a little bit, so that it falls on that holidays start // If we don't do this, it will be done automatically the next time task activities are recalculated, // and thus task end date will keep changing Date closestWorkingEndDate = cal.findClosest(endDate, timeUnit, GPCalendarCalc.MoveDirection.BACKWARD, GPCalendar.DayType.WORKING); Date closestNonWorkingEndDate = cal.findClosest(endDate, timeUnit, GPCalendarCalc.MoveDirection.BACKWARD, GPCalendar.DayType.NON_WORKING, closestWorkingEndDate); // If there is a non-working date between current task end and closest working date // then we're really just after holidays if (closestNonWorkingEndDate != null && closestWorkingEndDate.before(closestNonWorkingEndDate)) { // we need to adjust-right closest working date to position to the very beginning of the holidays interval Date nonWorkingPeriodStart = timeUnit.adjustRight(closestWorkingEndDate); if (nonWorkingPeriodStart.after(node.getTask().getStart().getTime())) { endDate = nonWorkingPeriodStart; } } } modifyTaskEnd(node.getTask(), endDate); } }