org.apache.hadoop.hbase.util.Bytes.startsWith()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(95)

本文整理了Java中org.apache.hadoop.hbase.util.Bytes.startsWith()方法的一些代码示例,展示了Bytes.startsWith()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes.startsWith()方法的具体详情如下:
包路径:org.apache.hadoop.hbase.util.Bytes
类名称:Bytes
方法名:startsWith

Bytes.startsWith介绍

[英]Return true if the byte array on the right is a prefix of the byte array on the left.
[中]如果右侧的字节数组是左侧字节数组的前缀,则返回true。

代码示例

代码示例来源:origin: apache/hbase

/** Return true if the given file info key is reserved for internal use. */
public static boolean isReservedFileInfoKey(byte[] key) {
 return Bytes.startsWith(key, FileInfo.RESERVED_PREFIX_BYTES);
}

代码示例来源:origin: apache/hbase

protected static boolean isNamespaceRowKey(final byte[] key) {
 return Bytes.startsWith(key, QUOTA_NAMESPACE_ROW_KEY_PREFIX);
}

代码示例来源:origin: apache/hbase

protected static boolean isRegionServerRowKey(final byte[] key) {
 return Bytes.startsWith(key, QUOTA_REGION_SERVER_ROW_KEY_PREFIX);
}

代码示例来源:origin: apache/hbase

protected static boolean isTableRowKey(final byte[] key) {
 return Bytes.startsWith(key, QUOTA_TABLE_ROW_KEY_PREFIX);
}

代码示例来源:origin: apache/hbase

protected static boolean isUserRowKey(final byte[] key) {
 return Bytes.startsWith(key, QUOTA_USER_ROW_KEY_PREFIX);
}

代码示例来源:origin: apache/hbase

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;
 }
}

代码示例来源:origin: apache/hbase

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);
  }
 }
}

代码示例来源:origin: apache/hbase

public void testStartsWith() {
 assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("h")));
 assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("")));
 assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("hello")));
 assertFalse(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("helloworld")));
 assertFalse(Bytes.startsWith(Bytes.toBytes(""), Bytes.toBytes("hello")));
}

代码示例来源:origin: apache/hive

if (qualPrefix != null && !Bytes.startsWith(e.getKey(), qualPrefix)) {

代码示例来源:origin: apache/phoenix

public static boolean isLocalIndexFamily(byte[] cf) {
  return Bytes.startsWith(cf, QueryConstants.LOCAL_INDEX_COLUMN_FAMILY_PREFIX_BYTES);
}

代码示例来源:origin: org.apache.hbase/hbase-client

protected static boolean isUserRowKey(final byte[] key) {
 return Bytes.startsWith(key, QUOTA_USER_ROW_KEY_PREFIX);
}

代码示例来源:origin: org.apache.hbase/hbase-client

protected static boolean isNamespaceRowKey(final byte[] key) {
 return Bytes.startsWith(key, QUOTA_NAMESPACE_ROW_KEY_PREFIX);
}

代码示例来源:origin: org.apache.hbase/hbase-client

protected static boolean isTableRowKey(final byte[] key) {
 return Bytes.startsWith(key, QUOTA_TABLE_ROW_KEY_PREFIX);
}

代码示例来源:origin: org.apache.hbase/hbase-client

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;
 }
}

代码示例来源:origin: org.apache.hbase/hbase-client

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);
  }
 }
}

代码示例来源:origin: apache/phoenix

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());
}

代码示例来源:origin: apache/phoenix

@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();
    }
  }
}

代码示例来源:origin: apache/phoenix

private static KeyRange getTrailingRange(RowKeySchema rowKeySchema, int pkPos, KeyRange range, KeyRange clippedResult, ImmutableBytesWritable ptr) {
  int separatorLength = rowKeySchema.getField(pkPos).getDataType().isFixedWidth() ? 0 : 1;
  byte[] lowerRange = KeyRange.UNBOUND;
  boolean lowerInclusive = false;
  // Lower range of trailing part of RVC must be true, so we can form a new range to intersect going forward
  if (!range.lowerUnbound() && Bytes.startsWith(range.getLowerRange(), clippedResult.getLowerRange())) {
    lowerRange = range.getLowerRange();
    int offset = clippedResult.getLowerRange().length + separatorLength;
    ptr.set(lowerRange, offset, lowerRange.length - offset);
    lowerRange = ptr.copyBytes();
    lowerInclusive = range.isLowerInclusive();
  }
  byte[] upperRange = KeyRange.UNBOUND;
  boolean upperInclusive = false;
  if (!range.upperUnbound() && Bytes.startsWith(range.getUpperRange(), clippedResult.getUpperRange())) {
    upperRange = range.getUpperRange();
    int offset = clippedResult.getUpperRange().length + separatorLength;
    ptr.set(upperRange, offset, upperRange.length - offset);
    upperRange = ptr.copyBytes();
    upperInclusive = range.isUpperInclusive();
  }
  return KeyRange.getKeyRange(lowerRange, lowerInclusive, upperRange, upperInclusive);
}

代码示例来源:origin: org.apache.hbase/hbase-common

public void testStartsWith() {
 assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("h")));
 assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("")));
 assertTrue(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("hello")));
 assertFalse(Bytes.startsWith(Bytes.toBytes("hello"), Bytes.toBytes("helloworld")));
 assertFalse(Bytes.startsWith(Bytes.toBytes(""), Bytes.toBytes("hello")));
}

代码示例来源:origin: apache/phoenix

if (Bytes.startsWith(otherLowerRange, trailingBytes) && 
    (isFixedWidthAtEnd || 
     otherLowerRange.length == trailingBytes.length ||

相关文章

微信公众号

最新文章

更多