Search in sources :

Example 26 with VoltTableRow

use of org.voltdb.VoltTableRow in project voltdb by VoltDB.

the class debugTPCCpayment method run.

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 };
    // 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;
}
Also used : ByteBuilder(org.voltdb.benchmark.tpcc.procedures.ByteBuilder) TimestampType(org.voltdb.types.TimestampType) VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow) Date(java.util.Date)

Example 27 with VoltTableRow

use of org.voltdb.VoltTableRow in project voltdb by VoltDB.

the class TestGroupBySuite method debug.

private void debug(ArrayList<VoltTableRow> sorted) {
    for (VoltTableRow row : sorted) {
        String d1 = (String) row.get(0, VoltType.STRING);
        String d2 = (String) row.get(1, VoltType.STRING);
        System.out.println("Row: " + d1 + ", " + d2);
    }
}
Also used : VoltTableRow(org.voltdb.VoltTableRow)

Example 28 with VoltTableRow

use of org.voltdb.VoltTableRow in project voltdb by VoltDB.

the class TestOrderBySuite method subtestOrderByMP_Agg.

private void subtestOrderByMP_Agg() throws Exception {
    Client client = getClient();
    client.callProcedure("TruncateP");
    client.callProcedure("@AdHoc", "insert into P values(1, 11, 1, 1)");
    client.callProcedure("@AdHoc", "insert into P values(1, 1, 2, 1)");
    client.callProcedure("@AdHoc", "insert into P values(3, 6, 2, 1)");
    client.callProcedure("@AdHoc", "insert into P values(4, 6, 1, 1)");
    client.callProcedure("@AdHoc", "insert into P values(5, 11, 2, 1)");
    client.callProcedure("@AdHoc", "insert into P values(7, 1, 4, 1)");
    client.callProcedure("@AdHoc", "insert into P values(7, 6, 1, 1)");
    String sql;
    VoltTable vt;
    long[][] expected;
    // Merge Receive with Serial aggregation
    //            select indexed_non_partition_key, max(col)
    //            from partitioned
    //            group by indexed_non_partition_key
    //            order by indexed_non_partition_key;"
    sql = "select P_D1, max(P_D2) from P where P_D1 > 0 group by P_D1 order by P_D1";
    vt = client.callProcedure("@AdHoc", sql).getResults()[0];
    expected = new long[][] { { 1, 4 }, { 6, 2 }, { 11, 2 } };
    validateTableOfLongs(vt, expected);
    vt = client.callProcedure("@Explain", sql).getResults()[0];
    assertTrue(vt.toString().contains("MERGE RECEIVE"));
    // Merge Receive with Partial aggregation
    //            select indexed_non_partition_key, col, max(col)
    //            from partitioned
    //            group by indexed_non_partition_key, col
    //            order by indexed_non_partition_key;
    sql = "select P_D1, P_D3, max(P_D2) from P group by P_D1, P_D3 order by P_D1";
    vt = client.callProcedure("@AdHoc", sql).getResults()[0];
    expected = new long[][] { { 1, 1, 4 }, { 6, 1, 2 }, { 11, 1, 2 } };
    validateTableOfLongs(vt, expected);
    vt = client.callProcedure("@Explain", sql).getResults()[0];
    assertTrue(vt.toString().contains("MERGE RECEIVE"));
    // No aggregation at coordinator
    //          select indexed_partition_key, max(col)
    //          from partitioned
    //          group by indexed_partition_key
    //          order by indexed_partition_key;"
    sql = "select max(P_D2), P_D0 from P group by P_D0  order by P_D0";
    vt = client.callProcedure("@AdHoc", sql).getResults()[0];
    expected = new long[][] { { 2, 1 }, { 2, 3 }, { 1, 4 }, { 2, 5 }, { 4, 7 } };
    validateTableOfLongs(vt, expected);
    vt = client.callProcedure("@Explain", sql).getResults()[0];
    assertTrue(vt.toString().contains("MERGE RECEIVE"));
    // No aggregation at coordinator
    //          select indexed_non_partition_key, max(col)
    //          from partitioned
    //          group by indexed_non_partition_key, indexed_partition_key
    //          order by indexed_partition_key;"
    sql = "select max(P_D2), P_D1, P_D0 from P group by P_D1, P_D0 order by P_D0  limit 3 offset 2";
    vt = client.callProcedure("@AdHoc", sql).getResults()[0];
    expected = new long[][] { { 2, 6, 3 }, { 1, 6, 4 }, { 2, 11, 5 } };
    validateTableOfLongs(vt, expected);
    vt = client.callProcedure("@Explain", sql).getResults()[0];
    assertTrue(vt.toString().contains("MERGE RECEIVE"));
    // Merge Receive with Serial aggregation
    //            select indexed_non_partition_key1, indexed_non_partition_key2, max(col)
    //            from partitioned
    //            group by indexed_non_partition_key1, indexed_non_partition_key2
    //            order by indexed_non_partition_key1, indexed_non_partition_key2;"
    sql = "select P_D3, P_D2, max (P_D0) from p where P_D3 > 0 group by P_D3, P_D2 order by P_D3, P_D2 limit 1 offset 1";
    vt = client.callProcedure("@AdHoc", sql).getResults()[0];
    expected = new long[][] { { 1, 2, 5 } };
    validateTableOfLongs(vt, expected);
    vt = client.callProcedure("@Explain", sql).getResults()[0];
    assertTrue(vt.toString().contains("MERGE RECEIVE"));
    sql = "select P_D3, P_D2, max (P_D0) from p where P_D3 > 0 group by P_D3, P_D2 order by P_D3, P_D2 offset 2";
    vt = client.callProcedure("@AdHoc", sql).getResults()[0];
    expected = new long[][] { { 1, 4, 7 } };
    validateTableOfLongs(vt, expected);
    sql = "select P_D3, P_D2, max (P_D0) from p where P_D3 > 0 group by P_D3, P_D2 order by P_D3, P_D2 limit 2";
    vt = client.callProcedure("@AdHoc", sql).getResults()[0];
    expected = new long[][] { { 1, 1, 7 }, { 1, 2, 5 } };
    validateTableOfLongs(vt, expected);
    // Merge Receive without aggregation at coordinator
    //            select indexed_non_partition_key1, indexed_non_partition_key2, col, max(col)
    //            from partitioned
    //            group by indexed_non_partition_key1, indexed_non_partition_key2, col
    //            order by indexed_non_partition_key1, indexed_non_partition_key2;"
    sql = "select P_D3, P_D2, max (P_D0) from p where P_D3 > 0 group by P_D3, P_D2, P_D0 order by P_D3, P_D2";
    vt = client.callProcedure("@AdHoc", sql).getResults()[0];
    expected = new long[][] { { 1, 1 }, { 1, 1 }, { 1, 1 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 4 } };
    assertEquals(expected.length, vt.getRowCount());
    for (int i = 0; i < expected.length; ++i) {
        VoltTableRow row = vt.fetchRow(i);
        assertEquals(expected[i][0], row.getLong("P_D3"));
        assertEquals(expected[i][1], row.getLong("P_D2"));
    }
    vt = client.callProcedure("@Explain", sql).getResults()[0];
    assertTrue(vt.toString().contains("MERGE RECEIVE"));
    //  Merge Receive from view, ordering by its non-partition-key grouping columns
    sql = "SELECT V_P_D1 FROM V_P order by V_P_D1";
    vt = client.callProcedure("@AdHoc", sql).getResults()[0];
    expected = new long[][] { { 1 }, { 1 }, { 6 }, { 6 }, { 11 }, { 11 } };
    validateTableOfLongs(vt, expected);
    vt = client.callProcedure("@Explain", sql).getResults()[0];
    assertTrue(vt.toString().contains("MERGE RECEIVE"));
    sql = "SELECT V_P_D1, V_P_D2 FROM V_P order by V_P_D1 DESC , V_P_D2 DESC";
    vt = client.callProcedure("@AdHoc", sql).getResults()[0];
    expected = new long[][] { { 11, 2 }, { 11, 1 }, { 6, 2 }, { 6, 1 }, { 1, 4 }, { 1, 2 } };
    validateTableOfLongs(vt, expected);
    vt = client.callProcedure("@Explain", sql).getResults()[0];
    assertTrue(vt.toString().contains("MERGE RECEIVE"));
}
Also used : Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow)

