Java Code Examples for org.apache.hadoop.hbase.util.Pair#setSecond()
The following examples show how to use
org.apache.hadoop.hbase.util.Pair#setSecond() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FuzzyRowFilter.java From hbase with Apache License 2.0 | 6 votes |
public FuzzyRowFilter(List<Pair<byte[], byte[]>> fuzzyKeysData) { List<Pair<byte[], byte[]>> fuzzyKeyDataCopy = new ArrayList<>(fuzzyKeysData.size()); for (Pair<byte[], byte[]> aFuzzyKeysData : fuzzyKeysData) { if (aFuzzyKeysData.getFirst().length != aFuzzyKeysData.getSecond().length) { Pair<String, String> readable = new Pair<>(Bytes.toStringBinary(aFuzzyKeysData.getFirst()), Bytes.toStringBinary(aFuzzyKeysData.getSecond())); throw new IllegalArgumentException("Fuzzy pair lengths do not match: " + readable); } Pair<byte[], byte[]> p = new Pair<>(); // create a copy of pair bytes so that they are not modified by the filter. p.setFirst(Arrays.copyOf(aFuzzyKeysData.getFirst(), aFuzzyKeysData.getFirst().length)); p.setSecond(Arrays.copyOf(aFuzzyKeysData.getSecond(), aFuzzyKeysData.getSecond().length)); // update mask ( 0 -> -1 (0xff), 1 -> 2) p.setSecond(preprocessMask(p.getSecond())); preprocessSearchKey(p); fuzzyKeyDataCopy.add(p); } this.fuzzyKeysData = fuzzyKeyDataCopy; this.tracker = new RowTracker(); }
Example 2
Source File: QueryCompiler.java From phoenix with Apache License 2.0 | 5 votes |
private boolean getKeyExpressionCombinations(Pair<Expression, Expression> combination, StatementContext context, SelectStatement select, TableRef table, JoinType type, final List<Expression> joinExpressions, final List<Expression> hashExpressions) throws SQLException { if ((type != JoinType.Inner && type != JoinType.Semi) || this.noChildParentJoinOptimization) return false; Scan scanCopy = ScanUtil.newScan(context.getScan()); StatementContext contextCopy = new StatementContext(statement, context.getResolver(), scanCopy, new SequenceManager(statement)); contextCopy.setCurrentTable(table); List<Expression> lhsCombination = Lists.<Expression> newArrayList(); boolean complete = WhereOptimizer.getKeyExpressionCombination(lhsCombination, contextCopy, select, joinExpressions); if (lhsCombination.isEmpty()) return false; List<Expression> rhsCombination = Lists.newArrayListWithExpectedSize(lhsCombination.size()); for (int i = 0; i < lhsCombination.size(); i++) { Expression lhs = lhsCombination.get(i); for (int j = 0; j < joinExpressions.size(); j++) { if (lhs == joinExpressions.get(j)) { rhsCombination.add(hashExpressions.get(j)); break; } } } if (lhsCombination.size() == 1) { combination.setFirst(lhsCombination.get(0)); combination.setSecond(rhsCombination.get(0)); } else { combination.setFirst(new RowValueConstructorExpression(lhsCombination, false)); combination.setSecond(new RowValueConstructorExpression(rhsCombination, false)); } return type == JoinType.Semi && complete; }
Example 3
Source File: PArrayDataType.java From phoenix with Apache License 2.0 | 5 votes |
public int estimateByteSize(Object o, Pair<Integer, Integer> nullsVsNullRepeationCounter, PDataType baseType) { if (baseType.isFixedWidth()) { return baseType.getByteSize(); } if (baseType.isArrayType()) { PhoenixArray array = (PhoenixArray)o; int noOfElements = array.numElements; int totalVarSize = 0; int nullsRepeationCounter = 0; int nulls = 0; int totalNulls = 0; for (int i = 0; i < noOfElements; i++) { totalVarSize += array.estimateByteSize(i); if (!PDataType.fromTypeId((baseType.getSqlType() - PDataType.ARRAY_TYPE_BASE)).isFixedWidth()) { if (array.isNull(i)) { nulls++; } else { if (nulls > 0) { totalNulls += nulls; nulls = 0; nullsRepeationCounter++; } } } } if (nullsVsNullRepeationCounter != null) { if (nulls > 0) { totalNulls += nulls; // do not increment nullsRepeationCounter to identify trailing nulls } nullsVsNullRepeationCounter.setFirst(totalNulls); nullsVsNullRepeationCounter.setSecond(nullsRepeationCounter); } return totalVarSize; } // Non fixed width types must override this throw new UnsupportedOperationException(); }
Example 4
Source File: VisibilityController.java From hbase with Apache License 2.0 | 5 votes |
/** * Checks whether cell contains any tag with type as VISIBILITY_TAG_TYPE. This * tag type is reserved and should not be explicitly set by user. * * @param cell The cell under consideration * @param pair An optional pair of type {@code <Boolean, Tag>} which would be reused if already * set and new one will be created if NULL is passed * @return If the boolean is false then it indicates that the cell has a RESERVERD_VIS_TAG and * with boolean as true, not null tag indicates that a string modified tag was found. */ private Pair<Boolean, Tag> checkForReservedVisibilityTagPresence(Cell cell, Pair<Boolean, Tag> pair) throws IOException { if (pair == null) { pair = new Pair<>(false, null); } else { pair.setFirst(false); pair.setSecond(null); } // Bypass this check when the operation is done by a system/super user. // This is done because, while Replication, the Cells coming to the peer cluster with reserved // typed tags and this is fine and should get added to the peer cluster table if (isSystemOrSuperUser()) { // Does the cell contain special tag which indicates that the replicated // cell visiblilty tags // have been modified Tag modifiedTag = null; Iterator<Tag> tagsIterator = PrivateCellUtil.tagsIterator(cell); while (tagsIterator.hasNext()) { Tag tag = tagsIterator.next(); if (tag.getType() == TagType.STRING_VIS_TAG_TYPE) { modifiedTag = tag; break; } } pair.setFirst(true); pair.setSecond(modifiedTag); return pair; } Iterator<Tag> tagsItr = PrivateCellUtil.tagsIterator(cell); while (tagsItr.hasNext()) { if (RESERVED_VIS_TAG_TYPES.contains(tagsItr.next().getType())) { return pair; } } pair.setFirst(true); return pair; }
Example 5
Source File: QueryCompiler.java From phoenix with Apache License 2.0 | 5 votes |
private boolean getKeyExpressionCombinations(Pair<Expression, Expression> combination, StatementContext context, SelectStatement select, TableRef table, JoinType type, final List<Expression> joinExpressions, final List<Expression> hashExpressions) throws SQLException { if ((type != JoinType.Inner && type != JoinType.Semi) || this.noChildParentJoinOptimization) return false; Scan scanCopy = ScanUtil.newScan(context.getScan()); StatementContext contextCopy = new StatementContext(statement, context.getResolver(), context.getBindManager(), scanCopy, new SequenceManager(statement)); contextCopy.setCurrentTable(table); List<Expression> lhsCombination = Lists.<Expression> newArrayList(); boolean complete = WhereOptimizer.getKeyExpressionCombination(lhsCombination, contextCopy, select, joinExpressions); if (lhsCombination.isEmpty()) return false; List<Expression> rhsCombination = Lists.newArrayListWithExpectedSize(lhsCombination.size()); for (int i = 0; i < lhsCombination.size(); i++) { Expression lhs = lhsCombination.get(i); for (int j = 0; j < joinExpressions.size(); j++) { if (lhs == joinExpressions.get(j)) { rhsCombination.add(hashExpressions.get(j)); break; } } } if (lhsCombination.size() == 1) { combination.setFirst(lhsCombination.get(0)); combination.setSecond(rhsCombination.get(0)); } else { combination.setFirst(new RowValueConstructorExpression(lhsCombination, false)); combination.setSecond(new RowValueConstructorExpression(rhsCombination, false)); } return type == JoinType.Semi && complete; }
Example 6
Source File: IndexRegionObserver.java From phoenix with Apache License 2.0 | 5 votes |
/** * This method applies the pending put mutations on the the next row states. * Before this method is called, the next row states is set to current row states. */ private void applyPendingPutMutations(MiniBatchOperationInProgress<Mutation> miniBatchOp, BatchMutateContext context, long now) throws IOException { for (Integer i = 0; i < miniBatchOp.size(); i++) { if (miniBatchOp.getOperationStatus(i) == IGNORE) { continue; } Mutation m = miniBatchOp.getOperation(i); // skip this mutation if we aren't enabling indexing if (!this.builder.isEnabled(m)) { continue; } // Unless we're replaying edits to rebuild the index, we update the time stamp // of the data table to prevent overlapping time stamps (which prevents index // inconsistencies as this case isn't handled correctly currently). setTimestamp(m, now); if (m instanceof Put) { ImmutableBytesPtr rowKeyPtr = new ImmutableBytesPtr(m.getRow()); Pair<Put, Put> dataRowState = context.dataRowStates.get(rowKeyPtr); if (dataRowState == null) { dataRowState = new Pair<Put, Put>(null, null); context.dataRowStates.put(rowKeyPtr, dataRowState); } Put nextDataRowState = dataRowState.getSecond(); dataRowState.setSecond((nextDataRowState != null) ? applyNew((Put) m, nextDataRowState) : new Put((Put) m)); } } }
Example 7
Source File: BaseResultIterators.java From phoenix with Apache License 2.0 | 5 votes |
private static void adjustQualifierRange(Integer qualifier, Pair<Integer, Integer> minMaxQualifiers) { if (minMaxQualifiers.getFirst() == null) { minMaxQualifiers.setFirst(qualifier); minMaxQualifiers.setSecond(qualifier); } else { if (minMaxQualifiers.getFirst() > qualifier) { minMaxQualifiers.setFirst(qualifier); } else if (minMaxQualifiers.getSecond() < qualifier) { minMaxQualifiers.setSecond(qualifier); } } }
Example 8
Source File: PArrayDataType.java From phoenix with Apache License 2.0 | 5 votes |
public int estimateByteSize(Object o, Pair<Integer, Integer> nullsVsNullRepeationCounter, PDataType baseType) { if (baseType.isFixedWidth()) { return baseType.getByteSize(); } if (baseType.isArrayType()) { PhoenixArray array = (PhoenixArray)o; int noOfElements = array.numElements; int totalVarSize = 0; int nullsRepeationCounter = 0; int nulls = 0; int totalNulls = 0; for (int i = 0; i < noOfElements; i++) { totalVarSize += array.estimateByteSize(i); if (!PDataType.fromTypeId((baseType.getSqlType() - PDataType.ARRAY_TYPE_BASE)).isFixedWidth()) { if (array.isNull(i)) { nulls++; } else { if (nulls > 0) { totalNulls += nulls; nulls = 0; nullsRepeationCounter++; } } } } if (nullsVsNullRepeationCounter != null) { if (nulls > 0) { totalNulls += nulls; // do not increment nullsRepeationCounter to identify trailing nulls } nullsVsNullRepeationCounter.setFirst(totalNulls); nullsVsNullRepeationCounter.setSecond(nullsRepeationCounter); } return totalVarSize; } // Non fixed width types must override this throw new UnsupportedOperationException(); }
Example 9
Source File: HBaseStoreManager.java From atlas with Apache License 2.0 | 4 votes |
/** * Convert JanusGraph internal Mutation representation into HBase native commands. * * @param mutations Mutations to convert into HBase commands. * @param putTimestamp The timestamp to use for Put commands. * @param delTimestamp The timestamp to use for Delete commands. * @return Commands sorted by key converted from JanusGraph internal representation. * @throws org.janusgraph.diskstorage.PermanentBackendException */ @VisibleForTesting Map<StaticBuffer, Pair<List<Put>, Delete>> convertToCommands(Map<String, Map<StaticBuffer, KCVMutation>> mutations, final long putTimestamp, final long delTimestamp) throws PermanentBackendException { // A map of rowkey to commands (list of Puts, Delete) final Map<StaticBuffer, Pair<List<Put>, Delete>> commandsPerKey = new HashMap<>(); for (Map.Entry<String, Map<StaticBuffer, KCVMutation>> entry : mutations.entrySet()) { String cfString = getCfNameForStoreName(entry.getKey()); byte[] cfName = Bytes.toBytes(cfString); for (Map.Entry<StaticBuffer, KCVMutation> m : entry.getValue().entrySet()) { final byte[] key = m.getKey().as(StaticBuffer.ARRAY_FACTORY); KCVMutation mutation = m.getValue(); Pair<List<Put>, Delete> commands = commandsPerKey.get(m.getKey()); // The firt time we go through the list of input <rowkey, KCVMutation>, // create the holder for a particular rowkey if (commands == null) { commands = new Pair<>(); // List of all the Puts for this rowkey, including the ones without TTL and with TTL. final List<Put> putList = new ArrayList<>(); commands.setFirst(putList); commandsPerKey.put(m.getKey(), commands); } if (mutation.hasDeletions()) { if (commands.getSecond() == null) { Delete d = new Delete(key); compat.setTimestamp(d, delTimestamp); commands.setSecond(d); } for (StaticBuffer b : mutation.getDeletions()) { // commands.getSecond() is a Delete for this rowkey. commands.getSecond().addColumns(cfName, b.as(StaticBuffer.ARRAY_FACTORY), delTimestamp); } } if (mutation.hasAdditions()) { // All the entries (column cells) with the rowkey use this one Put, except the ones with TTL. final Put putColumnsWithoutTtl = new Put(key, putTimestamp); // At the end of this loop, there will be one Put entry in the commands.getFirst() list that // contains all additions without TTL set, and possible multiple Put entries for columns // that have TTL set. for (Entry e : mutation.getAdditions()) { // Deal with TTL within the entry (column cell) first // HBase cell level TTL is actually set at the Mutation/Put level. // Therefore we need to construct a new Put for each entry (column cell) with TTL. // We can not combine them because column cells within the same rowkey may: // 1. have no TTL // 2. have TTL // 3. have different TTL final Integer ttl = (Integer) e.getMetaData().get(EntryMetaData.TTL); if (null != ttl && ttl > 0) { // Create a new Put Put putColumnWithTtl = new Put(key, putTimestamp); addColumnToPut(putColumnWithTtl, cfName, putTimestamp, e); // Convert ttl from second (JanusGraph TTL) to millisec (HBase TTL) // @see JanusGraphManagement#setTTL(JanusGraphSchemaType, Duration) // Cast Put to Mutation for backward compatibility with HBase 0.98.x // HBase supports cell-level TTL for versions 0.98.6 and above. ((Mutation) putColumnWithTtl).setTTL(ttl * 1000); // commands.getFirst() is the list of Puts for this rowkey. Add this // Put column with TTL to the list. commands.getFirst().add(putColumnWithTtl); } else { addColumnToPut(putColumnsWithoutTtl, cfName, putTimestamp, e); } } // If there were any mutations without TTL set, add them to commands.getFirst() if (!putColumnsWithoutTtl.isEmpty()) { commands.getFirst().add(putColumnsWithoutTtl); } } } } return commandsPerKey; }
Example 10
Source File: HBaseStoreManager.java From titan1withtp3.1 with Apache License 2.0 | 4 votes |
/** * Convert Titan internal Mutation representation into HBase native commands. * * @param mutations Mutations to convert into HBase commands. * @param putTimestamp The timestamp to use for Put commands. * @param delTimestamp The timestamp to use for Delete commands. * @return Commands sorted by key converted from Titan internal representation. * @throws com.thinkaurelius.titan.diskstorage.PermanentBackendException */ private Map<StaticBuffer, Pair<Put, Delete>> convertToCommands(Map<String, Map<StaticBuffer, KCVMutation>> mutations, final long putTimestamp, final long delTimestamp) throws PermanentBackendException { Map<StaticBuffer, Pair<Put, Delete>> commandsPerKey = new HashMap<StaticBuffer, Pair<Put, Delete>>(); for (Map.Entry<String, Map<StaticBuffer, KCVMutation>> entry : mutations.entrySet()) { String cfString = getCfNameForStoreName(entry.getKey()); byte[] cfName = cfString.getBytes(); for (Map.Entry<StaticBuffer, KCVMutation> m : entry.getValue().entrySet()) { byte[] key = m.getKey().as(StaticBuffer.ARRAY_FACTORY); KCVMutation mutation = m.getValue(); Pair<Put, Delete> commands = commandsPerKey.get(m.getKey()); if (commands == null) { commands = new Pair<Put, Delete>(); commandsPerKey.put(m.getKey(), commands); } if (mutation.hasDeletions()) { if (commands.getSecond() == null) { Delete d = new Delete(key); compat.setTimestamp(d, delTimestamp); commands.setSecond(d); } for (StaticBuffer b : mutation.getDeletions()) { commands.getSecond().deleteColumns(cfName, b.as(StaticBuffer.ARRAY_FACTORY), delTimestamp); } } if (mutation.hasAdditions()) { if (commands.getFirst() == null) { Put p = new Put(key, putTimestamp); commands.setFirst(p); } for (Entry e : mutation.getAdditions()) { commands.getFirst().add(cfName, e.getColumnAs(StaticBuffer.ARRAY_FACTORY), putTimestamp, e.getValueAs(StaticBuffer.ARRAY_FACTORY)); } } } } return commandsPerKey; }
Example 11
Source File: HBaseStoreManager.java From incubator-atlas with Apache License 2.0 | 4 votes |
/** * Convert Titan internal Mutation representation into HBase native commands. * * @param mutations Mutations to convert into HBase commands. * @param putTimestamp The timestamp to use for Put commands. * @param delTimestamp The timestamp to use for Delete commands. * @return Commands sorted by key converted from Titan internal representation. * @throws com.thinkaurelius.titan.diskstorage.PermanentBackendException */ private Map<StaticBuffer, Pair<Put, Delete>> convertToCommands(Map<String, Map<StaticBuffer, KCVMutation>> mutations, final long putTimestamp, final long delTimestamp) throws PermanentBackendException { Map<StaticBuffer, Pair<Put, Delete>> commandsPerKey = new HashMap<>(); for (Map.Entry<String, Map<StaticBuffer, KCVMutation>> entry : mutations.entrySet()) { String cfString = getCfNameForStoreName(entry.getKey()); byte[] cfName = cfString.getBytes(); for (Map.Entry<StaticBuffer, KCVMutation> m : entry.getValue().entrySet()) { byte[] key = m.getKey().as(StaticBuffer.ARRAY_FACTORY); KCVMutation mutation = m.getValue(); Pair<Put, Delete> commands = commandsPerKey.get(m.getKey()); if (commands == null) { commands = new Pair<>(); commandsPerKey.put(m.getKey(), commands); } if (mutation.hasDeletions()) { if (commands.getSecond() == null) { Delete d = new Delete(key); compat.setTimestamp(d, delTimestamp); commands.setSecond(d); } for (StaticBuffer b : mutation.getDeletions()) { commands.getSecond().deleteColumns(cfName, b.as(StaticBuffer.ARRAY_FACTORY), delTimestamp); } } if (mutation.hasAdditions()) { if (commands.getFirst() == null) { Put p = new Put(key, putTimestamp); commands.setFirst(p); } for (Entry e : mutation.getAdditions()) { commands.getFirst().add(cfName, e.getColumnAs(StaticBuffer.ARRAY_FACTORY), putTimestamp, e.getValueAs(StaticBuffer.ARRAY_FACTORY)); } } } } return commandsPerKey; }
Example 12
Source File: IndexRegionObserver.java From phoenix with Apache License 2.0 | 4 votes |
/** * This method applies pending delete mutations on the next row states */ private void applyPendingDeleteMutations(MiniBatchOperationInProgress<Mutation> miniBatchOp, BatchMutateContext context) throws IOException { for (int i = 0; i < miniBatchOp.size(); i++) { if (miniBatchOp.getOperationStatus(i) == IGNORE) { continue; } Mutation m = miniBatchOp.getOperation(i); if (!this.builder.isEnabled(m)) { continue; } if (!(m instanceof Delete)) { continue; } ImmutableBytesPtr rowKeyPtr = new ImmutableBytesPtr(m.getRow()); Pair<Put, Put> dataRowState = context.dataRowStates.get(rowKeyPtr); if (dataRowState == null) { dataRowState = new Pair<Put, Put>(null, null); context.dataRowStates.put(rowKeyPtr, dataRowState); } Put nextDataRowState = dataRowState.getSecond(); if (nextDataRowState == null) { if (dataRowState.getFirst() == null) { // This is a delete row mutation on a non-existing row. There is no need to apply this mutation // on the data table miniBatchOp.setOperationStatus(i, NOWRITE); } continue; } for (List<Cell> cells : m.getFamilyCellMap().values()) { for (Cell cell : cells) { switch (KeyValue.Type.codeToType(cell.getTypeByte())) { case DeleteFamily: case DeleteFamilyVersion: nextDataRowState.getFamilyCellMap().remove(CellUtil.cloneFamily(cell)); break; case DeleteColumn: case Delete: removeColumn(nextDataRowState, cell); } } } if (nextDataRowState != null && nextDataRowState.getFamilyCellMap().size() == 0) { dataRowState.setSecond(null); } } }