Search in sources :

Example 31 with VoltTableRow

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

the class TestGroupBySuite method testDistributedSumGroupMultiJoin.

/**
     * distributed sum of a view with 3-way join on replicated tables
     * (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
     * group by D1_NAME, D2_NAME
     * @throws InterruptedException
     */
public void testDistributedSumGroupMultiJoin() 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 V, D1, D2 " + "where V.V_D1_PKEY = D1.D1_PKEY and V.V_D2_PKEY = D2.D2_PKEY " + "group by D1.D1_NAME, D2.D2_NAME";
    vt = client.callProcedure("@AdHoc", qs).getResults()[0];
    System.out.println("DistributedSumGroupMultiJoin: " + vt);
    // sort the output by d2's value
    ArrayList<VoltTableRow> sorted = new ArrayList<VoltTableRow>();
    while (vt.advanceRow()) {
        String d1 = (String) vt.get(0, VoltType.STRING);
        String d2 = (String) vt.get(1, VoltType.STRING);
        System.out.println("Adding Row: " + d1 + ", " + d2);
        // 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);
    // 5 unique d2's for each of 10 d1's (so 10 * 5 rows)
    assertEquals(50, vt.getRowCount());
    Integer i = 0, j = 0;
    for (VoltTableRow row : sorted) {
        String d1_name = "D1_" + i;
        String d2_name = "D2_" + (i + (j * 10));
        // 20 unique combinations of d1, d2, d3
        int v3 = (i % 2) * 20;
        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);
        assertEquals(d1, d1_name);
        assertEquals(d2, d2_name);
        assertEquals(s1.intValue(), 40);
        assertEquals(s3.intValue(), v3);
        j++;
        if (j == 5) {
            i++;
            j = 0;
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow)

Example 32 with VoltTableRow

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

the class TestTPCCSuite method testDELIVERY.

public void testDELIVERY() throws IOException, ProcCallException {
    Client client = getClient();
    // create a District, Warehouse, and 4 Customers (multiple, since we
    // want to test for correct behavior of paymentByCustomerName.
    // long d_id, long d_w_id, String d_name, String d_street_1, String
    // d_street_2, String d_city, String d_state, String d_zip, double
    // d_tax, double d_ytd, long d_next_o_id
    VoltTable[] idresults = client.callProcedure("InsertDistrict", D_ID, W_ID, "A District", "Street Addy", "meh", "westerfield", "BA", "99999", .0825, 15241.45, 21L).getResults();
    // check that a district was inserted
    assertEquals(1L, idresults[0].asScalarLong());
    // long w_id, String w_name, String w_street_1, String w_street_2,
    // String w_city, String w_zip, double w_tax, long w_ytd
    VoltTable warehouse = client.callProcedure("InsertWarehouse", W_ID, "EZ Street WHouse", "Headquarters", "77 Mass. Ave.", "Cambridge", "AZ", "12938", .1234, 18837.57).getResults()[0];
    // check for successful insertion.
    assertEquals(1L, warehouse.asScalarLong());
    VoltTable customer = client.callProcedure("InsertCustomer", 5L, D_ID, W_ID, "We", "R", "Customer", "Random Department", "Place2", "BiggerPlace", "AL", "13908", "(913) 909 - 0928", new TimestampType(), "GC", 19298943.12, .13, 15.75, 18832.45, 45L, 15L, "Some History").getResults()[0];
    // check for successful insertion.
    assertEquals(1L, customer.asScalarLong());
    final long O_OL_CNT = 1;
    VoltTable orders = client.callProcedure("InsertOrders", O_ID, D_ID, W_ID, 5L, new TimestampType(), 10L, O_OL_CNT, 1L).getResults()[0];
    // check for successful insertion.
    assertEquals(1L, orders.asScalarLong());
    // Insert an order line for this order
    VoltTable line = client.callProcedure("InsertOrderLine", O_ID, D_ID, W_ID, 1L, I_ID, W_ID, new TimestampType(), 1L, 1.0, "ol_dist_info").getResults()[0];
    assertEquals(1L, line.asScalarLong());
    VoltTable newOrder = client.callProcedure("InsertNewOrder", O_ID, D_ID, W_ID).getResults()[0];
    // check for successful insertion.
    assertEquals(1L, newOrder.asScalarLong());
    System.out.println("DATA before DELIVERY transaction");
    TPCDataPrinter.printAllData(client);
    VoltTable[] results = client.callProcedure("delivery", W_ID, 10, new TimestampType()).getResults();
    System.out.println("DATA after DELIVERY transaction");
    TPCDataPrinter.printAllData(client);
    assertEquals(1, results.length);
    assertEquals(1, results[0].getRowCount());
    VoltTableRow r = results[0].fetchRow(0);
    assertEquals(D_ID, r.getLong(0));
    assertEquals(O_ID, r.getLong(1));
}
Also used : TimestampType(org.voltdb.types.TimestampType) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow)

