Search in sources :

Example 36 with ProcCallException

use of org.voltdb.client.ProcCallException in project voltdb by VoltDB.

the class TestFunctionsForVoltDBSuite method subtestDECODE.

private void subtestDECODE() throws NoConnectionsException, IOException, ProcCallException {
    System.out.println("STARTING DECODE");
    Client client = getClient();
    ClientResponse cr;
    VoltTable result;
    cr = client.callProcedure("@AdHoc", "Delete from P1;");
    cr = client.callProcedure("P1.insert", 1, "IBM", 10, 1.1);
    cr = client.callProcedure("P1.insert", 2, "Microsoft", 10, 1.1);
    cr = client.callProcedure("P1.insert", 3, "Hewlett Packard", 10, 1.1);
    cr = client.callProcedure("P1.insert", 4, "Gateway", 10, 1.1);
    cr = client.callProcedure("P1.insert", 5, null, 10, 1.1);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    // match 1st condition
    cr = client.callProcedure("DECODE", 1);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    result = cr.getResults()[0];
    assertEquals(1, result.getRowCount());
    assertTrue(result.advanceRow());
    assertEquals("zheng", result.getString(1));
    // match 2nd condition
    cr = client.callProcedure("DECODE", 2);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    result = cr.getResults()[0];
    assertEquals(1, result.getRowCount());
    assertTrue(result.advanceRow());
    assertEquals("li", result.getString(1));
    // match 3rd condition
    cr = client.callProcedure("DECODE", 3);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    result = cr.getResults()[0];
    assertEquals(1, result.getRowCount());
    assertTrue(result.advanceRow());
    assertEquals("at", result.getString(1));
    // match 4th condition
    cr = client.callProcedure("DECODE", 4);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    result = cr.getResults()[0];
    assertEquals(1, result.getRowCount());
    assertTrue(result.advanceRow());
    assertEquals("VoltDB", result.getString(1));
    // null case
    cr = client.callProcedure("DECODE", 5);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    result = cr.getResults()[0];
    assertEquals(1, result.getRowCount());
    assertTrue(result.advanceRow());
    assertEquals("where", result.getString(1));
    // param cases
    // For project.addStmtProcedure("DECODE_PARAM_INFER_STRING", "select desc,  DECODE (desc,?,?,desc) from P1 where id = ?");
    cr = client.callProcedure("DECODE_PARAM_INFER_STRING", "Gateway", "You got it!", 4);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    result = cr.getResults()[0];
    assertEquals(1, result.getRowCount());
    assertTrue(result.advanceRow());
    assertEquals("You got it!", result.getString(1));
    // For project.addStmtProcedure("DECODE_PARAM_INFER_INT", "select desc,  DECODE (id,?,?,id) from P1 where id = ?");
    cr = client.callProcedure("DECODE_PARAM_INFER_INT", 4, -4, 4);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    result = cr.getResults()[0];
    assertEquals(1, result.getRowCount());
    assertTrue(result.advanceRow());
    assertEquals(-4, result.getLong(1));
    // For project.addStmtProcedure("DECODE_PARAM_INFER_DEFAULT", "select desc,  DECODE (?,?,?,?) from P1 where id = ?");
    cr = client.callProcedure("DECODE_PARAM_INFER_DEFAULT", "Gateway", "Gateway", "You got it!", "You ain't got it!", 4);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    result = cr.getResults()[0];
    assertEquals(1, result.getRowCount());
    assertTrue(result.advanceRow());
    assertEquals("You got it!", result.getString(1));
    // For project.addStmtProcedure("DECODE_PARAM_INFER_CONFLICTING", "select desc,  DECODE (id,1,?,2,99,'99') from P1 where id = ?");
    cr = client.callProcedure("DECODE_PARAM_INFER_CONFLICTING", "贾鑫?贾鑫!", 1);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    result = cr.getResults()[0];
    assertEquals(1, result.getRowCount());
    assertTrue(result.advanceRow());
    assertEquals("贾鑫?贾鑫!", result.getString(1));
    // For project.addStmtProcedure("DECODE_PARAM_INFER_CONFLICTING", "select desc,  DECODE (id,1,?,2,99,'99') from P1 where id = ?");
    try {
        cr = client.callProcedure("DECODE_PARAM_INFER_CONFLICTING", 1000, 1);
        assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    } catch (ProcCallException pce) {
        fail("Should have thrown unfortunate type error.");
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) ProcCallException(org.voltdb.client.ProcCallException)

Example 37 with ProcCallException

use of org.voltdb.client.ProcCallException 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"));
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) ProcCallException(org.voltdb.client.ProcCallException)

Example 38 with ProcCallException

use of org.voltdb.client.ProcCallException 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);
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) ProcCallException(org.voltdb.client.ProcCallException)

Example 39 with ProcCallException

use of org.voltdb.client.ProcCallException in project voltdb by VoltDB.

the class TestFunctionsSuite method testCoalesce.

