Java Code Examples for org.apache.hadoop.hbase.util.Bytes#startsWith()
The following examples show how to use
org.apache.hadoop.hbase.util.Bytes#startsWith() .
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: QuotaTableUtil.java From hbase with Apache License 2.0 | 7 votes |
protected static void parseUserResult(final String userName, final Result result, final UserQuotasVisitor visitor) throws IOException { Map<byte[], byte[]> familyMap = result.getFamilyMap(QUOTA_FAMILY_INFO); if (familyMap == null || familyMap.isEmpty()) return; for (Map.Entry<byte[], byte[]> entry: familyMap.entrySet()) { Quotas quotas = quotasFromData(entry.getValue()); if (Bytes.startsWith(entry.getKey(), QUOTA_QUALIFIER_SETTINGS_PREFIX)) { String name = Bytes.toString(entry.getKey(), QUOTA_QUALIFIER_SETTINGS_PREFIX.length); if (name.charAt(name.length() - 1) == TableName.NAMESPACE_DELIM) { String namespace = name.substring(0, name.length() - 1); visitor.visitUserQuotas(userName, namespace, quotas); } else { TableName table = TableName.valueOf(name); visitor.visitUserQuotas(userName, table, quotas); } } else if (Bytes.equals(entry.getKey(), QUOTA_QUALIFIER_SETTINGS)) { visitor.visitUserQuotas(userName, quotas); } } }
Example 2
Source File: MultipleColumnPrefixFilter.java From hbase with Apache License 2.0 | 6 votes |
public ReturnCode filterColumn(Cell cell) { byte [] qualifier = CellUtil.cloneQualifier(cell); TreeSet<byte []> lesserOrEqualPrefixes = (TreeSet<byte []>) sortedPrefixes.headSet(qualifier, true); if (lesserOrEqualPrefixes.size() != 0) { byte [] largestPrefixSmallerThanQualifier = lesserOrEqualPrefixes.last(); if (Bytes.startsWith(qualifier, largestPrefixSmallerThanQualifier)) { return ReturnCode.INCLUDE; } if (lesserOrEqualPrefixes.size() == sortedPrefixes.size()) { return ReturnCode.NEXT_ROW; } else { hint = sortedPrefixes.higher(largestPrefixSmallerThanQualifier); return ReturnCode.SEEK_NEXT_USING_HINT; } } else { hint = sortedPrefixes.first(); return ReturnCode.SEEK_NEXT_USING_HINT; } }
Example 3
Source File: WhereOptimizer.java From phoenix with Apache License 2.0 | 6 votes |
private static KeyRange concatSuffix(KeyRange result, KeyRange otherRange) { byte[] lowerRange = result.getLowerRange(); byte[] clippedLowerRange = lowerRange; byte[] fullLowerRange = otherRange.getLowerRange(); if (!result.lowerUnbound() && Bytes.startsWith(fullLowerRange, clippedLowerRange)) { lowerRange = fullLowerRange; } byte[] upperRange = result.getUpperRange(); byte[] clippedUpperRange = upperRange; byte[] fullUpperRange = otherRange.getUpperRange(); if (!result.lowerUnbound() && Bytes.startsWith(fullUpperRange, clippedUpperRange)) { upperRange = fullUpperRange; } if (lowerRange == clippedLowerRange && upperRange == clippedUpperRange) { return result; } return KeyRange.getKeyRange(lowerRange, result.isLowerInclusive(), upperRange, result.isUpperInclusive()); }
Example 4
Source File: ImmutableIndexIT.java From phoenix with Apache License 2.0 | 6 votes |
@Override public void postPut(org.apache.hadoop.hbase.coprocessor.ObserverContext<RegionCoprocessorEnvironment> c, Put put, org.apache.hadoop.hbase.wal.WALEdit edit, Durability durability) throws java.io.IOException { String tableName = c.getEnvironment().getRegion().getRegionInfo().getTable().getNameAsString(); if (tableName.equalsIgnoreCase(TABLE_NAME) // create the index after the second batch && Bytes.startsWith(put.getRow(), Bytes.toBytes("varchar200_upsert_select"))) { Runnable r = new Runnable() { @Override public void run() { Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); try (Connection conn = DriverManager.getConnection(getUrl(), props)) { // Run CREATE INDEX call in separate thread as otherwise we block // this thread (not a realistic scenario) and prevent our catchup // query from adding the missing rows. conn.createStatement().execute(INDEX_DDL); } catch (SQLException e) { } } }; new Thread(r).start(); } }
Example 5
Source File: JobHistoryService.java From hraven with Apache License 2.0 | 6 votes |
/** * Converts serialized configuration properties back in to a Configuration * object. * * @param keyValues * @return */ public static Configuration parseConfiguration( Map<byte[], byte[]> keyValues) { Configuration config = new Configuration(false); byte[] configPrefix = Bytes.add(Constants.JOB_CONF_COLUMN_PREFIX_BYTES, Constants.SEP_BYTES); for (Map.Entry<byte[], byte[]> entry : keyValues.entrySet()) { byte[] key = entry.getKey(); if (Bytes.startsWith(key, configPrefix) && key.length > configPrefix.length) { byte[] name = Bytes.tail(key, key.length - configPrefix.length); config.set(Bytes.toString(name), Bytes.toString(entry.getValue())); } } return config; }
Example 6
Source File: JobHistoryService.java From hraven with Apache License 2.0 | 6 votes |
/** * Converts encoded key values back into counter objects. * * @param keyValues * @return */ public static CounterMap parseCounters(byte[] prefix, Map<byte[], byte[]> keyValues) { CounterMap counterValues = new CounterMap(); byte[] counterPrefix = Bytes.add(prefix, Constants.SEP_BYTES); for (Map.Entry<byte[], byte[]> entry : keyValues.entrySet()) { byte[] key = entry.getKey(); if (Bytes.startsWith(key, counterPrefix) && key.length > counterPrefix.length) { // qualifier should be in the format: g!countergroup!counterkey byte[][] qualifierFields = ByteUtil.split(Bytes.tail(key, key.length - counterPrefix.length), Constants.SEP_BYTES); if (qualifierFields.length != 2) { throw new IllegalArgumentException( "Malformed column qualifier for counter value: " + Bytes.toStringBinary(key)); } Counter c = new Counter(Bytes.toString(qualifierFields[0]), Bytes.toString(qualifierFields[1]), Bytes.toLong(entry.getValue())); counterValues.add(c); } } return counterValues; }
Example 7
Source File: AbstractPrefixMatchingExtractor.java From hbase-indexer with Apache License 2.0 | 6 votes |
@Override public Collection<byte[]> extract(Result result) { List<byte[]> values = Lists.newArrayList(); NavigableMap<byte[], byte[]> qualifiersToValues = result.getFamilyMap(columnFamily); if (qualifiersToValues != null) { for (byte[] qualifier : qualifiersToValues.navigableKeySet().tailSet(prefix)) { if (Bytes.startsWith(qualifier, prefix)) { values.add(extractInternal(qualifier, qualifiersToValues.get(qualifier))); } else { break; } } } return values; }
Example 8
Source File: HFileInfo.java From hbase with Apache License 2.0 | 4 votes |
/** Return true if the given file info key is reserved for internal use. */ public static boolean isReservedFileInfoKey(byte[] key) { return Bytes.startsWith(key, HFileInfo.RESERVED_PREFIX_BYTES); }
Example 9
Source File: QuotaTableUtil.java From hbase with Apache License 2.0 | 4 votes |
protected static boolean isNamespaceRowKey(final byte[] key) { return Bytes.startsWith(key, QUOTA_NAMESPACE_ROW_KEY_PREFIX); }
Example 10
Source File: QuotaTableUtil.java From hbase with Apache License 2.0 | 4 votes |
protected static boolean isRegionServerRowKey(final byte[] key) { return Bytes.startsWith(key, QUOTA_REGION_SERVER_ROW_KEY_PREFIX); }
Example 11
Source File: QuotaTableUtil.java From hbase with Apache License 2.0 | 4 votes |
protected static boolean isTableRowKey(final byte[] key) { return Bytes.startsWith(key, QUOTA_TABLE_ROW_KEY_PREFIX); }
Example 12
Source File: QuotaTableUtil.java From hbase with Apache License 2.0 | 4 votes |
protected static boolean isUserRowKey(final byte[] key) { return Bytes.startsWith(key, QUOTA_USER_ROW_KEY_PREFIX); }
Example 13
Source File: HBaseStorage.java From spork with Apache License 2.0 | 4 votes |
public boolean hasPrefixMatch(byte[] qualifier) { return Bytes.startsWith(qualifier, columnPrefix); }
Example 14
Source File: WhereOptimizer.java From phoenix with Apache License 2.0 | 4 votes |
/** * Intersects an RVC that starts at pkPos with an overlapping range that starts at otherPKPos. * For example, ((A, B) - (J, K)) intersected with (F - *) would return ((A,F) - (J, K)) * ((A, B) - (J, K)) intersected with (M - P) would return (A-J) since both of the trailing * part of the RVC, B and K, do not intersect with B and K. * @param result an RVC expression starting from pkPos and with length of at least otherPKPos - pkPos. * @param pkPos the PK position of the leading part of the RVC expression * @param otherRange the other range to intersect with the overlapping part of the RVC. * @param otherPKPos the PK position of the leading part of the other range * @return resulting KeyRange from the intersection, potentially an empty range if the result RVC * is a single key and the trailing part of the key does not intersect with the RVC. */ private KeyRange intersectTrailing(KeyRange result, int pkPos, KeyRange otherRange, int otherPKPos) { RowKeySchema rowKeySchema = table.getRowKeySchema(); ImmutableBytesWritable ptr = context.getTempPtr(); int separatorLength = table.getPKColumns().get(otherPKPos-1).getDataType().isFixedWidth() ? 0 : 1; boolean lowerInclusive = result.isLowerInclusive(); byte[] lowerRange = result.getLowerRange(); ptr.set(lowerRange); // Position ptr at the point at which the two ranges overlap if (rowKeySchema.position(ptr, pkPos, otherPKPos)) { int lowerOffset = ptr.getOffset(); // Increase the length of the ptr to include the entire trailing bytes ptr.set(ptr.get(), lowerOffset, lowerRange.length - lowerOffset); byte[] trailingBytes = ptr.copyBytes(); // Special case for single key since single keys of different span lengths // will never overlap. We do not need to process both the lower and upper // ranges since they are the same. if (result.isSingleKey() && otherRange.isSingleKey()) { int minSpan = rowKeySchema.computeMinSpan(pkPos, result, ptr); int otherMinSpan = rowKeySchema.computeMinSpan(otherPKPos, otherRange, ptr); byte[] otherLowerRange; boolean isFixedWidthAtEnd; if (pkPos + minSpan <= otherPKPos + otherMinSpan) { otherLowerRange = otherRange.getLowerRange(); isFixedWidthAtEnd = table.getPKColumns().get(pkPos + minSpan -1).getDataType().isFixedWidth(); } else { otherLowerRange = trailingBytes; trailingBytes = otherRange.getLowerRange(); isFixedWidthAtEnd = table.getPKColumns().get(otherPKPos + otherMinSpan -1).getDataType().isFixedWidth(); } // If the otherRange starts with the overlapping trailing byte *and* we're comparing // the entire key (i.e. not just a leading subset), then we have an intersection. if (Bytes.startsWith(otherLowerRange, trailingBytes) && (isFixedWidthAtEnd || otherLowerRange.length == trailingBytes.length || otherLowerRange[trailingBytes.length] == QueryConstants.SEPARATOR_BYTE)) { return result; } // Otherwise, there is no overlap return KeyRange.EMPTY_RANGE; } // If we're not dealing with single keys, then we can use our normal intersection if (otherRange.intersect(KeyRange.getKeyRange(trailingBytes)) == KeyRange.EMPTY_RANGE) { // Exit early since the upper range is the same as the lower range if (result.isSingleKey()) { return KeyRange.EMPTY_RANGE; } ptr.set(result.getLowerRange(), 0, lowerOffset - separatorLength); lowerRange = ptr.copyBytes(); } } boolean upperInclusive = result.isUpperInclusive(); byte[] upperRange = result.getUpperRange(); ptr.set(upperRange); if (rowKeySchema.position(ptr, pkPos, otherPKPos)) { int upperOffset = ptr.getOffset(); ptr.set(ptr.get(), upperOffset, upperRange.length - upperOffset); if (otherRange.intersect(KeyRange.getKeyRange(ptr.copyBytes())) == KeyRange.EMPTY_RANGE) { ptr.set(ptr.get(), 0, upperOffset - separatorLength); upperRange = ptr.copyBytes(); } } if (lowerRange == result.getLowerRange() && upperRange == result.getUpperRange()) { return result; } KeyRange range = KeyRange.getKeyRange(lowerRange, lowerInclusive, upperRange, upperInclusive); return range; }
Example 15
Source File: MetaDataUtil.java From phoenix with Apache License 2.0 | 4 votes |
public static boolean isLocalIndexFamily(byte[] cf) { return Bytes.startsWith(cf, QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX_BYTES); }
Example 16
Source File: AbstractPrefixMatchingExtractor.java From hbase-indexer with Apache License 2.0 | 4 votes |
@Override public boolean isApplicable(KeyValue keyValue) { return CellUtil.matchingFamily(keyValue, columnFamily) && Bytes.startsWith(CellUtil.cloneQualifier(keyValue), prefix); }