use of org.voltdb.client.NoConnectionsException in project voltdb by VoltDB.
the class TestFunctionsSuite method subtestTrimAny.
private void subtestTrimAny(Client client, String trimProc) throws NoConnectionsException, IOException, ProcCallException {
ClientResponse cr;
VoltTable result;
String trimFailed = trimProc + " got a wrong answer";
cr = client.callProcedure("@AdHoc", "TRUNCATE TABLE P1;");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
cr = client.callProcedure("P1.insert", 1, " VoltDB ", 1, 1.0, new Timestamp(1000000000000L));
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
cr = client.callProcedure(trimProc, " ", " ", " ", 1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals(trimFailed, "VoltDB ", result.getString(1));
assertEquals(trimFailed, " VoltDB", result.getString(2));
assertEquals(trimFailed, "VoltDB", result.getString(3));
try {
cr = client.callProcedure(trimProc, "", "", "", 1);
fail();
} catch (Exception ex) {
String exceptionMsg = ex.getMessage();
assertTrue(exceptionMsg.contains("data exception"));
assertTrue(exceptionMsg.contains("trim error"));
}
// Test TRIM with other character
cr = client.callProcedure("P1.insert", 2, "vVoltDBBB", 1, 1.0, new Timestamp(1000000000000L));
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
cr = client.callProcedure(trimProc, "v", "B", "B", 2);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals(trimFailed, "VoltDBBB", result.getString(1));
assertEquals(trimFailed, "vVoltD", result.getString(2));
assertEquals(trimFailed, "vVoltD", result.getString(3));
// Multiple character trim, Hsql does not support
if (!isHSQL()) {
cr = client.callProcedure(trimProc, "vV", "BB", "Vv", 2);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals(trimFailed, "oltDBBB", result.getString(1));
assertEquals(trimFailed, "vVoltDB", result.getString(2));
assertEquals(trimFailed, "vVoltDBBB", result.getString(3));
}
// Test null trim character
cr = client.callProcedure(trimProc, null, null, null, 2);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals(null, result.getString(1));
assertEquals(null, result.getString(2));
assertEquals(null, result.getString(3));
// Test non-ASCII trim_char
cr = client.callProcedure("P1.insert", 3, "贾vVoltDBBB", 1, 1.0, new Timestamp(1000000000000L));
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
cr = client.callProcedure(trimProc, "贾", "v", "贾", 3);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals(trimFailed, "vVoltDBBB", result.getString(1));
assertEquals(trimFailed, "贾vVoltDBBB", result.getString(2));
assertEquals(trimFailed, "vVoltDBBB", result.getString(3));
if (!isHSQL()) {
// Complete match
cr = client.callProcedure(trimProc, "贾vVoltDBBB", "贾vVoltDBBB", "贾vVoltDBBB", 3);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals(trimFailed, "", result.getString(1));
assertEquals(trimFailed, "", result.getString(2));
assertEquals(trimFailed, "", result.getString(3));
cr = client.callProcedure(trimProc, "贾vVoltDBBB_TEST", "贾vVoltDBBB贾vVoltDBBB", "贾vVoltDBBBT", 3);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals(trimFailed, "贾vVoltDBBB", result.getString(1));
assertEquals(trimFailed, "贾vVoltDBBB", result.getString(2));
assertEquals(trimFailed, "贾vVoltDBBB", result.getString(3));
}
// Complicated test
cr = client.callProcedure("P1.insert", 4, "贾贾vVoltDBBB贾贾贾", 1, 1.0, new Timestamp(1000000000000L));
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
// UTF-8 hex, 贾: 0xe8 0xb4 0xbe, 辴: 0xe8 0xbe 0xb4
cr = client.callProcedure(trimProc, "辴", "辴", "辴", 4);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals(trimFailed, "贾贾vVoltDBBB贾贾贾", result.getString(1));
assertEquals(trimFailed, "贾贾vVoltDBBB贾贾贾", result.getString(2));
assertEquals(trimFailed, "贾贾vVoltDBBB贾贾贾", result.getString(3));
cr = client.callProcedure(trimProc, "贾", "贾", "贾", 4);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals(trimFailed, "vVoltDBBB贾贾贾", result.getString(1));
assertEquals(trimFailed, "贾贾vVoltDBBB", result.getString(2));
assertEquals(trimFailed, "vVoltDBBB", result.getString(3));
if (!isHSQL()) {
cr = client.callProcedure(trimProc, "贾辴", "贾辴", "贾辴", 4);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals(trimFailed, "贾贾vVoltDBBB贾贾贾", result.getString(1));
assertEquals(trimFailed, "贾贾vVoltDBBB贾贾贾", result.getString(2));
assertEquals(trimFailed, "贾贾vVoltDBBB贾贾贾", result.getString(3));
cr = client.callProcedure(trimProc, "贾贾vV", "贾贾", "B贾贾贾", 4);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals(trimFailed, "oltDBBB贾贾贾", result.getString(1));
assertEquals(trimFailed, "贾贾vVoltDBBB贾", result.getString(2));
assertEquals(trimFailed, "贾贾vVoltDBB", result.getString(3));
}
}
use of org.voltdb.client.NoConnectionsException in project voltdb by VoltDB.
the class TestFunctionsSuite method testLeftAndRight.
public void testLeftAndRight() throws NoConnectionsException, IOException, ProcCallException {
System.out.println("STARTING Left and Right");
Client client = getClient();
ClientResponse cr;
VoltTable result;
cr = client.callProcedure("P1.insert", 1, "贾鑫Vo", 1, 1.0, new Timestamp(1000000000000L));
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
// test LEFT function
cr = client.callProcedure("LEFT", 0, 1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals("", result.getString(1));
cr = client.callProcedure("LEFT", 1, 1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals("贾", result.getString(1));
cr = client.callProcedure("LEFT", 2, 1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals("贾鑫", result.getString(1));
cr = client.callProcedure("LEFT", 3, 1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals("贾鑫V", result.getString(1));
cr = client.callProcedure("LEFT", 4, 1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals("贾鑫Vo", result.getString(1));
cr = client.callProcedure("LEFT", 5, 1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals("贾鑫Vo", result.getString(1));
// invalid case
Exception ex = null;
try {
cr = client.callProcedure("LEFT", -1, 1);
} catch (Exception e) {
assertTrue(e instanceof ProcCallException);
ex = e;
} finally {
assertNotNull(ex);
}
// test RIGHT function
cr = client.callProcedure("RIGHT", 0, 1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals("", result.getString(1));
cr = client.callProcedure("RIGHT", 1, 1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals("o", result.getString(1));
cr = client.callProcedure("RIGHT", 2, 1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals("Vo", result.getString(1));
cr = client.callProcedure("RIGHT", 3, 1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals("鑫Vo", result.getString(1));
cr = client.callProcedure("RIGHT", 4, 1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals("贾鑫Vo", result.getString(1));
cr = client.callProcedure("RIGHT", 5, 1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals("贾鑫Vo", result.getString(1));
ex = null;
try {
cr = client.callProcedure("RIGHT", -1, 1);
} catch (Exception e) {
assertTrue(e instanceof ProcCallException);
ex = e;
} finally {
assertNotNull(ex);
}
}
use of org.voltdb.client.NoConnectionsException in project voltdb by VoltDB.
the class TestUnionSuite method testUnionOrderLimitOffset.
/**
* Three table Union ALL - A.PKEY, B.I and C.I
* @throws NoConnectionsException
* @throws IOException
* @throws ProcCallException
*/
public void testUnionOrderLimitOffset() throws NoConnectionsException, IOException, ProcCallException {
Client client = this.getClient();
VoltTable vt;
//In the final result set
client.callProcedure("InsertA", 0, 1);
//In the final result set
client.callProcedure("InsertB", 1, 1);
//In the final result set
client.callProcedure("InsertB", 2, 1);
//In the final result set
client.callProcedure("InsertC", 1, 2);
//In the final result set
client.callProcedure("InsertC", 2, 3);
// No limit, offset
vt = client.callProcedure("@AdHoc", "SELECT PKEY FROM A WHERE PKEY = 0 UNION ALL SELECT I FROM B WHERE I = 1 " + "UNION ALL SELECT I FROM C WHERE PKEY > 0 order by pkey;").getResults()[0];
validateTableOfScalarLongs(vt, new long[] { 0, 1, 1, 2, 3 });
// Order by column
vt = client.callProcedure("@AdHoc", "SELECT PKEY FROM A WHERE PKEY = 0 UNION ALL SELECT I FROM B WHERE I = 1 " + "UNION ALL SELECT I FROM C WHERE PKEY > 0 ORDER BY PKEY DESC;").getResults()[0];
validateTableOfScalarLongs(vt, new long[] { 3, 2, 1, 1, 0 });
// order by number
vt = client.callProcedure("@AdHoc", "SELECT PKEY FROM A WHERE PKEY = 0 UNION ALL SELECT I FROM B WHERE I = 1 " + "UNION ALL SELECT I FROM C WHERE PKEY > 0 ORDER BY 1 DESC;").getResults()[0];
validateTableOfScalarLongs(vt, new long[] { 3, 2, 1, 1, 0 });
// order by parameter
try {
client.callProcedure("@AdHoc", "SELECT PKEY FROM A WHERE PKEY = 0 UNION ALL SELECT I FROM B WHERE I = 1 " + "UNION ALL SELECT I FROM C WHERE PKEY > 0 ORDER BY ? DESC;", 1);
fail();
} catch (Exception ex) {
assertTrue(ex.getMessage().contains("invalid ORDER BY expression"));
}
// Make sure the query is parameterized
vt = client.callProcedure("@Explain", "SELECT PKEY FROM A WHERE PKEY = 0 UNION ALL SELECT I FROM B WHERE I = 1 " + "UNION ALL SELECT I FROM C WHERE PKEY > 0 LIMIT 2 OFFSET 2;").getResults()[0];
String explainPlan = vt.toString();
assertTrue(explainPlan.contains("LIMIT with parameter"));
assertTrue(explainPlan.contains("uniquely match (PKEY = ?0)"));
assertTrue(explainPlan.contains("filter by (column#1 = ?1)"));
assertTrue(explainPlan.contains("range-scan covering from (PKEY > ?2)"));
vt = client.callProcedure("@AdHoc", "SELECT ABS(PKEY) as AP FROM A WHERE PKEY = 0 UNION ALL " + "SELECT I FROM B WHERE I = 1 UNION ALL SELECT I FROM C WHERE PKEY > 0 ORDER BY AP DESC;").getResults()[0];
validateTableOfScalarLongs(vt, new long[] { 3, 2, 1, 1, 0 });
vt = client.callProcedure("@AdHoc", "SELECT cast ((PKEY+1) as INTEGER) as AP FROM A WHERE PKEY = 0 UNION ALL " + "SELECT I FROM B WHERE I = 1 UNION ALL SELECT I FROM C WHERE PKEY > 0 ORDER BY AP DESC;").getResults()[0];
validateTableOfScalarLongs(vt, new long[] { 3, 2, 1, 1, 1 });
//
// with ORDER BY
//
// limit 3, no offset
vt = client.callProcedure("@AdHoc", "(SELECT PKEY FROM A WHERE PKEY = 0 UNION ALL SELECT I FROM B WHERE I = 1 " + "UNION ALL SELECT I FROM C WHERE PKEY > 0) order by pkey LIMIT 3;").getResults()[0];
validateTableOfScalarLongs(vt, new long[] { 0, 1, 1 });
vt = client.callProcedure("@AdHoc", "SELECT PKEY FROM A UNION ALL SELECT I FROM B " + "UNION ALL SELECT I FROM C order by pkey LIMIT ?;", 3).getResults()[0];
validateTableOfScalarLongs(vt, new long[] { 0, 1, 1 });
// limit 2, offset 2
vt = client.callProcedure("@AdHoc", "SELECT PKEY FROM A WHERE PKEY = 0 UNION ALL SELECT I FROM B WHERE I = 1 " + " UNION ALL SELECT I FROM C WHERE PKEY > 0 ORDER BY PKEY LIMIT 2 OFFSET 2;").getResults()[0];
validateTableOfScalarLongs(vt, new long[] { 1, 2 });
vt = client.callProcedure("@AdHoc", "SELECT PKEY FROM A UNION ALL SELECT I FROM B UNION ALL " + "SELECT I FROM C order by pkey LIMIT ? OFFSET ?;", 2, 2).getResults()[0];
validateTableOfScalarLongs(vt, new long[] { 1, 2 });
vt = client.callProcedure("@AdHoc", "(SELECT PKEY FROM A UNION ALL SELECT I FROM B order by pkey LIMIT 1) " + "UNION ALL SELECT I FROM C order by pkey;").getResults()[0];
assertEquals(3, vt.getRowCount());
validateTableOfScalarLongs(vt, new long[] { 0, 2, 3 });
vt = client.callProcedure("@AdHoc", "SELECT PKEY FROM A UNION ALL (SELECT I FROM B UNION ALL " + "SELECT I FROM C order by I LIMIT 1) order by pkey;").getResults()[0];
assertEquals(2, vt.getRowCount());
validateTableOfScalarLongs(vt, new long[] { 0, 1 });
vt = client.callProcedure("@AdHoc", "(SELECT PKEY FROM A UNION ALL SELECT I FROM B ORDER BY PKEY) UNION ALL " + "SELECT I FROM C order by pkey;").getResults()[0];
assertEquals(5, vt.getRowCount());
validateTableOfScalarLongs(vt, new long[] { 0, 1, 1, 2, 3 });
vt = client.callProcedure("@AdHoc", "SELECT PKEY FROM A UNION ALL (SELECT I FROM B UNION ALL " + "SELECT I FROM C ORDER BY I) order by pkey;").getResults()[0];
assertEquals(5, vt.getRowCount());
validateTableOfScalarLongs(vt, new long[] { 0, 1, 1, 2, 3 });
//
vt = client.callProcedure("@AdHoc", "SELECT PKEY FROM A UNION ALL SELECT I FROM B UNION ALL " + "SELECT I FROM C ORDER BY PKEY LIMIT 2 OFFSET 3;").getResults()[0];
assertEquals(2, vt.getRowCount());
validateTableOfScalarLongs(vt, new long[] { 2, 3 });
// hsqldb bug ENG-8382: hsqldb does not apply the LIMIT, returning wrong answers
if (!isHSQL()) {
// limit 3, no offset
vt = client.callProcedure("@AdHoc", "(SELECT PKEY FROM A WHERE PKEY = 0 UNION ALL SELECT I FROM B WHERE I = 1 " + "UNION ALL SELECT I FROM C WHERE PKEY > 0) LIMIT 3;").getResults()[0];
assertEquals(3, vt.getRowCount());
// parameter
vt = client.callProcedure("@AdHoc", "SELECT PKEY FROM A UNION ALL SELECT I FROM B " + "UNION ALL SELECT I FROM C LIMIT ?;", 3).getResults()[0];
assertEquals(3, vt.getRowCount());
// parameter
vt = client.callProcedure("@AdHoc", "SELECT PKEY FROM A UNION ALL SELECT I FROM B UNION ALL " + "SELECT I FROM C LIMIT ? OFFSET ?;", 2, 2).getResults()[0];
assertEquals(2, vt.getRowCount());
// hsqdldb bug ENG-8381: without LIMIT, the OFFSET has NPE in hsqldb backend
vt = client.callProcedure("@AdHoc", "SELECT PKEY FROM A UNION ALL SELECT I FROM B UNION ALL " + "SELECT I FROM C ORDER BY PKEY OFFSET 3;").getResults()[0];
assertEquals(2, vt.getRowCount());
validateTableOfScalarLongs(vt, new long[] { 2, 3 });
}
}
use of org.voltdb.client.NoConnectionsException in project voltdb by VoltDB.
the class Eng866Client method collectStats.
static void collectStats(Client client) {
try {
ClientResponse resp = client.callProcedure("@Statistics", "management", 0);
parseStats(resp);
} catch (NoConnectionsException e) {
System.err.println("Lost connection to database, terminating");
System.exit(-1);
} catch (IOException e) {
e.printStackTrace();
} catch (ProcCallException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.voltdb.client.NoConnectionsException in project voltdb by VoltDB.
the class TestSQLTypesSuite method testUpdateFromNull.
public void testUpdateFromNull() throws NoConnectionsException, ProcCallException, IOException {
final Client client = this.getClient();
final Object[] params = new Object[COLS + 2];
for (int k = 0; k < COLS; ++k) {
// build the parameter list as described above
// Fill the row with diagonal null data and insert
params[0] = "";
params[1] = pkey.incrementAndGet();
for (int i = 0; i < COLS; i++) {
params[i + 2] = (i == k) ? m_nullValues[i] : m_midValues[i];
assert (params[i + 2] != null);
}
params[0] = "ALLOW_NULLS";
client.callProcedure("Insert", params);
for (int i = 0; i < COLS; i++) {
params[i + 2] = m_midValues[i];
assert (params[i + 2] != null);
}
try {
client.callProcedure("Update", params);
} catch (final ProcCallException e) {
e.printStackTrace();
fail();
} catch (final NoConnectionsException e) {
e.printStackTrace();
fail();
}
// verify that the row was updated
final VoltTable[] result = client.callProcedure("Select", "ALLOW_NULLS", pkey.get()).getResults();
final VoltTableRow row = result[0].fetchRow(0);
for (int i = 0; i < COLS; ++i) {
final Object obj = row.get(i + 1, m_types[i]);
assertTrue(comparisonHelper(obj, params[i + 2], m_types[i]));
}
}
}
Aggregations