Examples of KeyRange


Examples of org.apache.phoenix.query.KeyRange

            KeySlots childSlots = childParts.get(0);
            KeySlot childSlot = childSlots.iterator().next();
            KeyPart childPart = childSlot.getKeyPart();
            SortOrder sortOrder = childPart.getColumn().getSortOrder();
            CompareOp op = sortOrder.transform(node.getFilterOp());
            KeyRange keyRange = childPart.getKeyRange(op, rhs);
            return newKeyParts(childSlot, node, keyRange);
        }
View Full Code Here

Examples of org.apache.phoenix.query.KeyRange

            Integer columnFixedLength = column.getMaxLength();
            if (type.isFixedWidth() && columnFixedLength != null) {
                lowerRange = StringUtil.padChar(lowerRange, columnFixedLength);
                upperRange = StringUtil.padChar(upperRange, columnFixedLength);
            }
            KeyRange keyRange = type.getKeyRange(lowerRange, true, upperRange, false);
            // Only extract LIKE expression if pattern ends with a wildcard and everything else was extracted
            return newKeyParts(childSlot, node.endsWithOnlyWildcard() ? node : null, keyRange);
        }
View Full Code Here

Examples of org.apache.phoenix.query.KeyRange

            Set<KeyRange> ranges = Sets.newHashSetWithExpectedSize(keyExpressions.size());
            KeySlot childSlot = childParts.get(0).iterator().next();
            KeyPart childPart = childSlot.getKeyPart();
            // Handles cases like WHERE substr(foo,1,3) IN ('aaa','bbb')
            for (Expression key : keyExpressions) {
                KeyRange range = childPart.getKeyRange(CompareOp.EQUAL, key);
                if (range != KeyRange.EMPTY_RANGE) { // null means it can't possibly be in range
                    ranges.add(range);
                }
            }
            return newKeyParts(childSlot, node, new ArrayList<KeyRange>(ranges), null);
View Full Code Here

Examples of org.apache.phoenix.query.KeyRange

            if (isFixedWidth) { // if column can't be null
                return node.isNegate() ? null :
                    newKeyParts(childSlot, node, type.getKeyRange(new byte[SchemaUtil.getFixedByteSize(column)], true,
                                                                  KeyRange.UNBOUND, true));
            } else {
                KeyRange keyRange = node.isNegate() ? KeyRange.IS_NOT_NULL_RANGE : KeyRange.IS_NULL_RANGE;
                return newKeyParts(childSlot, node, keyRange);
            }
        }
View Full Code Here

Examples of org.apache.phoenix.query.KeyRange

                                    }
                                    if (ptr.getLength() == 0) {
                                        ptr.set(ByteUtil.EMPTY_BYTE_ARRAY);
                                        return true;
                                    }
                                    KeyRange range = childPart.getKeyRange(rvcElementOp, rhs);
                                    // This can happen when an EQUAL operator is used and the expression cannot possibly match.
                                    if (range == KeyRange.EMPTY_RANGE) {
                                        return false;
                                    }
                                    // We have to take the range and condense it down to a single key. We use which ever
                                    // part of the range is inclusive (which implies being bound as well). This works in all
                                    // cases, including this substring one, which produces a lower inclusive range and an
                                    // upper non inclusive range.
                                    // (a, substr(b,1,1)) IN (('a','b'), ('c','d'))
                                    byte[] key = range.isLowerInclusive() ? range.getLowerRange() : range.getUpperRange();
                                    // FIXME: this is kind of a hack. The above call will fill a fixed width key, but
                                    // we don't want to fill the key yet because it can throw off our the logic we
                                    // use to compute the next key when we evaluate the RHS row value constructor
                                    // below.  We could create a new childPart with a delegate column that returns
                                    // null for getByteSize().
View Full Code Here

