use of org.voltdb.client.ClientResponse in project voltdb by VoltDB.
the class TestFunctionsForVoltDBSuite method testCharLength.
// this test is put here instead of TestFunctionSuite, because HSQL uses
// a different null case standard with standard sql
public void testCharLength() throws NoConnectionsException, IOException, ProcCallException {
System.out.println("STARTING Char length");
Client client = getClient();
ClientResponse cr;
VoltTable result;
cr = client.callProcedure("P1.insert", 1, "贾鑫Vo", 10, 1.1);
cr = client.callProcedure("P1.insert", 2, "Xin@Volt", 10, 1.1);
cr = client.callProcedure("P1.insert", 3, "क्षीण", 10, 1.1);
cr = client.callProcedure("P1.insert", 4, null, 10, 1.1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
cr = client.callProcedure("CHAR_LENGTH", 1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals(4, result.getLong(1));
cr = client.callProcedure("CHAR_LENGTH", 2);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals(8, result.getLong(1));
cr = client.callProcedure("CHAR_LENGTH", 3);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals(5, result.getLong(1));
cr = client.callProcedure("CHAR_LGTH_PARAM", "क्षीण", 3);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals(5, result.getLong(1));
// null case
cr = client.callProcedure("CHAR_LENGTH", 4);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals(VoltType.NULL_BIGINT, result.getLong(1));
// try char_length on incompatible data type
try {
cr = client.callProcedure("@AdHoc", "select bdata, CHAR_LENGTH(bdata) from BINARYTEST where ID = 1");
fail("char_length on columns which are not string expression is not supported");
} catch (ProcCallException pce) {
assertTrue(pce.getMessage().contains("incompatible data type in operation"));
}
}
use of org.voltdb.client.ClientResponse in project voltdb by VoltDB.
the class TestFunctionsSuite method testFoundHSQLBackendOutOfRange.
// Test some false alarm cases in HSQLBackend that were interfering with sqlcoverage.
public void testFoundHSQLBackendOutOfRange() throws IOException, InterruptedException, ProcCallException {
System.out.println("STARTING testFoundHSQLBackendOutOfRange");
Client client = getClient();
ClientResponse cr = null;
/*
CREATE TABLE P1 (
ID INTEGER DEFAULT '0' NOT NULL,
DESC VARCHAR(300),
NUM INTEGER,
RATIO FLOAT,
PAST TIMESTAMP DEFAULT NULL,
PRIMARY KEY (ID) );
*/
client.callProcedure("@AdHoc", "INSERT INTO P1 VALUES (0, 'wEoiXIuJwSIKBujWv', -405636, 1.38145922788945552107e-01, NULL)");
client.callProcedure("@AdHoc", "INSERT INTO P1 VALUES (2, 'wEoiXIuJwSIKBujWv', -29914, 8.98500019539639316335e-01, NULL)");
client.callProcedure("@AdHoc", "INSERT INTO P1 VALUES (4, 'WCfDDvZBPoqhanfGN', -1309657, 9.34160160574919795629e-01, NULL)");
client.callProcedure("@AdHoc", "INSERT INTO P1 VALUES (6, 'WCfDDvZBPoqhanfGN', 1414568, 1.14383710279231887164e-01, NULL)");
cr = client.callProcedure("@AdHoc", "select (5.25 + NUM) from P1");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
cr = client.callProcedure("@AdHoc", "SELECT FLOOR(NUM + 5.25) NUMSUM FROM P1 ORDER BY NUMSUM");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
// This test case requires HSQL to be taught to do (truncating) integer division of integers as VoltDB does.
// While not strictly required by the SQL standard, integer division is at least technically compliant,
// where HSQL's use of floating point division is not.
// cr = client.callProcedure("@AdHoc", "SELECT SUM(DISTINCT SQRT(ID / (NUM))) AS Q22 FROM P1");
// assertEquals(ClientResponse.SUCCESS, cr.getStatus());
}
use of org.voltdb.client.ClientResponse in project voltdb by VoltDB.
the class TestFunctionsSuite method testAbs.
public void testAbs() throws Exception {
System.out.println("STARTING testAbs");
Client client = getClient();
initialLoad(client, "P1");
ClientResponse cr = null;
VoltTable r = null;
// The next two queries used to fail due to ENG-3913,
// abuse of compound indexes for partial GT filters.
// An old issue only brought to light by the addition of a compound index to this suite.
cr = client.callProcedure("@AdHoc", "select count(*) from P1 where ABS(ID) > 9");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
// used to get 6, matching like >=
assertEquals(5, r.asScalarLong());
initialLoad(client, "R1");
cr = client.callProcedure("WHERE_ABS");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
// used to get 6, matching like >=
assertEquals(5, r.asScalarLong());
try {
// test decimal support and non-column expressions
cr = client.callProcedure("WHERE_ABSFF");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
assertEquals(5, r.asScalarLong());
} catch (ProcCallException hsqlFailed) {
// Give HSQLDB a pass on this query.
String msg = hsqlFailed.getMessage();
assertTrue(msg.matches(".*ExpectedProcedureException.*HSQLDB.*"));
}
// Test type promotions
cr = client.callProcedure("WHERE_ABSIF");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
assertEquals(5, r.asScalarLong());
try {
cr = client.callProcedure("WHERE_ABSFI");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
assertEquals(5, r.asScalarLong());
} catch (ProcCallException hsqlFailed) {
// Give HSQLDB a pass on this query.
String msg = hsqlFailed.getMessage();
assertTrue(msg.matches(".*ExpectedProcedureException.*HSQLDB.*"));
}
// Test application to weakly typed NUMERIC constants
try {
cr = client.callProcedure("WHERE_ABSWEAK");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
assertEquals(5, r.asScalarLong());
} catch (ProcCallException hsqlFailed) {
// Give HSQLDB a pass on this query.
String msg = hsqlFailed.getMessage();
assertTrue(msg.matches(".*ExpectedProcedureException.*HSQLDB.*"));
}
cr = client.callProcedure("DISPLAY_ABS");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
assertEquals(5, r.asScalarLong());
cr = client.callProcedure("ORDER_ABS");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
r.advanceRow();
long value = r.getLong(0);
assertEquals(5, value);
/*
cr = client.callProcedure("GROUP_ABS");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
assertEquals(5, r.asScalarLong());
*/
cr = client.callProcedure("AGG_OF_ABS");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
assertEquals(5, r.asScalarLong());
/*
cr = client.callProcedure("ABS_OF_AGG");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
assertEquals(5, r.asScalarLong());
*/
initialLoad(client, "R1");
initialLoad(client, "R2");
// The next 2 queries failed in 3.4 with a runtime type exception about casting from VARCHAR reported in ENG-5004
cr = client.callProcedure("@AdHoc", "select * from P1, R2 where P1.ID = R2.ID AND ABS(P1.NUM) > 0");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
System.out.println(r);
assertEquals(8, r.getRowCount());
cr = client.callProcedure("@AdHoc", "select * from P1, R2 where P1.ID = R2.ID AND ABS(P1.NUM+0) > 0");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
System.out.println(r);
assertEquals(8, r.getRowCount());
// These next queries fail in 3.5 with a runtime type exception about unrecognized type related?/similar? to ENG-5004?
cr = client.callProcedure("@AdHoc", "select count(*) from P1, R2 where P1.ID = R2.ID AND ABS(R2.NUM+0) > 0");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
System.out.println(r);
assertEquals(8, r.asScalarLong());
cr = client.callProcedure("@AdHoc", "select count(*) from P1, R2 where P1.ID = R2.ID AND ABS(R2.NUM) > 0");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
System.out.println(r);
assertEquals(8, r.asScalarLong());
// */
// Test null propagation
cr = client.callProcedure("INSERT_NULL", 99);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
cr = client.callProcedure("INSERT_NULL", 98);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
cr = client.callProcedure("INSERT_NULL", 97);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
cr = client.callProcedure("INSERT_NULL", 96);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
cr = client.callProcedure("INSERT_NULL", 95);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
long resultA;
long resultB;
cr = client.callProcedure("@AdHoc", "select count(*) from P1 where NUM > 9");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
resultA = r.asScalarLong();
cr = client.callProcedure("@AdHoc", "select count(*) from P1 where ABS(NUM) > 9");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
resultB = r.asScalarLong();
assertEquals(resultA, resultB);
cr = client.callProcedure("@AdHoc", "select count(*) from P1 where ABS(0-NUM) > 9");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
resultB = r.asScalarLong();
assertEquals(resultA, resultB);
cr = client.callProcedure("@AdHoc", "select count(*) from P1 where not NUM > 9");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
resultA = r.asScalarLong();
cr = client.callProcedure("@AdHoc", "select count(*) from P1 where not ABS(0-NUM) > 9");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
resultB = r.asScalarLong();
assertEquals(resultA, resultB);
cr = client.callProcedure("@AdHoc", "select count(*) from P1 where not ABS(NUM) > 9");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
resultB = r.asScalarLong();
assertEquals(resultA, resultB);
cr = client.callProcedure("@AdHoc", "select count(*) from P1 where ID = -2 - NUM");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
resultA = r.asScalarLong();
// These cases were originally failed attempts to trigger ENG-3191, but they still seem worth trying.
cr = client.callProcedure("@AdHoc", "select count(*) from P1 where ABS(ID) = 2 + NUM");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
resultB = r.asScalarLong();
assertEquals(resultA, resultB);
cr = client.callProcedure("@AdHoc", "select count(*) from P1 where ABS(NUM) = (2 - ID)");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
resultB = r.asScalarLong();
assertEquals(resultA, resultB);
cr = client.callProcedure("@AdHoc", "select count(*) from P1 where ID < 0");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
resultA = r.asScalarLong();
cr = client.callProcedure("@AdHoc", "select count(*) from P1 where ABS(ID) = (0 - ID)");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
resultB = r.asScalarLong();
assertEquals(resultA, resultB);
// Here's the ENG-3191 case, all better now.
cr = client.callProcedure("@AdHoc", "select count(*) from P1 where ID = (0 - ABS(ID))");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
resultB = r.asScalarLong();
assertEquals(resultA, resultB);
// Here's the ENG-3196 case, all better now
cr = client.callProcedure("@AdHoc", "SELECT ABS(ID) AS ENG3196 FROM R1 ORDER BY (ID) LIMIT 5;");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
r = cr.getResults()[0];
System.out.println("DEBUG ENG-3196: " + r);
long resultCount = r.getRowCount();
assertEquals(5, resultCount);
r.advanceRow();
resultB = r.getLong(0);
assertEquals(14, resultB);
r.advanceToRow(4);
resultB = r.getLong(0);
assertEquals(10, resultB);
boolean caught = false;
caught = false;
try {
cr = client.callProcedure("@AdHoc", "select count(*) from P1 where not ABS(DESC) > 9");
assertTrue(cr.getStatus() != ClientResponse.SUCCESS);
} catch (ProcCallException e) {
String msg = e.getMessage();
assertTrue(msg.indexOf("incompatible data type") != -1);
caught = true;
}
assertTrue(caught);
caught = false;
try {
cr = client.callProcedure("@AdHoc", "select count(*) from P1 where not ABS(DESC) > 'ABC'");
assertTrue(cr.getStatus() != ClientResponse.SUCCESS);
} catch (ProcCallException e) {
String msg = e.getMessage();
assertTrue(msg.indexOf("incompatible data type") != -1);
caught = true;
}
assertTrue(caught);
cr = client.callProcedure("@AdHoc", "insert into R1 values (1, null, null, null, null)");
caught = false;
try {
// This should violate the UNIQUE ABS constraint without violating the primary key constraint.
cr = client.callProcedure("@AdHoc", "insert into R1 values (-1, null, null, null, null)");
} catch (ProcCallException e) {
String msg = e.getMessage();
assertTrue(msg.indexOf("violation of constraint") != -1);
caught = true;
}
// If the insert succeeds on VoltDB, the constraint failed to trigger.
// If the insert fails on HSQL, the test is invalid -- HSQL should not detect the subtle constraint violation we are trying to trigger.
assertEquals(!isHSQL(), caught);
}
use of org.voltdb.client.ClientResponse in project voltdb by VoltDB.
the class TestFunctionsSuite method testReplace.
public void testReplace() throws NoConnectionsException, IOException, ProcCallException {
System.out.println("STARTING test Replace");
Client client = getClient();
ClientResponse cr;
VoltTable result;
cr = client.callProcedure("P1.insert", 1, "foo", 1, 1.0, new Timestamp(1000000000000L));
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = client.callProcedure("REPLACE", "o", "XX", 1).getResults()[0];
assertTrue(result.advanceRow());
assertEquals("fXXXX", result.getString(1));
result = client.callProcedure("REPLACE", "o", null, 1).getResults()[0];
assertTrue(result.advanceRow());
if (isHSQL()) {
// NULL means empty string for Hsql
assertEquals("f", result.getString(1));
} else {
assertEquals(null, result.getString(1));
}
result = client.callProcedure("REPLACE", null, "XX", 1).getResults()[0];
assertTrue(result.advanceRow());
if (isHSQL()) {
// NULL means not change for the original string for Hsql
assertEquals("foo", result.getString(1));
} else {
assertEquals(null, result.getString(1));
}
result = client.callProcedure("REPLACE", "fo", "V", 1).getResults()[0];
assertTrue(result.advanceRow());
assertEquals("Vo", result.getString(1));
// UTF-8 String
cr = client.callProcedure("P1.insert", 2, "贾鑫@VoltDB", 1, 1.0, new Timestamp(1000000000000L));
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = client.callProcedure("REPLACE", "鑫", "XX", 2).getResults()[0];
assertTrue(result.advanceRow());
assertEquals("贾XX@VoltDB", result.getString(1));
}
use of org.voltdb.client.ClientResponse in project voltdb by VoltDB.
the class TestFunctionsSuite method orderFunctionRun.
private FunctionTestCase[] orderFunctionRun(Client client, String fname, int rowCount) throws Exception {
ClientResponse cr;
VoltTable result;
FunctionTestCase[] resultSet = new FunctionTestCase[numTypeNames.length * rowCount];
int ii = 0;
for (String numTypeName : numTypeNames) {
String proc = "ORDER_" + fname + "_" + numTypeName;
cr = client.callProcedure(proc);
result = cr.getResults()[0];
assertEquals(rowCount, result.getRowCount());
int jj = 0;
while (result.advanceRow()) {
try {
resultSet[ii] = new FunctionTestCase(proc + " ROW " + jj, result.getLong(0));
ii++;
} catch (IllegalArgumentException iae) {
// HSQL has been known to claim that the INTEGERNUM column is being returned as a float -- WTF!
resultSet[ii] = new FunctionTestCase(proc + " ROW " + jj, result.getDouble(0));
ii++;
}
// Extraneous columns beyond the first are provided for debug purposes only
for (int kk = 1; kk < result.getColumnCount(); ++kk) {
if (result.getColumnType(kk) == VoltType.FLOAT) {
System.out.println("DEBUG " + proc + " Extra column #" + kk + " = " + result.getDouble(kk));
} else if (result.getColumnType(kk) == VoltType.DECIMAL) {
System.out.println("DEBUG " + proc + " Extra column #" + kk + " = " + result.getDecimalAsBigDecimal(kk));
} else if (result.getColumnType(kk) == VoltType.STRING) {
System.out.println("DEBUG " + proc + " Extra column #" + kk + " = " + result.getString(kk));
} else {
System.out.println("DEBUG " + proc + " Extra column #" + kk + " = " + result.getLong(kk));
}
}
++jj;
}
}
return resultSet;
}
Aggregations