コード例 #1
0
  public VoltTable[] run(
      short w_id,
      byte d_id,
      double h_amount,
      short c_w_id,
      byte c_d_id,
      byte[] c_last,
      TimestampType timestamp)
      throws VoltAbortException {
    voltQueueSQL(getCustomersByLastName, c_last, c_d_id, c_w_id);
    final VoltTable customers = voltExecuteSQL()[0];
    final int namecnt = customers.getRowCount();
    if (namecnt == 0) {
      String c_lastString = null;
      try {
        c_lastString = new String(c_last, "UTF-8");
      } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
      }
      throw new VoltAbortException(
          "paymentByCustomerNameC: no customers with last name: "
              + c_lastString
              + " in warehouse: "
              + c_w_id
              + " and in district "
              + c_d_id);
    }

    final int index = (namecnt - 1) / 2;
    final VoltTableRow customer = customers.fetchRow(index);
    final int c_id = (int) customer.getLong(C_ID_IDX);
    return processPayment(w_id, d_id, c_w_id, c_d_id, c_id, h_amount, customer, timestamp);
  }
コード例 #2
0
 public void testAggregatesOnEmptyTable() throws IOException, ProcCallException {
   String[] aggs = {"count", "sum", "min", "max"};
   String[] tables = {"P1", "R1"};
   for (String table : tables) {
     Client client = getClient();
     for (int i = 0; i < aggs.length; ++i) {
       String query = String.format("select %s(%s.NUM) from %s", aggs[i], table, table);
       VoltTable[] results = client.callProcedure("@AdHoc", query).getResults();
       if (aggs[i].equals("count")) {
         assertEquals(0, results[0].asScalarLong());
       } else {
         final VoltTableRow row = results[0].fetchRow(0);
         row.get(0, results[0].getColumnType(0));
         if (!isHSQL()) {
           assertTrue(row.wasNull());
         }
       }
     }
     // Do avg separately since the column is a float and makes
     // asScalarLong() unhappy
     String query = String.format("select avg(%s.NUM) from %s", table, table);
     VoltTable[] results = client.callProcedure("@AdHoc", query).getResults();
     results[0].advanceRow();
     @SuppressWarnings("unused")
     final double value = ((Number) results[0].get(0, results[0].getColumnType(0))).doubleValue();
     if (!isHSQL()) {
       assertTrue(results[0].wasNull());
     }
   }
 }
コード例 #3
0
ファイル: ClientMain.java プロジェクト: pettermahlen/voltdb
 /** sums the contents of a latency bucket table. */
 private long[] latencySummaryHelper(VoltTable vt) {
   long sums[] = new long[20];
   for (int i = 0; i < vt.getRowCount(); i++) {
     VoltTableRow row = vt.fetchRow(i);
     // 20  buckets
     for (int c = 0; c < 20; c++) {
       // 7 ignored header columns
       sums[c] += row.getLong(c + 7);
     }
   }
   return sums;
 }
コード例 #4
0
 public void testStatistics_Initiator() throws Exception {
   Client client = getClient();
   VoltTable results[] = null;
   results = client.callProcedure("@Statistics", "INITIATOR", 0).getResults();
   results = client.callProcedure("@Statistics", "INITIATOR", 0).getResults();
   // one aggregate table returned
   assertTrue(results.length == 1);
   System.out.println("Test initiators table: " + results[0].toString());
   assertEquals(1, results[0].getRowCount());
   VoltTableRow resultRow = results[0].fetchRow(0);
   assertNotNull(resultRow);
   assertEquals("@Statistics", resultRow.getString("PROCEDURE_NAME"));
   assertEquals(1, resultRow.getLong("INVOCATIONS"));
 }
