Package org.apache.phoenix.schema

Examples of org.apache.phoenix.schema.RowKeySchema


    public static Object[] decodePK(Connection conn, String name, byte[] value) throws SQLException {
        PTable table = getTable(conn, name);
        PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
        int offset = (table.getBucketNum() == null ? 0 : 1) + (table.isMultiTenant() && pconn.getTenantId() != null ? 1 : 0);
        int nValues = table.getPKColumns().size() - offset;
        RowKeySchema schema = table.getRowKeySchema();
        Object[] values = new Object[nValues];
        ImmutableBytesWritable ptr = new ImmutableBytesWritable();
        schema.iterator(value, ptr);
        int i = 0;
        int fieldIdx = offset;
        while (i < nValues && schema.next(ptr, fieldIdx, value.length) != null) {
            values[i] = schema.getField(fieldIdx).getDataType().toObject(ptr);
            i++;
            fieldIdx++;
        }
        return values;
    }
View Full Code Here


        List<IndexMaintainer> maintainers = Collections.emptyList();
        try {
            int size = WritableUtils.readVInt(input);
            boolean isDataTableSalted = size < 0;
            size = Math.abs(size);
            RowKeySchema rowKeySchema = new RowKeySchema();
            rowKeySchema.readFields(input);
            maintainers = Lists.newArrayListWithExpectedSize(size);
            for (int i = 0; i < size; i++) {
                IndexMaintainer maintainer = new IndexMaintainer(rowKeySchema, isDataTableSalted);
                maintainer.readFields(input);
                maintainers.add(maintainer);
View Full Code Here

    private IndexMaintainer(PTable dataTable, PTable index) {
        this(dataTable.getRowKeySchema(), dataTable.getBucketNum() != null);
        this.isMultiTenant = dataTable.isMultiTenant();
        this.viewIndexId = index.getViewIndexId() == null ? null : MetaDataUtil.getViewIndexIdDataType().toBytes(index.getViewIndexId());

        RowKeySchema dataRowKeySchema = dataTable.getRowKeySchema();
        boolean isDataTableSalted = dataTable.getBucketNum() != null;
        byte[] indexTableName = index.getPhysicalName().getBytes();
        Integer nIndexSaltBuckets = index.getBucketNum();
        boolean indexWALDisabled = index.isWALDisabled();
        int indexPosOffset = (index.getBucketNum() == null ? 0 : 1) + (this.isMultiTenant ? 1 : 0) + (this.viewIndexId == null ? 0 : 1);
        int nIndexColumns = index.getColumns().size() - indexPosOffset;
        int nIndexPKColumns = index.getPKColumns().size() - indexPosOffset;
        this.rowKeyMetaData = newRowKeyMetaData(nIndexPKColumns);
        BitSet bitSet = this.rowKeyMetaData.getViewConstantColumnBitSet();

        int dataPosOffset = (isDataTableSalted ? 1 : 0) + (this.isMultiTenant ? 1 : 0);
        int nDataPKColumns = dataRowKeySchema.getFieldCount() - dataPosOffset;
        // For indexes on views, we need to remember which data columns are "constants"
        // These are the values in a VIEW where clause. For these, we don't put them in the
        // index, as they're the same for every row in the index.
        if (dataTable.getType() == PTableType.VIEW) {
            List<PColumn>dataPKColumns = dataTable.getPKColumns();
View Full Code Here

        return targetKey;
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        RowKeySchema schema = new RowKeySchema();
        schema.readFields(in);
        int andLen = in.readInt();
        List<List<KeyRange>> slots = Lists.newArrayListWithExpectedSize(andLen);
        for (int i=0; i<andLen; i++) {
            int orlen = in.readInt();
            List<KeyRange> orclause = Lists.newArrayListWithExpectedSize(orlen);
View Full Code Here

        return keyRanges;
    }

    public static byte[] nextKey(byte[] key, PTable table, ImmutableBytesWritable ptr) {
        int pos = 0;
        RowKeySchema schema = table.getRowKeySchema();
        int maxOffset = schema.iterator(key, ptr);
        while (schema.next(ptr, pos, maxOffset) != null) {
            pos++;
        }
        if (!schema.getField(pos-1).getDataType().isFixedWidth()) {
            byte[] newLowerRange = new byte[key.length + 1];
            System.arraycopy(key, 0, newLowerRange, 0, key.length);
            newLowerRange[key.length] = QueryConstants.SEPARATOR_BYTE;
            key = newLowerRange;
        } else {
View Full Code Here

        int pkPos = 0;
        int nPKColumns = table.getPKColumns().size();
        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++;
View Full Code Here

                } else {
                    // Assumes that only single keys occur in RVCs (i.e. when a PK spans columns)
                    assert(this.getPKSpan() > 1);
                    assert(this.getPKPosition() <= that.getPKPosition());
                    ImmutableBytesWritable ptr = context.getTempPtr();
                    RowKeySchema schema = table.getRowKeySchema();
                    if (this.getPKSpan() > 1 && that.getPKSpan() > 1) {
                        // TODO: Trickiest case: both key slots are multi-span RVCs.
                        // Punt for now: we could intersect these, but it'd be a fair amount of code.
                        // Instead, just keep the original slot and don't extract
                        // the other expressions (so they'll be evaluated row by row).
                        return this;
                    } else {
                        assert(this.getPKSpan() > 1);
                        assert(this.getPKPosition() <= that.getPKPosition());
                        int position = this.getPKPosition();
                        int thatPosition = that.getPKPosition();
                        List<KeyRange> newKeyRanges = Lists.newArrayListWithExpectedSize(this.getKeyRanges().size());
                        // We know we have a set of RVCs (i.e. multi-span key ranges)
                        // Get the PK slot value in the RVC for the position of the other KeySlot
                        // If they don't intersect, we cannot have a match for the RVC, so filter it out.
                        // Otherwise, we keep it.
                        for (KeyRange keyRange : this.getKeyRanges()) {
                            assert(keyRange.isSingleKey());
                            byte[] key = keyRange.getLowerRange();
                            schema.iterator(key, ptr); // initialize for iteration
                            while (position < thatPosition) { // skip to part of RVC that overlaps
                                schema.next(ptr, position++, key.length);
                            }
                            // Create a range just for the overlapping column
                            List<KeyRange> slotKeyRanges = Collections.singletonList(KeyRange.getKeyRange(ByteUtil.copyKeyBytesIfNecessary(ptr)));
                            // Intersect with other ranges and add to list if it overlaps
                            if (!isDegenerate(KeyRange.intersect(slotKeyRanges, that.getKeyRanges()))) {
View Full Code Here

    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();
View Full Code Here

    public static List<Mutation> generateIndexData(PTable indexTable, PTable dataTable,
            Mutation dataMutation, ImmutableBytesWritable ptr, KeyValueBuilder builder)
            throws SQLException {
        byte[] dataRowKey = dataMutation.getRow();
        RowKeySchema dataRowKeySchema = dataTable.getRowKeySchema();
        List<PColumn> dataPKColumns = dataTable.getPKColumns();
        int i = 0;
        int indexOffset = 0;
        Boolean hasValue;
        // Skip salt column
        int maxOffset = dataRowKey.length;
        dataRowKeySchema.iterator(dataRowKey, ptr, dataTable.getBucketNum() == null ? i : ++i);
        List<PColumn> indexPKColumns = indexTable.getPKColumns();
        List<PColumn> indexColumns = indexTable.getColumns();
        int nIndexColumns = indexPKColumns.size();
        int maxIndexValues = indexColumns.size() - nIndexColumns - indexOffset;
        BitSet indexValuesSet = new BitSet(maxIndexValues);
        byte[][] indexValues = new byte[indexColumns.size() - indexOffset][];
        while ((hasValue = dataRowKeySchema.next(ptr, i, maxOffset)) != null) {
            if (hasValue) {
                PColumn dataColumn = dataPKColumns.get(i);
                PColumn indexColumn = indexTable.getColumn(IndexUtil.getIndexColumnName(dataColumn));
                coerceDataValueToIndexValue(dataColumn, indexColumn, ptr);
                indexValues[indexColumn.getPosition()-indexOffset] = ptr.copyBytes();
View Full Code Here

        ret.add(new Object[] {scan, scanRanges, Arrays.<KeyRange>asList(expectedSplits)});
        return ret;
    }

    private static Collection<?> foreach(KeyRange[][] ranges, int[] widths, KeyRange[] expectedSplits) {
        RowKeySchema schema = buildSchema(widths);
        List<List<KeyRange>> slots = Lists.transform(Lists.newArrayList(ranges), ARRAY_TO_LIST);
        SkipScanFilter filter = new SkipScanFilter(slots, schema);
        // Always set start and stop key to max to verify we are using the information in skipscan
        // filter over the scan's KMIN and KMAX.
        Scan scan = new Scan().setFilter(filter).setStartRow(KeyRange.UNBOUND).setStopRow(KeyRange.UNBOUND);
View Full Code Here

TOP

Related Classes of org.apache.phoenix.schema.RowKeySchema

Copyright © 2018 www.massapicom. 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.