Example 33 with VoltTableRow

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

the class TestTPCCSuite method testNEWORDER.

public void testNEWORDER() throws IOException, ProcCallException {
    Client client = getClient();
    final double W_TAX = 0.1234;
    // long w_id, String w_name, String w_street_1, String w_street_2,
    // String w_city, String w_zip, double w_tax, long w_ytd
    VoltTable warehouse = client.callProcedure("InsertWarehouse", W_ID, "EZ Street WHouse", "Headquarters", "77 Mass. Ave.", "Cambridge", "AZ", "12938", W_TAX, 18837.57).getResults()[0];
    // check for successful insertion.
    assertEquals(1L, warehouse.asScalarLong());
    final double D_TAX = 0.0825;
    final int D_NEXT_O_ID = 21;
    // long d_id, long d_w_id, String d_name, String d_street_1, String
    // d_street_2, String d_city, String d_state, String d_zip, double
    // d_tax, double d_ytd, long d_next_o_id
    VoltTable district = client.callProcedure("InsertDistrict", D_ID, W_ID, "A District", "Street Addy", "meh", "westerfield", "BA", "99999", D_TAX, 15241.45, D_NEXT_O_ID).getResults()[0];
    // check that a district was inserted
    assertEquals(1L, district.asScalarLong());
    final double C_DISCOUNT = 0.13;
    // long c_id, long c_d_id, long c_w_id, String c_first, String c_middle,
    // String c_last, String c_street_1, String c_street_2, String d_city,
    // String d_state, String d_zip, String c_phone, Date c_since, String
    // c_credit, double c_credit_lim, double c_discount, double c_balance,
    // double c_ytd_payment, double c_payment_cnt, double c_delivery_cnt,
    // String c_data
    VoltTable customer = client.callProcedure("InsertCustomer", C_ID, D_ID, W_ID, "I", "Is", "Name", "Place", "Place2", "BiggerPlace", "AL", "91083", "(913) 909 - 0928", new TimestampType(), "GC", 19298943.12, C_DISCOUNT, 15.75, 18832.45, 45L, 15L, "Some History").getResults()[0];
    // check for successful insertion.
    assertEquals(1L, customer.asScalarLong());
    final int[] s_quantities = { 45, 85, 15 };
    final long INITIAL_S_YTD = 5582L;
    final long INITIAL_S_ORDER_CNT = 152L;
    // long pkey, long s_i_id, long s_w_id, long s_quantity, String
    // s_dist_01, String s_dist_02, String s_dist_03, String s_dist_04,
    // String s_dist_05, String s_dist_06, String s_dist_07, String
    // s_dist_08, String s_dist_09, String s_dist_10, long s_ytd, long
    // s_order_cnt, long s_remote_cnt, String s_data
    VoltTable stock1 = client.callProcedure("InsertStock", 4L, W_ID, s_quantities[0], "INFO", "INFO", "INFO", "INFO", "INFO", "INFO", "INFO", "INFO", "INFO", "INFO", INITIAL_S_YTD, INITIAL_S_ORDER_CNT, 32L, "DATA").getResults()[0];
    VoltTable stock2 = client.callProcedure("InsertStock", 5L, W_ID, s_quantities[1], "INFO", "INFO", "INFO", "INFO", "INFO", "INFO", "INFO", "INFO", "INFO", "INFO", INITIAL_S_YTD + 10, INITIAL_S_ORDER_CNT + 10, 32L, "foo" + Constants.ORIGINAL_STRING + "bar").getResults()[0];
    VoltTable stock3 = client.callProcedure("InsertStock", 6L, W_ID, s_quantities[2], "INFO", "INFO", "INFO", "INFO", "INFO", "INFO", "INFO", "INFO", "INFO", "INFO", INITIAL_S_YTD + 20, INITIAL_S_ORDER_CNT + 20, 32L, "DATA").getResults()[0];
    final double PRICE = 2341.23;
    // long i_id, long i_im_id, String i_name, double i_price, String i_data
    VoltTable item1 = client.callProcedure("InsertItem", 4L, 4L, "ITEM1", PRICE, Constants.ORIGINAL_STRING).getResults()[0];
    VoltTable item2 = client.callProcedure("InsertItem", 5L, 5L, "ITEM2", PRICE, Constants.ORIGINAL_STRING).getResults()[0];
    VoltTable item3 = client.callProcedure("InsertItem", 6L, 6L, "ITEM3", PRICE, Constants.ORIGINAL_STRING).getResults()[0];
    // check the inserts went through.
    assertEquals(1L, stock1.asScalarLong());
    assertEquals(1L, stock2.asScalarLong());
    assertEquals(1L, stock3.asScalarLong());
    assertEquals(1L, item1.asScalarLong());
    assertEquals(1L, item2.asScalarLong());
    assertEquals(1L, item3.asScalarLong());
    // call the neworder transaction:
    // if(ol_supply_w_id != w_id) all_local = 0;
    // test all_local behavior, first, then remote warehouse situation.
    // long w_id, long d_id, long c_id, long ol_cnt, long all_local, long[]
    // item_id, long[] supware, long[] quantity
    int[] items = { 4, 5, 6 };
    short[] warehouses = { W_ID, W_ID, W_ID };
    int[] quantities = { 3, 5, 1 };
    TPCDataPrinter.printAllData(client);
    TimestampType timestamp = new TimestampType();
    VoltTable[] neworder = client.callProcedure("neworder", W_ID, D_ID, C_ID, timestamp, items, warehouses, quantities).getResults();
    // Now to check returns are correct. We assume that inserts and such
    // within the actual transaction went through since it didn't rollback
    // and error out.
    VoltTableRow customerData = neworder[0].fetchRow(0);
    VoltTableRow miscData = neworder[1].fetchRow(0);
    assertEquals("Name", customerData.getString("C_LAST"));
    assertEquals("GC", customerData.getString("C_CREDIT"));
    assertEquals(.13, customerData.getDouble("C_DISCOUNT"));
    assertEquals(W_TAX, miscData.getDouble("w_tax"));
    assertEquals(D_TAX, miscData.getDouble("d_tax"));
    assertEquals(21L, miscData.getLong("o_id"));
    final double AMOUNT = PRICE * (3 + 5 + 1) * (1 - C_DISCOUNT) * (1 + D_TAX + W_TAX);
    assertEquals(AMOUNT, miscData.getDouble("total"), 0.001);
    // Check each item
    VoltTable itemResults = neworder[2];
    assertEquals(quantities.length, itemResults.getRowCount());
    for (int i = 0; i < itemResults.getRowCount(); ++i) {
        VoltTableRow itemRow = itemResults.fetchRow(i);
        assertEquals("ITEM" + (i + 1), itemRow.getString("i_name"));
        //~ assertEquals(quantities[i], itemRow.getLong("));
        long expected = s_quantities[i] - quantities[i];
        if (expected < 10)
            expected += 91;
        assertEquals(expected, itemRow.getLong("s_quantity"));
        if (i == 1) {
            assertEquals("B", itemRow.getString("brand_generic"));
        } else {
            assertEquals("G", itemRow.getString("brand_generic"));
        }
        assertEquals(PRICE, itemRow.getDouble("i_price"));
        assertEquals(PRICE * quantities[i], itemRow.getDouble("ol_amount"));
    }
    // verify that stock was updated correctly
    VoltTable[] allTables = client.callProcedure("SelectAll").getResults();
    VoltTable stock = allTables[TPCDataPrinter.nameMap.get("STOCK")];
    for (int i = 0; i < stock.getRowCount(); ++i) {
        VoltTableRow stockRow = stock.fetchRow(i);
        assertEquals(INITIAL_S_YTD + i * 10 + quantities[i], stockRow.getLong("S_YTD"));
        assertEquals(INITIAL_S_ORDER_CNT + i * 10 + 1, stockRow.getLong("S_ORDER_CNT"));
    }
    // New order with a missing item
    items = new int[] { Constants.NUM_ITEMS + 1 };
    warehouses = new short[] { W_ID };
    quantities = new int[] { 42 };
    try {
        client.callProcedure("neworder", W_ID, D_ID, C_ID, timestamp, items, warehouses, quantities);
    } catch (ProcCallException e) {
        assertTrue(e.getMessage().indexOf(Constants.INVALID_ITEM_MESSAGE) > 0);
    }
    // Verify that we only inserted one new order
    allTables = client.callProcedure("SelectAll").getResults();
    TPCDataPrinter.nameMap.get("ORDERS");
    // only 1 order, from the first new order call
    district = allTables[TPCDataPrinter.nameMap.get("DISTRICT")];
    assertEquals(1, district.getRowCount());
    assertEquals(D_NEXT_O_ID + 1, district.fetchRow(0).getLong("D_NEXT_O_ID"));
// TODO(evanj): Verify that everything else is updated correctly
}
Also used : TimestampType(org.voltdb.types.TimestampType) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow) ProcCallException(org.voltdb.client.ProcCallException)

