@Override
 public QueryResult<OrderedRows<String, String, String>> execute() {
   RangeSlicesQuery<String, String, String> rangeSlicesQuery =
       HFactory.createRangeSlicesQuery(
           keyspace, stringSerializer, stringSerializer, stringSerializer);
   rangeSlicesQuery.setColumnFamily("Npanxx");
   rangeSlicesQuery.setColumnNames("city", "state", "lat", "lng");
   rangeSlicesQuery.setKeys("512202", "512205");
   rangeSlicesQuery.setRowCount(5);
   QueryResult<OrderedRows<String, String, String>> results = rangeSlicesQuery.execute();
   return results;
 }
  void readData(String datapoint) {
    int row_count = 100;
    System.out.println("\n\n Readind data from con1 table =>\n");
    DateSerializer dt = new DateSerializer();
    LongSerializer ls = new LongSerializer();
    // UUIDSerializer ud=new UUIDSerializer();
    DoubleSerializer ds = new DoubleSerializer();
    RangeSlicesQuery<Date, Long, Double> sl = HFactory.createRangeSlicesQuery(keyspace, dt, ls, ds);
    // ColumnSliceIterator<Date, UUID, Double> csit=new ColumnSliceIterator<Date, UUID,
    // Double>(sl,null,FINISH,false);
    sl.setColumnFamily(datapoint).setRange(null, null, false, 10).setRowCount(row_count);
    Date Lastkey = null;

    /*QueryResult<ColumnSlice<UUID,Double>> qr=sl.execute();
    System.out.println("\nInserted data is as follows:\n" + qr.get());*/
    while (true) {
      sl.setKeys(Lastkey, null);
      QueryResult<OrderedRows<Date, Long, Double>> result = sl.execute();
      OrderedRows<Date, Long, Double> rows = result.get();
      Iterator<Row<Date, Long, Double>> rowsIterator = rows.iterator();

      // we'll skip this first one, since it is the same as the last one from previous time we
      // executed
      if (Lastkey != null && rowsIterator != null) rowsIterator.next();

      while (rowsIterator.hasNext()) {
        Row<Date, Long, Double> row = rowsIterator.next();
        Lastkey = row.getKey();

        if (row.getColumnSlice().getColumns().isEmpty()) {
          continue;
        }

        System.out.println(row);
      }

      if (rows.getCount() < row_count) break;
    }
  }
  public List<String> queryAllRowKeys(String keyspace, int limit) {
    int row_count = (limit > 100) ? 100 : limit;
    List<String> results = new ArrayList<String>();

    String decoded_keyspace = this.decodeKeyspace(keyspace);
    // String(row), String(column_name), String(column_value)
    Keyspace k = getExistingKeyspace(keyspace);
    RangeSlicesQuery<String, String, String> rangeSlicesQuery =
        HFactory.createRangeSlicesQuery(
                k, StringSerializer.get(), StringSerializer.get(), StringSerializer.get())
            .setColumnFamily("SPO")
            .setRange(null, null, false, row_count)
            .setRowCount(
                (row_count == 1)
                    ? 2
                    : row_count); // do this trick because if row_count=1 and only one "null"
    // record, then stucks in a loop
    String last_key = null;

    while (true) {
      rangeSlicesQuery.setKeys(last_key, null);
      QueryResult<OrderedRows<String, String, String>> result = rangeSlicesQuery.execute();
      OrderedRows<String, String, String> rows = result.get();
      Iterator<Row<String, String, String>> rowsIterator = rows.iterator();

      // we'll skip this first one, since it is the same as the last one from previous time we
      // executed
      if (last_key != null && rowsIterator != null) rowsIterator.next();

      while (rowsIterator.hasNext()) {
        Row<String, String, String> row = rowsIterator.next();
        last_key = row.getKey();
        results.add(row.getKey());
      }
      if (rows.getCount() < row_count) break;
    }
    return results;
  }
