use of org.voltdb.client.ProcCallException in project voltdb by VoltDB.
the class TestFixedSQLSuite method subTestInsertNullPartitionString.
private void subTestInsertNullPartitionString() throws IOException, ProcCallException {
// This test is for issue ENG-697
Client client = getClient();
boolean caught = false;
try {
client.callProcedure("InsertNullString", null, 0, 1);
} catch (final ProcCallException e) {
if (e.getMessage().contains("CONSTRAINT VIOLATION"))
caught = true;
else {
e.printStackTrace();
fail();
}
}
assertTrue(caught);
}
use of org.voltdb.client.ProcCallException in project voltdb by VoltDB.
the class TestFixedSQLSuite method subTestTicketEng397.
private void subTestTicketEng397() throws IOException, ProcCallException {
Client client = getClient();
for (int i = 0; i < 20; i++) {
client.callProcedure("Insert", "P1", i, "desc", 100 + i, 4.5);
}
// base case
VoltTable[] results = client.callProcedure("Eng397Limit1", new Integer(10)).getResults();
assertEquals(10, results[0].getRowCount());
// negative limit rollsback
boolean caught = false;
try {
results = client.callProcedure("Eng397Limit1", new Integer(-1)).getResults();
} catch (ProcCallException ignored) {
caught = true;
} catch (Exception ex) {
ex.printStackTrace();
}
assertTrue(caught);
truncateTable(client, "P1");
}
use of org.voltdb.client.ProcCallException in project voltdb by VoltDB.
the class TestFunctionsForVoltDBSuite method testTO_TIMESTAMP.
public void testTO_TIMESTAMP() throws NoConnectionsException, IOException, ProcCallException {
System.out.println("STARTING TO_TIMESTAMP");
Client client = getClient();
ClientResponse cr;
VoltTable result;
cr = client.callProcedure("P2.insert", 0, new Timestamp(0L));
cr = client.callProcedure("P2.insert", 1, new Timestamp(1L));
cr = client.callProcedure("P2.insert", 2, new Timestamp(1000L));
cr = client.callProcedure("P2.insert", 3, new Timestamp(-1000L));
// Test AdHoc
cr = client.callProcedure("@AdHoc", "select to_timestamp(second, 1372640523) from P2 limit 1");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals(1372640523 * 1000000L, result.getTimestampAsLong(0));
// Test string input number, expect error
try {
cr = client.callProcedure("@AdHoc", "select to_timestamp(second, '1372640523') from P2 limit 1");
fail();
} catch (Exception ex) {
assertTrue(ex.getMessage().contains("PlanningErrorException"));
assertTrue(ex.getMessage().contains("incompatible data type"));
}
String[] procedures = { "FROM_UNIXTIME", "TO_TIMESTAMP_SECOND", "TO_TIMESTAMP_MILLIS", "TO_TIMESTAMP_MILLISECOND", "TO_TIMESTAMP_MICROS", "TO_TIMESTAMP_MICROSECOND" };
for (int i = 0; i < procedures.length; i++) {
String proc = procedures[i];
cr = client.callProcedure(proc, 0L, 0);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
if (proc == "TO_TIMESTAMP_SECOND" || proc == "FROM_UNIXTIME") {
assertEquals(0L, result.getTimestampAsLong(0));
} else if (proc == "TO_TIMESTAMP_MILLIS" || proc == "TO_TIMESTAMP_MILLISECOND") {
assertEquals(0L, result.getTimestampAsLong(0));
} else if (proc == "TO_TIMESTAMP_MICROS" || proc == "TO_TIMESTAMP_MICROSECOND") {
assertEquals(0L, result.getTimestampAsLong(0));
} else {
fail();
}
cr = client.callProcedure(proc, 1L, 1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
if (proc == "TO_TIMESTAMP_SECOND" || proc == "FROM_UNIXTIME") {
assertEquals(1000000L, result.getTimestampAsLong(0));
} else if (proc == "TO_TIMESTAMP_MILLIS" || proc == "TO_TIMESTAMP_MILLISECOND") {
assertEquals(1000L, result.getTimestampAsLong(0));
} else if (proc == "TO_TIMESTAMP_MICROS" || proc == "TO_TIMESTAMP_MICROSECOND") {
assertEquals(1L, result.getTimestampAsLong(0));
} else {
fail();
}
cr = client.callProcedure(proc, 1000L, 1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
if (proc == "TO_TIMESTAMP_SECOND" || proc == "FROM_UNIXTIME") {
assertEquals(1000000000L, result.getTimestampAsLong(0));
} else if (proc == "TO_TIMESTAMP_MILLIS" || proc == "TO_TIMESTAMP_MILLISECOND") {
assertEquals(1000000L, result.getTimestampAsLong(0));
} else if (proc == "TO_TIMESTAMP_MICROS" || proc == "TO_TIMESTAMP_MICROSECOND") {
assertEquals(1000L, result.getTimestampAsLong(0));
} else {
fail();
}
cr = client.callProcedure(proc, -1000, 1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
if (proc == "TO_TIMESTAMP_SECOND" || proc == "FROM_UNIXTIME") {
assertEquals(-1000000000L, result.getTimestampAsLong(0));
} else if (proc == "TO_TIMESTAMP_MILLIS" || proc == "TO_TIMESTAMP_MILLISECOND") {
assertEquals(-1000000L, result.getTimestampAsLong(0));
} else if (proc == "TO_TIMESTAMP_MICROS" || proc == "TO_TIMESTAMP_MICROSECOND") {
assertEquals(-1000L, result.getTimestampAsLong(0));
} else {
fail();
}
final long maxSec = GREGORIAN_EPOCH / 1000000;
cr = client.callProcedure(proc, maxSec, 1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
if (proc == "TO_TIMESTAMP_SECOND" || proc == "FROM_UNIXTIME") {
assertEquals(maxSec * 1000000, result.getTimestampAsLong(0));
} else if (proc == "TO_TIMESTAMP_MILLIS" || proc == "TO_TIMESTAMP_MILLISECOND") {
assertEquals(maxSec * 1000, result.getTimestampAsLong(0));
} else if (proc == "TO_TIMESTAMP_MICROS" || proc == "TO_TIMESTAMP_MICROSECOND") {
assertEquals(maxSec, result.getTimestampAsLong(0));
} else {
fail();
}
}
}
use of org.voltdb.client.ProcCallException in project voltdb by VoltDB.
the class TestFunctionsForVoltDBSuite method testDateadd.
public void testDateadd() throws NoConnectionsException, IOException, ProcCallException {
System.out.println("STARTING test DATEADD function tests");
/*
* "CREATE TABLE P2 ( " +
"ID INTEGER DEFAULT '0' NOT NULL, " +
"TM TIMESTAMP DEFAULT NULL, " +
"PRIMARY KEY (ID) ); " +
"PARTITION TABLE P2 ON COLUMN ID;\n" +
*/
Client client = getClient();
ClientResponse cr = null;
VoltTable vt = null;
cr = client.callProcedure("@AdHoc", "INSERT INTO P2 (ID, TM) VALUES (10000, '2000-01-01 01:00:00.000000');");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(year, 1, TM) FROM P2 WHERE ID = 10000").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2001-01-01 01:00:00.000000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(quarter, 1, TM) FROM P2 WHERE ID = 10000").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2000-04-01 01:00:00.000000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(month, 1, TM) FROM P2 WHERE ID = 10000").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2000-02-01 01:00:00.000000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(day, 1, TM) FROM P2 WHERE ID = 10000").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(vt.getTimestampAsSqlTimestamp(0), Timestamp.valueOf("2000-01-02 01:00:00.000000"));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(hour, 1, TM) FROM P2 WHERE ID = 10000").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2000-01-01 02:00:00.000000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(minute, 1, TM) FROM P2 WHERE ID = 10000").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2000-01-01 01:01:00.000000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(second, 1, TM) FROM P2 WHERE ID = 10000").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2000-01-01 01:00:01.000000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(millisecond, 1, TM) FROM P2 WHERE ID = 10000").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2000-01-01 01:00:00.001000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(millis, 1, TM) FROM P2 WHERE ID = 10000").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2000-01-01 01:00:00.001000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(microsecond, 1, TM) FROM P2 WHERE ID = 10000").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2000-01-01 01:00:00.000001"), vt.getTimestampAsSqlTimestamp(0));
cr = client.callProcedure("@AdHoc", "INSERT INTO P2 (ID, TM) VALUES (20000, '2007-01-01 13:10:10.111111');");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(millisecond, 1, TM) FROM P2 WHERE ID = 20000").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2007-01-01 13:10:10.112111"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(millisecond, 2, TM) FROM P2 WHERE ID = 20000").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2007-01-01 13:10:10.113111"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(microsecond, 1, TM) FROM P2 WHERE ID = 20000").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2007-01-01 13:10:10.111112"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(microsecond, 2, TM) FROM P2 WHERE ID = 20000").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2007-01-01 13:10:10.111113"), vt.getTimestampAsSqlTimestamp(0));
cr = client.callProcedure("@AdHoc", "INSERT INTO P2 (ID, TM) VALUES (20001, '2007-01-01 01:01:01.111111');");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(quarter, 4, TM) FROM P2 WHERE ID = 20001").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2008-01-01 01:01:01.111111"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(month, 13, TM) FROM P2 WHERE ID = 20001").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2008-02-01 01:01:01.111111"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(day, 365, TM) FROM P2 WHERE ID = 20001").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2008-01-01 01:01:01.111111"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(hour, 23, TM) FROM P2 WHERE ID = 20001").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2007-01-02 00:01:01.111111"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(minute, 59, TM) FROM P2 WHERE ID = 20001").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2007-01-01 02:00:01.111111"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(second, 59, TM) FROM P2 WHERE ID = 20001").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2007-01-01 01:02:00.111111"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(millisecond, 59, TM) FROM P2 WHERE ID = 20001").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2007-01-01 01:01:01.170111"), vt.getTimestampAsSqlTimestamp(0));
cr = client.callProcedure("@AdHoc", "INSERT INTO P2 (ID, TM) VALUES (20002, '2000-01-01 00:00:00.000000');");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(year, -1, TM) FROM P2 WHERE ID = 20002").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("1999-01-01 00:00:00.000000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(quarter, -1, TM) FROM P2 WHERE ID = 20002").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("1999-10-01 00:00:00.000000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(month, -1, TM) FROM P2 WHERE ID = 20002").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("1999-12-01 00:00:00.000000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(day, -1, TM) FROM P2 WHERE ID = 20002").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("1999-12-31 00:00:00.000000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(hour, -1, TM) FROM P2 WHERE ID = 20002").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("1999-12-31 23:00:00.000000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(minute, -1, TM) FROM P2 WHERE ID = 20002").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("1999-12-31 23:59:00.000000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(second, -1, TM) FROM P2 WHERE ID = 20002").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("1999-12-31 23:59:59.000000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(millisecond, -1, TM) FROM P2 WHERE ID = 20002").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("1999-12-31 23:59:59.999000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(microsecond, -1, TM) FROM P2 WHERE ID = 20002").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("1999-12-31 23:59:59.999999"), vt.getTimestampAsSqlTimestamp(0));
//leap year test case
cr = client.callProcedure("@AdHoc", "INSERT INTO P2 (ID, TM) VALUES (20003, '2000-02-29 00:00:00.000000');");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(year, 1, TM) FROM P2 WHERE ID = 20003").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2001-02-28 00:00:00.000000"), vt.getTimestampAsSqlTimestamp(0));
cr = client.callProcedure("@AdHoc", "INSERT INTO P2 (ID, TM) VALUES (20004, '2000-01-31 00:00:00.000000');");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(month, 1, TM) FROM P2 WHERE ID = 20004").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2000-02-29 00:00:00.000000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(day, 31, TM) FROM P2 WHERE ID = 20004").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2000-03-02 00:00:00.000000"), vt.getTimestampAsSqlTimestamp(0));
cr = client.callProcedure("@AdHoc", "INSERT INTO P2 (ID, TM) VALUES (20005, '1999-12-31 00:00:00.000000');");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(year, 1, TM) FROM P2 WHERE ID = 20005").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2000-12-31 00:00:00.000000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(quarter, 2, TM) FROM P2 WHERE ID = 20005").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2000-06-30 00:00:00.000000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(month, 2, TM) FROM P2 WHERE ID = 20005").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2000-02-29 00:00:00.000000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(day, 60, TM) FROM P2 WHERE ID = 20005").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2000-02-29 00:00:00.000000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(hour, 1440, TM) FROM P2 WHERE ID = 20005").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2000-02-29 00:00:00.000000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(minute, 86400, TM) FROM P2 WHERE ID = 20005").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2000-02-29 00:00:00.000000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(second, 5184000, TM) FROM P2 WHERE ID = 20005").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2000-02-29 00:00:00.000000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(millisecond, 5184000000, TM) FROM P2 WHERE ID = 20005").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2000-02-29 00:00:00.000000"), vt.getTimestampAsSqlTimestamp(0));
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(microsecond, 5184000000000, TM) FROM P2 WHERE ID = 20005").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(Timestamp.valueOf("2000-02-29 00:00:00.000000"), vt.getTimestampAsSqlTimestamp(0));
// Test null interval
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(YEAR, NULL, TM), DATEADD(QUARTER, NULL,TM), DATEADD(MONTH, NULL,TM), " + "DATEADD(DAY, NULL,TM), DATEADD(HOUR, NULL,TM), DATEADD(MINUTE, NULL,TM), " + "DATEADD(SECOND, NULL,TM), DATEADD(MILLISECOND, NULL,TM), " + "DATEADD(MICROSECOND, NULL,TM) FROM P2 WHERE ID = 20005;").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(null, vt.getTimestampAsTimestamp(0));
assertEquals(null, vt.getTimestampAsTimestamp(1));
assertEquals(null, vt.getTimestampAsTimestamp(2));
assertEquals(null, vt.getTimestampAsTimestamp(3));
assertEquals(null, vt.getTimestampAsTimestamp(4));
assertEquals(null, vt.getTimestampAsTimestamp(5));
assertEquals(null, vt.getTimestampAsTimestamp(6));
assertEquals(null, vt.getTimestampAsTimestamp(7));
assertEquals(null, vt.getTimestampAsTimestamp(8));
// Test null timestamp
cr = client.callProcedure("@AdHoc", "INSERT INTO P2 (ID, TM) VALUES (20006, null)");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
vt = client.callProcedure("@AdHoc", "SELECT DATEADD(YEAR, 1, TM), DATEADD(QUARTER, 1, TM), DATEADD(MONTH, 1, TM), " + "DATEADD(DAY, 1, TM), DATEADD(HOUR, 1, TM), DATEADD(MINUTE, 1, TM), " + "DATEADD(SECOND, 1, TM), DATEADD(MILLISECOND, 1, TM), " + "DATEADD(MICROSECOND, 1, TM) FROM P2 WHERE ID = 20006;").getResults()[0];
assertTrue(vt.advanceRow());
assertEquals(null, vt.getTimestampAsTimestamp(0));
assertEquals(null, vt.getTimestampAsTimestamp(1));
assertEquals(null, vt.getTimestampAsTimestamp(2));
assertEquals(null, vt.getTimestampAsTimestamp(3));
assertEquals(null, vt.getTimestampAsTimestamp(4));
assertEquals(null, vt.getTimestampAsTimestamp(5));
assertEquals(null, vt.getTimestampAsTimestamp(6));
assertEquals(null, vt.getTimestampAsTimestamp(7));
assertEquals(null, vt.getTimestampAsTimestamp(8));
// Test null or illegal datepart
boolean throwed = false;
try {
client.callProcedure("@AdHoc", "SELECT DATEADD(NULL, 1, TM) FROM P2 WHERE ID = 20005;");
} catch (ProcCallException e) {
assertEquals(ClientResponse.GRACEFUL_FAILURE, e.getClientResponse().getStatus());
assertTrue(e.getClientResponse().getStatusString().contains("Unexpected Ad Hoc Planning Error"));
throwed = true;
}
assertTrue(throwed);
throwed = false;
try {
client.callProcedure("@AdHoc", "SELECT DATEADD(WEEK, 1, TM) FROM P2 WHERE ID = 20005;");
} catch (ProcCallException e) {
assertEquals(ClientResponse.GRACEFUL_FAILURE, e.getClientResponse().getStatus());
assertTrue(e.getClientResponse().getStatusString().contains("Unexpected Ad Hoc Planning Error"));
throwed = true;
}
assertTrue(throwed);
// Test large intervals caused exceptions
throwed = false;
try {
client.callProcedure("@AdHoc", "SELECT DATEADD(YEAR, " + ((long) Integer.MAX_VALUE + 1) + ", TM) FROM P2 WHERE ID = 20005;");
} catch (ProcCallException e) {
assertEquals(ClientResponse.GRACEFUL_FAILURE, e.getClientResponse().getStatus());
assertTrue(e.getClientResponse().getStatusString().contains("interval is too large for DATEADD function"));
throwed = true;
}
assertTrue(throwed);
throwed = false;
try {
client.callProcedure("@AdHoc", "SELECT DATEADD(YEAR, " + ((long) Integer.MIN_VALUE - 1) + ", TM) FROM P2 WHERE ID = 20005;");
} catch (ProcCallException e) {
assertEquals(ClientResponse.GRACEFUL_FAILURE, e.getClientResponse().getStatus());
assertTrue(e.getClientResponse().getStatusString().contains("interval is too large for DATEADD function"));
throwed = true;
}
assertTrue(throwed);
throwed = false;
try {
client.callProcedure("@AdHoc", "SELECT DATEADD(QUARTER, " + ((long) Integer.MAX_VALUE + 1) + ", TM) FROM P2 WHERE ID = 20005;");
} catch (ProcCallException e) {
assertEquals(ClientResponse.GRACEFUL_FAILURE, e.getClientResponse().getStatus());
assertTrue(e.getClientResponse().getStatusString().contains("interval is too large for DATEADD function"));
throwed = true;
}
assertTrue(throwed);
throwed = false;
try {
client.callProcedure("@AdHoc", "SELECT DATEADD(QUARTER, " + ((long) Integer.MIN_VALUE - 1) + ", TM) FROM P2 WHERE ID = 20005;");
} catch (ProcCallException e) {
assertEquals(ClientResponse.GRACEFUL_FAILURE, e.getClientResponse().getStatus());
assertTrue(e.getClientResponse().getStatusString().contains("interval is too large for DATEADD function"));
throwed = true;
}
assertTrue(throwed);
throwed = false;
try {
client.callProcedure("@AdHoc", "SELECT DATEADD(MONTH, " + ((long) Integer.MAX_VALUE + 1) + ", TM) FROM P2 WHERE ID = 20005;");
} catch (ProcCallException e) {
assertEquals(ClientResponse.GRACEFUL_FAILURE, e.getClientResponse().getStatus());
assertTrue(e.getClientResponse().getStatusString().contains("interval is too large for DATEADD function"));
throwed = true;
}
assertTrue(throwed);
throwed = false;
try {
client.callProcedure("@AdHoc", "SELECT DATEADD(MONTH, " + ((long) Integer.MIN_VALUE - 1) + ", TM) FROM P2 WHERE ID = 20005;");
} catch (ProcCallException e) {
assertEquals(ClientResponse.GRACEFUL_FAILURE, e.getClientResponse().getStatus());
assertTrue(e.getClientResponse().getStatusString().contains("interval is too large for DATEADD function"));
throwed = true;
}
assertTrue(throwed);
throwed = false;
try {
client.callProcedure("@AdHoc", "SELECT DATEADD(DAY, " + Long.MAX_VALUE + ", TM) FROM P2 WHERE ID = 20005;");
} catch (ProcCallException e) {
assertEquals(ClientResponse.GRACEFUL_FAILURE, e.getClientResponse().getStatus());
assertTrue(e.getClientResponse().getStatusString().contains("interval is too large for DATEADD function"));
throwed = true;
}
assertTrue(throwed);
throwed = false;
try {
client.callProcedure("@AdHoc", "SELECT DATEADD(DAY, " + (Long.MIN_VALUE + 1) + ", TM) FROM P2 WHERE ID = 20005;");
} catch (ProcCallException e) {
assertEquals(ClientResponse.GRACEFUL_FAILURE, e.getClientResponse().getStatus());
assertTrue(e.getClientResponse().getStatusString().contains("interval is too large for DATEADD function"));
throwed = true;
}
assertTrue(throwed);
throwed = false;
try {
client.callProcedure("@AdHoc", "SELECT DATEADD(HOUR, " + Long.MAX_VALUE + ", TM) FROM P2 WHERE ID = 20005;");
} catch (ProcCallException e) {
assertEquals(ClientResponse.GRACEFUL_FAILURE, e.getClientResponse().getStatus());
assertTrue(e.getClientResponse().getStatusString().contains("interval is too large for DATEADD function"));
throwed = true;
}
assertTrue(throwed);
throwed = false;
try {
client.callProcedure("@AdHoc", "SELECT DATEADD(HOUR, " + (Long.MIN_VALUE + 1) + ", TM) FROM P2 WHERE ID = 20005;");
} catch (ProcCallException e) {
assertEquals(ClientResponse.GRACEFUL_FAILURE, e.getClientResponse().getStatus());
assertTrue(e.getClientResponse().getStatusString().contains("interval is too large for DATEADD function"));
throwed = true;
}
assertTrue(throwed);
throwed = false;
try {
client.callProcedure("@AdHoc", "SELECT DATEADD(MINUTE, " + Long.MAX_VALUE + ", TM) FROM P2 WHERE ID = 20005;");
} catch (ProcCallException e) {
assertEquals(ClientResponse.GRACEFUL_FAILURE, e.getClientResponse().getStatus());
assertTrue(e.getClientResponse().getStatusString().contains("interval is too large for DATEADD function"));
throwed = true;
}
assertTrue(throwed);
throwed = false;
try {
client.callProcedure("@AdHoc", "SELECT DATEADD(MINUTE, " + (Long.MIN_VALUE + 1) + ", TM) FROM P2 WHERE ID = 20005;");
} catch (ProcCallException e) {
assertEquals(ClientResponse.GRACEFUL_FAILURE, e.getClientResponse().getStatus());
assertTrue(e.getClientResponse().getStatusString().contains("interval is too large for DATEADD function"));
throwed = true;
}
assertTrue(throwed);
throwed = false;
try {
client.callProcedure("@AdHoc", "SELECT DATEADD(SECOND, " + Long.MAX_VALUE + ", TM) FROM P2 WHERE ID = 20005;");
} catch (ProcCallException e) {
assertEquals(ClientResponse.GRACEFUL_FAILURE, e.getClientResponse().getStatus());
assertTrue(e.getClientResponse().getStatusString().contains("interval is too large for DATEADD function"));
throwed = true;
}
assertTrue(throwed);
throwed = false;
try {
client.callProcedure("@AdHoc", "SELECT DATEADD(SECOND, " + (Long.MIN_VALUE + 1) + ", TM) FROM P2 WHERE ID = 20005;");
} catch (ProcCallException e) {
assertEquals(ClientResponse.GRACEFUL_FAILURE, e.getClientResponse().getStatus());
assertTrue(e.getClientResponse().getStatusString().contains("interval is too large for DATEADD function"));
throwed = true;
}
assertTrue(throwed);
throwed = false;
try {
client.callProcedure("@AdHoc", "SELECT DATEADD(MILLISECOND, " + Long.MAX_VALUE + ", TM) FROM P2 WHERE ID = 20005;");
} catch (ProcCallException e) {
assertEquals(ClientResponse.GRACEFUL_FAILURE, e.getClientResponse().getStatus());
assertTrue(e.getClientResponse().getStatusString().contains("interval is too large for DATEADD function"));
throwed = true;
}
assertTrue(throwed);
throwed = false;
try {
client.callProcedure("@AdHoc", "SELECT DATEADD(MILLISECOND, " + (Long.MIN_VALUE + 1) + ", TM) FROM P2 WHERE ID = 20005;");
} catch (ProcCallException e) {
assertEquals(ClientResponse.GRACEFUL_FAILURE, e.getClientResponse().getStatus());
assertTrue(e.getClientResponse().getStatusString().contains("interval is too large for DATEADD function"));
throwed = true;
}
assertTrue(throwed);
throwed = false;
try {
client.callProcedure("@AdHoc", "SELECT DATEADD(MICROSECOND, " + Long.MAX_VALUE + ", TM) FROM P2 WHERE ID = 20005;");
} catch (ProcCallException e) {
assertEquals(ClientResponse.GRACEFUL_FAILURE, e.getClientResponse().getStatus());
assertTrue(e.getClientResponse().getStatusString().contains("interval is too large for DATEADD function"));
throwed = true;
}
assertTrue(throwed);
throwed = false;
try {
client.callProcedure("@AdHoc", "SELECT DATEADD(MICROSECOND, " + (Long.MIN_VALUE + 1) + ", TM) FROM P2 WHERE ID = 20005;");
} catch (ProcCallException e) {
assertEquals(ClientResponse.GRACEFUL_FAILURE, e.getClientResponse().getStatus());
assertTrue(e.getClientResponse().getStatusString().contains("interval is too large for DATEADD function"));
throwed = true;
}
assertTrue(throwed);
}
use of org.voltdb.client.ProcCallException in project voltdb by VoltDB.
the class TestFunctionsForVoltDBSuite method testBitwiseShift.
public void testBitwiseShift() throws NoConnectionsException, IOException, ProcCallException {
System.out.println("STARTING test bitwise shifting tests");
bitwiseShiftChecker(1, 1, 1);
bitwiseShiftChecker(2, -1, 1);
bitwiseShiftChecker(3, 3, 60);
bitwiseShiftChecker(4, -3, 60);
bitwiseShiftChecker(5, 3, 64);
bitwiseShiftChecker(6, -3, 64);
bitwiseShiftChecker(7, 3, 65);
bitwiseShiftChecker(8, -3, 65);
bitwiseShiftChecker(9, 3, 127);
bitwiseShiftChecker(10, -3, 127);
bitwiseShiftChecker(11, 3, 128);
bitwiseShiftChecker(12, -3, 128);
bitwiseShiftChecker(13, 3, 129);
bitwiseShiftChecker(14, -3, 129);
bitwiseShiftChecker(15, 8, 63);
bitwiseShiftChecker(16, -8, 63);
bitwiseShiftChecker(17, 8, 0);
bitwiseShiftChecker(18, -8, 0);
// Min/MAX
bitwiseShiftChecker(50, Long.MAX_VALUE, 3);
bitwiseShiftChecker(51, 3, Long.MAX_VALUE);
bitwiseShiftChecker(52, Long.MAX_VALUE, -3);
bitwiseShiftChecker(53, -3, Long.MAX_VALUE);
bitwiseShiftChecker(54, Long.MIN_VALUE + 1, 6);
bitwiseShiftChecker(55, 6, Long.MIN_VALUE + 1);
bitwiseShiftChecker(56, Long.MIN_VALUE + 1, -6);
bitwiseShiftChecker(57, -6, Long.MIN_VALUE + 1);
try {
bitwiseShiftChecker(19, 3, 63);
fail();
} catch (Exception ex) {
assertTrue(ex.getMessage().contains("would produce INT64_MIN, which is reserved for SQL NULL values"));
}
try {
bitwiseShiftChecker(20, -3, 63);
fail();
} catch (Exception ex) {
assertTrue(ex.getMessage().contains("would produce INT64_MIN, which is reserved for SQL NULL values"));
}
Client client = getClient();
// out of range tests
verifyStmtFails(client, "select BIT_SHIFT_LEFT(big, 9223372036854775809) from R3;", "numeric value out of range");
verifyStmtFails(client, "select BIT_SHIFT_LEFT(big, 0.5) from R3;", "incompatible data type in conversion");
verifyStmtFails(client, "select BIT_SHIFT_RIGHT(3.6, 2) from R3;", "incompatible data type in conversion");
// negative shifting tests
verifyStmtFails(client, "select BIT_SHIFT_LEFT(big, -1) from R3;", "unsupported negative value for bit shifting");
verifyStmtFails(client, "select BIT_SHIFT_RIGHT(big, -1) from R3;", "unsupported negative value for bit shifting");
VoltTable vt;
// NULL tests: null in null out
client.callProcedure("@AdHoc", "insert into R3(id, big) values (100, null)");
vt = client.callProcedure("BITWISE_SHIFT_PARAM_1", 2, 2, 100).getResults()[0];
validateRowOfLongs(vt, new long[] { Long.MIN_VALUE, Long.MIN_VALUE });
vt = client.callProcedure("BITWISE_SHIFT_PARAM_2", 2, 2, 100).getResults()[0];
validateRowOfLongs(vt, new long[] { Long.MIN_VALUE, Long.MIN_VALUE });
}
Aggregations