Community Articles

Find and share helpful community-sourced technical articles.
Announcements
Celebrating as our community reaches 100,000 members! Thank you!
Labels (1)
avatar
Expert Contributor

Here is an example of constructing a complex filter in HBase using Stargate REST API

Consider a Sample Input Table called 'datatable' with the following data:

hbase(main):026:0> scan 'datatable'
ROW                                            COLUMN+CELL
key1                                        column=cf1:col1, timestamp=1465135446446, value=value1
key1                                        column=cf1:col2, timestamp=1465135452934, value=value1
key2                                        column=cf2:col1, timestamp=1465135471613, value=value2
key2                                        column=cf2:col2, timestamp=1465135481068, value=value2
key3                                        column=cf1:col1, timestamp=1465137223212, value=value3
key3                                        column=cf2:col2, timestamp=1465137232291, value=value3
3 row(s) in 0.0300 seconds

Requirement

Filter the rows that matches any one of the following conditions:

Row key is "key1", where Column is {cf1:col1}

(OR)

Column is {cf2:col2}

Expected Output

  	ROW                                            COLUMN+CELL   	                              key1                                column=cf1:col1, timestamp=1465135446446, value=value1
 key2                                column=cf2:col2, timestamp=1465135481068, value=value2
 key3                                column=cf2:col2, timestamp=1465137232291, value=value3

Steps :

First, we find the Base64 equivalent conversion for CF and columns :

cf1 => Y2Yx

col1 => Y29sMQ==

key1 => a2V5MQ==

cf2=> Y2Yy

col2 => Y29sMg==

OPERATORS(op) : LESS, LESS_OR_EQUAL, EQUAL, NOT_EQUAL, GREATER_OR_EQUAL, GREATER, NO_OP; FILTER LIST (op) : MUST_PASS_ALL, MUST_PASS_ONE

Create the file complex_filter.txt, with the following contents:

<Scanner> 
<filter> 
{
	"type": "FilterList",
	"op": "MUST_PASS_ONE",
	"filters": [{
		"type": "FilterList",
		"op": "MUST_PASS_ALL",
		"filters": [{
			"type": "FamilyFilter",
			"op": "EQUAL",
			"comparator": {
				"type": "BinaryComparator",
				"value": "Y2Yx"
			}
		}, {
			"type": "QualifierFilter",
			"op": "EQUAL",
			"comparator": {
				"type": "BinaryComparator",
				"value": "Y29sMQ =="
			}
		}, {
			"type": "RowFilter",
			"op": "EQUAL",
			"comparator": {
				"type": "BinaryComparator",
				"value": "a2V5MQ=="
			}
		}]
	}, {
		"type": "FilterList",
		"op": "MUST_PASS_ALL",
		"filters": [{
			"type": "FamilyFilter",
			"op": "EQUAL",
			"comparator": {
				"type": "BinaryComparator",
				"value": "Y2Yy"
			}
		}, {
			"type": "QualifierFilter",
			"op": "EQUAL",
			"comparator": {
				"type": "BinaryComparator",
				"value": "Y29sMg=="
			}
		}]
	}]
}
</filter> 
</Scanner>

Result:

$ curl -i -H "Content-Type: text/xml" -d @complex_filter.txt http://shva1.hwxblr.com:9292/datatable/scanner

HTTP/1.1 201 Created

$ curl -i -H "Accept: application/json" http://shva1.hwxblr.com:9292/datatable/scanner/146513894809742c1664a

{"Row":[{"key":"a2V5MQ==","Cell":[{"column":"Y2YxOmNvbDE=","timestamp":1465135446446,"$":"dmFsdWUx"}]},{"key":"a2V5Mg==","Cell":[{"column":"Y2YyOmNvbDI=","timestamp":1465135481068,"$":"dmFsdWUy"}]},{"key":"a2V5Mw==","Cell":[{"column":"Y2YyOmNvbDI=","timestamp":1465137232291,"$":"dmFsdWUz"}]}]}

1,984 Views