use of org.voltdb.types.TimestampType 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;
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class TestFixedSQLSuite method subTestENG7041ViewAndExportTable.
private void subTestENG7041ViewAndExportTable() throws Exception {
Client client = getClient();
// Materialized view wasn't being updated, because the
// connection with its source table wasn't getting created
// when there was a (completely unrelated) export table in the
// database.
//
// When loading the catalog in the EE, we were erroneously
// aborting view processing when encountering an export table.
client.callProcedure("TRANSACTION.insert", 1, 99, 100.0, "NH", "Manchester", new TimestampType(), 20);
validateTableOfLongs(client, "select count(*) from transaction", new long[][] { { 1 } });
// The buggy behavior would show zero rows in the view.
validateTableOfLongs(client, "select count(*) from acct_vendor_totals", new long[][] { { 1 } });
truncateTable(client, "TRANSACTION");
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class TestRollbackSuite method allTypesTestHelper.
// ENG-487
/**
* Test whether the transactions are correctly rolled back
* given a sequence of CRUD operations. The input is the name
* of a stored procedure, a sequence of integers denoting
* operations and an integer id. The stored procedure will
* execute the operations in order, then abort with some
* kind of an error. After the stored procedure's execution
* has completed, we verify that the database contents have
* not changed, and that the rollback was successful.
*
* @param procName The name of the stored procedure.
* @param order The sequence of names of operations.
* @param id An integer id.
* @throws IOException
*/
public void allTypesTestHelper(String procName, int[] order, int id) throws IOException {
Client client = getClient();
final double EPSILON = 0.00001;
final BigDecimal moneyOne = new BigDecimal(BigInteger.valueOf(7700000000000L), 12);
final BigDecimal moneyTwo = new BigDecimal(BigInteger.valueOf(1100000000000L), 12);
try {
client.callProcedure("InsertAllTypes", 1, 2, 3, 4, new TimestampType(5), 0.6, moneyOne, "inlined", "uninlined");
client.callProcedure("InsertAllTypes", 7, 6, 5, 4, new TimestampType(3), 0.2, moneyTwo, "INLINED", "UNINLINED");
} catch (ProcCallException e1) {
e1.printStackTrace();
fail();
}
try {
if (procName.contains("MultiOps"))
client.callProcedure("AllTypesMultiOpsJavaError", order, id);
else if (procName.contains("Update"))
client.callProcedure(procName, 7);
else
client.callProcedure(procName);
fail();
} catch (ProcCallException e) {
} catch (IOException e) {
e.printStackTrace();
fail();
}
try {
VoltTable[] results = client.callProcedure("@AdHoc", "SELECT * FROM ALL_TYPES ORDER BY ID ASC;").getResults();
// get the table
VoltTable table = results[0];
assertTrue(table.getRowCount() == 2);
table.advanceRow();
assertEquals(1, table.getLong(0));
assertEquals(2, table.getLong(1));
assertEquals(3, table.getLong(2));
assertEquals(4, table.getLong(3));
assertEquals(new TimestampType(5), table.getTimestampAsTimestamp(4));
assertTrue(Math.abs(0.6 - table.getDouble(5)) < EPSILON);
assertEquals(moneyOne, table.getDecimalAsBigDecimal(6));
assertTrue(table.getString(7).equals("inlined"));
assertTrue(table.getString(8).equals("uninlined"));
table.advanceRow();
assertEquals(7, table.getLong(0));
assertEquals(6, table.getLong(1));
assertEquals(5, table.getLong(2));
assertEquals(4, table.getLong(3));
assertEquals(new TimestampType(3), table.getTimestampAsTimestamp(4));
assertTrue(Math.abs(0.2 - table.getDouble(5)) < EPSILON);
assertEquals(moneyTwo, table.getDecimalAsBigDecimal(6));
assertTrue(table.getString(7).equals("INLINED"));
assertTrue(table.getString(8).equals("UNINLINED"));
// Check by using the indexes
results = client.callProcedure("@AdHoc", "SELECT * FROM ALL_TYPES WHERE ID > 3;").getResults();
// get the table
table = results[0];
assertTrue(table.getRowCount() == 1);
table.advanceRow();
assertEquals(7, table.getLong(0));
assertEquals(6, table.getLong(1));
assertEquals(5, table.getLong(2));
assertEquals(4, table.getLong(3));
assertEquals(new TimestampType(3), table.getTimestampAsTimestamp(4));
assertTrue(Math.abs(0.2 - table.getDouble(5)) < EPSILON);
assertEquals(moneyTwo, table.getDecimalAsBigDecimal(6));
assertTrue(table.getString(7).equals("INLINED"));
assertTrue(table.getString(8).equals("UNINLINED"));
// unique hash index
results = client.callProcedure("@AdHoc", "SELECT * FROM ALL_TYPES WHERE ID = 1;").getResults();
// get the table
table = results[0];
assertTrue(table.getRowCount() == 1);
table.advanceRow();
assertEquals(1, table.getLong(0));
assertEquals(2, table.getLong(1));
assertEquals(3, table.getLong(2));
assertEquals(4, table.getLong(3));
assertEquals(new TimestampType(5), table.getTimestampAsTimestamp(4));
assertTrue(Math.abs(0.6 - table.getDouble(5)) < EPSILON);
assertEquals(moneyOne, table.getDecimalAsBigDecimal(6));
assertTrue(table.getString(7).equals("inlined"));
assertTrue(table.getString(8).equals("uninlined"));
// multimap tree index
results = client.callProcedure("@AdHoc", "SELECT * FROM ALL_TYPES ORDER BY TINY, SMALL, BIG, T, RATIO, MONEY, INLINED DESC;").getResults();
// get the table
table = results[0];
assertTrue(table.getRowCount() == 2);
table.advanceRow();
assertEquals(1, table.getLong(0));
assertEquals(2, table.getLong(1));
assertEquals(3, table.getLong(2));
assertEquals(4, table.getLong(3));
assertEquals(new TimestampType(5), table.getTimestampAsTimestamp(4));
assertTrue(Math.abs(0.6 - table.getDouble(5)) < EPSILON);
assertEquals(moneyOne, table.getDecimalAsBigDecimal(6));
assertTrue(table.getString(7).equals("inlined"));
assertTrue(table.getString(8).equals("uninlined"));
table.advanceRow();
assertEquals(7, table.getLong(0));
assertEquals(6, table.getLong(1));
assertEquals(5, table.getLong(2));
assertEquals(4, table.getLong(3));
assertEquals(new TimestampType(3), table.getTimestampAsTimestamp(4));
assertTrue(Math.abs(0.2 - table.getDouble(5)) < EPSILON);
assertEquals(moneyTwo, table.getDecimalAsBigDecimal(6));
assertTrue(table.getString(7).equals("INLINED"));
assertTrue(table.getString(8).equals("UNINLINED"));
// multimap hash index
results = client.callProcedure("@AdHoc", "SELECT * FROM ALL_TYPES WHERE TINY = 6 AND SMALL = 5 AND BIG = 4;").getResults();
// get the table
table = results[0];
assertTrue(table.getRowCount() == 1);
table.advanceRow();
assertEquals(7, table.getLong(0));
assertEquals(6, table.getLong(1));
assertEquals(5, table.getLong(2));
assertEquals(4, table.getLong(3));
assertEquals(new TimestampType(3), table.getTimestampAsTimestamp(4));
assertTrue(Math.abs(0.2 - table.getDouble(5)) < EPSILON);
assertEquals(moneyTwo, table.getDecimalAsBigDecimal(6));
assertTrue(table.getString(7).equals("INLINED"));
assertTrue(table.getString(8).equals("UNINLINED"));
// clean up
client.callProcedure("@AdHoc", "DELETE FROM ALL_TYPES");
} catch (ProcCallException e) {
e.printStackTrace();
fail();
} catch (IOException e) {
e.printStackTrace();
fail();
}
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class MetroBenchmark method generateCard.
public void generateCard() throws Exception {
// default card (pay per fare)
int enabled = 1;
int card_type = 0;
int balance = balances[rand.nextInt(balances.length)];
String preName = "T Ryder ";
String phone = "6174567890";
String email = "tryder@gmail.com";
int notify = randomizeNotify();
TimestampType expires = null;
// disable 1/10000 cards
if (rand.nextInt(10000) == 0)
enabled = 0;
// make 1/3 cards unlimited (weekly or monthly pass)
if (rand.nextInt(3) == 0) {
card_type = 1;
balance = 0;
// expired last night at midnight, or any of the next 30 days
Calendar cal2 = (Calendar) cal.clone();
cal2.add(Calendar.DATE, rand.nextInt(30));
expires = new TimestampType(cal2.getTime());
}
client.callProcedure(new BenchmarkCallback("CARDS.upsert"), "CARDS.upsert", ++cardCount, enabled, card_type, balance, expires, // create synthetic numeric person
preName + cardCount, phone, email, notify);
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class CardSwipe method run.
public VoltTable run(int cardId, int stationId) throws VoltAbortException {
// check station fare, card status, get card owner's particulars
voltQueueSQL(checkCard, EXPECT_ZERO_OR_ONE_ROW, cardId);
voltQueueSQL(checkStationFare, EXPECT_ONE_ROW, stationId);
VoltTable[] checks = voltExecuteSQL();
VoltTable cardInfo = checks[0];
VoltTable stationInfo = checks[1];
// check that card exists
if (cardInfo.getRowCount() == 0) {
return buildResult(0, "Card Invalid");
}
// card exists, so advanceRow to read the record
cardInfo.advanceRow();
int enabled = (int) cardInfo.getLong(0);
int cardType = (int) cardInfo.getLong(1);
int balance = (int) cardInfo.getLong(2);
TimestampType expires = cardInfo.getTimestampAsTimestamp(3);
String owner = cardInfo.getString(4);
String phone = cardInfo.getString(5);
String email = cardInfo.getString(6);
int notify = (int) cardInfo.getLong(7);
// read station fare
stationInfo.advanceRow();
int fare = (int) stationInfo.getLong(0);
String stationName = stationInfo.getString(1);
// if card is disabled
if (enabled == 0) {
return buildResult(0, "Card Disabled");
}
// check balance or expiration for valid cards
if (cardType == 0) {
// pay per ride
if (balance > fare) {
// charge the fare
voltQueueSQL(chargeCard, balance - fare, cardId);
voltQueueSQL(insertActivity, cardId, getTransactionTime(), stationId, 1, fare);
voltExecuteSQL(true);
return buildResult(1, "Remaining Balance: " + intToCurrency(balance - fare));
} else {
// insufficient balance
voltQueueSQL(insertActivity, cardId, getTransactionTime(), stationId, 0, 0);
if (notify != 0) {
// only export if notify is 1 or 2 -- email or text
voltQueueSQL(exportActivity, cardId, getTransactionTime().getTime(), stationName, owner, phone, email, notify, "Insufficient Balance");
}
voltExecuteSQL(true);
return buildResult(0, "Card has insufficient balance: " + intToCurrency(balance));
}
} else {
// unlimited card (e.g. monthly or weekly pass)
if (expires.compareTo(new TimestampType(getTransactionTime())) > 0) {
voltQueueSQL(insertActivity, cardId, getTransactionTime(), stationId, 1, 0);
voltExecuteSQL(true);
return buildResult(1, "Card Expires: " + expires.toString());
} else {
voltQueueSQL(insertActivity, cardId, getTransactionTime(), stationId, 0, 0);
voltExecuteSQL(true);
return buildResult(0, "Card Expired");
}
}
}
Aggregations