Exemplo n.º 1
0
  @Test
  public void testBulkTableUpdateCommandUpdateRecordToExistingRow() throws Exception {
    FileSystem fileSystem = miniCluster.getFileSystem();
    Path root = new Path(fileSystem.getUri() + "/");

    String tableName = "testBulkTableUpdateCommandUpdateRecordToExistingRow";
    Iface client = getClient();
    Path mrIncWorkingPath = new Path(new Path(root, "working"), tableName);
    creatTable(tableName, new Path(root, "tables"), true, mrIncWorkingPath.toString());
    String rowId = "row1";
    String recordId = "record1";
    addRow(client, tableName, rowId, recordId, "value1");

    generateData(mrIncWorkingPath.toString(), rowId, recordId, "value2");

    {
      Selector selector = new Selector();
      selector.setRowId(rowId);
      FetchResult fetchRow = client.fetchRow(tableName, selector);
      Row row = fetchRow.getRowResult().getRow();
      assertEquals(rowId, row.getId());
      List<Record> records = row.getRecords();
      assertEquals(1, records.size());
      Record record = records.get(0);
      assertEquals(recordId, record.getRecordId());
      List<Column> columns = record.getColumns();
      assertEquals(1, columns.size());
      Column column = columns.get(0);
      assertEquals("col0", column.getName());
      assertEquals("value1", column.getValue());
    }

    BulkTableUpdateCommand bulkTableUpdateCommand = new BulkTableUpdateCommand();
    bulkTableUpdateCommand.setAutoLoad(true);
    bulkTableUpdateCommand.setTable(tableName);
    bulkTableUpdateCommand.setWaitForDataBeVisible(true);
    bulkTableUpdateCommand.addExtraConfig(conf);
    assertEquals(0, (int) bulkTableUpdateCommand.run(getClient()));

    TableStats tableStats = client.tableStats(tableName);
    assertEquals(1, tableStats.getRowCount());
    assertEquals(1, tableStats.getRecordCount());

    {
      Selector selector = new Selector();
      selector.setRowId(rowId);
      FetchResult fetchRow = client.fetchRow(tableName, selector);
      Row row = fetchRow.getRowResult().getRow();
      assertEquals(rowId, row.getId());
      List<Record> records = row.getRecords();
      assertEquals(1, records.size());
      Record record = records.get(0);
      assertEquals(recordId, record.getRecordId());
      List<Column> columns = record.getColumns();
      assertEquals(1, columns.size());
      Column column = columns.get(0);
      assertEquals("col0", column.getName());
      assertEquals("value2", column.getValue());
    }
  }
  @Override
  public boolean next() throws SQLException {
    if (displayRows != null && displayRowsPosition + 1 < displayRows.size()) {
      overallRowPosition++;
      displayRowsPosition++;
      return true;
    } else if (resultPosition + 1 < size) {
      INNER:
      while (resultPosition + 1 < size) {
        displayRows.clear();
        resultPosition++;
        displayRowsPosition = 0;
        overallRowPosition++;

        final BlurResult result = results.results.get(resultPosition);
        try {
          FetchRecordResult recordResult = result.getFetchResult().getRecordResult();
          selector.setRowId(recordResult.getRowid());
          selector.setRecordId(recordResult.getRecord().getRecordId());
          fetchResult = client.fetchRow(tableName, selector);
          Record record = fetchResult.recordResult.record;
          if (!record.family.equals(columnFamily)) {
            continue INNER;
          }
          String rowId = fetchResult.recordResult.rowid;
          displayRows.add(
              addColumns(result.getScore(), result.getLocationId(), rowId, record.family, record));
          return true;

        } catch (Exception e) {
          e.printStackTrace();
          throw new SQLException(e);
        }
      }
      return next();
    } else if (overallRowPosition < totalResults) {
      currentStart += currentFetch;
      runSearch(currentStart, currentFetch);
      displayRowsPosition = 0;
      resultPosition = -1;
      return next();
    }
    return false;
  }
  private void runSearch(int start, int fetch) throws SQLException {
    currentStart = start;
    currentFetch = fetch;
    BlurQuery blurQuery = new BlurQuery();
    blurQuery.minimumNumberOfResults = Long.MAX_VALUE;
    blurQuery.maxQueryTime = Long.MAX_VALUE;
    blurQuery.uuid = UUID.randomUUID().toString();
    blurQuery.fetch = fetch;
    blurQuery.start = start;
    blurQuery.query = new Query();
    blurQuery.query.query = parser.getWhere();
    blurQuery.query.rowQuery = false;

    try {
      schema = client.schema(tableName);
    } catch (BlurException e) {
      e.printStackTrace();
      throw new SQLException(e);
    } catch (TException e) {
      e.printStackTrace();
      throw new SQLException(e);
    }

    selector = new Selector();
    setupSelector(selector, schema, columnNames);
    selector.recordOnly = !blurQuery.query.rowQuery;
    Map<String, Map<String, ColumnDefinition>> columnFamilies = schema.getFamilies();
    Map<String, ColumnDefinition> cfSet = columnFamilies.get(columnFamily);
    columnFamilies.clear();
    columnFamilies.put(columnFamily, cfSet);
    blurResultSetMetaData = new BlurResultSetMetaData(columnNames, columnFamilies);
    try {
      results = client.query(tableName, blurQuery);
    } catch (BlurException e) {
      e.printStackTrace();
      throw new SQLException(e);
    } catch (TException e) {
      e.printStackTrace();
      throw new SQLException(e);
    }
    if (results.totalResults > 0) {
      size = results.results.size();
    }
    totalResults = results.totalResults;
  }