Example #4
0
  public Map<String, Map<String, String>> getRows(
      String keyspace,
      String cf,
      String startKey,
      String colRange,
      int numRows,
      boolean reverse,
      int numCols) {
    Keyspace ks = getKeyspaceForName(keyspace);
    RangeSlicesQuery<String, String, String> rowsQuery =
        HFactory.createRangeSlicesQuery(ks, s, s, s);
    rowsQuery.setColumnFamily(cf);
    rowsQuery.setKeys(startKey, "");
    if (colRange != null) {
      // String[] cols = colRange.split(",");
      // rowsQuery.setRange(cols[0], cols[1], reverse, numCols);

      String[] cols = colRange.split("-");
      if (colRange.equals(cols[0])) {
        cols = colRange.split(",");
        Arrays.sort(cols);
        rowsQuery.setColumnNames(cols);
      } else {
        Arrays.sort(cols);
        // TODO Check size, throw invalid request trigger
        rowsQuery.setRange(cols[0], cols[1], reverse, numCols);
      }
    } else {
      rowsQuery.setRange("", "", reverse, numCols);
    }

    rowsQuery.setRowCount(numRows + 1);

    OrderedRows<String, String, String> result = rowsQuery.execute().get();
    return resultToMap(keyspace, cf, null, numRows, colRange, result);
  }
  // TM: added for supporting (?,?,?,g) queries
  // NOTE: pass the actual name of the keyspace (hashed value in case of graphs)
  public int queryEntireKeyspace(String keyspace, Writer out, int limit) throws IOException {
    int row_count = (limit > 100) ? 100 : limit;
    int total_row_count = 0;

    String decoded_keyspace = this.decodeKeyspace(keyspace);
    // String(row), String(column_name), String(column_value)
    Keyspace k = getExistingKeyspace(keyspace);
    RangeSlicesQuery<String, String, String> rangeSlicesQuery =
        HFactory.createRangeSlicesQuery(
                k, StringSerializer.get(), StringSerializer.get(), StringSerializer.get())
            .setColumnFamily("SPO")
            .setRange(null, null, false, Integer.MAX_VALUE)
            .setRowCount(
                (row_count == 1)
                    ? 2
                    : row_count); // do this trick because if row_count=1 and only one "null"
    // record, then stucks in a loop
    String last_key = null;

    while (true) {
      rangeSlicesQuery.setKeys(last_key, null);
      try {
        QueryResult<OrderedRows<String, String, String>> result = rangeSlicesQuery.execute();
        OrderedRows<String, String, String> rows = result.get();
        Iterator<Row<String, String, String>> rowsIterator = rows.iterator();

        // we'll skip this first one, since it is the same as the last one from previous time we
        // executed
        if (last_key != null && rowsIterator != null) rowsIterator.next();

        while (rowsIterator.hasNext()) {
          Row<String, String, String> row = rowsIterator.next();
          last_key = row.getKey();
          // print even if we just have row_key but none columns ?!
          if (row.getColumnSlice().getColumns().isEmpty()) {
            /*StringBuffer buf = new StringBuffer();
            		        buf.append(row.getKey());
            buf.append(" NULL NULL . ");
                   buf.append(keyspace + "\n");
            	    	out.println(buf.toString());
            ++total_row_count;
                   if( total_row_count >= limit )
            	return total_row_count;*/
            continue;
          }
          for (Iterator it = row.getColumnSlice().getColumns().iterator(); it.hasNext(); ) {
            HColumn c = (HColumn) it.next();
            StringBuffer buf = new StringBuffer();
            buf.append(row.getKey());
            buf.append(" ");
            buf.append(c.getName());
            buf.append(" ");
            buf.append(c.getValue());
            buf.append(decoded_keyspace + "\n");
            out.write(buf.toString());
            // because the same row key can contain multiple column records, we consider a row each
            // of them rather than the entire row :)
            // (see how cumulusrdf flat storage works)
            ++total_row_count;
            if (total_row_count >= limit) return total_row_count;
          }
        }
        if (rows.getCount() < row_count) break;
      } catch (Exception e) {
        e.printStackTrace();
        out.write("Exception message: " + e.getMessage() + "\n");
        out.write("Exception: " + e.toString());
        return -1;
      }
    }
    return total_row_count;
  }