Java 类org.apache.hadoop.hbase.filter.FirstKeyValueMatchingQualifiersFilter 实例源码

项目:ditb    文件:TestPartialResultsFromClientSide.java   
/**
 * Test partial Result re-assembly in the presence of different filters. The Results from the
 * partial scanner should match the Results returned from a scanner that receives all of the
 * results in one RPC to the server. The partial scanner is tested with a variety of different
 * result sizes (all of which are less than the size necessary to fetch an entire row)
 * @throws Exception
 */
@Test
public void testPartialResultsWithColumnFilter() throws Exception {
  testPartialResultsWithColumnFilter(new FirstKeyOnlyFilter());
  testPartialResultsWithColumnFilter(new ColumnPrefixFilter(Bytes.toBytes("testQualifier5")));
  testPartialResultsWithColumnFilter(new ColumnRangeFilter(Bytes.toBytes("testQualifer1"), true,
      Bytes.toBytes("testQualifier7"), true));

  Set<byte[]> qualifiers = new LinkedHashSet<>();
  qualifiers.add(Bytes.toBytes("testQualifier5"));
  testPartialResultsWithColumnFilter(new FirstKeyValueMatchingQualifiersFilter(qualifiers));
}
项目:hbase    文件:TestPartialResultsFromClientSide.java   
/**
 * Test partial Result re-assembly in the presence of different filters. The Results from the
 * partial scanner should match the Results returned from a scanner that receives all of the
 * results in one RPC to the server. The partial scanner is tested with a variety of different
 * result sizes (all of which are less than the size necessary to fetch an entire row)
 * @throws Exception
 */
@Test
public void testPartialResultsWithColumnFilter() throws Exception {
  testPartialResultsWithColumnFilter(new FirstKeyOnlyFilter());
  testPartialResultsWithColumnFilter(new ColumnPrefixFilter(Bytes.toBytes("testQualifier5")));
  testPartialResultsWithColumnFilter(new ColumnRangeFilter(Bytes.toBytes("testQualifer1"), true,
      Bytes.toBytes("testQualifier7"), true));

  Set<byte[]> qualifiers = new LinkedHashSet<>();
  qualifiers.add(Bytes.toBytes("testQualifier5"));
  testPartialResultsWithColumnFilter(new FirstKeyValueMatchingQualifiersFilter(qualifiers));
}
项目:HIndex    文件:RowCounter.java   
/**
 * Sets up the actual job.
 *
 * @param conf  The current configuration.
 * @param args  The command line parameters.
 * @return The newly created job.
 * @throws IOException When setting up the job fails.
 */
public static Job createSubmittableJob(Configuration conf, String[] args)
throws IOException {
  String tableName = args[0];
  String startKey = null;
  String endKey = null;
  StringBuilder sb = new StringBuilder();

  final String rangeSwitch = "--range=";

  // First argument is table name, starting from second
  for (int i = 1; i < args.length; i++) {
    if (args[i].startsWith(rangeSwitch)) {
      String[] startEnd = args[i].substring(rangeSwitch.length()).split(",", 2);
      if (startEnd.length != 2 || startEnd[1].contains(",")) {
        printUsage("Please specify range in such format as \"--range=a,b\" " +
            "or, with only one boundary, \"--range=,b\" or \"--range=a,\"");
        return null;
      }
      startKey = startEnd[0];
      endKey = startEnd[1];
    }
    else {
      // if no switch, assume column names
      sb.append(args[i]);
      sb.append(" ");
    }
  }

  Job job = new Job(conf, NAME + "_" + tableName);
  job.setJarByClass(RowCounter.class);
  Scan scan = new Scan();
  scan.setCacheBlocks(false);
  Set<byte []> qualifiers = new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR);
  if (startKey != null && !startKey.equals("")) {
    scan.setStartRow(Bytes.toBytes(startKey));
  }
  if (endKey != null && !endKey.equals("")) {
    scan.setStopRow(Bytes.toBytes(endKey));
  }
  scan.setFilter(new FirstKeyOnlyFilter());
  if (sb.length() > 0) {
    for (String columnName : sb.toString().trim().split(" ")) {
      String family = StringUtils.substringBefore(columnName, ":");
      String qualifier = StringUtils.substringAfter(columnName, ":");

      if (StringUtils.isBlank(qualifier)) {
        scan.addFamily(Bytes.toBytes(family));
      }
      else {
        scan.addColumn(Bytes.toBytes(family), Bytes.toBytes(qualifier));
      }
    }
  }
  // specified column may or may not be part of first key value for the row.
  // Hence do not use FirstKeyOnlyFilter if scan has columns, instead use
  // FirstKeyValueMatchingQualifiersFilter.
  if (qualifiers.size() == 0) {
    scan.setFilter(new FirstKeyOnlyFilter());
  } else {
    scan.setFilter(new FirstKeyValueMatchingQualifiersFilter(qualifiers));
  }
  job.setOutputFormatClass(NullOutputFormat.class);
  TableMapReduceUtil.initTableMapperJob(tableName, scan,
    RowCounterMapper.class, ImmutableBytesWritable.class, Result.class, job);
  job.setNumReduceTasks(0);
  return job;
}
项目:PyroDB    文件:RowCounter.java   
/**
 * Sets up the actual job.
 *
 * @param conf  The current configuration.
 * @param args  The command line parameters.
 * @return The newly created job.
 * @throws IOException When setting up the job fails.
 */
