Search in sources :

Example 71 with TimestampType

use of org.voltdb.types.TimestampType 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 72 with TimestampType

use of org.voltdb.types.TimestampType in project voltdb by VoltDB.

the class TestCatalogUpdateSuite method testUpdateWithNoDeploymentFile.

public void testUpdateWithNoDeploymentFile() throws Exception {
    System.out.println("\n\n-----\n testUpdateWithNoDeploymentFile \n-----\n\n");
    Client client = getClient();
    String newCatalogURL;
    CatTestCallback callback;
    loadSomeData(client, 0, 25);
    assertCallbackSuccess(client);
    negativeTests(client);
    assertCallbackSuccess(client);
    // asynchronously call some random inserts
    loadSomeData(client, 25, 25);
    assertCallbackSuccess(client);
    // add a procedure "InsertOrderLineBatched"
    newCatalogURL = Configuration.getPathToCatalogForTest("catalogupdate-cluster-expanded.jar");
    callback = new CatTestCallback(ClientResponse.SUCCESS);
    client.updateApplicationCatalog(callback, new File(newCatalogURL), null);
    // don't care if this succeeds or fails.
    // calling the new proc before the cat change returns is not guaranteed to work
    // we just hope it doesn't crash anything
    int x = 3;
    SyncCallback cb = new SyncCallback();
    client.callProcedure(cb, org.voltdb.benchmark.tpcc.procedures.InsertOrderLineBatched.class.getSimpleName(), new long[] { x }, new long[] { x }, x, new long[] { x }, new long[] { x }, new long[] { x }, new TimestampType[] { new TimestampType() }, new long[] { x }, new double[] { x }, new String[] { "a" });
    cb.waitForResponse();
    // make sure the previous catalog change has completed
    assertCallbackSuccess(client);
    // now calling the new proc better work
    x = 2;
    client.callProcedure(org.voltdb.benchmark.tpcc.procedures.InsertOrderLineBatched.class.getSimpleName(), new long[] { x }, new long[] { x }, (short) x, new long[] { x }, new long[] { x }, new long[] { x }, new TimestampType[] { new TimestampType() }, new long[] { x }, new double[] { x }, new String[] { "a" });
    loadSomeData(client, 50, 5);
    assertCallbackSuccess(client);
}
Also used : TimestampType(org.voltdb.types.TimestampType) Client(org.voltdb.client.Client) File(java.io.File) SyncCallback(org.voltdb.client.SyncCallback)

Example 73 with TimestampType

use of org.voltdb.types.TimestampType in project voltdb by VoltDB.

the class TestSqlAggregateSuite method testInlineVarcharCountDistinct.

// This is a regression test for ENG-9394
public void testInlineVarcharCountDistinct() throws IOException, ProcCallException {
    Client client = getClient();
    // These values were empirically determined to
    // produce a wrong answer before this bug was fixed.
    String[] codeValues = { "x9knsslnDEx1vPVE3AmoJSyF", "x9iMVxN9IM3PbKn0rVuPfK0GI", "xcsj3vLpLh", "x8DuKNF0GeQ8UG", "xiqRc8iVY2u1oN5kizy3CA7", "xecZXl8bsE4Pw3LBhI7B8G", "xfKP25a2foPTw2FiCRdUsZj", "xp7KR8SOp5B8kopvUdnc3gmeAskWVwJ", "xG6", "xhw0OVDvKJRyYdmUj9z3UcODKNB", "xPy5PXeRtJcZhUFuyIiV09h", "x8Vc4ExuM4c7SU5F6XZ6pWiUnnrO93v", "xNe2H70Em", "x8cepckgTyLhKR8cF10JgR4JzWCUu", "xuT6JlTjfObhqUJ", "xovLMc0FWA04m", "xJroR", "xdSjQW", "xHw", "xMMnkLHq8b493PhefMjtLQjV" };
    for (int i = 0; i < codeValues.length; ++i) {
        client.callProcedure("ENG_9394.insert", codeValues[i], codeValues[i], Integer.toString(i), new TimestampType("2010-10-31 11:11:26"), new TimestampType("2048-10-31 11:11:27"), "000");
    }
    VoltTable vt;
    String stmt = "select count(distinct code) " + "from ENG_9394 " + "where dt1 <= current_timestamp " + "and dt2 >= current_timestamp " + "and acode < '999'";
    vt = client.callProcedure("@AdHoc", stmt).getResults()[0];
    vt.advanceRow();
    long countDistinct = vt.getLong(0);
    stmt = "select count(*) " + "from (" + "  select distinct code " + "  from ENG_9394 " + "  where dt1 <= current_timestamp " + "  and dt2 >= current_timestamp " + "  and acode < '999') as subq";
    vt = client.callProcedure("@AdHoc", stmt).getResults()[0];
    vt.advanceRow();
    long countStarSubquery = vt.getLong(0);
    assertEquals(countStarSubquery, countDistinct);
}
Also used : TimestampType(org.voltdb.types.TimestampType) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable)