コード例 #5
0
    @Override
    public void clientCallback(ClientResponse response) throws Exception {
      // Track the result of the operation (Success, Failure, Payload traffic...)
      if (response.getStatus() == ClientResponse.SUCCESS) {
        successfulPuts.incrementAndGet();
        if (rand < config.multisingleratio) successfulPutsMPT.incrementAndGet();
        else successfulPutsMPF.incrementAndGet();

        final VoltTable pairData = response.getResults()[0];
        final VoltTableRow tablerow = pairData.fetchRow(0);
        final long counter = tablerow.getLong(0);
        hashMap.put(thisPair.Key, counter);
      } else {
        failedPuts.incrementAndGet();
      }
      networkPutData.addAndGet(storeValueLength);
      rawPutData.addAndGet(rawValueLength);
    }
コード例 #6
0
ファイル: VoltDatabase.java プロジェクト: skunkiferous/LongDB
  /**
   * Queries all the tables present in default database and load them into 'tables' map.
   *
   * @param theTables the tables
   */
  @Override
  protected void openInternal(final Map<Base36, VoltDBTable> theTables) {

    theTables.clear();
    final VoltTable[] results;
    try {
      results = backend.client().callProcedure("@SystemCatalog", "TABLES").getResults();
      for (final VoltTable node : results) {
        int count = 0;
        while (node.advanceRow()) {
          final VoltTableRow row = node.fetchRow(count++);
          final String tName = row.getString("TABLE_NAME");
          theTables.put(Base36.get(tName.toLowerCase()), new VoltDBTable(this, tName));
        }
      }
    } catch (final Exception e) {
      throw new DBException("Error Opening Database: " + theTables, e);
    }
  }
コード例 #7
0
  public long run(int id) throws VoltAbortException {
    long numRows = 0;

    voltQueueSQL(insertSQL, 1, "one");
    voltQueueSQL(insertSQL, 2, "two");
    voltQueueSQL(insertSQL, 3, "three");

    voltExecuteSQL();

    // comparing STRINGVAL to integer 1 causes ENG-800
    voltQueueSQL(selectSQL, 1);

    VoltTable results1[] = voltExecuteSQL(true);

    if (results1[0].getRowCount() == 1) {
      VoltTableRow row1 = results1[0].fetchRow(0);
      numRows = row1.getLong(0);
    }

    return numRows;
  }
コード例 #8
0
  public long run(int id) throws VoltAbortException {
    long numRows = 0;

    voltQueueSQL(insertSQL, 1, 1.1);
    voltQueueSQL(insertSQL, 2, 2.2);
    voltQueueSQL(insertSQL, 3, 3.3);

    voltExecuteSQL();

    // comparing FLOATVAL to string causes ENG-800
    voltQueueSQL(selectSQL, "onepointone");

    VoltTable results1[] = voltExecuteSQL(true);

    if (results1[0].getRowCount() == 1) {
      VoltTableRow row1 = results1[0].fetchRow(0);
      numRows = row1.getLong(0);
    }

    return numRows;
  }
コード例 #9
0
  public VoltTable[] run(short w_id, byte d_id, byte[] c_last) {
    voltQueueSQL(getCustomersByLastName, w_id, d_id, c_last);
    VoltTable customers = voltExecuteSQL()[0];

    // Get the midpoint customer's id
    final int namecnt = customers.getRowCount();
    final int index = (namecnt - 1) / 2;
    final VoltTableRow customer = customers.fetchRow(index);
    final long c_id = customer.getLong(C_ID_IDX);

    // Build an VoltTable with a single customer row
    final VoltTable customerResultTable = result_template.clone(1024);
    customerResultTable.addRow(
        c_id,
        customer.getStringAsBytes(1),
        customer.getStringAsBytes(2),
        customer.getStringAsBytes(3),
        customer.getDouble(4));

    // Do the rest of the work
    return getOrderStatus(w_id, d_id, c_id, customerResultTable);
  }
