Hbase DependentColumnFilter
Here you have a more complex filter that does not simply filter out data based on directly available information. Rather, it lets you specify a dependent column—or reference column—that controls how other columns are filtered. It uses th
Here you have a more complex filter that does not simply filter out data based on
directly available information. Rather, it lets you specify a dependent column—or
reference column—that controls how other columns are filtered. It uses the timestamp
of the reference column and includes all other columns that have the same timestamp.
尝试找到该列所在的每一行,并返回该行具有相同时间戳的全部键值对。如果某一行不包含指定的列,则该行的任何键值对都不返回。
如果dropDependentColumn=true,则从属列不返回。
via: http://abloz.com/2012/08/22/the-hbases-content-query-2.html
package com.fatkun.filter.comparison; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.HBaseAdmin; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.filter.BinaryPrefixComparator; import org.apache.hadoop.hbase.filter.CompareFilter; import org.apache.hadoop.hbase.filter.DependentColumnFilter; import org.apache.hadoop.hbase.filter.Filter; import org.apache.hadoop.hbase.filter.SubstringComparator; import org.apache.hadoop.hbase.filter.ValueFilter; import org.apache.hadoop.hbase.filter.WritableByteArrayComparable; import org.apache.hadoop.hbase.util.Bytes; public class TestHbaseDependentColumnFilter { String tableName = "test_value_filter"; Configuration config = HBaseConfiguration.create(); public void filter(boolean drop, CompareFilter.CompareOp operator, WritableByteArrayComparable comparator) throws IOException { HTable table = new HTable(config, tableName); // Filter filter; if (comparator != null) { // drop为true时,filter表示对"col1"列以外的所有"data1"列族数据做filter操作 // drop为false时,表示对所有"data1"列族的数据做filter操作 filter = new DependentColumnFilter(Bytes.toBytes("data1"), Bytes.toBytes("col1"), drop, operator, comparator); } else { filter = new DependentColumnFilter(Bytes.toBytes("data1"), Bytes.toBytes("col1"), drop); } // filter应用于scan Scan scan = new Scan(); scan.setFilter(filter); ResultScanner scanner = table.getScanner(scan); for (Result result : scanner) { for (KeyValue kv : result.list()) { System.out.println("kv=" + kv.toString() + ",value=" + Bytes.toString(kv.getValue())); } } scanner.close(); table.close(); } /** * 部分代码来自hbase权威指南 * * @throws IOException */ public void testFilter() throws IOException { // The dropDependentColumn parameter is giving you additional control // over how the reference column is handled: it is either included or // dropped by the filter // 1.获取整个"data1"列族当前Version中的所有timestamp等于参照列"data1:col1"的数据 System.out.println("drop=false"); filter(false, CompareFilter.CompareOp.NO_OP, null); // 2.获取除了"col1"列以外的"data1"列族中的所有timestamp等于参照列"data1:col1"的数据 System.out.println("drop=true"); filter(true, CompareFilter.CompareOp.NO_OP, null); // 3.获取除了"col1"列以外的"data1"列族当前Version中的所有timestamp等于参照列"data1:col1"的,value以"data100"开头的所有数据 System.out.println("比较"); filter(true, CompareFilter.CompareOp.EQUAL, new BinaryPrefixComparator( Bytes.toBytes("data100"))); } /** * 初始化数据 */ public void init() { // 创建表和初始化数据 try { HBaseAdmin admin = new HBaseAdmin(config); if (!admin.tableExists(tableName)) { HTableDescriptor htd = new HTableDescriptor(tableName); HColumnDescriptor hcd1 = new HColumnDescriptor("data1"); htd.addFamily(hcd1); HColumnDescriptor hcd2 = new HColumnDescriptor("data2"); htd.addFamily(hcd2); HColumnDescriptor hcd3 = new HColumnDescriptor("data3"); htd.addFamily(hcd3); admin.createTable(htd); } HTable table = new HTable(config, tableName); table.setAutoFlush(false); int count = 50; for (int i = 1; i <p class="copyright"> 原文地址:Hbase DependentColumnFilter, 感谢原作者分享。 </p>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

With the advent of the big data era, data processing and storage have become more and more important, and how to efficiently manage and analyze large amounts of data has become a challenge for enterprises. Hadoop and HBase, two projects of the Apache Foundation, provide a solution for big data storage and analysis. This article will introduce how to use Hadoop and HBase in Beego for big data storage and query. 1. Introduction to Hadoop and HBase Hadoop is an open source distributed storage and computing system that can

Dependency: org.springframework.dataspring-data-hadoop-hbase2.5.0.RELEASEorg.apache.hbasehbase-client1.1.2org.springframework.dataspring-data-hadoop2.5.0.RELEASE The official way to add configuration is through xml, which is simple After rewriting, it is as follows: @ConfigurationpublicclassHBaseConfiguration{@Value("${hbase.zooke

How to use Java to develop a NoSQL database application based on HBase Introduction: With the advent of the big data era, NoSQL databases have become one of the important tools for processing massive data. HBase, as an open source distributed NoSQL database system, has extensive applications in the field of big data. This article will introduce how to use Java to develop NoSQL database applications based on HBase and provide specific code examples. 1. Introduction to HBase: HBase is a distribution system based on Hadoop.

With the advent of the big data era, the storage and processing of massive data has become particularly important. In terms of NoSQL databases, HBase is currently a widely used solution. As a statically strongly typed programming language, Go language is increasingly used in fields such as cloud computing, website development, and data science due to its simple syntax and excellent performance. This article will introduce how to use HBase in Go language to implement efficient NoSQL database applications. HBase introduction HBase is a highly scalable, highly reliable, basic

With the continuous growth of Internet applications and data volume, traditional relational databases can no longer meet the needs of storing and processing massive data. As a new type of database management system, NoSQL (NotOnlySQL) has significant advantages in massive data storage and processing, and has received more and more attention and applications. Among NoSQL databases, ApacheHBase is a very popular open source distributed database. It is designed based on Google’s BigTable idea and has

Using HBase for data storage and query in Beego framework With the continuous development of the Internet era, data storage and query have become more and more critical. With the advent of the big data era, various data sources occupy an important position in their respective fields. Non-relational databases are a database with obvious advantages in data storage and query, and HBase is a distributed non-relational database based on Hadoop. Relational Database. This article will introduce how to use HBase for data storage and query in the Beego framework. 1.H

Workerman is a high-performance PHPsocket framework that can host a large number of concurrent connections. Unlike traditional PHP frameworks, Workerman does not rely on web servers such as Apache or Nginx. Instead, it runs the entire application by itself by starting a PHP process. Workerman has extremely high operating efficiency and better load capacity. At the same time, HBase is a distributed NoSQL database system that is widely used in big data

HBase is a Hadoop-based distributed storage system designed to store and process large-scale structured data. In order to optimize its read and write performance, HBase provides a variety of caching mechanisms, which can improve query efficiency and reduce read and write delays through reasonable configuration. This article will introduce HBase caching technology and how to configure it. HBase cache types HBase provides two basic cache mechanisms: block cache (BlockCache) and MemStore cache (also called write cache). The block cache is in