Example 29 with VoltTableRow

use of org.voltdb.VoltTableRow in project voltdb by VoltDB.

the class debugTPCCdelivery method run.

public VoltTable[] run(long zip) throws VoltAbortException {
    Date timestamp = new Date();
    long o_carrier_id = 10L;
    voltQueueSQL(insertDistrict, 7L, 3L, "A District", "Street Addy", "meh", "westerfield", "BA", "99999", .0825, 15241.45, 21L);
    // check that a district was inserted
    long results = voltExecuteSQL()[0].asScalarLong();
    assert (results == 1);
    voltQueueSQL(insertWarehouse, 3L, "EZ Street WHouse", "Headquarters", "77 Mass. Ave.", "Cambridge", "AZ", "12938", .1234, 18837.57);
    // check that a warehouse was inserted
    results = voltExecuteSQL()[0].asScalarLong();
    assert (results == 1);
    voltQueueSQL(insertCustomer, 5L, D_ID, W_ID, "We", "Represent", "Customer", "Random Department", "Place2", "BiggerPlace", "AL", "13908", "(913) 909 - 0928", new Date(), "GC", 19298943.12, .13, 15.75, 18832.45, 45L, 15L, "Some History");
    // check that a customer was inserted
    results = voltExecuteSQL()[0].asScalarLong();
    assert (results == 1);
    final long O_OL_CNT = 1;
    voltQueueSQL(insertOrders, O_ID, D_ID, W_ID, 5L, new Date(), 10L, O_OL_CNT, 1L);
    // check that an orders was inserted
    results = voltExecuteSQL()[0].asScalarLong();
    assert (results == 1);
    voltQueueSQL(insertOrderLine, O_ID, D_ID, W_ID, 1L, I_ID, W_ID, null, 1L, 1.0, "ol_dist_info");
    // check that an orderline was inserted
    results = voltExecuteSQL()[0].asScalarLong();
    assert (results == 1);
    voltQueueSQL(insertOrderLine, O_ID, D_ID, W_ID, 2L, I_ID + 1, W_ID, null, 1L, 1.0, "ol_dist_info");
    // check that an orderline was inserted
    results = voltExecuteSQL()[0].asScalarLong();
    assert (results == 1);
    voltQueueSQL(insertNewOrder, O_ID, D_ID, W_ID);
    // check that an orders was inserted
    results = voltExecuteSQL()[0].asScalarLong();
    assert (results == 1);
    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(getOrderlines);
        VoltTable olResult = voltExecuteSQL()[0];
        try {
            System.out.println("All Orderlines: " + olResult.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        voltQueueSQL(sumOLAmount, no_o_id, d_id, W_ID);
        VoltTable sumResult = voltExecuteSQL()[0];
        try {
            System.out.println("Sum Result: " + sumResult.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        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(8192);
    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();
    VoltTableRow r = result.fetchRow(0);
    assert (D_ID == r.getLong(0));
    assert (O_ID == r.getLong(1));
    return null;
}
Also used : Date(java.util.Date) VoltTableRow(org.voltdb.VoltTableRow)

Example 30 with VoltTableRow

use of org.voltdb.VoltTableRow in project voltdb by VoltDB.

the class TestGroupBySuite method testDistributedSumGroupMultiJoinOneDim.

/**
     * distributed sum of a view with 3-way join on replicated table for
     * specific dim1 (REDUNDANT GROUP BY)
     * select D1.D1_NAME, D2.D2_NAME, sum(V.SUM_V1),
     * sum(V.SUM_V2), sum(V.SUM_V3) from D1, D2, V where V.V_D1_PKEY =
     * D1.D1_PKEY and V.V_D2_PKEY = D2.D2_PKEY and D1.D1_PKEY = ?
     * group by D1_NAME, D2_NAME
     * @throws InterruptedException
     */
public void testDistributedSumGroupMultiJoinOneDim() throws IOException, ProcCallException, InterruptedException {
    VoltTable vt;
    Client client = getClient();
    loadF(client, 0);
    loadDims(client);
    String qs = "select D1.D1_NAME, D2.D2_NAME, sum(V.SUM_V1), sum(V.SUM_V2), sum(V.SUM_V3) " + "from D1, D2, V " + "where V.V_D1_PKEY = D1.D1_PKEY and V.V_D2_PKEY = D2.D2_PKEY and D1.D1_PKEY = 6 " + "group by D1.D1_NAME, D2.D2_NAME;";
    vt = client.callProcedure("@AdHoc", qs).getResults()[0];
    // 5 unique values of d2 for each value of d1 (and a single d1 value is selected above)
    assertEquals(vt.getRowCount(), 5);
    // sort the output by d2's value
    ArrayList<VoltTableRow> sorted = new ArrayList<VoltTableRow>();
    while (vt.advanceRow()) {
        // this will add the active row of vt
        sorted.add(vt.cloneRow());
    }
    System.out.println("DSGMJonedim");
    debug(sorted);
    Collections.sort(sorted, new VRowComparator<VoltTableRow>());
    System.out.println("DSGMJonedim: ");
    debug(sorted);
    int i = 0;
    for (VoltTableRow row : sorted) {
        String d2_name = "D2_" + ((i * 10) + 6);
        String d1 = (String) row.get(0, VoltType.STRING);
        String d2 = (String) row.get(1, VoltType.STRING);
        Integer s1 = (Integer) row.get(2, VoltType.INTEGER);
        Integer s3 = (Integer) row.get(4, VoltType.INTEGER);
        System.out.println("D2 expected: " + d2_name + " actual: " + d2);
        assertEquals(d1, "D1_6");
        assertEquals(d2, d2_name);
        // 20 unique combinations * 2.
        assertEquals(s1.intValue(), 40);
        // all even d1's are 0 in s3
        assertEquals(s3.intValue(), 0);
        i++;
    }
}
Also used : ArrayList(java.util.ArrayList) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow)

Aggregations

VoltTableRow (org.voltdb.VoltTableRow)65 VoltTable (org.voltdb.VoltTable)57 Client (org.voltdb.client.Client)23 ProcCallException (org.voltdb.client.ProcCallException)11 TimestampType (org.voltdb.types.TimestampType)7 NoConnectionsException (org.voltdb.client.NoConnectionsException)6 IOException (java.io.IOException)5 VoltAbortException (org.voltdb.VoltProcedure.VoltAbortException)5 Date (java.util.Date)4 WorkWithBigString (org.voltdb_testprocs.regressionsuites.sqlfeatureprocs.WorkWithBigString)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 ClientResponse (org.voltdb.client.ClientResponse)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 PrintStream (java.io.PrintStream)1 BigDecimal (java.math.BigDecimal)1 HashSet (java.util.HashSet)1 ByteBuilder (org.voltdb.benchmark.tpcc.procedures.ByteBuilder)1