use of org.voltdb.VoltTableRow in project voltdb by VoltDB.
the class EndCall method run.
/**
* Procedure main logic.
*
* @param uuid Column value for tuple insertion and partitioning key for this procedure.
* @param val Column value for tuple insertion.
* @param update_ts Column value for tuple insertion.
* @param maxTotalRows The desired number of rows per partition.
* @param targetMaxRowsToDelete The upper limit on the number of rows to delete per transaction.
* @return The number of deleted rows.
* @throws VoltAbortException on bad input.
*/
public long run(int agent_id, String phone_no, long call_id, TimestampType end_ts) {
voltQueueSQL(findOpenCall, EXPECT_ZERO_OR_ONE_ROW, call_id, agent_id, phone_no);
voltQueueSQL(findCompletedCall, EXPECT_ZERO_OR_ONE_ROW, call_id, agent_id, phone_no);
VoltTable[] results = voltExecuteSQL();
boolean completedCall = results[1].getRowCount() > 0;
if (completedCall) {
return -1;
}
VoltTable openRowTable = results[0];
if (openRowTable.getRowCount() > 0) {
VoltTableRow existingCall = openRowTable.fetchRow(0);
// check if this is the second begin we've seen for this open call
existingCall.getTimestampAsTimestamp("end_ts");
if (existingCall.wasNull() == false) {
return -1;
}
// check if this completes the call
TimestampType start_ts = existingCall.getTimestampAsTimestamp("start_ts");
if (existingCall.wasNull() == false) {
int durationms = (int) ((end_ts.getTime() - start_ts.getTime()) / 1000);
// update per-day running stddev calculation
computeRunningStdDev(agent_id, end_ts, durationms);
// completes the call
voltQueueSQL(deleteOpenCall, EXPECT_SCALAR_MATCH(1), call_id, agent_id, phone_no);
voltQueueSQL(insertCompletedCall, EXPECT_SCALAR_MATCH(1), call_id, agent_id, phone_no, start_ts, end_ts, durationms);
voltExecuteSQL(true);
return 0;
}
}
voltQueueSQL(upsertOpenCall, EXPECT_SCALAR_MATCH(1), call_id, agent_id, phone_no, end_ts);
voltExecuteSQL(true);
return 0;
}
use of org.voltdb.VoltTableRow in project voltdb by VoltDB.
the class TestSQLFeaturesSuite method testUpdates.
public void testUpdates() throws Exception {
Client client = getClient();
client.callProcedure("ORDER_LINE.insert", (byte) 1, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1.5, "poo");
client.callProcedure("UpdateTests", (byte) 1);
VoltTable[] results = client.callProcedure("FeaturesSelectAll").getResults();
assertEquals(5, results.length);
// get the order line table
VoltTable table = results[2];
assertEquals(table.getColumnName(0), "OL_O_ID");
assertTrue(table.getRowCount() == 1);
VoltTableRow row = table.fetchRow(0);
assertEquals(row.getLong("OL_O_ID"), 1);
assertEquals(row.getLong("OL_D_ID"), 6);
assertEquals(row.getLong("OL_W_ID"), 1);
assertEquals(row.getLong("OL_QUANTITY"), 1);
assertEquals(row.getLong("OL_SUPPLY_W_ID"), 5);
assertTrue(true);
}
use of org.voltdb.VoltTableRow in project voltdb by VoltDB.
the class TestSQLFeaturesSuite method testLongStringUsage.
public void testLongStringUsage() throws IOException {
final int STRLEN = 5000;
Client client = getClient();
String longStringPart = "volt!";
StringBuilder sb = new StringBuilder();
while (sb.length() < STRLEN) sb.append(longStringPart);
String longString = sb.toString();
assertEquals(STRLEN, longString.length());
VoltTable[] results = null;
try {
results = client.callProcedure("WorkWithBigString", 1, longString).getResults();
} catch (ProcCallException e) {
e.printStackTrace();
fail();
}
assertEquals(1, results.length);
VoltTableRow row = results[0].fetchRow(0);
assertEquals(1, row.getLong(0));
assertEquals(0, row.getString(2).compareTo(longString));
}
use of org.voltdb.VoltTableRow in project voltdb by VoltDB.
the class TestSQLFeaturesSuite method testPassAllArgTypes.
public void testPassAllArgTypes() throws IOException {
byte b = 100;
byte[] bArray = new byte[] { 100, 101, 102 };
short s = 32000;
short[] sArray = new short[] { 32000, 32001, 32002 };
int i = 2147483640;
int[] iArray = new int[] { 2147483640, 2147483641, 2147483642 };
long l = Long.MAX_VALUE - 10;
long[] lArray = new long[] { Long.MAX_VALUE - 10, Long.MAX_VALUE - 9, Long.MAX_VALUE - 8 };
String str = "foo";
byte[] bString = "bar".getBytes("UTF-8");
TimestampType tst = new TimestampType(PassAllArgTypes.MILLISECONDS_SINCE_EPOCH_TEST_VALUE * 1000);
java.util.Date utild = new java.util.Date(PassAllArgTypes.MILLISECONDS_SINCE_EPOCH_TEST_VALUE);
java.sql.Date sqld = new java.sql.Date(PassAllArgTypes.MILLISECONDS_SINCE_EPOCH_TEST_VALUE);
java.sql.Timestamp ts = new java.sql.Timestamp(PassAllArgTypes.MILLISECONDS_SINCE_EPOCH_TEST_VALUE);
Client client = getClient();
try {
ClientResponse cr = client.callProcedure("PassAllArgTypes", b, bArray, s, sArray, i, iArray, l, lArray, str, bString, tst, utild, sqld, ts);
assert (cr.getStatus() == ClientResponse.SUCCESS);
VoltTable[] result = cr.getResults();
assert (result.length == 4);
VoltTable vt = result[0];
assert (vt.getRowCount() == 1);
VoltTableRow row = vt.fetchRow(0);
assertEquals(row.getLong("b"), b);
byte[] gotArray = row.getVarbinary("bArray");
assertEquals(gotArray.length, bArray.length);
for (int j = 0; j < gotArray.length; j++) {
assertEquals(gotArray[j], bArray[j]);
}
assertEquals(gotArray.length, bArray.length);
assertEquals(row.getLong("s"), s);
assertEquals(row.getLong("i"), i);
assertEquals(row.getLong("l"), l);
assertEquals(row.getString("str"), str);
byte[] gotString = row.getVarbinary("bString");
assertEquals(gotString.length, bString.length);
for (int j = 0; j < gotString.length; j++) {
assertEquals(gotString[j], bString[j]);
}
String tsColName;
int tsColIndex;
tsColName = "tst";
assertEquals(row.getTimestampAsLong(tsColName), tst.getTime());
assertEquals(row.getTimestampAsTimestamp(tsColName), tst);
assertEquals(row.getTimestampAsSqlTimestamp(tsColName), ts);
assertEquals(row.getTimestampAsSqlTimestamp(tsColName).getTime(), sqld.getTime());
assertEquals(row.getTimestampAsSqlTimestamp(tsColName).getTime(), utild.getTime());
tsColIndex = vt.getColumnIndex(tsColName);
assertEquals(row.getTimestampAsLong(tsColIndex), tst.getTime());
assertEquals(row.getTimestampAsTimestamp(tsColIndex), tst);
assertEquals(row.getTimestampAsSqlTimestamp(tsColIndex), ts);
assertEquals(row.getTimestampAsSqlTimestamp(tsColIndex).getTime(), sqld.getTime());
assertEquals(row.getTimestampAsSqlTimestamp(tsColIndex).getTime(), utild.getTime());
tsColName = "sqld";
assertEquals(row.getTimestampAsLong(tsColName), tst.getTime());
assertEquals(row.getTimestampAsTimestamp(tsColName), tst);
assertEquals(row.getTimestampAsSqlTimestamp(tsColName), ts);
assertEquals(row.getTimestampAsSqlTimestamp(tsColName).getTime(), sqld.getTime());
assertEquals(row.getTimestampAsSqlTimestamp(tsColName).getTime(), utild.getTime());
tsColIndex = vt.getColumnIndex(tsColName);
assertEquals(row.getTimestampAsLong(tsColIndex), tst.getTime());
assertEquals(row.getTimestampAsTimestamp(tsColIndex), tst);
assertEquals(row.getTimestampAsSqlTimestamp(tsColIndex), ts);
assertEquals(row.getTimestampAsSqlTimestamp(tsColIndex).getTime(), sqld.getTime());
assertEquals(row.getTimestampAsSqlTimestamp(tsColIndex).getTime(), utild.getTime());
tsColName = "utild";
assertEquals(row.getTimestampAsLong(tsColName), tst.getTime());
assertEquals(row.getTimestampAsTimestamp(tsColName), tst);
assertEquals(row.getTimestampAsSqlTimestamp(tsColName), ts);
assertEquals(row.getTimestampAsSqlTimestamp(tsColName).getTime(), sqld.getTime());
assertEquals(row.getTimestampAsSqlTimestamp(tsColName).getTime(), utild.getTime());
tsColIndex = vt.getColumnIndex(tsColName);
assertEquals(row.getTimestampAsLong(tsColIndex), tst.getTime());
assertEquals(row.getTimestampAsTimestamp(tsColIndex), tst);
assertEquals(row.getTimestampAsSqlTimestamp(tsColIndex), ts);
assertEquals(row.getTimestampAsSqlTimestamp(tsColIndex).getTime(), sqld.getTime());
assertEquals(row.getTimestampAsSqlTimestamp(tsColIndex).getTime(), utild.getTime());
tsColName = "ts";
assertEquals(row.getTimestampAsLong(tsColName), tst.getTime());
assertEquals(row.getTimestampAsTimestamp(tsColName), tst);
assertEquals(row.getTimestampAsSqlTimestamp(tsColName), ts);
assertEquals(row.getTimestampAsSqlTimestamp(tsColName).getTime(), sqld.getTime());
assertEquals(row.getTimestampAsSqlTimestamp(tsColName).getTime(), utild.getTime());
tsColIndex = vt.getColumnIndex(tsColName);
assertEquals(row.getTimestampAsLong(tsColIndex), tst.getTime());
assertEquals(row.getTimestampAsTimestamp(tsColIndex), tst);
assertEquals(row.getTimestampAsSqlTimestamp(tsColIndex), ts);
assertEquals(row.getTimestampAsSqlTimestamp(tsColIndex).getTime(), sqld.getTime());
assertEquals(row.getTimestampAsSqlTimestamp(tsColIndex).getTime(), utild.getTime());
vt = result[1];
assert (vt.getRowCount() == sArray.length);
for (int j = 0; j < sArray.length; j++) {
assertEquals(vt.fetchRow(j).getLong("sArray"), sArray[j]);
}
vt = result[2];
assert (vt.getRowCount() == iArray.length);
for (int j = 0; j < iArray.length; j++) {
assertEquals(vt.fetchRow(j).getLong("iArray"), iArray[j]);
}
vt = result[3];
assert (vt.getRowCount() == lArray.length);
for (int j = 0; j < lArray.length; j++) {
assertEquals(vt.fetchRow(j).getLong("lArray"), lArray[j]);
}
} catch (Exception e) {
fail("An argument value was mishandled in PassAllArgTypes");
}
// Now, go overboard, trying to preserve nano accuracy.
// XXX: The following test is a little controversial.
// Some would prefer a gentler response -- just truncating/rounding to the nearest microsecond.
// When these voices of reason prevail, this test should be replaced by a test that nano-noise
// gets filtered out but the result is still correct to microsecond granularity.
java.sql.Timestamp ts_nano = new java.sql.Timestamp(PassAllArgTypes.MILLISECONDS_SINCE_EPOCH_TEST_VALUE);
assertEquals(ts, ts_nano);
// Extract the 1000000 nanos (doubly-counted milliseconds)
assertEquals(1000000, ts_nano.getNanos());
// and explicitly add in 1001 nanos (1 microsecond + 1 nanosecond)
ts_nano.setNanos(ts_nano.getNanos() + 1001);
boolean caught;
try {
caught = false;
// system-defined CRUD inputs
client.callProcedure("PassAllArgTypes", b, bArray, s, sArray, i, iArray, l, lArray, str, bString, ts_nano, /* Here's the problem! */
utild, sqld, ts);
} catch (RuntimeException e) {
caught = true;
} catch (Exception e) {
// but not quite how it was expected to be.
caught = true;
fail("Some other exception while testing nano noise in PassAllArgTypes" + e);
}
assert (caught);
}
use of org.voltdb.VoltTableRow in project voltdb by VoltDB.
the class TestSQLTypesSuite method testUpdateDecimalWithPVE.
public void testUpdateDecimalWithPVE() throws NoConnectionsException, ProcCallException, IOException {
// insert a couple of rows.
final Client client = this.getClient();
final Object[] params = new Object[COLS + 2];
params[0] = "ALLOW_NULLS";
params[1] = 0;
for (int i = 0; i < COLS; i++) {
params[i + 2] = m_midValues[i];
}
client.callProcedure("Insert", params);
// insert one row with the max values
params[0] = "ALLOW_NULLS";
params[1] = 1;
for (int i = 0; i < COLS; i++) {
params[i + 2] = m_maxValues[i];
}
client.callProcedure("Insert", params);
// update the mid value to the minimum decimal value
VoltTable[] result = client.callProcedure("UpdateDecimal", m_minValues[12], m_midValues[12]).getResults();
// select that same row again by primary key
result = client.callProcedure("Select", "ALLOW_NULLS", 0).getResults();
// and verify the row
final VoltTableRow row = result[0].fetchRow(0);
final BigDecimal bd = (row.getDecimalAsBigDecimal(13));
assertTrue(comparisonHelper(m_minValues[12], bd, m_types[12]));
}
Aggregations