Example 34 with VoltTableRow

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

the class getNextFromPtn method run.

public long run(int id, long inc) {
    voltQueueSQL(getCounterStmt, EXPECT_ZERO_OR_ONE_ROW, id);
    VoltTable[] validation = voltExecuteSQL();
    if (validation[0].getRowCount() != 1) {
        return ERR_INVALID_COUNTER;
    }
    VoltTableRow row = validation[0].fetchRow(0);
    // what happens when this overflows?
    long count = row.getLong(0) + inc;
    voltQueueSQL(updateCounterStmt, EXPECT_ONE_ROW, count, id, row.getLong(0));
    VoltTable[] result = voltExecuteSQL(true);
    // return the updated value
    return count;
}
Also used : VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow)

Example 35 with VoltTableRow

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

the class TestIndexesSuite method subTestOrderedMultiMultiIntGTEFailure.

private void subTestOrderedMultiMultiIntGTEFailure() throws IOException, ProcCallException {
    final Client client = getClient();
    final VoltTable[] results = client.callProcedure("CheckMultiMultiIntGTEFailure").getResults();
    if (results == null) {
        fail();
    }
    //
    // Must pass 10 tests
    //
    assertEquals(10, results.length);
    // Start off easy, with COUNT(*)s
    // Actually, these exercise a different (counted index) code path which has experienced its own regressions.
    // Test 1 -- count EQ first component of compound key
    int tableI = 0;
    final VoltTableRow countEQ = results[tableI].fetchRow(0);
    assertEquals(2, countEQ.getLong(0));
    // Test 2 -- count GTE first component of compound key
    tableI++;
    final VoltTableRow countGT = results[tableI].fetchRow(0);
    assertEquals(3, countGT.getLong(0));
    // Test 3 -- count GT first component of compound key
    tableI++;
    final VoltTableRow countGTE = results[tableI].fetchRow(0);
    assertEquals(1, countGTE.getLong(0));
    // Test 4 -- count LTE first component of compound key
    tableI++;
    final VoltTableRow countLTE = results[tableI].fetchRow(0);
    assertEquals(3, countLTE.getLong(0));
    // Test 5 -- count LT first component of compound key
    tableI++;
    final VoltTableRow countLT = results[tableI].fetchRow(0);
    assertEquals(1, countLT.getLong(0));
    // Test 6 -- EQ first component of compound key
    tableI++;
    int rowI = 0;
    assertEquals(2, results[tableI].getRowCount());
    final VoltTableRow rowEQ0 = results[tableI].fetchRow(rowI++);
    assertEquals(0, rowEQ0.getLong(0));
    assertEquals(0, rowEQ0.getLong(1));
    final VoltTableRow rowEQ1 = results[tableI].fetchRow(rowI++);
    assertEquals(0, rowEQ1.getLong(0));
    assertEquals(1, rowEQ1.getLong(1));
    // Test 7 -- GTE first component of compound key
    tableI++;
    rowI = 0;
    assertEquals(3, results[tableI].getRowCount());
    final VoltTableRow rowGTE0 = results[tableI].fetchRow(rowI++);
    assertEquals(0, rowGTE0.getLong(0));
    assertEquals(0, rowGTE0.getLong(1));
    final VoltTableRow rowGTE1 = results[tableI].fetchRow(rowI++);
    assertEquals(0, rowGTE1.getLong(0));
    assertEquals(1, rowGTE1.getLong(1));
    final VoltTableRow rowGTE2 = results[tableI].fetchRow(rowI++);
    assertEquals(1, rowGTE2.getLong(0));
    assertEquals(1, rowGTE2.getLong(1));
    // Test 8 -- GT first component of compound key
    tableI++;
    rowI = 0;
    assertEquals(1, results[tableI].getRowCount());
    final VoltTableRow rowGT0 = results[tableI].fetchRow(rowI++);
    assertEquals(1, rowGT0.getLong(0));
    assertEquals(1, rowGT0.getLong(1));
    // Test 9 -- LTE first component of compound key
    tableI++;
    rowI = 0;
    assertEquals(3, results[tableI].getRowCount());
    // after adding reserve scan, JNI and HSQL will report
    // tuples in different order
    // so, add them to a set and ignore the order instead
    final VoltTableRow rowLTE0 = results[tableI].fetchRow(rowI++);
    final VoltTableRow rowLTE1 = results[tableI].fetchRow(rowI++);
    final VoltTableRow rowLTE2 = results[tableI].fetchRow(rowI++);
    HashSet<Long> TID = new HashSet<Long>();
    HashSet<Long> BID = new HashSet<Long>();
    HashSet<Long> expectedTID = new HashSet<Long>();
    HashSet<Long> expectedBID = new HashSet<Long>();
    expectedTID.add(-1L);
    expectedTID.add(0L);
    expectedTID.add(0L);
    expectedBID.add(0L);
    expectedBID.add(0L);
    expectedBID.add(1L);
    TID.add(rowLTE0.getLong(0));
    TID.add(rowLTE1.getLong(0));
    TID.add(rowLTE2.getLong(0));
    BID.add(rowLTE0.getLong(1));
    BID.add(rowLTE1.getLong(1));
    BID.add(rowLTE2.getLong(1));
    assertTrue(TID.equals(expectedTID));
    assertTrue(BID.equals(expectedBID));
    // Test 10 -- LT first component of compound key
    tableI++;
    rowI = 0;
    assertEquals(1, results[tableI].getRowCount());
    final VoltTableRow rowLT0 = results[tableI].fetchRow(rowI++);
    assertEquals(-1, rowLT0.getLong(0));
    assertEquals(0, rowLT0.getLong(1));
    truncateTables(new String[] { "BINGO_BOARD" });
}
Also used : Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow) HashSet(java.util.HashSet)

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