コード例 #10
0
  public VoltTable[] run(long rowid, long ignore) {
    @SuppressWarnings("deprecation")
    long txid = getVoltPrivateRealTransactionIdDontUseMe();

    // Critical for proper determinism: get a cluster-wide consistent Random instance
    Random rand = new Random(txid);

    // Check if the record exists first
    voltQueueSQL(check, rowid);

    // Grab resultset for possibly existing record
    VoltTable item = voltExecuteSQL()[0];

    // If the record exist perform an update or delete
    if (item.getRowCount() > 0) {
      // Randomly decide whether to delete (or update) the record
      if (rand.nextBoolean()) {
        voltQueueSQL(delete, rowid);
        // Export deletion
        VoltTableRow row = item.fetchRow(0);
        voltQueueSQL(
            export,
            txid,
            rowid,
            row.get(1, VoltType.TINYINT),
            row.get(2, VoltType.TINYINT),
            row.get(3, VoltType.TINYINT),
            row.get(4, VoltType.SMALLINT),
            row.get(5, VoltType.SMALLINT),
            row.get(6, VoltType.INTEGER),
            row.get(7, VoltType.INTEGER),
            row.get(8, VoltType.BIGINT),
            row.get(9, VoltType.BIGINT),
            row.get(10, VoltType.TIMESTAMP),
            row.get(11, VoltType.TIMESTAMP),
            row.get(12, VoltType.FLOAT),
            row.get(13, VoltType.FLOAT),
            row.get(14, VoltType.DECIMAL),
            row.get(15, VoltType.DECIMAL),
            row.get(16, VoltType.STRING),
            row.get(17, VoltType.STRING),
            row.get(18, VoltType.STRING),
            row.get(19, VoltType.STRING),
            row.get(20, VoltType.STRING),
            row.get(21, VoltType.STRING));
      } else {
        SampleRecord record = new SampleRecord(rowid, rand);
        voltQueueSQL(
            update,
            record.type_null_tinyint,
            record.type_not_null_tinyint,
            record.type_null_smallint,
            record.type_not_null_smallint,
            record.type_null_integer,
            record.type_not_null_integer,
            record.type_null_bigint,
            record.type_not_null_bigint,
            record.type_null_timestamp,
            record.type_not_null_timestamp,
            record.type_null_float,
            record.type_not_null_float,
            record.type_null_decimal,
            record.type_not_null_decimal,
            record.type_null_varchar25,
            record.type_not_null_varchar25,
            record.type_null_varchar128,
            record.type_not_null_varchar128,
            record.type_null_varchar1024,
            record.type_not_null_varchar1024,
            rowid);
      }
    } else {
      // Insert a new record
      SampleRecord record = new SampleRecord(rowid, rand);
      voltQueueSQL(
          insert,
          rowid,
          record.rowid_group,
          record.type_null_tinyint,
          record.type_not_null_tinyint,
          record.type_null_smallint,
          record.type_not_null_smallint,
          record.type_null_integer,
          record.type_not_null_integer,
          record.type_null_bigint,
          record.type_not_null_bigint,
          record.type_null_timestamp,
          record.type_not_null_timestamp,
          record.type_null_float,
          record.type_not_null_float,
          record.type_null_decimal,
          record.type_not_null_decimal,
          record.type_null_varchar25,
          record.type_not_null_varchar25,
          record.type_null_varchar128,
          record.type_not_null_varchar128,
          record.type_null_varchar1024,
          record.type_not_null_varchar1024);
    }

    // Execute last SQL batch
    voltExecuteSQL(true);

    // Retun to caller
    return null;
  }