Examples of org.apache.phoenix.query.KeyRange

        int[] slotSpan = new int[nPKColumns];
        List<Expression> removeFromExtractNodes = null;
        Integer nBuckets = table.getBucketNum();
        RowKeySchema schema = table.getRowKeySchema();
        List<List<KeyRange>> cnf = Lists.newArrayListWithExpectedSize(schema.getMaxFields());
        KeyRange minMaxRange = keySlots.getMinMaxRange();
        boolean hasMinMaxRange = (minMaxRange != null);
        int minMaxRangeOffset = 0;
        byte[] minMaxRangePrefix = null;
       
        Iterator<KeyExpressionVisitor.KeySlot> iterator = keySlots.iterator();
        // Add placeholder for salt byte ranges
        if (nBuckets != null) {
            cnf.add(SALT_PLACEHOLDER);
            // Increment the pkPos, as the salt column is in the row schema
            // Do not increment the iterator, though, as there will never be
            // an expression in the keySlots for the salt column
            pkPos++;
        }
       
        // Add tenant data isolation for tenant-specific tables
        if (tenantId != null && table.isMultiTenant()) {
            byte[] tenantIdBytes = tenantId.getBytes();
            KeyRange tenantIdKeyRange = KeyRange.getKeyRange(tenantIdBytes);
            cnf.add(singletonList(tenantIdKeyRange));
            if (hasMinMaxRange) {
                minMaxRangePrefix = new byte[tenantIdBytes.length + MetaDataUtil.getViewIndexIdDataType().getByteSize() + 1];
                System.arraycopy(tenantIdBytes, 0, minMaxRangePrefix, 0, tenantIdBytes.length);
                minMaxRangeOffset += tenantIdBytes.length;
                if (!schema.getField(pkPos).getDataType().isFixedWidth()) {
                    minMaxRangePrefix[minMaxRangeOffset] = QueryConstants.SEPARATOR_BYTE;
                    minMaxRangeOffset++;
                }
            }
            pkPos++;
        }
        // Add unique index ID for shared indexes on views. This ensures
        // that different indexes don't interleave.
        if (table.getViewIndexId() != null) {
            byte[] viewIndexBytes = MetaDataUtil.getViewIndexIdDataType().toBytes(table.getViewIndexId());
            KeyRange indexIdKeyRange = KeyRange.getKeyRange(viewIndexBytes);
            cnf.add(singletonList(indexIdKeyRange));
            if (hasMinMaxRange) {
                if (minMaxRangePrefix == null) {
                    minMaxRangePrefix = new byte[viewIndexBytes.length];
                }
                System.arraycopy(viewIndexBytes, 0, minMaxRangePrefix, minMaxRangeOffset, viewIndexBytes.length);
                minMaxRangeOffset += viewIndexBytes.length;
            }
            pkPos++;
        }
       
        // Prepend minMaxRange with fixed column values so we can properly intersect the
        // range with the other range.
        if (minMaxRange != null) {
            minMaxRange = minMaxRange.prependRange(minMaxRangePrefix, 0, minMaxRangeOffset);
        }
        boolean forcedSkipScan = statement.getHint().hasHint(Hint.SKIP_SCAN);
        boolean forcedRangeScan = statement.getHint().hasHint(Hint.RANGE_SCAN);
        boolean hasUnboundedRange = false;
        boolean hasMultiRanges = false;
        boolean hasMultiColumnSpan = false;
        boolean hasNonPointKey = false;
        boolean stopExtracting = false;
        // Concat byte arrays of literals to form scan start key
        while (iterator.hasNext()) {
            KeyExpressionVisitor.KeySlot slot = iterator.next();
            // If the position of the pk columns in the query skips any part of the row k
            // then we have to handle in the next phase through a key filter.
            // If the slot is null this means we have no entry for this pk position.
            if (slot == null || slot.getKeyRanges().isEmpty())  {
                if (!forcedSkipScan || hasMultiColumnSpan) break;
                continue;
            }
            if (slot.getPKPosition() != pkPos) {
                if (!forcedSkipScan || hasMultiColumnSpan) break;
                for (int i=pkPos; i < slot.getPKPosition(); i++) {
                    cnf.add(Collections.singletonList(KeyRange.EVERYTHING_RANGE));
                }
            }
            KeyPart keyPart = slot.getKeyPart();
            slotSpan[cnf.size()] = slot.getPKSpan() - 1;
            pkPos = slot.getPKPosition() + slot.getPKSpan();
            hasMultiColumnSpan |= slot.getPKSpan() > 1;
            // Skip span-1 slots as we skip one at the top of the loop
            for (int i = 1; i < slot.getPKSpan() && iterator.hasNext(); i++) {
                iterator.next();
            }
            List<KeyRange> keyRanges = slot.getKeyRanges();
            for (int i = 0; (!hasUnboundedRange || !hasNonPointKey) && i < keyRanges.size(); i++) {
                KeyRange range  = keyRanges.get(i);
                if (range.isUnbound()) {
                    hasUnboundedRange = hasNonPointKey = true;
                } else if (!range.isSingleKey()) {
                    hasNonPointKey = true;
                }
            }
            hasMultiRanges |= keyRanges.size() > 1;
            // Force a range scan if we've encountered a multi-span slot (i.e. RVC)
View Full Code Here

Examples of org.apache.phoenix.query.KeyRange

       
    }
   
    private void appendScanRow(StringBuilder buf, Bound bound) {
        ScanRanges scanRanges = context.getScanRanges();
        KeyRange minMaxRange = context.getMinMaxRange();
        Iterator<byte[]> minMaxIterator = Iterators.emptyIterator();
        if (minMaxRange != null) {
            RowKeySchema schema = tableRef.getTable().getRowKeySchema();
            if (!minMaxRange.isUnbound(bound)) {
                minMaxIterator = new RowKeyValueIterator(schema, minMaxRange.getRange(bound));
            }
        }
        int nRanges = scanRanges.getRanges().size();
        for (int i = 0, minPos = 0; minPos < nRanges || minMaxIterator.hasNext(); i++) {
            List<KeyRange> ranges = minPos >= nRanges ? EVERYTHING :  scanRanges.getRanges().get(minPos++);
            KeyRange range = bound == Bound.LOWER ? ranges.get(0) : ranges.get(ranges.size()-1);
            byte[] b = range.getRange(bound);
            Boolean isNull = KeyRange.IS_NULL_RANGE == range ? Boolean.TRUE : KeyRange.IS_NOT_NULL_RANGE == range ? Boolean.FALSE : null;
            if (minMaxIterator.hasNext()) {
                byte[] bMinMax = minMaxIterator.next();
                int cmp = Bytes.compareTo(bMinMax, b) * (bound == Bound.LOWER ? 1 : -1);
                if (cmp > 0) {
View Full Code Here

Examples of org.apache.phoenix.query.KeyRange

        }
    }
   
    private void appendKeyRanges(StringBuilder buf) {
        ScanRanges scanRanges = context.getScanRanges();
        KeyRange minMaxRange = context.getMinMaxRange();
        if (minMaxRange == null && (scanRanges == ScanRanges.EVERYTHING || scanRanges == ScanRanges.NOTHING)) {
            return;
        }
        buf.append(" [");
        StringBuilder buf1 = new StringBuilder();
View Full Code Here

Examples of org.apache.phoenix.query.KeyRange

            // Intersect with existing start/stop key if the table is salted
            // If not salted, we've already intersected it. If salted, we need
            // to wait until now to intersect, as we're running parallel scans
            // on all the possible regions here.
            if (tableRef.getTable().getBucketNum() != null) {
                KeyRange minMaxRange = context.getMinMaxRange();
                if (minMaxRange != null) {
                    // Add salt byte based on current split, as minMaxRange won't have it
                    minMaxRange = SaltingUtil.addSaltByte(split.getLowerRange(), minMaxRange);
                    // FIXME: seems like this should be possible when we set the scan start/stop
                    // in StatementContext.setScanRanges(). If it doesn't intersect the range for
                    // one salt byte, I don't see how it could intersect it with any of them.
                    if (!ScanUtil.intersectScanRange(splitScan, minMaxRange.getLowerRange(), minMaxRange.getUpperRange())) {
                        continue; // Skip this chunk if no intersection based on minMaxRange
                    }
                }
            }
            if (ScanUtil.intersectScanRange(splitScan, split.getLowerRange(), split.getUpperRange(), this.context.getScanRanges().useSkipScanFilter())) {
View Full Code Here

Examples of org.apache.phoenix.query.KeyRange

    public KeyPart newKeyPart(final KeyPart childPart) {
        return new KeyPart() {

            @Override
            public KeyRange getKeyRange(CompareOp op, Expression rhs) {
                KeyRange range = childPart.getKeyRange(op, rhs);
                return range.invert();
            }

            @Override
            public List<Expression> getExtractNodes() {
                return childPart.getExtractNodes();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.