use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class TestVoltTableUtil method testCSVTimestamp.
/**
* Round-trip the time, see if it's still the same.
* @throws IOException
*/
@Test
public void testCSVTimestamp() throws IOException {
CSVWriter writer = mock(CSVWriter.class);
ColumnInfo[] columns = new ColumnInfo[] { new ColumnInfo("", VoltType.TIMESTAMP) };
ArrayList<VoltType> columnTypes = new ArrayList<VoltType>();
// To make sure we have microseconds we get millisecond from current timestamp
// and add remainder to ensure we have micros in timestamp.
TimestampType ts = new TimestampType((System.currentTimeMillis() * 1000) + System.currentTimeMillis() % 1000);
VoltTable vt = new VoltTable(columns);
vt.addRow(ts);
for (ColumnInfo ci : columns) {
columnTypes.add(ci.type);
}
VoltTableUtil.toCSVWriter(writer, vt, columnTypes);
ArgumentCaptor<String[]> captor = ArgumentCaptor.forClass(String[].class);
verify(writer).writeNext(captor.capture());
String[] values = captor.getValue();
assertEquals(1, values.length);
TimestampType newTs = new TimestampType(values[0]);
assertEquals(ts, newTs);
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class TestVoltType method testTimestampToString.
public void testTimestampToString() {
// to try to avoid the false negative.
for (int ii = 0; ii < 5; ++ii) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
TimestampType now = new TimestampType();
Date date = new Date();
if (now.toString().startsWith(sdf.format(date))) {
assertTrue(now.toString().startsWith(sdf.format(date)));
return;
}
}
fail();
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class TestVoltType method testTimestampCreation.
/* round trip the constructors */
public void testTimestampCreation() {
long usec = 999999999;
TimestampType ts1 = new TimestampType(usec);
assertEquals(usec, ts1.getTime());
String ts1string = ts1.toString();
TimestampType ts1prime = new TimestampType(ts1string);
assertEquals(usec, ts1prime.getTime());
usec = 999999000;
ts1 = new TimestampType(usec);
assertEquals(usec, ts1.getTime());
// the 0 at the start of microseconds is important
// for round-trip string/string correctness test
String date = "2011-06-24 10:30:26.123012";
TimestampType ts3 = new TimestampType(date);
assertEquals(date, ts3.toString());
boolean caught = false;
caught = false;
try {
// Date string inputs interpreted as Dates should not have sub-millisecond granularity.
// This is the utility function that does this validation.
TimestampType.millisFromJDBCformat(date);
} catch (IllegalArgumentException ex) {
caught = true;
}
assertTrue(caught);
caught = false;
try {
// Date string inputs interpreted as TimestampType should not have sub-microsecond granularity.
String nanoNoNos = "2011-06-24 10:30:26.123012001";
new TimestampType(nanoNoNos);
} catch (IllegalArgumentException ex) {
caught = true;
}
assertTrue(caught);
// Test timestamp before epoch
usec = -923299922232L;
ts1 = new TimestampType(usec);
assertEquals(usec, ts1.getTime());
ts1string = ts1.toString();
ts1prime = new TimestampType(ts1string);
assertEquals(usec, ts1prime.getTime());
date = "1966-06-24 10:30:26.123012";
ts3 = new TimestampType(date);
assertEquals(date, ts3.toString());
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class paymentByCustomerNameC method processPayment.
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 };
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class paymentByCustomerId method processPayment.
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) {
voltQueueSQL(getWarehouse, w_id);
voltQueueSQL(getDistrict, w_id, d_id);
final VoltTable[] results = voltExecuteSQL();
final VoltTable warehouse = results[0];
final VoltTable district = results[1];
voltQueueSQL(updateWarehouseBalance, h_amount, w_id);
voltQueueSQL(updateDistrictBalance, h_amount, w_id, d_id);
voltExecuteSQL();
//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) - 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);
}
// 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, c_d_id, c_w_id, d_id, w_id, timestamp, h_amount, 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(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);
// Hand back all the warehouse, district, and customer data
return new VoltTable[] { warehouse, district, misc };
}
Aggregations