コード例 #11
0
  public VoltTable[] processPayment(
      short w_id,
      byte d_id,
      short c_w_id,
      byte c_d_id,
      int c_id,
      double h_amount,
      VoltTableRow customer,
      TimestampType timestamp) {

    // customer info
    final byte[] c_first = customer.getStringAsBytes(C_FIRST_IDX);
    final byte[] c_middle = customer.getStringAsBytes(C_MIDDLE_IDX);
    final byte[] c_last = customer.getStringAsBytes(C_LAST_IDX);
    final byte[] c_street_1 = customer.getStringAsBytes(C_STREET_1_IDX);
    final byte[] c_street_2 = customer.getStringAsBytes(C_STREET_2_IDX);
    final byte[] c_city = customer.getStringAsBytes(C_CITY_IDX);
    final byte[] c_state = customer.getStringAsBytes(C_STATE_IDX);
    final byte[] c_zip = customer.getStringAsBytes(C_ZIP_IDX);
    final byte[] c_phone = customer.getStringAsBytes(C_PHONE_IDX);
    final TimestampType c_since = customer.getTimestampAsTimestamp(C_SINCE_IDX);
    final byte[] c_credit = customer.getStringAsBytes(C_CREDIT_IDX);
    final double c_credit_lim = customer.getDouble(C_CREDIT_LIM_IDX);
    final double c_discount = customer.getDouble(C_DISCOUNT_IDX);
    final double c_balance = customer.getDouble(C_BALANCE_IDX) - h_amount;
    final double c_ytd_payment = customer.getDouble(C_YTD_PAYMENT_IDX) + h_amount;
    final int c_payment_cnt = (int) customer.getLong(C_PAYMENT_CNT_IDX) + 1;
    byte[] c_data;
    if (Arrays.equals(c_credit, Constants.BAD_CREDIT_BYTES)) {
      c_data = customer.getStringAsBytes(C_DATA_IDX);
      byte[] newData =
          (c_id + " " + c_d_id + " " + c_w_id + " " + d_id + " " + w_id + " " + h_amount + "|")
              .getBytes();

      int newLength = newData.length + c_data.length;
      if (newLength > Constants.MAX_C_DATA) {
        newLength = Constants.MAX_C_DATA;
      }
      ByteBuilder builder = new ByteBuilder(newLength);

      int minLength = newLength;
      if (newData.length < minLength) minLength = newData.length;
      builder.append(newData, 0, minLength);

      int remaining = newLength - minLength;
      builder.append(c_data, 0, remaining);
      c_data = builder.array();
      voltQueueSQL(
          updateBCCustomer, c_balance, c_ytd_payment, c_payment_cnt, c_data, c_w_id, c_d_id, c_id);
    } else {
      c_data = new byte[0];
      voltQueueSQL(updateGCCustomer, c_balance, c_ytd_payment, c_payment_cnt, c_w_id, c_d_id, c_id);
    }
    voltExecuteSQL();

    // TPC-C 2.5.3.3: Must display the following fields:
    // W_ID, D_ID, C_ID, C_D_ID, C_W_ID, W_STREET_1, W_STREET_2, W_CITY, W_STATE, W_ZIP,
    // D_STREET_1, D_STREET_2, D_CITY, D_STATE, D_ZIP, C_FIRST, C_MIDDLE, C_LAST, C_STREET_1,
    // C_STREET_2, C_CITY, C_STATE, C_ZIP, C_PHONE, C_SINCE, C_CREDIT, C_CREDIT_LIM,
    // C_DISCOUNT, C_BALANCE, the first 200 characters of C_DATA (only if C_CREDIT = "BC"),
    // H_AMOUNT, and H_DATE.

    // Return the entire warehouse and district tuples. The client provided:
    // w_id, d_id, c_d_id, c_w_id, h_amount, h_data.
    // Build a table for the rest
    final VoltTable misc = misc_template.clone(1024);
    misc.addRow(
        c_id,
        c_first,
        c_middle,
        c_last,
        c_street_1,
        c_street_2,
        c_city,
        c_state,
        c_zip,
        c_phone,
        c_since,
        c_credit,
        c_credit_lim,
        c_discount,
        c_balance,
        c_data);
    return new VoltTable[] {misc};
  }
