Example usage for java.util NavigableMap entrySet

List of usage examples for java.util NavigableMap entrySet

Introduction

In this page you can find the example usage for java.util NavigableMap entrySet.

Prototype

Set<Map.Entry<K, V>> entrySet();

Source Link

Document

Returns a Set view of the mappings contained in this map.

Usage

From source file:org.trustedanalytics.examples.hbase.services.ConversionsService.java

public RowValue constructRowValue(Result r) {
    RowValue result = null;//from   w  w  w .j a v  a2s.co m

    if (r != null && !r.isEmpty()) {
        String rowKey = new String(r.getRow());

        // Map<family,Map<qualifier,value>>
        NavigableMap<byte[], NavigableMap<byte[], byte[]>> valueMap = r.getNoVersionMap();

        List<ColumnFamilyValue> families = valueMap.entrySet().stream()
                .map(b -> new ColumnFamilyValue(new String(b.getKey()), constructColumnValues(b.getValue())))
                .collect(Collectors.toList());

        result = new RowValue(rowKey, families);
    }

    return result;
}

From source file:org.ff4j.hbase.mapper.HBaseFeatureMapper.java

/** {@inheritDoc} */
public Feature fromStore(Result result) {
    // uid//from   w w  w  . ja v  a 2s .co  m
    String uid = Bytes.toString(result.getValue(B_FEATURES_CF_CORE, B_FEAT_UID));
    Feature fout = new Feature(uid);
    // description
    fout.setDescription(Bytes.toString(result.getValue(B_FEATURES_CF_CORE, B_FEAT_DESCRIPTION)));
    // enable
    fout.setEnable(Bytes.toBoolean(result.getValue(B_FEATURES_CF_CORE, B_FEAT_ENABLE)));
    // group
    fout.setGroup(Bytes.toString(result.getValue(B_FEATURES_CF_CORE, B_FEAT_GROUPNAME)));
    if ("null".equals(fout.getGroup())) {
        fout.setGroup(null);
    }
    // permissions
    fout.setPermissions(FeatureJsonParser
            .parsePermissions(Bytes.toString(result.getValue(B_FEATURES_CF_CORE, B_FEAT_ROLES))));
    // Flipping Strategy
    fout.setFlippingStrategy(FeatureJsonParser.parseFlipStrategyAsJson(uid,
            Bytes.toString(result.getValue(B_FEATURES_CF_CORE, B_FEAT_STRATEGY))));
    // Custom Properties
    NavigableMap<byte[], byte[]> map = result.getFamilyMap(B_FEATURES_CF_PROPERTIES);
    for (Map.Entry<byte[], byte[]> property : map.entrySet()) {
        fout.getCustomProperties().put(Bytes.toString(property.getKey()),
                PropertyJsonParser.parseProperty(Bytes.toString(property.getValue())));
    }
    return fout;
}

From source file:ch.sentric.hbase.service.QueryDaoImpl.java

@Override
public Map<String, String> getQueries() throws IOException {
    final Map<String, String> queries = new HashMap<String, String>(0);
    HTable table = this.rm.getTable(AccountTable.NAME);

    Scan scan = new Scan();
    ResultScanner scanner = table.getScanner(scan);

    Iterator<Result> results = scanner.iterator();
    int errors = 0;
    while (results.hasNext()) {
        Result result = results.next();
        if (!result.isEmpty()) {
            try {
                String accountName = Bytes.toString(result.getRow());
                NavigableMap<byte[], NavigableMap<byte[], byte[]>> noVersionMap = result.getNoVersionMap();

                for (Entry<byte[], NavigableMap<byte[], byte[]>> entry : noVersionMap.entrySet()) {

                    NavigableMap<byte[], byte[]> agents = entry.getValue();
                    for (Entry<byte[], byte[]> agent : agents.entrySet()) {
                        String agentName = Bytes.toString(agent.getKey()); // qualifier
                        String agentQuery = Bytes.toString(agent.getValue()); // value
                        queries.put(accountName + "/" + agentName, agentQuery);
                    }//from  ww  w  . j a v  a  2  s.c  o  m

                }

            } catch (Exception e) {
                errors++;
            }
        }
    }

    if (errors > 0) {
        LOG.error(String.format("Encountered %d errors in getUsers", errors));
    }
    this.rm.putTable(table);
    return queries;
}