Example 74 with TimestampType

use of org.voltdb.types.TimestampType in project voltdb by VoltDB.

the class TestVoltBulkLoader method testOpenQuote.

public void testOpenQuote() throws Exception {
    String mySchema = "create table BLAH (" + // column that is partitioned on
    "clm_integer integer default 0 not null, " + "clm_integer1 integer default 0, " + "clm_bigint bigint default 0, " + "clm_string varchar(200) default null, " + "clm_timestamp timestamp default null, " + "clm_geo geography default null," + "clm_geopt geography_point default null " + "); ";
    int myBatchSize = 200;
    TimestampType timeParam = new TimestampType("7777-12-25 14:35:26");
    Object[][] myData = { { 1, 1, 1, "\"Jesus\\\"\"loves" + "\n" + "you\"", timeParam, geo, geopt } };
    Integer[] failures = {};
    ArrayList<Integer> expectedFailures = new ArrayList<Integer>(Arrays.asList(failures));
    test_Interface(mySchema, myData, myBatchSize, expectedFailures, 0);
}
Also used : ArrayList(java.util.ArrayList) TimestampType(org.voltdb.types.TimestampType)

Example 75 with TimestampType

use of org.voltdb.types.TimestampType in project voltdb by VoltDB.

the class TestVoltBulkLoader method testBatchOptionThatSplitsAndGetsViolationsAndDataIsSmallInLastBatchFlush.

//Test batch option that splits and gets constraint violations.
public void testBatchOptionThatSplitsAndGetsViolationsAndDataIsSmallInLastBatchFlush() throws Exception {
    String mySchema = "create table BLAH (" + "clm_integer integer not null, " + // column that is partitioned on
    "clm_tinyint tinyint default 0, " + "clm_smallint smallint default 0, " + "clm_bigint bigint default 0, " + "clm_string varchar(20) default null, " + "clm_decimal decimal default null, " + "clm_float float default null, " + "clm_timestamp timestamp default null, " + "clm_geo geography default null," + "clm_geopt geography_point default null, " + "PRIMARY KEY(clm_integer) " + "); ";
    int myBatchSize = 2;
    TimestampType currentTime = new TimestampType();
    Object[][] myData = { { 1, 1, 1, 11111111, "first", 1.10, 1.11, currentTime, geo, geopt }, { 2, 1, 1, 11111111, "first", 1.10, 1.11, currentTime, geo, geopt }, { 2, 1, 1, 11111111, "first", 1.10, 1.11, currentTime, geo, geopt } };
    Integer[] failures = { 3 };
    ArrayList<Integer> expectedFailures = new ArrayList<Integer>(Arrays.asList(failures));
    test_Interface(mySchema, myData, myBatchSize, expectedFailures, 2);
}
Also used : ArrayList(java.util.ArrayList) TimestampType(org.voltdb.types.TimestampType)

Aggregations

TimestampType (org.voltdb.types.TimestampType)127 VoltTable (org.voltdb.VoltTable)37 BigDecimal (java.math.BigDecimal)30 Test (org.junit.Test)23 Client (org.voltdb.client.Client)19 ArrayList (java.util.ArrayList)16 IOException (java.io.IOException)11 GeographyValue (org.voltdb.types.GeographyValue)11 GeographyPointValue (org.voltdb.types.GeographyPointValue)10 Date (java.util.Date)9 File (java.io.File)7 VoltTableRow (org.voltdb.VoltTableRow)7 ProcCallException (org.voltdb.client.ProcCallException)7 ByteBuffer (java.nio.ByteBuffer)5 SimpleDateFormat (java.text.SimpleDateFormat)5 ColumnInfo (org.voltdb.VoltTable.ColumnInfo)5 ClientResponse (org.voltdb.client.ClientResponse)5 Random (java.util.Random)4 VoltType (org.voltdb.VoltType)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2