Package org.apache.phoenix.index

Examples of org.apache.phoenix.index.IndexMaintainer$IntSizedRowKeyMetaData


    public static List<Mutation> generateIndexData(final PTable table, PTable index,
            List<Mutation> dataMutations, ImmutableBytesWritable ptr, final KeyValueBuilder kvBuilder)
            throws SQLException {
        try {
            IndexMaintainer maintainer = index.getIndexMaintainer(table);
            List<Mutation> indexMutations = Lists.newArrayListWithExpectedSize(dataMutations.size());
           for (final Mutation dataMutation : dataMutations) {
                long ts = MetaDataUtil.getClientTimeStamp(dataMutation);
                ptr.set(dataMutation.getRow());
                if (dataMutation instanceof Put) {
                    // TODO: is this more efficient than looking in our mutation map
                    // using the key plus finding the PColumn?
                    ValueGetter valueGetter = new ValueGetter() {
       
                        @Override
                        public ImmutableBytesPtr getLatestValue(ColumnReference ref) {
                            // Always return null for our empty key value, as this will cause the index
                            // maintainer to always treat this Put as a new row.
                            if (isEmptyKeyValue(table, ref)) {
                                return null;
                            }
                            Map<byte [], List<KeyValue>> familyMap = dataMutation.getFamilyMap();
                            byte[] family = ref.getFamily();
                            List<KeyValue> kvs = familyMap.get(family);
                            if (kvs == null) {
                                return null;
                            }
                            byte[] qualifier = ref.getQualifier();
                            for (KeyValue kv : kvs) {
                                if kvBuilder.compareFamily(kv, family, 0, family.length) == 0
                                   && kvBuilder.compareQualifier(kv, qualifier, 0, qualifier.length) == 0) {
                                    ImmutableBytesPtr ptr = new ImmutableBytesPtr();
                                    kvBuilder.getValueAsPtr(kv, ptr);
                                    return ptr;
                                }
                            }
                            return null;
                        }
                       
                    };
                    indexMutations.add(maintainer.buildUpdateMutation(kvBuilder, valueGetter, ptr, ts));
                } else {
                    // We can only generate the correct Delete if we have no KV columns in our index.
                    // Perhaps it'd be best to ignore Delete mutations all together here, as this
                    // gets triggered typically for an initial population where Delete markers make
                    // little sense.
                    if (maintainer.getIndexedColumns().isEmpty()) {
                        indexMutations.add(maintainer.buildDeleteMutation(kvBuilder, ptr, ts));
                    }
                }
            }
            return indexMutations;
        } catch (IOException e) {
View Full Code Here


        return (Bytes.compareTo(emptyKeyValueCF, ref.getFamily()) == 0 &&
                Bytes.compareTo(QueryConstants.EMPTY_COLUMN_BYTES, ref.getQualifier()) == 0);
    }
    public static List<Mutation> generateIndexData(final PTable table, PTable index, List<Mutation> dataMutations, ImmutableBytesWritable ptr) throws SQLException {
        try {
            IndexMaintainer maintainer = index.getIndexMaintainer(table);
            List<Mutation> indexMutations = Lists.newArrayListWithExpectedSize(dataMutations.size());
           for (final Mutation dataMutation : dataMutations) {
                long ts = MetaDataUtil.getClientTimeStamp(dataMutation);
                ptr.set(dataMutation.getRow());
                if (dataMutation instanceof Put) {
                    // TODO: is this more efficient than looking in our mutation map
                    // using the key plus finding the PColumn?
                    ValueGetter valueGetter = new ValueGetter() {
       
                        @Override
                        public ImmutableBytesPtr getLatestValue(ColumnReference ref) {
                            // Always return null for our empty key value, as this will cause the index
                            // maintainer to always treat this Put as a new row.
                            if (isEmptyKeyValue(table, ref)) {
                                return null;
                            }
                            Map<byte [], List<KeyValue>> familyMap = dataMutation.getFamilyMap();
                            byte[] family = ref.getFamily();
                            List<KeyValue> kvs = familyMap.get(family);
                            if (kvs == null) {
                                return null;
                            }
                            byte[] qualifier = ref.getQualifier();
                            for (KeyValue kv : kvs) {
                                if (Bytes.compareTo(kv.getBuffer(), kv.getFamilyOffset(), kv.getFamilyLength(), family, 0, family.length) == 0 &&
                                    Bytes.compareTo(kv.getBuffer(), kv.getQualifierOffset(), kv.getQualifierLength(), qualifier, 0, qualifier.length) == 0) {
                                    return new ImmutableBytesPtr(kv.getBuffer(), kv.getValueOffset(), kv.getValueLength());
                                }
                            }
                            return null;
                        }
                       
                    };
                    indexMutations.add(maintainer.buildUpdateMutation(valueGetter, ptr, ts));
                } else {
                    if (!maintainer.getIndexedColumns().isEmpty()) {
                        throw new SQLExceptionInfo.Builder(SQLExceptionCode.NO_DELETE_IF_IMMUTABLE_INDEX).setSchemaName(table.getSchemaName().getString())
                        .setTableName(table.getTableName().getString()).build().buildException();
                    }
                    indexMutations.add(maintainer.buildDeleteMutation(ptr, ts));
                }
            }
            return indexMutations;
        } catch (IOException e) {
            throw new SQLException(e);
View Full Code Here

    public static List<Mutation> generateIndexData(final PTable table, PTable index,
            List<Mutation> dataMutations, ImmutableBytesWritable ptr, final KeyValueBuilder kvBuilder)
            throws SQLException {
        try {
            IndexMaintainer maintainer = index.getIndexMaintainer(table);
            List<Mutation> indexMutations = Lists.newArrayListWithExpectedSize(dataMutations.size());
           for (final Mutation dataMutation : dataMutations) {
                long ts = MetaDataUtil.getClientTimeStamp(dataMutation);
                ptr.set(dataMutation.getRow());
                if (dataMutation instanceof Put) {
                    // TODO: is this more efficient than looking in our mutation map
                    // using the key plus finding the PColumn?
                    ValueGetter valueGetter = new ValueGetter() {
       
                        @Override
                        public ImmutableBytesPtr getLatestValue(ColumnReference ref) {
                            // Always return null for our empty key value, as this will cause the index
                            // maintainer to always treat this Put as a new row.
                            if (isEmptyKeyValue(table, ref)) {
                                return null;
                            }
                            Map<byte [], List<KeyValue>> familyMap = dataMutation.getFamilyMap();
                            byte[] family = ref.getFamily();
                            List<KeyValue> kvs = familyMap.get(family);
                            if (kvs == null) {
                                return null;
                            }
                            byte[] qualifier = ref.getQualifier();
                            for (KeyValue kv : kvs) {
                                if kvBuilder.compareFamily(kv, family, 0, family.length) == 0
                                   && kvBuilder.compareQualifier(kv, qualifier, 0, qualifier.length) == 0) {
                                    ImmutableBytesPtr ptr = new ImmutableBytesPtr();
                                    kvBuilder.getValueAsPtr(kv, ptr);
                                    return ptr;
                                }
                            }
                            return null;
                        }
                       
                    };
                    indexMutations.add(maintainer.buildUpdateMutation(kvBuilder, valueGetter, ptr, ts));
                } else {
                    // We can only generate the correct Delete if we have no KV columns in our index.
                    // Perhaps it'd be best to ignore Delete mutations all together here, as this
                    // gets triggered typically for an initial population where Delete markers make
                    // little sense.
                    if (maintainer.getIndexedColumns().isEmpty()) {
                        indexMutations.add(maintainer.buildDeleteMutation(kvBuilder, ptr, ts));
                    }
                }
            }
            return indexMutations;
        } catch (IOException e) {
View Full Code Here

    public static List<Mutation> generateIndexData(final PTable table, PTable index,
            List<Mutation> dataMutations, ImmutableBytesWritable ptr, final KeyValueBuilder kvBuilder)
            throws SQLException {
        try {
            IndexMaintainer maintainer = index.getIndexMaintainer(table);
            List<Mutation> indexMutations = Lists.newArrayListWithExpectedSize(dataMutations.size());
           for (final Mutation dataMutation : dataMutations) {
                long ts = MetaDataUtil.getClientTimeStamp(dataMutation);
                ptr.set(dataMutation.getRow());
                if (dataMutation instanceof Put) {
                    // TODO: is this more efficient than looking in our mutation map
                    // using the key plus finding the PColumn?
                    ValueGetter valueGetter = new ValueGetter() {
       
                        @Override
                        public ImmutableBytesPtr getLatestValue(ColumnReference ref) {
                            // Always return null for our empty key value, as this will cause the index
                            // maintainer to always treat this Put as a new row.
                            if (isEmptyKeyValue(table, ref)) {
                                return null;
                            }
                            Map<byte [], List<Cell>> familyMap = dataMutation.getFamilyCellMap();
                            byte[] family = ref.getFamily();
                            List<Cell> kvs = familyMap.get(family);
                            if (kvs == null) {
                                return null;
                            }
                            byte[] qualifier = ref.getQualifier();
                            for (Cell kv : kvs) {
                                if (Bytes.compareTo(kv.getFamilyArray(), kv.getFamilyOffset(), kv.getFamilyLength(), family, 0, family.length) == 0 &&
                                    Bytes.compareTo(kv.getQualifierArray(), kv.getQualifierOffset(), kv.getQualifierLength(), qualifier, 0, qualifier.length) == 0) {
                                  ImmutableBytesPtr ptr = new ImmutableBytesPtr();
                                  kvBuilder.getValueAsPtr(kv, ptr);
                                  return ptr;
                                }
                            }
                            return null;
                        }
                       
                    };
                    indexMutations.add(maintainer.buildUpdateMutation(kvBuilder, valueGetter, ptr, ts, null, null));
                } else {
                    // We can only generate the correct Delete if we have no KV columns in our index.
                    // Perhaps it'd be best to ignore Delete mutations all together here, as this
                    // gets triggered typically for an initial population where Delete markers make
                    // little sense.
                    if (maintainer.getIndexedColumns().isEmpty()) {
                        indexMutations.add(maintainer.buildDeleteMutation(kvBuilder, ptr, ts));
                    }
                }
            }
            return indexMutations;
        } catch (IOException e) {
View Full Code Here

        List<KeyValueColumnExpression> arrayKVRefs = new ArrayList<KeyValueColumnExpression>();
        Expression[] arrayFuncRefs = deserializeArrayPostionalExpressionInfoFromScan(
                scan, innerScanner, arrayKVRefs);
        TupleProjector tupleProjector = null;
        HRegion dataRegion = null;
        IndexMaintainer indexMaintainer = null;
        byte[][] viewConstants = null;
        ColumnReference[] dataColumns = IndexUtil.deserializeDataTableColumnsToJoin(scan);
        if (dataColumns != null) {
            tupleProjector = IndexUtil.getTupleProjector(scan, dataColumns);
            dataRegion = IndexUtil.getDataRegion(c.getEnvironment());
View Full Code Here

                indexes.add(index);
                IndexMaintainer.serialize(dataTable, ptr, indexes);
                scan.setAttribute(BaseScannerRegionObserver.LOCAL_INDEX_BUILD, ByteUtil.copyKeyBytesIfNecessary(ptr));
                // By default, we'd use a FirstKeyOnly filter as nothing else needs to be projected for count(*).
                // However, in this case, we need to project all of the data columns that contribute to the index.
                IndexMaintainer indexMaintainer = index.getIndexMaintainer(dataTable);
                for (ColumnReference columnRef : indexMaintainer.getAllColumns()) {
                    scan.addColumn(columnRef.getFamily(), columnRef.getQualifier());
                }
                Cell kv = plan.iterator().next().getValue(0);
                ImmutableBytesWritable tmpPtr = new ImmutableBytesWritable(kv.getValueArray(), kv.getValueOffset(), kv.getValueLength());
                // A single Cell will be returned with the count(*) - we decode that here
View Full Code Here

                List<PTable> indexes = dataTable.getIndexes();
                Map<ImmutableBytesWritable, IndexMaintainer> indexMaintainers =
                        new HashMap<ImmutableBytesWritable, IndexMaintainer>();
                for (PTable index : indexes) {
                    if (index.getIndexType() == IndexType.LOCAL) {
                        IndexMaintainer indexMaintainer = index.getIndexMaintainer(dataTable);
                        indexMaintainers.put(new ImmutableBytesWritable(MetaDataUtil
                                .getViewIndexIdDataType().toBytes(index.getViewIndexId())),
                            indexMaintainer);
                    }
                }
View Full Code Here

        }
        ImmutableBytesWritable rowKey =
                new ImmutableBytesWritable(kv.getRowArray(), kv.getRowOffset() + offset,
                        kv.getRowLength() - offset);
        Entry<ImmutableBytesWritable, IndexMaintainer> entry = indexMaintainers.entrySet().iterator().next();
        IndexMaintainer indexMaintainer = entry.getValue();
        byte[] viewIndexId = indexMaintainer.getViewIndexIdFromIndexRowKey(rowKey);
        IndexMaintainer actualIndexMaintainer = indexMaintainers.get(new ImmutableBytesWritable(viewIndexId));
        byte[] dataRowKey = actualIndexMaintainer.buildDataRowKey(rowKey, this.viewConstants);
        int compareResult = Bytes.compareTo(dataRowKey, splitRow);
        if (top) {
            if (compareResult >= 0) {
                return true;
            }
View Full Code Here

    public static List<Mutation> generateIndexData(final PTable table, PTable index,
            List<Mutation> dataMutations, ImmutableBytesWritable ptr, final KeyValueBuilder kvBuilder)
            throws SQLException {
        try {
            IndexMaintainer maintainer = index.getIndexMaintainer(table);
            List<Mutation> indexMutations = Lists.newArrayListWithExpectedSize(dataMutations.size());
           for (final Mutation dataMutation : dataMutations) {
                long ts = MetaDataUtil.getClientTimeStamp(dataMutation);
                ptr.set(dataMutation.getRow());
                if (dataMutation instanceof Put) {
                    // TODO: is this more efficient than looking in our mutation map
                    // using the key plus finding the PColumn?
                    ValueGetter valueGetter = new ValueGetter() {
       
                        @Override
                        public ImmutableBytesPtr getLatestValue(ColumnReference ref) {
                            // Always return null for our empty key value, as this will cause the index
                            // maintainer to always treat this Put as a new row.
                            if (isEmptyKeyValue(table, ref)) {
                                return null;
                            }
                            Map<byte [], List<Cell>> familyMap = dataMutation.getFamilyCellMap();
                            byte[] family = ref.getFamily();
                            List<Cell> kvs = familyMap.get(family);
                            if (kvs == null) {
                                return null;
                            }
                            byte[] qualifier = ref.getQualifier();
                            for (Cell kv : kvs) {
                                if (Bytes.compareTo(kv.getFamilyArray(), kv.getFamilyOffset(), kv.getFamilyLength(), family, 0, family.length) == 0 &&
                                    Bytes.compareTo(kv.getQualifierArray(), kv.getQualifierOffset(), kv.getQualifierLength(), qualifier, 0, qualifier.length) == 0) {
                                  ImmutableBytesPtr ptr = new ImmutableBytesPtr();
                                  kvBuilder.getValueAsPtr(kv, ptr);
                                  return ptr;
                                }
                            }
                            return null;
                        }
                       
                    };
                    indexMutations.add(maintainer.buildUpdateMutation(kvBuilder, valueGetter, ptr, ts));
                } else {
                    // We can only generate the correct Delete if we have no KV columns in our index.
                    // Perhaps it'd be best to ignore Delete mutations all together here, as this
                    // gets triggered typically for an initial population where Delete markers make
                    // little sense.
                    if (maintainer.getIndexedColumns().isEmpty()) {
                        indexMutations.add(maintainer.buildDeleteMutation(kvBuilder, ptr, ts));
                    }
                }
            }
            return indexMutations;
        } catch (IOException e) {
View Full Code Here

TOP

Related Classes of org.apache.phoenix.index.IndexMaintainer$IntSizedRowKeyMetaData

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.