use of org.voltdb.client.ClientResponse in project voltdb by VoltDB.
the class TestFunctionsSuite method whereVarCharCastRun.
private FunctionVarCharTestCase[] whereVarCharCastRun(Client client, Set<String> filters) throws Exception {
ClientResponse cr;
VoltTable result;
FunctionVarCharTestCase[] resultSet = new FunctionVarCharTestCase[numTypeNames.length * filters.size()];
int kk = 0;
int jj = 0;
for (String numTypeName : numTypeNames) {
for (String filter : filters) {
String proc = "WHERE_VARCHAR_CAST_" + numTypeName;
String param = filter;
String[] decimalParts = filter.split("\\.");
if (jj < FLOATCOLINDEX) {
// Truncate an integer decimal before the decimal point to match an integer column.
if (decimalParts.length < 2 || decimalParts[1].equals("0")) {
param = decimalParts[0];
}
// Else fall through to pass a fractional decimal as it is
// to purposely force a mismatch with an integer column.
} else if (jj > FLOATCOLINDEX) {
// Pad the decimal string.
if (decimalParts.length < 2 || decimalParts[1].equals("0")) {
param = decimalParts[0] + ".000000000000";
} else {
param = decimalParts[0] + "." + (decimalParts[1] + "000000000000").substring(0, 12);
}
} else // Handle float-to-string cast formatting
// TODO: this code may not be right for multiples of 10 or decimals of magnitude < .1
// which we don't happen to be using currently to drive this numeric test framework.
{
if (decimalParts.length < 2 || decimalParts[1].equals("0")) {
if (decimalParts[0].equals("0")) {
param = "0E0";
} else {
int signedDigitWidth = (decimalParts[0].charAt(0) == '-') ? 2 : 1;
param = decimalParts[0].substring(0, signedDigitWidth) + "." + decimalParts[0].substring(signedDigitWidth) + "E" + (decimalParts[0].length() - signedDigitWidth);
}
} else {
if (decimalParts[0].equals("0")) {
param = decimalParts[1].substring(0, 1) + "." + decimalParts[1].substring(1) + "E-1";
} else if (decimalParts[0].equals("-0")) {
param = "-" + decimalParts[1].substring(0, 1) + "." + decimalParts[1].substring(1) + "E-1";
} else {
int signedDigitWidth = (decimalParts[0].charAt(0) == '-') ? 2 : 1;
param = decimalParts[0].substring(0, signedDigitWidth) + "." + decimalParts[0].substring(signedDigitWidth) + decimalParts[1] + "E" + (decimalParts[0].length() - signedDigitWidth);
}
}
}
cr = client.callProcedure(proc, param);
result = cr.getResults()[0];
int rowCount = result.getRowCount();
assertEquals(rowCount, 1);
long tupleCount = result.asScalarLong();
//*VERBOSIFY TO DEBUG:*/ System.out.println("DEBUG " + proc + " " + numTypeName + " GOT count " + tupleCount);
resultSet[kk++] = new FunctionVarCharTestCase(proc, filter, tupleCount);
}
++jj;
}
return resultSet;
}
use of org.voltdb.client.ClientResponse in project voltdb by VoltDB.
the class TestFunctionsSuite method testRepeat.
public void testRepeat() throws NoConnectionsException, IOException, ProcCallException {
System.out.println("STARTING test Repeat");
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());
cr = client.callProcedure("REPEAT", 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("REPEAT", 1, 1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals("foo", result.getString(1));
cr = client.callProcedure("REPEAT", 3, 1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals("foofoofoo", result.getString(1));
if (!isHSQL()) {
String expectedError = "VOLTDB ERROR: SQL ERROR\\s*+The result of the REPEAT function is larger than the maximum size allowed " + "for strings \\(1048576 bytes\\)\\. Reduce either the string size or repetition count\\.";
verifyProcFails(client, expectedError, "REPEAT", 10000000, 1);
// The multiply needed to do the size check for this call to REPEAT will
// overflow a 64-bit signed int. This was ticket ENG-11559.
verifyProcFails(client, expectedError, "REPEAT", 4611686018427387903L, 1);
}
// Make sure that repeat of an empty string doesn't take a long time
// This verifies the fix for ENG-12118
long startTime = System.nanoTime();
cr = client.callProcedure("@AdHoc", "select repeat('', 10000000000000) from P1 limit 1");
assertContentOfTable(new Object[][] { { "" } }, cr.getResults()[0]);
long elapsedNanos = System.nanoTime() - startTime;
// It should take less than a minute (much much less) to complete this query
assertTrue("Repeat with empty string took too long!", elapsedNanos < 1000000000L * 60L);
}
use of org.voltdb.client.ClientResponse in project voltdb by VoltDB.
the class TestFunctionsSuite method testAbsWithLimit_ENG3572.
public void testAbsWithLimit_ENG3572() throws Exception {
System.out.println("STARTING testAbsWithLimit_ENG3572");
Client client = getClient();
/*
CREATE TABLE P1 (
ID INTEGER DEFAULT '0' NOT NULL,
DESC VARCHAR(300),
NUM INTEGER,
RATIO FLOAT,
PAST TIMESTAMP DEFAULT NULL,
PRIMARY KEY (ID)
);
*/
ClientResponse cr = null;
cr = client.callProcedure("@AdHoc", "select abs(NUM) from P1 where ID = 0 limit 1");
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
}
use of org.voltdb.client.ClientResponse in project voltdb by VoltDB.
the class TestFunctionsForVoltDBSuite method subtestDECODEVeryLong.
private void subtestDECODEVeryLong() throws NoConnectionsException, IOException, ProcCallException {
System.out.println("STARTING DECODE Exceed Limit");
Client client = getClient();
ClientResponse cr;
VoltTable result;
cr = client.callProcedure("@AdHoc", "Delete from P1;");
cr = client.callProcedure("P1.insert", 1, "zheng", 10, 1.1);
cr = client.callProcedure("P1.insert", 2, "li", 10, 1.1);
cr = client.callProcedure("P1.insert", 3, null, 10, 1.1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
// null case
cr = client.callProcedure("DECODEVERYLONG", 3);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
assertEquals("where", result.getString(1));
}
use of org.voltdb.client.ClientResponse in project voltdb by VoltDB.
the class TestFunctionsForVoltDBSuite method testTRUNCATE.
public void testTRUNCATE() throws Exception {
System.out.println("STARTING TRUNCATE with timestamp");
Client client = getClient();
ClientResponse cr;
VoltTable result;
VoltDB.setDefaultTimezone();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
//System.out.println(dateFormat.getTimeZone());
Date time = null;
// Test Standard TRUNCATE function for floating numbers
Exception ex = null;
try {
cr = client.callProcedure("@AdHoc", "select TRUNCATE (1.2, 1), TM from P2 where id = 0");
} catch (Exception e) {
System.out.println(e.getMessage());
ex = e;
} finally {
assertNotNull(ex);
assertTrue((ex.getMessage().contains("PlanningErrorException")));
assertTrue((ex.getMessage().contains("TRUNCATE")));
}
// Test date before Gregorian calendar beginning.
cr = client.callProcedure("P2.insert", 0, Timestamp.valueOf("1582-03-06 13:56:40.123456"));
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
ex = null;
try {
cr = client.callProcedure("TRUNCATE", 0);
} catch (Exception e) {
System.out.println(e.getMessage());
ex = e;
} finally {
assertNotNull(ex);
assertTrue((ex.getMessage().contains("SQL ERROR")));
}
// Test Timestamp Null value
cr = client.callProcedure("P2.insert", 1, null);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
cr = client.callProcedure("TRUNCATE", 1);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
for (int i = 0; i < 11; i++) {
assertNull(result.getTimestampAsTimestamp(i));
}
// Test normal TRUNCATE functionalities
cr = client.callProcedure("P2.insert", 2, Timestamp.valueOf("2001-09-09 01:46:40.035123"));
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
cr = client.callProcedure("TRUNCATE", 2);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
cr = client.callProcedure("TRUNCATE", 2);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
time = dateFormat.parse("2001-01-01 00:00:00.000");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(0));
time = dateFormat.parse("2001-07-01 00:00:00.000");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(1));
time = dateFormat.parse("2001-09-01 00:00:00.000");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(2));
time = dateFormat.parse("2001-09-09 00:00:00.000");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(3));
time = dateFormat.parse("2001-09-09 01:00:00.000");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(4));
time = dateFormat.parse("2001-09-09 01:46:00.000");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(5));
time = dateFormat.parse("2001-09-09 01:46:40.000");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(6));
time = dateFormat.parse("2001-09-09 01:46:40.035");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(7));
time = dateFormat.parse("2001-09-09 01:46:40.035");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(8));
assertEquals(1000000000035123L, result.getTimestampAsLong(9));
assertEquals(1000000000035123L, result.getTimestampAsLong(10));
// Test time before EPOCH
cr = client.callProcedure("P2.insert", 3, Timestamp.valueOf("1583-11-24 13:56:40.123456"));
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
cr = client.callProcedure("TRUNCATE", 3);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
time = dateFormat.parse("1583-01-01 00:00:00.000");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(0));
time = dateFormat.parse("1583-10-01 00:00:00.000");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(1));
time = dateFormat.parse("1583-11-01 00:00:00.000");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(2));
time = dateFormat.parse("1583-11-24 00:00:00.000");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(3));
time = dateFormat.parse("1583-11-24 13:00:00.000");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(4));
time = dateFormat.parse("1583-11-24 13:56:00.000");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(5));
time = dateFormat.parse("1583-11-24 13:56:40.000");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(6));
time = dateFormat.parse("1583-11-24 13:56:40.123");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(7));
time = dateFormat.parse("1583-11-24 13:56:40.123");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(7));
assertEquals(-12184250599876544L, result.getTimestampAsLong(9));
assertEquals(-12184250599876544L, result.getTimestampAsLong(10));
// Test date in far future
cr = client.callProcedure("P2.insert", 4, Timestamp.valueOf("2608-03-06 13:56:40.123456"));
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
cr = client.callProcedure("TRUNCATE", 4);
assertEquals(ClientResponse.SUCCESS, cr.getStatus());
result = cr.getResults()[0];
assertEquals(1, result.getRowCount());
assertTrue(result.advanceRow());
time = dateFormat.parse("2608-01-01 00:00:00.000");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(0));
time = dateFormat.parse("2608-01-01 00:00:00.000");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(1));
time = dateFormat.parse("2608-03-01 00:00:00.000");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(2));
time = dateFormat.parse("2608-03-06 00:00:00.000");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(3));
time = dateFormat.parse("2608-03-06 13:00:00.000");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(4));
time = dateFormat.parse("2608-03-06 13:56:00.000");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(5));
time = dateFormat.parse("2608-03-06 13:56:40.000");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(6));
time = dateFormat.parse("2608-03-06 13:56:40.123");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(7));
time = dateFormat.parse("2608-03-06 13:56:40.123");
assertEquals(time.getTime() * 1000, result.getTimestampAsLong(7));
assertEquals(20138939800123456L, result.getTimestampAsLong(9));
assertEquals(20138939800123456L, result.getTimestampAsLong(10));
}
Aggregations