public static Job createSubmittableJob(Configuration conf, String[] args)
throws IOException {
  String tableName = args[0];
  String startKey = null;
  String endKey = null;
  StringBuilder sb = new StringBuilder();

  final String rangeSwitch = "--range=";

  // First argument is table name, starting from second
  for (int i = 1; i < args.length; i++) {
    if (args[i].startsWith(rangeSwitch)) {
      String[] startEnd = args[i].substring(rangeSwitch.length()).split(",", 2);
      if (startEnd.length != 2 || startEnd[1].contains(",")) {
        printUsage("Please specify range in such format as \"--range=a,b\" " +
            "or, with only one boundary, \"--range=,b\" or \"--range=a,\"");
        return null;
      }
      startKey = startEnd[0];
      endKey = startEnd[1];
    }
    else {
      // if no switch, assume column names
      sb.append(args[i]);
      sb.append(" ");
    }
  }

  Job job = new Job(conf, NAME + "_" + tableName);
  job.setJarByClass(RowCounter.class);
  Scan scan = new Scan();
  scan.setCacheBlocks(false);
  Set<byte []> qualifiers = new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR);
  if (startKey != null && !startKey.equals("")) {
    scan.setStartRow(Bytes.toBytes(startKey));
  }
  if (endKey != null && !endKey.equals("")) {
    scan.setStopRow(Bytes.toBytes(endKey));
  }
  if (sb.length() > 0) {
    for (String columnName : sb.toString().trim().split(" ")) {
      String family = StringUtils.substringBefore(columnName, ":");
      String qualifier = StringUtils.substringAfter(columnName, ":");

      if (StringUtils.isBlank(qualifier)) {
        scan.addFamily(Bytes.toBytes(family));
      }
      else {
        scan.addColumn(Bytes.toBytes(family), Bytes.toBytes(qualifier));
      }
    }
  }
  // specified column may or may not be part of first key value for the row.
  // Hence do not use FirstKeyOnlyFilter if scan has columns, instead use
  // FirstKeyValueMatchingQualifiersFilter.
  if (qualifiers.size() == 0) {
    scan.setFilter(new FirstKeyOnlyFilter());
  } else {
    scan.setFilter(new FirstKeyValueMatchingQualifiersFilter(qualifiers));
  }
  job.setOutputFormatClass(NullOutputFormat.class);
  TableMapReduceUtil.initTableMapperJob(tableName, scan,
    RowCounterMapper.class, ImmutableBytesWritable.class, Result.class, job);
  job.setNumReduceTasks(0);
  return job;
}
项目:c5    文件:RowCounter.java   
/**
 * Sets up the actual job.
 *
 * @param conf  The current configuration.
 * @param args  The command line parameters.
 * @return The newly created job.
 * @throws IOException When setting up the job fails.
 */
