use of org.voltdb.VoltTableRow in project voltdb by VoltDB.
the class TestSQLTypesSuite method testSimpleExpressions.
//
// Apply a simple expression to each type that supports math.
//
public void testSimpleExpressions() throws NoConnectionsException, ProcCallException, IOException {
final Client client = this.getClient();
// Build a simple expression to do addition and select one column at
// a time, using that expression in a trivial projection.
// insert one row with the mid values
final Object[] params = new Object[COLS + 2];
params[0] = "NO_NULLS";
params[1] = pkey.incrementAndGet();
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] = "NO_NULLS";
params[1] = pkey.incrementAndGet();
for (int i = 0; i < COLS; i++) {
params[i + 2] = m_maxValues[i];
}
client.callProcedure("Insert", params);
// select A + 11 from no_nulls where A = mid_value
for (int i = 0; i < COLS; i++) {
if (!m_supportsMath[i])
continue;
// TODO see trac 236.
// Would be better here to select where the column under test
// equals its mid value - but decimals can't do that.
final String sql = "SELECT (" + m_columnNames[i] + " + 11) from NO_NULLS where " + m_columnNames[3] + " = " + m_midValues[3];
System.out.println("testsimpleexpression: " + sql);
final VoltTable[] result = client.callProcedure("@AdHoc", sql).getResults();
final VoltTableRow row = result[0].fetchRow(0);
final Object obj = row.get(0, m_types[i]);
final double expect = ((Number) m_midValues[i]).doubleValue() + 11;
final double got = ((Number) obj).doubleValue();
System.out.println("Expect: " + expect + " got: " + got);
assertEquals(expect, got);
}
}
use of org.voltdb.VoltTableRow in project voltdb by VoltDB.
the class TestSQLTypesSuite method testInsertMaxValues_No_Nulls.
//
// Round trip the maximum value
//
public void testInsertMaxValues_No_Nulls() throws NoConnectionsException, ProcCallException, IOException {
final Client client = this.getClient();
// Insert a MAX value for each column. For the first
// row, insert MAX in the first column, for the 5th row
// in the 5 column, etc.
final Object[] params = new Object[COLS + 2];
for (int k = 0; k < COLS; ++k) {
// build the parameter list as described above
params[0] = "";
params[1] = pkey.incrementAndGet();
for (int i = 0; i < COLS; i++) {
params[i + 2] = (i == k) ? m_maxValues[i] : m_midValues[i];
assert (params[i + 2] != null);
}
// Perform the inserts and execute selects, verifying the
// content of the select matches the parameters passed to
// insert
System.out.println("testInsertMaxValues: " + k + " MAX type is " + m_types[k]);
params[0] = "NO_NULLS";
client.callProcedure("Insert", params);
// verify that the row was updated
final VoltTable[] result = client.callProcedure("Select", "NO_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(!row.wasNull());
assertTrue(comparisonHelper(obj, params[i + 2], m_types[i]));
}
}
}
use of org.voltdb.VoltTableRow in project voltdb by VoltDB.
the class TestSQLFeaturesSuite method testUTF8.
/** Verify that non-latin-1 characters can be stored and retrieved */
public void testUTF8() throws IOException {
Client client = getClient();
final String testString = "並丧";
try {
client.callProcedure("ORDER_LINE.insert", 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1.5, testString);
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);
String resultString = row.getString("OL_DIST_INFO");
assertEquals(testString, resultString);
// reset
client.callProcedure("@AdHoc", "delete from ORDER_LINE;");
// Intentionally using a one byte string to make sure length preceded strings are handled correctly in the EE.
client.callProcedure("ORDER_LINE.insert", 2L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 1.5, "a");
client.callProcedure("ORDER_LINE.insert", 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1.5, testString);
client.callProcedure("ORDER_LINE.insert", 3L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 1.5, "def");
results = client.callProcedure("SelectOrderLineByDistInfo", testString).getResults();
assertEquals(1, results.length);
table = results[0];
assertTrue(table.getRowCount() == 1);
row = table.fetchRow(0);
resultString = row.getString("OL_DIST_INFO");
assertEquals(testString, resultString);
} catch (ProcCallException e) {
e.printStackTrace();
fail();
} catch (IOException e) {
e.printStackTrace();
fail();
}
}
use of org.voltdb.VoltTableRow 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]));
}
}
}
use of org.voltdb.VoltTableRow in project voltdb by VoltDB.
the class TestSQLTypesSuite method testMissingAttributeInsert_With_Null_Defaults.
public void testMissingAttributeInsert_With_Null_Defaults() throws NoConnectionsException, ProcCallException, IOException {
Client client = this.getClient();
Object[] params = new Object[COLS + 2];
params[0] = "WITH_NULL_DEFAULTS";
params[1] = pkey.incrementAndGet();
for (int i = 0; i < COLS; i++) {
params[i + 2] = m_nullValues[i];
assert (params[i + 2] != null);
}
try {
client.callProcedure("Insert", params);
} catch (ProcCallException e) {
e.printStackTrace();
fail();
} catch (NoConnectionsException e) {
e.printStackTrace();
fail();
}
VoltTable[] result = client.callProcedure("Select", "WITH_NULL_DEFAULTS", pkey.get()).getResults();
VoltTableRow row = result[0].fetchRow(0);
for (int i = 0; i < COLS; ++i) {
Object obj = row.get(i + 1, m_types[i]);
assertTrue("Expected to be equal: (" + obj + ", " + params[i + 2] + ")", comparisonHelper(obj, params[i + 2], m_types[i]));
}
}
Aggregations