From source file:com.jivesoftware.os.upena.service.UpenaStoreChanges.java

@Override
public void changes(RowsChanged changes) throws Exception {
    NavigableMap<RowIndexKey, RowIndexValue> appliedRows = changes.getApply();
    for (Map.Entry<RowIndexKey, RowIndexValue> entry : appliedRows.entrySet()) {
        RowIndexKey rawKey = entry.getKey();
        RowIndexValue rawValue = entry.getValue();
        if (entry.getValue().getTombstoned() && removes != null) {
            Collection<RowIndexValue> got = changes.getClobbered().get(rawKey);
            if (got != null) {
                for (RowIndexValue g : got) {
                    K k = null;/* w ww  .j  a  v a 2s .c  o  m*/
                    try {
                        k = rawKey.getKey() == null ? null : mapper.readValue(rawKey.getKey(), keyClass);
                    } catch (Exception x) {
                        LOG.warn("Failed converting key {} of class {} to class {}",
                                new Object[] { rawKey.getKey(),
                                        rawKey.getKey() != null ? rawKey.getKey().getClass() : "null",
                                        keyClass },
                                x);
                        throw x;
                    }
                    V v = null;
                    try {
                        if (g.getValue() == null || g.getTombstoned()) {
                            v = null;
                        } else {
                            v = mapper.readValue(g.getValue(), valueClass);
                        }
                    } catch (Exception x) {
                        LOG.warn("Failed converting value {} of class {} to class {}",
                                new Object[] { g.getValue(),
                                        g.getValue() != null ? g.getValue().getClass() : "null", valueClass },
                                x);
                        //throw x;
                    }
                    removes.change(k, new BasicTimestampedValue<>(v, g.getTimestampId(), g.getTombstoned()));
                }
            }
        } else if (adds != null) {
            K k = null;
            try {
                k = rawKey.getKey() == null ? null : mapper.readValue(rawKey.getKey(), keyClass);
            } catch (Exception x) {
                LOG.warn("Failed converting key {} of class {} to class {}", new Object[] { rawKey.getKey(),
                        rawKey.getKey() != null ? rawKey.getKey().getClass() : "null", keyClass }, x);
                throw x;
            }
            V v = null;
            try {
                v = rawValue.getValue() == null ? null : mapper.readValue(rawValue.getValue(), valueClass);
            } catch (Exception x) {
                LOG.warn("Failed converting value {} of class {} to class {}",
                        new Object[] { rawValue.getValue(),
                                rawValue.getValue() != null ? rawValue.getValue().getClass() : "null",
                                valueClass },
                        x);
                throw x;
            }
            adds.change(k, new BasicTimestampedValue<>(v, rawValue.getTimestampId(), rawValue.getTombstoned()));
        }
    }
}

From source file:edu.umd.shrawanraina.BooleanRetrievalHBase.java

private Set<Integer> fetchDocumentSet(String term) throws IOException {
    Set<Integer> set = new TreeSet<Integer>();
    Result result = fetchHBase(term);
    //String[] Quantifers = new String[familyMap.size()];
    //int counter = 0;
    NavigableMap<byte[], byte[]> postings = result.getFamilyMap(BuildInvertedIndexHBase.CF);
    for (Entry<byte[], byte[]> entry : postings.entrySet()) {
        //System.out.println("Key : <<<<<<<<<<<" + Bytes.toInt(entry.getKey()));
        //System.out.println("Value : <<<<<<<<<<<" + Bytes.toInt(entry.getValue()));

        set.add(Bytes.toInt(entry.getKey()));
    }/*from w ww.  j av  a  2s  . c om*/
    //System.out.println("Word : <<<<<<<<<<" + term + "Set : <<<<<<<<<<" + set);
    return set;
}

From source file:org.trafodion.dtm.HBaseTmZK.java

/**
 * @param node/*from  ww  w  . j  ava  2 s  .c o m*/
 * @param recovTable
 * @throws IOException
 */