コード例 #12
0
ファイル: debugTPCCpayment.java プロジェクト: victori/voltdb
  public VoltTable[] run(long zip) throws VoltAbortException {
    Date timestamp = new Date();

    // create a District, Warehouse, and 4 Customers (multiple, since we
    // want to test for correct behavior of paymentByCustomerName.

    final double initialYTD = 15241.45;
    voltQueueSQL(
        insertDistrict,
        7L,
        3L,
        "A District",
        "Street Addy",
        "meh",
        "westerfield",
        "BA",
        "99999",
        .0825,
        initialYTD,
        21L);
    // check that a district was inserted
    long resultsl = voltExecuteSQL()[0].asScalarLong();
    assert (resultsl == 1);

    voltQueueSQL(
        insertWarehouse,
        3L,
        "EZ Street WHouse",
        "Headquarters",
        "77 Mass. Ave.",
        "Cambridge",
        "AZ",
        "12938",
        .1234,
        initialYTD);
    // check that a warehouse was inserted
    resultsl = voltExecuteSQL()[0].asScalarLong();
    assert (resultsl == 1);

    final double initialBalance = 15.75;
    voltQueueSQL(
        insertCustomer,
        C_ID,
        D_ID,
        W_ID,
        "I",
        "Be",
        "lastname",
        "Place",
        "Place2",
        "BiggerPlace",
        "AL",
        "91083",
        "(193) 099 - 9082",
        new Date(),
        "BC",
        19298943.12,
        .13,
        initialBalance,
        initialYTD,
        0L,
        15L,
        "Some History");
    // check that a customer was inserted
    resultsl = voltExecuteSQL()[0].asScalarLong();
    assert (resultsl == 1);
    voltQueueSQL(
        insertCustomer,
        C_ID + 1,
        D_ID,
        W_ID,
        "We",
        "Represent",
        "Customer",
        "Random Department",
        "Place2",
        "BiggerPlace",
        "AL",
        "13908",
        "(913) 909 - 0928",
        new Date(),
        "GC",
        19298943.12,
        .13,
        initialBalance,
        initialYTD,
        1L,
        15L,
        "Some History");
    // check that a customer was inserted
    resultsl = voltExecuteSQL()[0].asScalarLong();
    assert (resultsl == 1);
    voltQueueSQL(
        insertCustomer,
        C_ID + 2,
        D_ID,
        W_ID,
        "Who",
        "Is",
        "Customer",
        "Receiving",
        "450 Mass F.X.",
        "BiggerPlace",
        "CI",
        "91083",
        "(541) 931 - 0928",
        new Date(),
        "GC",
        19899324.21,
        .13,
        initialBalance,
        initialYTD,
        2L,
        15L,
        "Some History");
    // check that a customer was inserted
    resultsl = voltExecuteSQL()[0].asScalarLong();
    assert (resultsl == 1);
    voltQueueSQL(
        insertCustomer,
        C_ID + 3,
        D_ID,
        W_ID,
        "ICanBe",
        "",
        "Customer",
        "street",
        "place",
        "BiggerPlace",
        "MA",
        "91083",
        "(913) 909 - 0928",
        new Date(),
        "GC",
        19298943.12,
        .13,
        initialBalance,
        initialYTD,
        3L,
        15L,
        "Some History");
    // check that a customer was inserted
    resultsl = voltExecuteSQL()[0].asScalarLong();
    assert (resultsl == 1);

    // long d_id, long w_id, double h_amount, String c_last, long c_w_id,
    // long c_d_id
    final double paymentAmount = 500.25;

    // VoltTable[] results = client.callProcedure("paymentByCustomerName", W_ID,
    //      D_ID, paymentAmount, W_ID, D_ID, "Customer", new Date());
    // assertEquals(3, results.length);

    // being proc
    voltQueueSQL(getCustomersByLastName, "Customer", D_ID, W_ID);
    final VoltTable customers = voltExecuteSQL()[0];
    final int namecnt = customers.getRowCount();
    if (namecnt == 0) {
      throw new VoltAbortException(
          "no customers with last name: "
              + "Customer"
              + " in warehouse: "
              + W_ID
              + " and in district "
              + D_ID);
    }

    try {
      System.out.println("PAYMENT FOUND CUSTOMERS: " + customers.toString());
    } catch (Exception e) {
      e.printStackTrace();
    }

    final int index = (namecnt - 1) / 2;
    final VoltTableRow customer = customers.fetchRow(index);
    final long c_id = customer.getLong(C_ID_IDX);

    voltQueueSQL(getWarehouse, W_ID);
    voltQueueSQL(getDistrict, W_ID, D_ID);
    final VoltTable[] results = voltExecuteSQL();
    final VoltTable warehouse = results[0];
    final VoltTable district = results[1];

    try {
      System.out.println("WAREHOUSE PRE: " + warehouse.toString());
    } catch (Exception e) {
      e.printStackTrace();
    }

    voltQueueSQL(getWarehouses);
    VoltTable warehouses = voltExecuteSQL()[0];
    try {
      System.out.println("WAREHOUSE PRE: " + warehouses.toString());
    } catch (Exception e) {
      e.printStackTrace();
    }

    voltQueueSQL(updateWarehouseBalance, paymentAmount, W_ID);
    voltQueueSQL(updateDistrictBalance, paymentAmount, W_ID, D_ID);
    voltExecuteSQL();

    voltQueueSQL(getWarehouses);
    warehouses = voltExecuteSQL()[0];
    try {
      System.out.println("WAREHOUSE PRE: " + warehouses.toString());
    } catch (Exception e) {
      e.printStackTrace();
    }

    // do stuff to extract district and warehouse info.

    // customer info
    final byte[] c_first = customer.getStringAsBytes(C_FIRST_IDX);
    final byte[] c_middle = customer.getStringAsBytes(C_MIDDLE_IDX);
    final byte[] c_last = customer.getStringAsBytes(C_LAST_IDX);
    final byte[] c_street_1 = customer.getStringAsBytes(C_STREET_1_IDX);
    final byte[] c_street_2 = customer.getStringAsBytes(C_STREET_2_IDX);
    final byte[] c_city = customer.getStringAsBytes(C_CITY_IDX);
    final byte[] c_state = customer.getStringAsBytes(C_STATE_IDX);
    final byte[] c_zip = customer.getStringAsBytes(C_ZIP_IDX);
    final byte[] c_phone = customer.getStringAsBytes(C_PHONE_IDX);
    final TimestampType c_since = customer.getTimestampAsTimestamp(C_SINCE_IDX);
    final byte[] c_credit = customer.getStringAsBytes(C_CREDIT_IDX);
    final double c_credit_lim = customer.getDouble(C_CREDIT_LIM_IDX);
    final double c_discount = customer.getDouble(C_DISCOUNT_IDX);
    final double c_balance = customer.getDouble(C_BALANCE_IDX) - paymentAmount;
    final double c_ytd_payment = customer.getDouble(C_YTD_PAYMENT_IDX) + paymentAmount;
    final long c_payment_cnt = customer.getLong(C_PAYMENT_CNT_IDX) + 1;
    byte[] c_data;
    if (Arrays.equals(c_credit, Constants.BAD_CREDIT_BYTES)) {
      c_data = customer.getStringAsBytes(C_DATA_IDX);
      byte[] newData =
          (c_id + " " + D_ID + " " + W_ID + " " + D_ID + " " + W_ID + " " + paymentAmount + "|")
              .getBytes();

      int newLength = newData.length + c_data.length;
      if (newLength > Constants.MAX_C_DATA) {
        newLength = Constants.MAX_C_DATA;
      }
      ByteBuilder builder = new ByteBuilder(newLength);

      int minLength = newLength;
      if (newData.length < minLength) minLength = newData.length;
      builder.append(newData, 0, minLength);

      int remaining = newLength - minLength;
      builder.append(c_data, 0, remaining);
      c_data = builder.array();
      voltQueueSQL(
          updateBCCustomer, c_balance, c_ytd_payment, c_payment_cnt, c_data, W_ID, D_ID, c_id);
    } else {
      c_data = new byte[0];
      voltQueueSQL(updateGCCustomer, c_balance, c_ytd_payment, c_payment_cnt, W_ID, D_ID, c_id);
    }

    // Concatenate w_name, four spaces, d_name
    byte[] w_name = warehouse.fetchRow(0).getStringAsBytes(W_NAME_IDX);
    final byte[] FOUR_SPACES = {' ', ' ', ' ', ' '};
    byte[] d_name = district.fetchRow(0).getStringAsBytes(D_NAME_IDX);
    ByteBuilder builder = new ByteBuilder(w_name.length + FOUR_SPACES.length + d_name.length);
    builder.append(w_name);
    builder.append(FOUR_SPACES);
    builder.append(d_name);
    byte[] h_data = builder.array();

    // Create the history record
    voltQueueSQL(insertHistory, c_id, D_ID, W_ID, D_ID, W_ID, timestamp, paymentAmount, h_data);
    voltExecuteSQL();

    // TPC-C 2.5.3.3: Must display the following fields:
    // W_ID, D_ID, C_ID, C_D_ID, C_W_ID, W_STREET_1, W_STREET_2, W_CITY, W_STATE, W_ZIP,
    // D_STREET_1, D_STREET_2, D_CITY, D_STATE, D_ZIP, C_FIRST, C_MIDDLE, C_LAST, C_STREET_1,
    // C_STREET_2, C_CITY, C_STATE, C_ZIP, C_PHONE, C_SINCE, C_CREDIT, C_CREDIT_LIM,
    // C_DISCOUNT, C_BALANCE, the first 200 characters of C_DATA (only if C_CREDIT = "BC"),
    // H_AMOUNT, and H_DATE.

    // Return the entire warehouse and district tuples. The client provided:
    // w_id, d_id, c_d_id, c_w_id, h_amount, h_data.
    // Build a table for the rest
    final VoltTable misc = misc_template.clone(8192);
    misc.addRow(
        c_id,
        c_first,
        c_middle,
        c_last,
        c_street_1,
        c_street_2,
        c_city,
        c_state,
        c_zip,
        c_phone,
        c_since,
        c_credit,
        c_credit_lim,
        c_discount,
        c_balance,
        c_data);

    // Hand back all the warehouse, district, and customer data
    VoltTable[] resultsX = new VoltTable[] {warehouse, district, misc};

    // resume test code

    // check that the middle "Customer" was returned
    assert ((C_ID + 1) == (resultsX[2].fetchRow(0).getLong("c_id")));
    assert ("".equals(resultsX[2].fetchRow(0).getString("c_data")));

    // Verify that both warehouse, district and customer were updated
    // correctly
    // VoltTable[] allTables = client.callProcedure("SelectAll");
    voltQueueSQL(getWarehouses);
    warehouses = voltExecuteSQL()[0];
    try {
      System.out.println("WAREHOUSE POST: " + warehouses.toString());
    } catch (Exception e) {
      e.printStackTrace();
    }

    assert (1 == warehouses.getRowCount());
    double amt1 = initialYTD + paymentAmount;
    double amt2 = warehouses.fetchRow(0).getDouble("W_YTD");

    assert (amt1 == amt2);

    voltQueueSQL(getDistricts);
    VoltTable districts = voltExecuteSQL()[0];
    assert (1 == districts.getRowCount());
    assert ((initialYTD + paymentAmount) == districts.fetchRow(0).getDouble("D_YTD"));

    voltQueueSQL(getCustomers);
    VoltTable customersX = voltExecuteSQL()[0];
    assert (4 == customersX.getRowCount());
    assert ((C_ID + 1) == customersX.fetchRow(1).getLong("C_ID"));
    assert ((initialBalance - paymentAmount) == customersX.fetchRow(1).getDouble("C_BALANCE"));
    assert ((initialYTD + paymentAmount) == customersX.fetchRow(1).getDouble("C_YTD_PAYMENT"));
    assert (2 == customersX.fetchRow(1).getLong("C_PAYMENT_CNT"));

    return null;
  }
