HBase 数据库:是否可以使用 Java API/REST API 对列限定符进行过滤?
HBase database : Is it possible to filter on a column qualifier using Java API/REST API?
我是 HBase 的新手,我习惯了 RDBMS 数据库,我可以在其中使用 WHERE 子句 来过滤记录。
那么,是否有类似于 RDBMS 使用 Java API 或 REST API 的东西由 HBase 暴露给使用 列限定符 ?
过滤记录
是的,这是可能的。
如果您只想获得某些列限定符,那么您应该使用 Get or Scan 实例的 addColumn(byte[] family, byte[] qualifier)
方法。这是查询所需限定符的最有效方式,因为只需要访问表示请求中特定列的 HBase 存储。使用示例:
Get = new Get(Bytes.toBytes("rowKey"));
get.addColumn(Bytes.toBytes("columnFamily", Bytes.toBytes("Qual"));
Scan scan = new Scan();
scan.addColumn(Bytes.toBytes("columnFamily"), Bytes.toBytes("Qual1"));
scan.addColumn(Bytes.toBytes("columnFamily"), Bytes.toBytes("Qual2"));
如果您需要更复杂的工具来过滤限定词,那么您可以使用 Java API 中的 QualifierFilter class。如何使用特定限定符查询所有列的示例:
Filter filter = new QualifierFilter(CompareFilter.CompareOp.EQUAL,
new BinaryComparator(Bytes.toBytes("columnQual")));
Get = new Get(Bytes.toBytes("rowKey"));
get.setFilter(filter);
Scan scan = new Scan();
scan.setFilter(filter);
您还可以在官方 HBase 文档中阅读 another HBase filters and how combine them。
我是 HBase 的新手,我习惯了 RDBMS 数据库,我可以在其中使用 WHERE 子句 来过滤记录。 那么,是否有类似于 RDBMS 使用 Java API 或 REST API 的东西由 HBase 暴露给使用 列限定符 ?
过滤记录是的,这是可能的。
如果您只想获得某些列限定符,那么您应该使用 Get or Scan 实例的 addColumn(byte[] family, byte[] qualifier)
方法。这是查询所需限定符的最有效方式,因为只需要访问表示请求中特定列的 HBase 存储。使用示例:
Get = new Get(Bytes.toBytes("rowKey"));
get.addColumn(Bytes.toBytes("columnFamily", Bytes.toBytes("Qual"));
Scan scan = new Scan();
scan.addColumn(Bytes.toBytes("columnFamily"), Bytes.toBytes("Qual1"));
scan.addColumn(Bytes.toBytes("columnFamily"), Bytes.toBytes("Qual2"));
如果您需要更复杂的工具来过滤限定词,那么您可以使用 Java API 中的 QualifierFilter class。如何使用特定限定符查询所有列的示例:
Filter filter = new QualifierFilter(CompareFilter.CompareOp.EQUAL,
new BinaryComparator(Bytes.toBytes("columnQual")));
Get = new Get(Bytes.toBytes("rowKey"));
get.setFilter(filter);
Scan scan = new Scan();
scan.setFilter(filter);
您还可以在官方 HBase 文档中阅读 another HBase filters and how combine them。