public void testCoalesce() throws Exception {
    System.out.println("STARTING test COALESCE function...");
    Client cl = getClient();
    // one row with three sets of nulls
    cl.callProcedure("@AdHoc", "insert into C_NULL(ID) values (0);");
    // one row with one set of non-null columns and two sets of nulls
    cl.callProcedure("@AdHoc", "insert into C_NULL(ID,S1,I1,F1,D1,V1,T1) values (1,1,1,1,1,'1',100000)");
    // TODO: below is wrong, because the null timestamp will be regarded as an invalid input by hsql
    //cl.callProcedure("C_NULL.insert", 1,1,1,1,1,"1",new Timestamp(1000000000000L), null, null, null, null, null);
    // two sets of non-null columns and one set of null column
    cl.callProcedure("@AdHoc", "insert into C_NULL(ID,S1,I1,F1,D1,V1,T1,I2,F2,D2,V2,T2)" + " values (2,1,1,1,1,'1',100000,2,2,2,'2',200000)");
    // three set non-nulls
    cl.callProcedure("C_NULL.insert", 3, 1, 1, 1, 1, "1", new Timestamp(1000000000000L), 2, 2, 2, "2", new Timestamp(2000000000000L), 3, 3, 3, "3", new Timestamp(3000000000000L));
    doTestTwoColCoalesce(cl, "I1", "I2");
    doTestTwoColCoalesce(cl, "F1", "F2");
    doTestTwoColCoalesce(cl, "D1", "D2");
    doTestTwoColCoalesce(cl, "V1", "V2");
    doTestTwoColCoalesce(cl, "T1", "T2");
    doTestThreeColCoalesce(cl, "I1", "I2", "I3", "100");
    doTestThreeColCoalesce(cl, "F1", "F2", "F3", "100.0");
    doTestThreeColCoalesce(cl, "D1", "D2", "D3", "100.0");
    doTestThreeColCoalesce(cl, "V1", "V2", "V3", "'hahaha'");
    doTestThreeColCoalesce(cl, "T1", "T2", "T3", "CAST ('2014-07-09 00:00:00.000000' as TIMESTAMP)");
    // test compatiable types
    doTestThreeColCoalesce(cl, "S1", "I2", "I3", "100");
    doTestThreeColCoalesce(cl, "S1", "F2", "D3", "100.0");
    doTestThreeColCoalesce(cl, "I1", "F2", "D3", "100.0");
    // TODO: Is the exception throwed by coalesce? Or by decode?
    try {
        doTestThreeColCoalesce(cl, "S1", "I2", "V3", "100");
        fail();
    } catch (ProcCallException pcex) {
        assertTrue(pcex.getMessage().contains("incompatible data types"));
    }
    try {
        doTestThreeColCoalesce(cl, "S1", "I2", "T3", "100");
        fail();
    } catch (ProcCallException pcex) {
        assertTrue(pcex.getMessage().contains("incompatible data types"));
    }
}
Also used : Client(org.voltdb.client.Client) Timestamp(java.sql.Timestamp) ProcCallException(org.voltdb.client.ProcCallException)

Example 40 with ProcCallException

use of org.voltdb.client.ProcCallException in project voltdb by VoltDB.

the class TestFunctionsForVoltDBSuite method testRegexpPosition.

