/** * Adds the option to pre-load filters at startup. * * @param conf The current configuration instance. */ protected static void registerFilters(Configuration conf) { String[] filters = conf.getStrings("hbase.thrift.filters"); if(filters != null) { for(String filterClass: filters) { String[] filterPart = filterClass.split(":"); if(filterPart.length != 2) { log.warn("Invalid filter specification " + filterClass + " - skipping"); } else { ParseFilter.registerFilter(filterPart[0], filterPart[1]); } } } }
public static void registerFilters(Configuration conf) { String[] filters = conf.getStrings("hbase.thrift.filters"); if(filters != null) { for(String filterClass: filters) { String[] filterPart = filterClass.split(":"); if(filterPart.length != 2) { LOG.warn("Invalid filter specification " + filterClass + " - skipping"); } else { ParseFilter.registerFilter(filterPart[0], filterPart[1]); } } } }
@Test public void testFilterRegistration() throws Exception { Configuration conf = UTIL.getConfiguration(); conf.set("hbase.thrift.filters", "MyFilter:filterclass"); ThriftServer.registerFilters(conf); Map<String, String> registeredFilters = ParseFilter.getAllFilters(); assertEquals("filterclass", registeredFilters.get("MyFilter")); }
private void registerCustomFilter(Configuration conf) { String[] filterList = conf.getStrings(Constants.CUSTOM_FILTERS); if (filterList != null) { for (String filterClass : filterList) { String[] filterPart = filterClass.split(":"); if (filterPart.length != 2) { LOG.warn( "Invalid filter specification " + filterClass + " - skipping"); } else { ParseFilter.registerFilter(filterPart[0], filterPart[1]); } } } }
/** * Creates a {@link Get} (HBase) from a {@link TGet} (Thrift). * * This ignores any timestamps set on {@link TColumn} objects. * * @param in the <code>TGet</code> to convert * * @return <code>Get</code> object * * @throws IOException if an invalid time range or max version parameter is given */ public static Get getFromThrift(TGet in) throws IOException { Get out = new Get(in.getRow()); // Timestamp overwrites time range if both are set if (in.isSetTimestamp()) { out.setTimeStamp(in.getTimestamp()); } else if (in.isSetTimeRange()) { out.setTimeRange(in.getTimeRange().getMinStamp(), in.getTimeRange().getMaxStamp()); } if (in.isSetMaxVersions()) { out.setMaxVersions(in.getMaxVersions()); } if (in.isSetFilterString()) { ParseFilter parseFilter = new ParseFilter(); out.setFilter(parseFilter.parseFilterString(in.getFilterString())); } if (in.isSetAttributes()) { addAttributes(out,in.getAttributes()); } if (!in.isSetColumns()) { return out; } for (TColumn column : in.getColumns()) { if (column.isSetQualifier()) { out.addColumn(column.getFamily(), column.getQualifier()); } else { out.addFamily(column.getFamily()); } } return out; }
public int scannerOpenWithScan(ByteBuffer tableName, TScan tScan, Map<ByteBuffer, ByteBuffer> attributes) throws IOError { try { HTable table = getTable(tableName); Scan scan = new Scan(); addAttributes(scan, attributes); if (tScan.isSetStartRow()) { scan.setStartRow(tScan.getStartRow()); } if (tScan.isSetStopRow()) { scan.setStopRow(tScan.getStopRow()); } if (tScan.isSetTimestamp()) { scan.setTimeRange(Long.MIN_VALUE, tScan.getTimestamp()); } if (tScan.isSetCaching()) { scan.setCaching(tScan.getCaching()); } if (tScan.isSetColumns() && tScan.getColumns().size() != 0) { for(ByteBuffer column : tScan.getColumns()) { byte [][] famQf = KeyValue.parseColumn(getBytes(column)); if(famQf.length == 1) { scan.addFamily(famQf[0]); } else { scan.addColumn(famQf[0], famQf[1]); } } } if (tScan.isSetFilterString()) { ParseFilter parseFilter = new ParseFilter(); scan.setFilter( parseFilter.parseFilterString(tScan.getFilterString())); } return addScanner(table.getScanner(scan), tScan.sortColumns); } catch (IOException e) { LOG.warn(e.getMessage(), e); throw new IOError(e.getMessage()); } }
public int scannerOpenWithScan(ByteBuffer tableName, TScan tScan) throws IOError { try { HTable table = getTable(tableName); Scan scan = new Scan(); if (tScan.isSetStartRow()) { scan.setStartRow(tScan.getStartRow()); } if (tScan.isSetStopRow()) { scan.setStopRow(tScan.getStopRow()); } if (tScan.isSetTimestamp()) { scan.setTimeRange(Long.MIN_VALUE, tScan.getTimestamp()); } if (tScan.isSetCaching()) { scan.setCaching(tScan.getCaching()); } if(tScan.isSetColumns() && tScan.getColumns().size() != 0) { for(ByteBuffer column : tScan.getColumns()) { byte [][] famQf = KeyValue.parseColumn(getBytes(column)); if(famQf.length == 1) { scan.addFamily(famQf[0]); } else { scan.addColumn(famQf[0], famQf[1]); } } } if (tScan.isSetFilterString()) { ParseFilter parseFilter = new ParseFilter(); scan.setFilter(parseFilter.parseFilterString(tScan.getFilterString())); } return addScanner(table.getScanner(scan)); } catch (IOException e) { throw new IOError(e.getMessage()); } }
public int scannerOpenWithScan(ByteBuffer tableName, TScan tScan, Map<ByteBuffer, ByteBuffer> attributes) throws IOError { try { HTable table = getTable(tableName); Scan scan = new Scan(); addAttributes(scan, attributes); if (tScan.isSetStartRow()) { scan.setStartRow(tScan.getStartRow()); } if (tScan.isSetStopRow()) { scan.setStopRow(tScan.getStopRow()); } if (tScan.isSetTimestamp()) { scan.setTimeRange(Long.MIN_VALUE, tScan.getTimestamp()); } if (tScan.isSetCaching()) { scan.setCaching(tScan.getCaching()); } if (tScan.isSetColumns() && tScan.getColumns().size() != 0) { for(ByteBuffer column : tScan.getColumns()) { byte [][] famQf = KeyValue.parseColumn(getBytes(column)); if(famQf.length == 1) { scan.addFamily(famQf[0]); } else { scan.addColumn(famQf[0], famQf[1]); } } } if (tScan.isSetFilterString()) { ParseFilter parseFilter = new ParseFilter(); scan.setFilter( parseFilter.parseFilterString(tScan.getFilterString())); } return addScanner(table.getScanner(scan)); } catch (IOException e) { LOG.warn(e.getMessage(), e); throw new IOError(e.getMessage()); } }
/** * Creates a {@link Get} (HBase) from a {@link TGet} (Thrift). * * This ignores any timestamps set on {@link TColumn} objects. * * @param in the <code>TGet</code> to convert * * @return <code>Get</code> object * * @throws IOException if an invalid time range or max version parameter is given */ public static Get getFromThrift(TGet in) throws IOException { Get out = new Get(in.getRow()); // Timestamp overwrites time range if both are set if (in.isSetTimestamp()) { out.setTimeStamp(in.getTimestamp()); } else if (in.isSetTimeRange()) { out.setTimeRange(in.getTimeRange().getMinStamp(), in.getTimeRange().getMaxStamp()); } if (in.isSetMaxVersions()) { out.setMaxVersions(in.getMaxVersions()); } if (in.isSetFilterString()) { ParseFilter parseFilter = new ParseFilter(); out.setFilter(parseFilter.parseFilterString(in.getFilterString())); } if (in.isSetAttributes()) { addAttributes(out,in.getAttributes()); } if (in.isSetAuthorizations()) { out.setAuthorizations(new Authorizations(in.getAuthorizations().getLabels())); } if (!in.isSetColumns()) { return out; } for (TColumn column : in.getColumns()) { if (column.isSetQualifier()) { out.addColumn(column.getFamily(), column.getQualifier()); } else { out.addFamily(column.getFamily()); } } return out; }
public static Scan scanFromThrift(TScan in) throws IOException { Scan out = new Scan(); if (in.isSetStartRow()) out.setStartRow(in.getStartRow()); if (in.isSetStopRow()) out.setStopRow(in.getStopRow()); if (in.isSetCaching()) out.setCaching(in.getCaching()); if (in.isSetMaxVersions()) { out.setMaxVersions(in.getMaxVersions()); } if (in.isSetColumns()) { for (TColumn column : in.getColumns()) { if (column.isSetQualifier()) { out.addColumn(column.getFamily(), column.getQualifier()); } else { out.addFamily(column.getFamily()); } } } TTimeRange timeRange = in.getTimeRange(); if (timeRange != null && timeRange.isSetMinStamp() && timeRange.isSetMaxStamp()) { out.setTimeRange(timeRange.getMinStamp(), timeRange.getMaxStamp()); } if (in.isSetBatchSize()) { out.setBatch(in.getBatchSize()); } if (in.isSetFilterString()) { ParseFilter parseFilter = new ParseFilter(); out.setFilter(parseFilter.parseFilterString(in.getFilterString())); } if (in.isSetAttributes()) { addAttributes(out,in.getAttributes()); } if (in.isSetAuthorizations()) { out.setAuthorizations(new Authorizations(in.getAuthorizations().getLabels())); } if (in.isSetReversed()) { out.setReversed(in.isReversed()); } return out; }
@Override public int scannerOpenWithScan(ByteBuffer tableName, TScan tScan, Map<ByteBuffer, ByteBuffer> attributes) throws IOError { Table table = null; try { table = getTable(tableName); Scan scan = new Scan(); addAttributes(scan, attributes); if (tScan.isSetStartRow()) { scan.setStartRow(tScan.getStartRow()); } if (tScan.isSetStopRow()) { scan.setStopRow(tScan.getStopRow()); } if (tScan.isSetTimestamp()) { scan.setTimeRange(0, tScan.getTimestamp()); } if (tScan.isSetCaching()) { scan.setCaching(tScan.getCaching()); } if (tScan.isSetBatchSize()) { scan.setBatch(tScan.getBatchSize()); } if (tScan.isSetColumns() && tScan.getColumns().size() != 0) { for(ByteBuffer column : tScan.getColumns()) { byte [][] famQf = KeyValue.parseColumn(getBytes(column)); if(famQf.length == 1) { scan.addFamily(famQf[0]); } else { scan.addColumn(famQf[0], famQf[1]); } } } if (tScan.isSetFilterString()) { ParseFilter parseFilter = new ParseFilter(); scan.setFilter( parseFilter.parseFilterString(tScan.getFilterString())); } if (tScan.isSetReversed()) { scan.setReversed(tScan.isReversed()); } return addScanner(table.getScanner(scan), tScan.sortColumns); } catch (IOException e) { LOG.warn(e.getMessage(), e); throw new IOError(Throwables.getStackTraceAsString(e)); } finally{ closeTable(table); } }
public static Filter createFilterFromArguments(ArrayList<byte[]> filterArguments) { byte[] prefix = ParseFilter.removeQuotesFromByteArray(filterArguments.get(0)); return new CustomFilter(prefix); }
public static Scan scanFromThrift(TScan in) throws IOException { Scan out = new Scan(); if (in.isSetStartRow()) out.setStartRow(in.getStartRow()); if (in.isSetStopRow()) out.setStopRow(in.getStopRow()); if (in.isSetCaching()) out.setCaching(in.getCaching()); if (in.isSetMaxVersions()) { out.setMaxVersions(in.getMaxVersions()); } if (in.isSetColumns()) { for (TColumn column : in.getColumns()) { if (column.isSetQualifier()) { out.addColumn(column.getFamily(), column.getQualifier()); } else { out.addFamily(column.getFamily()); } } } TTimeRange timeRange = in.getTimeRange(); if (timeRange != null && timeRange.isSetMinStamp() && timeRange.isSetMaxStamp()) { out.setTimeRange(timeRange.getMinStamp(), timeRange.getMaxStamp()); } if (in.isSetBatchSize()) { out.setBatch(in.getBatchSize()); } if (in.isSetFilterString()) { ParseFilter parseFilter = new ParseFilter(); out.setFilter(parseFilter.parseFilterString(in.getFilterString())); } if (in.isSetAttributes()) { addAttributes(out,in.getAttributes()); } return out; }