public static Job createSubmittableJob(Configuration conf, String[] args)
throws IOException {
  String tableName = args[0];
  String startKey = null;
  String endKey = null;
  StringBuilder sb = new StringBuilder();

  final String rangeSwitch = "--range=";

  // First argument is table name, starting from second
  for (int i = 1; i < args.length; i++) {
    if (args[i].startsWith(rangeSwitch)) {
      String[] startEnd = args[i].substring(rangeSwitch.length()).split(",", 2);
      if (startEnd.length != 2 || startEnd[1].contains(",")) {
        printUsage("Please specify range in such format as \"--range=a,b\" " +
            "or, with only one boundary, \"--range=,b\" or \"--range=a,\"");
        return null;
      }
      startKey = startEnd[0];
      endKey = startEnd[1];
    }
    else {
      // if no switch, assume column names
      sb.append(args[i]);
      sb.append(" ");
    }
  }

  Job job = new Job(conf, NAME + "_" + tableName);
  job.setJarByClass(RowCounter.class);
  Scan scan = new Scan();
  scan.setCacheBlocks(false);
  Set<byte []> qualifiers = new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR);
  if (startKey != null && !startKey.equals("")) {
    scan.setStartRow(Bytes.toBytes(startKey));
  }
  if (endKey != null && !endKey.equals("")) {
    scan.setStopRow(Bytes.toBytes(endKey));
  }
  scan.setFilter(new FirstKeyOnlyFilter());
  if (sb.length() > 0) {
    for (String columnName : sb.toString().trim().split(" ")) {
      String [] fields = columnName.split(":");
      if(fields.length == 1) {
        scan.addFamily(Bytes.toBytes(fields[0]));
      } else {
        byte[] qualifier = Bytes.toBytes(fields[1]);
        qualifiers.add(qualifier);
        scan.addColumn(Bytes.toBytes(fields[0]), qualifier);
      }
    }
  }
  // specified column may or may not be part of first key value for the row.
  // Hence do not use FirstKeyOnlyFilter if scan has columns, instead use
  // FirstKeyValueMatchingQualifiersFilter.
  if (qualifiers.size() == 0) {
    scan.setFilter(new FirstKeyOnlyFilter());
  } else {
    scan.setFilter(new FirstKeyValueMatchingQualifiersFilter(qualifiers));
  }
  job.setOutputFormatClass(NullOutputFormat.class);
  TableMapReduceUtil.initTableMapperJob(tableName, scan,
    RowCounterMapper.class, ImmutableBytesWritable.class, Result.class, job);
  job.setNumReduceTasks(0);
  return job;
}
项目:DominoHBase    文件:RowCounter.java   
/**
 * Sets up the actual job.
 *
 * @param conf  The current configuration.
 * @param args  The command line parameters.
 * @return The newly created job.
 * @throws IOException When setting up the job fails.
 */
public static Job createSubmittableJob(Configuration conf, String[] args)
throws IOException {
  String tableName = args[0];
  String startKey = null;
  String endKey = null;
  StringBuilder sb = new StringBuilder();

  final String rangeSwitch = "--range=";

  // First argument is table name, starting from second
  for (int i = 1; i < args.length; i++) {
    if (args[i].startsWith(rangeSwitch)) {
      String[] startEnd = args[i].substring(rangeSwitch.length()).split(",", 2);
      if (startEnd.length != 2 || startEnd[1].contains(",")) {
        printUsage("Please specify range in such format as \"--range=a,b\" " +
            "or, with only one boundary, \"--range=,b\" or \"--range=a,\"");
        return null;
      }
      startKey = startEnd[0];
      endKey = startEnd[1];
    }
    else {
      // if no switch, assume column names
      sb.append(args[i]);
      sb.append(" ");
    }
  }

  Job job = new Job(conf, NAME + "_" + tableName);
  job.setJarByClass(RowCounter.class);
  Scan scan = new Scan();
  scan.setCacheBlocks(false);
  Set<byte []> qualifiers = new TreeSet<byte[]>(Bytes.BYTES_COMPARATOR);
  if (startKey != null && !startKey.equals("")) {
    scan.setStartRow(Bytes.toBytes(startKey));
  }
  if (endKey != null && !endKey.equals("")) {
    scan.setStopRow(Bytes.toBytes(endKey));
  }
  scan.setFilter(new FirstKeyOnlyFilter());
  if (sb.length() > 0) {
    for (String columnName : sb.toString().trim().split(" ")) {
      String [] fields = columnName.split(":");
      if(fields.length == 1) {
        scan.addFamily(Bytes.toBytes(fields[0]));
      } else {
        byte[] qualifier = Bytes.toBytes(fields[1]);
        qualifiers.add(qualifier);
        scan.addColumn(Bytes.toBytes(fields[0]), qualifier);
      }
    }
  }
  // specified column may or may not be part of first key value for the row.
  // Hence do not use FirstKeyOnlyFilter if scan has columns, instead use
  // FirstKeyValueMatchingQualifiersFilter.
  if (qualifiers.size() == 0) {
    scan.setFilter(new FirstKeyOnlyFilter());
  } else {
    scan.setFilter(new FirstKeyValueMatchingQualifiersFilter(qualifiers));
  }
  job.setOutputFormatClass(NullOutputFormat.class);
  TableMapReduceUtil.initTableMapperJob(tableName, scan,
    RowCounterMapper.class, ImmutableBytesWritable.class, Result.class, job);
  job.setNumReduceTasks(0);
  return job;
}