public void postAllRegionEntries(HTable recovTable) throws IOException {
    LOG.info("HBaseTmZK:postAllRegionEntries: recovTable: " + recovTable);
    NavigableMap<HRegionInfo, ServerName> regionMap = recovTable.getRegionLocations();
    Iterator<Map.Entry<HRegionInfo, ServerName>> it = regionMap.entrySet().iterator();
    while (it.hasNext()) { // iterate entries.
        NavigableMap.Entry<HRegionInfo, ServerName> pairs = it.next();
        HRegionInfo region = pairs.getKey();
        LOG.info("postAllRegionEntries: region: " + region.getRegionNameAsString());
        ServerName serverValue = regionMap.get(region);
        String hostAndPort = new String(serverValue.getHostAndPort());
        StringTokenizer tok = new StringTokenizer(hostAndPort, ":");
        String hostName = new String(tok.nextElement().toString());
        int portNumber = Integer.parseInt(tok.nextElement().toString());
        byte[] lv_byte_region_info = region.toByteArray();
        try {
            LOG.info("Calling createRecoveryzNode for encoded region: " + region.getEncodedName());
            createRecoveryzNode(hostName, portNumber, region.getEncodedName(), lv_byte_region_info);
        } catch (Exception e2) {
            LOG.error("postAllRegionEntries exception in createRecoveryzNode "
                    + region.getTable().getNameAsString() + " exception: " + e2);
        }
    } // while
}

From source file:com.wibidata.shopping.servlet.HomePageServlet.java

private List<ProductRating> getRecentRatings(KijiTable userTable, String login) throws IOException {
    KijiTableReader reader = userTable.openTableReader();
    try {//from www. j a  va2s. c  o  m
        final long now = System.currentTimeMillis();
        final long lastWeek = now - DateUtils.MILLIS_PER_DAY * 7L;

        EntityId entityId = userTable.getEntityId(login);
        KijiDataRequestBuilder drBuilder = KijiDataRequest.builder();
        drBuilder.newColumnsDef().addFamily("rating");
        drBuilder.withTimeRange(lastWeek, HConstants.LATEST_TIMESTAMP);
        KijiDataRequest dataRequest = drBuilder.build();

        KijiRowData row = reader.get(entityId, dataRequest);
        if (row.containsColumn("rating")) {
            NavigableMap<String, NavigableMap<Long, ProductRating>> ratingsMap = row.getValues("rating");
            NavigableMap<Long, ProductRating> sortedRatings = new TreeMap<Long, ProductRating>();
            for (NavigableMap<Long, ProductRating> value : ratingsMap.values()) {
                for (NavigableMap.Entry<Long, ProductRating> entry : value.entrySet()) {
                    sortedRatings.put(entry.getKey(), entry.getValue());
                }
            }
            return new ArrayList<ProductRating>(sortedRatings.descendingMap().values());
        }
        return null;
    } catch (KijiDataRequestException e) {
        throw new IOException(e);
    } finally {
        IOUtils.closeQuietly(reader);
    }
}

From source file:org.lilyproject.tools.recordrowvisualizer.RecordRowVisualizer.java

