@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()); } }
@Test public void testDriverAddSingleRecordToExistingRow() throws Exception { FileSystem fileSystem = miniCluster.getFileSystem(); Path root = new Path(fileSystem.getUri() + "/"); String tableName = "testDriverAddSingleRecordToExistingRow"; Iface client = getClient(); creatTable(tableName, new Path(root, "tables"), true); addRow(client, tableName, "row1", "record1", "value1"); Driver driver = new Driver(); driver.setConf(conf); String mrIncWorkingPathStr = new Path(root, "working").toString(); generateData(mrIncWorkingPathStr); String outputPathStr = new Path(root, "output").toString(); String blurZkConnection = miniCluster.getZkConnectionString(); assertEquals( 0, driver.run( new String[] {tableName, mrIncWorkingPathStr, outputPathStr, blurZkConnection, "1"})); client.loadData(tableName, outputPathStr); waitUntilAllImportsAreCompleted(client, tableName); TableStats tableStats = client.tableStats(tableName); assertEquals(1, tableStats.getRowCount()); assertEquals(2, tableStats.getRecordCount()); }
private void waitUntilAllImportsAreCompleted(Iface client, String tableName) throws BlurException, TException, InterruptedException { while (true) { Thread.sleep(1000); TableStats tableStats = client.tableStats(tableName); if (tableStats.getSegmentImportInProgressCount() == 0 && tableStats.getSegmentImportPendingCount() == 0) { return; } } }
@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()); } }