コード例 #13
0
ファイル: delivery.java プロジェクト: eoneil1942/tpc-bc
  public VoltTable run(short w_id, int o_carrier_id, TimestampType timestamp)
      throws VoltAbortException {
    for (long d_id = 1; d_id <= Constants.DISTRICTS_PER_WAREHOUSE; ++d_id) {
      voltQueueSQL(getNewOrder, d_id, w_id);
    }
    final VoltTable[] neworderresults = voltExecuteSQL();
    assert neworderresults.length == Constants.DISTRICTS_PER_WAREHOUSE;
    final Long[] no_o_ids = new Long[Constants.DISTRICTS_PER_WAREHOUSE];
    int valid_neworders = 0;
    int[] result_offsets = new int[Constants.DISTRICTS_PER_WAREHOUSE];
    for (long d_id = 1; d_id <= Constants.DISTRICTS_PER_WAREHOUSE; ++d_id) {
      final VoltTable newOrder = neworderresults[(int) d_id - 1];

      if (newOrder.getRowCount() == 0) {
        // No orders for this district: skip it. Note: This must be reported if > 1%
        result_offsets[(int) d_id - 1] = -1;
        continue;
      }
      assert newOrder.getRowCount() == 1;

      result_offsets[(int) d_id - 1] = valid_neworders * 2;
      ++valid_neworders;
      final Long no_o_id = newOrder.asScalarLong();
      no_o_ids[(int) d_id - 1] = no_o_id;
      voltQueueSQL(getCId, no_o_id, d_id, w_id);
      voltQueueSQL(sumOLAmount, no_o_id, d_id, w_id);
    }
    final VoltTable[] otherresults = voltExecuteSQL();
    assert otherresults.length == valid_neworders * 2;

    for (long d_id = 1; d_id <= Constants.DISTRICTS_PER_WAREHOUSE; ++d_id) {
      final VoltTable newOrder = neworderresults[(int) d_id - 1];

      if (newOrder.getRowCount() == 0) {
        // No orders for this district: skip it. Note: This must be reported if > 1%
        continue;
      }
      assert newOrder.getRowCount() == 1;

      final Long no_o_id = newOrder.asScalarLong();
      no_o_ids[(int) d_id - 1] = no_o_id;
      voltQueueSQL(deleteNewOrder, d_id, w_id, no_o_id);
      voltQueueSQL(updateOrders, o_carrier_id, no_o_id, d_id, w_id);
      voltQueueSQL(updateOrderLine, timestamp, no_o_id, d_id, w_id);
    }
    voltExecuteSQL();

    // these must be logged in the "result file" according to TPC-C 2.7.2.2 (page 39)
    // We remove the queued time, completed time, w_id, and o_carrier_id: the client can figure
    // them out
    final VoltTable result = result_template.clone(1024);
    for (long d_id = 1; d_id <= Constants.DISTRICTS_PER_WAREHOUSE; ++d_id) {
      int resultoffset = result_offsets[(int) d_id - 1];

      if (resultoffset < 0) {
        continue;
      }
      assert otherresults[resultoffset + 0].getRowCount() == 1;
      assert otherresults[resultoffset + 1].getRowCount() == 1;
      final long c_id = (otherresults[resultoffset + 0].asScalarLong());
      final VoltTableRow row = otherresults[resultoffset + 1].fetchRow(0);
      final double ol_total = row.getDouble(0);
      final boolean ol_total_wasnull = row.wasNull();

      // If there are no order lines, SUM returns null. There should always be order lines.
      if (ol_total_wasnull) {
        throw new VoltAbortException(
            "ol_total is NULL: there are no order lines. This should not happen");
      }
      assert ol_total > 0.0;

      voltQueueSQL(updateCustomer, ol_total, c_id, d_id, w_id);

      final Long no_o_id = no_o_ids[(int) d_id - 1];
      result.addRow(d_id, no_o_id);
    }
    voltExecuteSQL();

    return result;
  }