private void readColumns(NavigableMap<byte[], NavigableMap<Long, byte[]>> cf) throws Exception {
    Fields fields = recordRow.fields;/*from   w  w  w. j  av a  2 s.com*/

    for (Map.Entry<byte[], NavigableMap<Long, byte[]>> column : cf.entrySet()) {
        byte[] columnKey = column.getKey();

        if (columnKey[0] == RecordColumn.DATA_PREFIX) {
            SchemaId fieldId = new SchemaIdImpl(Arrays.copyOfRange(columnKey, 1, columnKey.length));

            for (Map.Entry<Long, byte[]> version : column.getValue().entrySet()) {
                long versionNr = version.getKey();
                byte[] value = version.getValue();

                FieldType fieldType = fields.registerFieldType(fieldId, typeMgr);

                Map<SchemaId, Object> columns = fields.values.get(versionNr);
                if (columns == null) {
                    columns = new HashMap<SchemaId, Object>();
                    fields.values.put(versionNr, columns);
                }

                Object decodedValue;
                if (FieldFlags.isDeletedField(value[0])) {
                    decodedValue = Fields.DELETED;
                } else {
                    decodedValue = fieldType.getValueType()
                            .read(new DataInputImpl(EncodingUtil.stripPrefix(value)));
                }

                columns.put(fieldId, decodedValue);
            }
        } else if (Arrays.equals(columnKey, RecordColumn.DELETED.bytes)) {
            setSystemField("Deleted", column.getValue(), BOOLEAN_DECODER);
        } else if (Arrays.equals(columnKey, RecordColumn.NON_VERSIONED_RT_ID.bytes)) {
            setSystemField("Non-versioned Record Type ID", column.getValue(),
                    new RecordTypeValueDecoder(typeMgr));
        } else if (Arrays.equals(columnKey, RecordColumn.NON_VERSIONED_RT_VERSION.bytes)) {
            setSystemField("Non-versioned Record Type Version", column.getValue(), LONG_DECODER);
        } else if (Arrays.equals(columnKey, RecordColumn.VERSIONED_RT_ID.bytes)) {
            setSystemField("Versioned Record Type ID", column.getValue(), new RecordTypeValueDecoder(typeMgr));
        } else if (Arrays.equals(columnKey, RecordColumn.VERSIONED_RT_VERSION.bytes)) {
            setSystemField("Versioned Record Type Version", column.getValue(), LONG_DECODER);
        } else if (Arrays.equals(columnKey, RecordColumn.VERSIONED_MUTABLE_RT_ID.bytes)) {
            setSystemField("Versioned-mutable Record Type ID", column.getValue(),
                    new RecordTypeValueDecoder(typeMgr));
        } else if (Arrays.equals(columnKey, RecordColumn.VERSIONED_MUTABLE_RT_VERSION.bytes)) {
            setSystemField("Versioned-mutable Record Type Version", column.getValue(), LONG_DECODER);
        } else if (Arrays.equals(columnKey, RecordColumn.VERSION.bytes)) {
            setSystemField("Record Version", column.getValue(), LONG_DECODER);
        } else {
            recordRow.unknownColumns.add(Bytes.toString(columnKey));
        }
    }
}

From source file:org.kiji.schema.tools.LayoutTool.java

/**
 * Dumps the history of layouts of a given table.
 *
 * @param admin kiji admin interface./*from   w  w w. ja va2 s  . c  om*/
 * @throws Exception on error.
 */
private void history(KijiAdmin admin) throws Exception {
    // Gather all of the layouts stored in the metaTable.
    final NavigableMap<Long, KijiTableLayout> timedLayouts = getKiji().getMetaTable()
            .getTimedTableLayoutVersions(mTableName, mMaxVersions);
    if (timedLayouts.isEmpty()) {
        throw new RuntimeException("No such table: " + mTableName);
    }
    for (Map.Entry<Long, KijiTableLayout> entry : timedLayouts.entrySet()) {
        final long timestamp = entry.getKey();
        final KijiTableLayout layout = entry.getValue();
        final String json = ToJson.toJsonString(layout.getDesc());

        if (mWriteTo.isEmpty()) {
            System.out.printf("timestamp: %d:%n%s", timestamp, json);
        } else {
            final String fileName = String.format("%s-%d.json", mWriteTo, timestamp);
            final FileOutputStream fos = new FileOutputStream(fileName);
            try {
                fos.write(Bytes.toBytes(json));
            } finally {
                IOUtils.closeQuietly(fos);
            }
        }
    }
}

From source file:org.apache.kylin.rest.service.AclTableMigrationTool.java

private Map<String, AceInfo> getAllAceInfo(Result result) throws IOException {
    Map<String, AceInfo> allAceInfoMap = new HashMap<>();
    NavigableMap<byte[], byte[]> familyMap = result.getFamilyMap(Bytes.toBytes(AclConstant.ACL_ACES_FAMILY));
    if (familyMap != null && !familyMap.isEmpty()) {
        for (Map.Entry<byte[], byte[]> entry : familyMap.entrySet()) {
            String sid = new String(entry.getKey());
            AceInfo aceInfo = aceSerializer.deserialize(entry.getValue());
            if (null != aceInfo) {
                allAceInfoMap.put(sid, aceInfo);
            }//from  w w w .ja v a2s  .com
        }
    }
    return allAceInfoMap;
}