Beispiel #1
0
 // ALL OF THE VALIDATION SCHEMAS IN THIS TEST ARE BASED OFF OF
 // THE VOLTDB DOCS, RATHER THAN REUSING THE CODE THAT GENERATES THEM.
 // IN SOME MAGICAL FUTURE MAYBE THEY ALL CAN BE GENERATED FROM THE
 // SAME METADATA.
 protected static void validateSchema(VoltTable result, VoltTable expected) {
   assertEquals(expected.getColumnCount(), result.getColumnCount());
   for (int i = 0; i < result.getColumnCount(); i++) {
     assertEquals("Failed name column: " + i, expected.getColumnName(i), result.getColumnName(i));
     assertEquals("Failed type column: " + i, expected.getColumnType(i), result.getColumnType(i));
   }
 }
Beispiel #2
0
  protected void assertTablesAreEqual(String prefix, VoltTable expectedRows, VoltTable actualRows) {
    assertEquals(
        prefix
            + "column count mismatch.  Expected: "
            + expectedRows.getColumnCount()
            + " actual: "
            + actualRows.getColumnCount(),
        expectedRows.getColumnCount(),
        actualRows.getColumnCount());

    int i = 0;
    while (expectedRows.advanceRow()) {
      assertTrue(
          prefix + "too few actual rows; expected more than " + (i + 1), actualRows.advanceRow());

      for (int j = 0; j < actualRows.getColumnCount(); j++) {
        String columnName = actualRows.getColumnName(j);
        String colPrefix = prefix + "row " + i + ": column: " + columnName + ": ";
        VoltType actualTy = actualRows.getColumnType(j);
        VoltType expectedTy = expectedRows.getColumnType(j);
        assertEquals(colPrefix + "type mismatch", expectedTy, actualTy);

        Object expectedObj = expectedRows.get(j, expectedTy);
        Object actualObj = expectedRows.get(j, actualTy);
        assertEquals(
            colPrefix + "values not equal: expected: " + expectedObj + ", actual: " + actualObj,
            expectedObj,
            actualObj);
      }

      i++;
    }
    assertFalse(prefix + "too many actual rows; expected only " + i, actualRows.advanceRow());
  }
Beispiel #3
0
  /**
   * Perform a schema change to a mutated version of the current table (80%) or to a new table
   * entirely (20%, drops and adds the new table).
   */
  static VoltTable catalogChange(VoltTable t1, boolean newTable) throws Exception {
    CatalogBuilder builder = new CatalogBuilder();
    VoltTable t2 = null;
    String currentName = t1 == null ? "B" : TableHelper.getTableName(t1);
    String newName = currentName;

    if (newTable) {
      newName = currentName.equals("A") ? "B" : "A";
      t2 = TableHelper.getTotallyRandomTable(newName, rand);
    } else {
      t2 = TableHelper.mutateTable(t1, false, rand);
    }

    System.out.printf("New Schema:\n%s\n", TableHelper.ddlForTable(t2));

    builder.addLiteralSchema(TableHelper.ddlForTable(t2));
    // make tables name A partitioned and tables named B replicated
    if (newName.equalsIgnoreCase("A")) {
      int pkeyIndex = TableHelper.getBigintPrimaryKeyIndexIfExists(t2);
      builder.addPartitionInfo(newName, t2.getColumnName(pkeyIndex));
    }
    byte[] catalogData = builder.compileToBytes();
    assert (catalogData != null);

    long count = tupleCount(t1);
    long start = System.nanoTime();

    if (newTable) {
      System.out.println("Starting catalog update to swap tables.");
    } else {
      System.out.println("Starting catalog update to change schema.");
    }

    ClientResponse cr = client.callProcedure("@UpdateApplicationCatalog", catalogData, null);
    assert (cr.getStatus() == ClientResponse.SUCCESS);

    long end = System.nanoTime();
    double seconds = (end - start) / 1000000000.0;

    if (newTable) {
      System.out.printf("Completed catalog update that swapped tables in %.4f seconds\n", seconds);
    } else {
      System.out.printf(
          "Completed catalog update of %d tuples in %.4f seconds (%d tuples/sec)\n",
          count, seconds, (long) (count / seconds));
    }

    System.out.println("Sleeping for 5s");
    Thread.sleep(5000);

    return t2;
  }
 @Override
 public void printTable(PrintStream stream, VoltTable t, boolean includeColumnNames)
     throws IOException {
   final int columnCount = t.getColumnCount();
   List<VoltType> columnTypes = new ArrayList<VoltType>(columnCount);
   for (int i = 0; i < columnCount; i++) {
     columnTypes.add(t.getColumnType(i));
   }
   CSVWriter csvWriter = new CSVWriter(new OutputStreamWriter(stream));
   if (includeColumnNames) {
     String[] columnNames = new String[columnCount];
     for (int i = 0; i < columnCount; i++) {
       columnNames[i] = t.getColumnName(i);
     }
     csvWriter.writeNext(columnNames);
   }
   VoltTableUtil.toCSVWriter(csvWriter, t, columnTypes);
 }