public void testRegexpPosition() throws Exception {
    System.out.println("STARTING testRegexpPosition");
    Client client = getClient();
    ClientResponse cr = null;
    VoltTable vt = null;
    /*
            "CREATE TABLE P1 ( " +
            "ID INTEGER DEFAULT 0 NOT NULL, " +
            "DESC VARCHAR(300), " +
            "NUM INTEGER, " +
            "RATIO FLOAT, " +
            "PAST TIMESTAMP DEFAULT NULL, " +
            "PRIMARY KEY (ID) ); " +
         */
    cr = client.callProcedure("@AdHoc", "INSERT INTO P1 (ID, DESC) VALUES (200, 'TEST reGexp_poSiTion123456Test')");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    vt = client.callProcedure("@AdHoc", "SELECT REGEXP_POSITION(DESC, 'TEST') FROM P1 WHERE REGEXP_POSITION(DESC, 'TEST') > 0;").getResults()[0];
    assertTrue(vt.advanceRow());
    assertEquals(1, vt.asScalarLong());
    vt = client.callProcedure("@AdHoc", "SELECT REGEXP_POSITION(DESC, '[a-z](\\d+)[a-z]') FROM P1 WHERE REGEXP_POSITION(DESC, '[a-z](\\d+)[a-z]') > 0").getResults()[0];
    assertFalse(vt.advanceRow());
    vt = client.callProcedure("@AdHoc", "SELECT REGEXP_POSITION(DESC, '[a-z](\\d+)[A-Z]') FROM P1 WHERE REGEXP_POSITION(DESC, '[a-z](\\d+)[A-Z]') > 0").getResults()[0];
    assertTrue(vt.advanceRow());
    assertEquals(20, vt.asScalarLong());
    vt = client.callProcedure("@AdHoc", "SELECT REGEXP_POSITION(DESC, '[a-z](\\d+)[a-z]', 'i') FROM P1 WHERE REGEXP_POSITION(DESC, '[a-z](\\d+)[a-z]', 'i') > 0").getResults()[0];
    assertTrue(vt.advanceRow());
    assertEquals(20, vt.asScalarLong());
    vt = client.callProcedure("@AdHoc", "SELECT REGEXP_POSITION(DESC, '[a-z](\\d+)[a-z]', 'ci') FROM P1 WHERE REGEXP_POSITION(DESC, '[a-z](\\d+)[A-Z]') > 0").getResults()[0];
    assertTrue(vt.advanceRow());
    assertEquals(20, vt.asScalarLong());
    vt = client.callProcedure("@AdHoc", "SELECT REGEXP_POSITION(DESC, '[a-z](\\d+)[a-z]', 'iiccii') FROM P1 WHERE REGEXP_POSITION(DESC, '[a-z](\\d+)[A-Z]') > 0").getResults()[0];
    assertTrue(vt.advanceRow());
    assertEquals(20, vt.asScalarLong());
    boolean expectedExceptionThrowed = false;
    try {
        client.callProcedure("@AdHoc", "SELECT REGEXP_POSITION(DESC, '[a-z](a]') FROM P1 WHERE REGEXP_POSITION(DESC, '[a-z](a]') > 0");
        assertFalse("Expected exception for illegal regular expression in regexp_position.", true);
    } catch (ProcCallException e) {
        assertEquals(ClientResponse.GRACEFUL_FAILURE, e.getClientResponse().getStatus());
        assertTrue(e.getClientResponse().getStatusString().contains("Regular Expression Compilation Error: missing closing parenthesis"));
        expectedExceptionThrowed = true;
    }
    assertTrue(expectedExceptionThrowed);
    expectedExceptionThrowed = false;
    try {
        client.callProcedure("@AdHoc", "SELECT REGEXP_POSITION(DESC, '[a-z](\\d+)[A-Z]', 'k') FROM P1 WHERE REGEXP_POSITION(DESC, '[a-z](\\d+)[A-Z]', 'k') > 0");
        assertFalse("Expected exception for illegal match flag in regexp_position.", true);
    } catch (ProcCallException e) {
        assertEquals(ClientResponse.GRACEFUL_FAILURE, e.getClientResponse().getStatus());
        assertTrue(e.getClientResponse().getStatusString().contains("Illegal Match Flags"));
        expectedExceptionThrowed = true;
    }
    assertTrue(expectedExceptionThrowed);
    // test null strings
    vt = client.callProcedure("@AdHoc", "SELECT REGEXP_POSITION(DESC, NULL) FROM P1 WHERE ID = 200").getResults()[0];
    assertTrue(vt.advanceRow());
    vt.getLong(0);
    assertTrue(vt.wasNull());
    cr = client.callProcedure("@AdHoc", "INSERT INTO P1 (ID, DESC) VALUES (201, NULL);");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    vt = client.callProcedure("@AdHoc", "SELECT REGEXP_POSITION(DESC, 'TEST') FROM P1 WHERE ID = 201").getResults()[0];
    assertTrue(vt.advanceRow());
    vt.getLong(0);
    assertTrue(vt.wasNull());
    // test utf-8 strings
    cr = client.callProcedure("@AdHoc", "INSERT INTO P1 (ID, DESC) VALUES (202, 'vVoltDBBB贾贾贾');");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    vt = client.callProcedure("@AdHoc", "SELECT REGEXP_POSITION(DESC, '[A-Z]贾') FROM P1 WHERE ID = 202;").getResults()[0];
    assertTrue(vt.advanceRow());
    assertEquals(9, vt.getLong(0));
    vt = client.callProcedure("@AdHoc", "SELECT REGEXP_POSITION(DESC, '[a-z]贾', 'i') FROM P1 WHERE ID = 202;").getResults()[0];
    assertTrue(vt.advanceRow());
    assertEquals(9, vt.getLong(0));
    // clear test data
    cr = client.callProcedure("@AdHoc", "DELETE FROM P1 WHERE ID IN (200, 201, 202);");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) ProcCallException(org.voltdb.client.ProcCallException)

Aggregations

ProcCallException (org.voltdb.client.ProcCallException)239 Client (org.voltdb.client.Client)151 VoltTable (org.voltdb.VoltTable)120 ClientResponse (org.voltdb.client.ClientResponse)91 IOException (java.io.IOException)81 NoConnectionsException (org.voltdb.client.NoConnectionsException)55 Test (org.junit.Test)44 Configuration (org.voltdb.VoltDB.Configuration)41 VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)36 File (java.io.File)21 InMemoryJarfile (org.voltdb.utils.InMemoryJarfile)19 VoltCompiler (org.voltdb.compiler.VoltCompiler)15 VoltDB (org.voltdb.VoltDB)10 VoltTableRow (org.voltdb.VoltTableRow)10 Timestamp (java.sql.Timestamp)5 TimestampType (org.voltdb.types.TimestampType)5 BigDecimal (java.math.BigDecimal)4 Date (java.util.Date)4 HashSet (java.util.HashSet)3 ClientResponseImpl (org.voltdb.ClientResponseImpl)3