Exemplo n.º 4
0
  @Test
  public void testDriverUpdateRecordToExistingRow() throws Exception {
    FileSystem fileSystem = miniCluster.getFileSystem();
    Path root = new Path(fileSystem.getUri() + "/");

    String tableName = "testDriverUpdateRecordToExistingRow";
    Iface client = getClient();
    creatTable(tableName, new Path(root, "tables"), true);
    String rowId = "row1";
    String recordId = "record1";
    addRow(client, tableName, rowId, recordId, "value1");

    Driver driver = new Driver();
    driver.setConf(conf);

    String mrIncWorkingPathStr = new Path(root, "working").toString();
    generateData(mrIncWorkingPathStr, rowId, recordId, "value2");
    String outputPathStr = new Path(root, "output").toString();
    String blurZkConnection = miniCluster.getZkConnectionString();

    assertEquals(
        0,
        driver.run(
            new String[] {tableName, mrIncWorkingPathStr, outputPathStr, blurZkConnection, "1"}));
    {
      Selector selector = new Selector();
      selector.setRowId(rowId);
      FetchResult fetchRow = client.fetchRow(tableName, selector);
      Row row = fetchRow.getRowResult().getRow();
      assertEquals(rowId, row.getId());
      List<Record> records = row.getRecords();
      assertEquals(1, records.size());
      Record record = records.get(0);
      assertEquals(recordId, record.getRecordId());
      List<Column> columns = record.getColumns();
      assertEquals(1, columns.size());
      Column column = columns.get(0);
      assertEquals("col0", column.getName());
      assertEquals("value1", column.getValue());
    }

    client.loadData(tableName, outputPathStr);

    waitUntilAllImportsAreCompleted(client, tableName);

    TableStats tableStats = client.tableStats(tableName);
    assertEquals(1, tableStats.getRowCount());
    assertEquals(1, tableStats.getRecordCount());

    {
      Selector selector = new Selector();
      selector.setRowId(rowId);
      FetchResult fetchRow = client.fetchRow(tableName, selector);
      Row row = fetchRow.getRowResult().getRow();
      assertEquals(rowId, row.getId());
      List<Record> records = row.getRecords();
      assertEquals(1, records.size());
      Record record = records.get(0);
      assertEquals(recordId, record.getRecordId());
      List<Column> columns = record.getColumns();
      assertEquals(1, columns.size());
      Column column = columns.get(0);
      assertEquals("col0", column.getName());
      assertEquals("value2", column.getValue());
    }
  }