Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Bergqvist dbergqvist

  • New York, New York
  • Twitter @bexie
View GitHub Profile
View grantAccess.txt
gcloud projects add-iam-policy-binding my-project --member user:alice@example.com --role roles/cloudsql.admin
View MultiRangeScan.java
Query query = Query.create(TABLE_ID);
for (String busLine : MANHATTAN_BUS_LINES) {
query.range("MTA/" + busLine + "/1496275200000", "MTA/" + busLine + "/1496275200001");
}
query.filter(FILTERS
.interleave()
.filter(FILTERS.qualifier().exactMatch(LAT_COLUMN_NAME_STRING))
.filter(FILTERS.qualifier().exactMatch(LONG_COLUMN_NAME_STRING)));
View MultiRangeScanHBase.java
private static final String[] MANHATTAN_BUS_LINES = {"M1","M2","M3",...
List<RowRange> ranges = new ArrayList<>();
for (String busLine : MANHATTAN_BUS_LINES) {
ranges.add(
new RowRange(
Bytes.toBytes("MTA/" + busLine + "/1496275200000"), true,
Bytes.toBytes("MTA/" + busLine + "/1496275200001"), false));
}
Filter filter = new MultiRowRangeFilter(ranges);
View FiltersWest.java
.filter(FILTERS.qualifier().exactMatch("DestinationName"))
.filter(FILTERS.value().exactMatch("Select Bus Service Westside West End AV")))
View FiltersWestHBase.java
SingleColumnValueFilter valueFilter =
new SingleColumnValueFilter(
COLUMN_FAMILY_NAME,
Bytes.toBytes("DestinationName"),
CompareOp.EQUAL,
Bytes.toBytes("Select Bus Service Westside West End AV"));
View FiltersEast.java
Filters.ChainFilter chain = FILTERS
.chain()
.filter(FILTERS.limit().cellsPerColumn(1))
.filter(FILTERS.condition(
FILTERS.chain()
.filter(FILTERS.limit().cellsPerColumn(1))
.filter(FILTERS.qualifier().exactMatch("DestinationName"))
.filter(FILTERS.value().exactMatch("Select Bus Service Yorkville East End AV")))
.then(FILTERS
.interleave()
View FiltersEastHBase.java
Scan scan = new Scan();
SingleColumnValueFilter valueFilter =
new SingleColumnValueFilter(
COLUMN_FAMILY_NAME,
Bytes.toBytes("DestinationName"),
CompareOp.EQUAL,
Bytes.toBytes("Select Bus Service Yorkville East End AV"));
scan.setMaxVersions(1)
View ScanPartial.java
Query.create(TABLE_ID)
.prefix("MTA/M86-SBS/")
.filter(FILTERS.limit().cellsPerColumn(1))
View ScanHBasePartial.java
scan.withStartRow(Bytes.toBytes("MTA/M86-SBS/"))
.setRowPrefixFilter(Bytes.toBytes("MTA/M86-SBS/"));
//Optionally, reduce the result to receive one version per column
scan.setMaxVersions(1);
View Scan.java
Query query = Query.create(TABLE_ID)
.prefix("MTA/M86-SBS/1496275200000")
.filter(FILTERS
.interleave()
.filter(FILTERS.qualifier().exactMatch(LAT_COLUMN_NAME_STRING))
.filter(FILTERS.qualifier().exactMatch(LONG_COLUMN_NAME_STRING)));
ServerStream<Row> rows = dataClient.readRows(query);