Search in sources :

Example 71 with ClientResponse

use of org.voltdb.client.ClientResponse 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)

Example 72 with ClientResponse

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

the class TestFunctionsForVoltDBSuite method subtestDECODEWithNULL.

private void subtestDECODEWithNULL() throws NoConnectionsException, IOException, ProcCallException {
    System.out.println("STARTING DECODE with NULL");
    Client client = getClient();
    ClientResponse cr;
    cr = client.callProcedure("@AdHoc", "Delete from R3;");
    cr = client.callProcedure("R3.insert", 1, 1, 1, 1, 1, 1.1, "2013-07-18 02:00:00.123457", "IBM", 1);
    cr = client.callProcedure("R3.insert", 2, null, null, null, null, null, null, null, null);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    // Stored procedure tests
    cr = client.callProcedure("TestDecodeNull", 1);
    checkDecodeNullResult(cr, new String[] { "1", "1", "1", "1", "1.1", "tm", "IBM", "1" });
    cr = client.callProcedure("TestDecodeNull", 2);
    checkDecodeNullResult(cr, new String[] { "null tiny", "null small", "null num", "null big", "null ratio", "null tm", "null var", "null dec" });
    cr = client.callProcedure("TestDecodeNullParam", null, null, null, null, null, null, null, null, 1);
    checkDecodeNullResult(cr, new String[] { "1", "1", "1", "1", "1.1", "tm", "IBM", "1" });
    cr = client.callProcedure("TestDecodeNullParam", null, null, null, null, null, null, null, null, 2);
    checkDecodeNullResult(cr, new String[] { "null tiny", "null small", "null num", "null big", "null ratio", "null tm", "null var", "null dec" });
    // Test CSV_NULL for params
    cr = client.callProcedure("TestDecodeNullParam", "\\N", "\\N", "\\N", "\\N", "\\N", "\\N", "\\N", "\\N", 1);
    checkDecodeNullResult(cr, new String[] { "1", "1", "1", "1", "1.1", "tm", "IBM", "1" });
    cr = client.callProcedure("TestDecodeNullParam", "\\N", "\\N", "\\N", "\\N", "\\N", "\\N", "\\N", "\\N", 2);
    checkDecodeNullResult(cr, new String[] { "null tiny", "null small", "null num", "null big", "null ratio", "null tm", "null var", "null dec" });
    // AdHoc queries tests
    cr = client.callProcedure("@AdHoc", "select DECODE(tiny, NULL, 'null tiny', tiny)," + "DECODE(small, NULL, 'null small', small), DECODE(num, NULL, 'null num', num),  " + "DECODE(big, NULL, 'null big', big), DECODE(ratio, NULL, 'null ratio', ratio),  " + "DECODE(tm, NULL, 'null tm', 'tm'), DECODE(var, NULL, 'null var', var), " + "DECODE(dec, NULL, 'null dec', dec) from R3 where id = 1");
    checkDecodeNullResult(cr, new String[] { "1", "1", "1", "1", "1.1", "tm", "IBM", "1" });
    cr = client.callProcedure("@AdHoc", "select DECODE(tiny, NULL, 'null tiny', tiny)," + "DECODE(small, NULL, 'null small', small), DECODE(num, NULL, 'null num', num),  " + "DECODE(big, NULL, 'null big', big), DECODE(ratio, NULL, 'null ratio', ratio),  " + "DECODE(tm, NULL, 'null tm', 'tm'), DECODE(var, NULL, 'null var', var), " + "DECODE(dec, NULL, 'null dec', dec) from R3 where id = 2");
    checkDecodeNullResult(cr, new String[] { "null tiny", "null small", "null num", "null big", "null ratio", "null tm", "null var", "null dec" });
    cr = client.callProcedure("P2.insert", 1, new Timestamp(1000L));
    cr = client.callProcedure("P2.insert", 2, null);
    // Test timestamp
    cr = client.callProcedure("TestDecodeNullTimestamp", 1);
    checkDecodeNullResult(cr, new String[] { "2013-07-18 02:00:00.123457" });
    // Test NULL as the second search expression.
    cr = client.callProcedure("@AdHoc", "select DECODE(tiny, -1, -1, NULL, 0, tiny)," + "DECODE(small, -1, -1, NULL, 0, small), DECODE(num, -1, -1, NULL, 0, num),  " + "DECODE(big, -1, -1, NULL, 0, big) from R3 where id = 1");
    checkDecodeNullResult(cr, new Long[] { 1L, 1L, 1L, 1L });
    cr = client.callProcedure("@AdHoc", "select DECODE(tiny, -1, -1, NULL, 0, tiny)," + "DECODE(small, -1, -1, NULL, 0, small), DECODE(num, -1, -1, NULL, 0, num),  " + "DECODE(big, -1, -1, NULL, 0, big) from R3 where id = 2");
    checkDecodeNullResult(cr, new Long[] { 0L, 0L, 0L, 0L });
    // Test Null return type
    cr = client.callProcedure("@AdHoc", "select DECODE(tiny, 4, 5, NULL, NULL, 10) " + " from R3 where id = 2");
    assertTrue(cr.getResults()[0].getRowCount() == 1);
    assertTrue(cr.getResults()[0].advanceRow());
    assertEquals(Integer.MIN_VALUE, cr.getResults()[0].getLong(0));
    verifyStmtFails(client, "select DECODE(tiny, 4, 5, NULL, 'tiny null', tiny)  from R3 where id = 2", "Could not convert to number");
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Client(org.voltdb.client.Client) BadParamTypesForTimestamp(org.voltdb_testprocs.regressionsuites.failureprocs.BadParamTypesForTimestamp) Timestamp(java.sql.Timestamp)

Example 73 with ClientResponse

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

the class TestFunctionsForVoltDBSuite method testExplicitErrorUDF.

public void testExplicitErrorUDF() throws Exception {
    System.out.println("STARTING testExplicitErrorUDF");
    Client client = getClient();
    ProcedureCallback callback = new ProcedureCallback() {

        @Override
        public void clientCallback(ClientResponse clientResponse) throws Exception {
            if (clientResponse.getStatus() != ClientResponse.SUCCESS) {
                throw new RuntimeException("Failed with response: " + clientResponse.getStatusString());
            }
        }
    };
    /*
        CREATE TABLE P1 (
                ID INTEGER DEFAULT '0' NOT NULL,
                DESC VARCHAR(300),
                NUM INTEGER,
                RATIO FLOAT,
                PRIMARY KEY (ID)
                );
        */
    for (int id = 7; id < 15; id++) {
        client.callProcedure(callback, "P1.insert", -id, "X" + String.valueOf(id), 10, 1.1);
        client.drain();
    }
    ClientResponse cr = null;
    // Exercise basic syntax without runtime invocation.
    cr = client.callProcedure("@AdHoc", "select SQL_ERROR(123) from P1 where ID = 0");
    assertEquals(cr.getStatus(), ClientResponse.SUCCESS);
    cr = client.callProcedure("@AdHoc", "select SQL_ERROR('abc') from P1 where ID = 0");
    assertEquals(cr.getStatus(), ClientResponse.SUCCESS);
    cr = client.callProcedure("@AdHoc", "select SQL_ERROR(123, 'abc') from P1 where ID = 0");
    assertEquals(cr.getStatus(), ClientResponse.SUCCESS);
    // negative tests
    verifyStmtFails(client, "select SQL_ERROR(123, 'abc') from P1", "abc");
    verifyStmtFails(client, "select SQL_ERROR('abc') from P1", "abc");
    verifyStmtFails(client, "select SQL_ERROR(123, 123) from P1", ".*SQL ERROR\n.*VARCHAR.*");
    verifyStmtFails(client, "select SQL_ERROR(123.5) from P1", "Type DECIMAL can't be cast as BIGINT");
    verifyStmtFails(client, "select SQL_ERROR(123.5E-2) from P1", "Type FLOAT can't be cast as BIGINT");
}
Also used : ProcedureCallback(org.voltdb.client.ProcedureCallback) ClientResponse(org.voltdb.client.ClientResponse) Client(org.voltdb.client.Client)

Example 74 with ClientResponse

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

the class TestFunctionsForVoltDBSuite method testFunc_Str.

public void testFunc_Str() throws Exception {
    System.out.println("STARTING testFunc_Str");
    Client client = getClient();
    ClientResponse cr = null;
    VoltTable result;
    String str;
    cr = client.callProcedure("@AdHoc", "Delete from D1;");
    assertEquals(cr.getStatus(), ClientResponse.SUCCESS);
    cr = client.callProcedure("@AdHoc", "Delete from R3;");
    assertEquals(cr.getStatus(), ClientResponse.SUCCESS);
    String[] decimal_strs = { // id = 0
    "123456.64565", // id = 1
    "-123456.64565", // id = 2
    "1123456785.555", // id = 3
    "-1123456785.555", // id = 4
    "0.0", // id = 5
    "-0.0", // id = 6
    "0", // id = 7
    "-0", // id = 8
    "99999999999999999999999999.999999999999", // id = 9
    "-99999999999999999999999999.99999999999", // id = 10
    "1500", // id = 11
    "2500", // id = 12
    "8223372036854775807.123456789125", // id = 13
    "8223372036854775807.123456789175" };
    for (int i = 0; i < decimal_strs.length; i++) {
        BigDecimal bd = new BigDecimal(decimal_strs[i]);
        cr = client.callProcedure("D1.insert", i, bd);
        assertEquals(cr.getStatus(), ClientResponse.SUCCESS);
    }
    cr = client.callProcedure("R3.insert", 1, 1, 1, 1, 1, 1.1, "2013-07-18 02:00:00.123457", "IBM", 1);
    assertEquals(cr.getStatus(), ClientResponse.SUCCESS);
    cr = client.callProcedure("@AdHoc", "select STR(DEC, 12, 1), STR(DEC, 12, 2)," + "STR(DEC, 12, 3), STR(DEC, 12, 4)," + "STR(DEC, 12, 0) from D1 where id = 0");
    assertEquals(cr.getStatus(), ClientResponse.SUCCESS);
    result = cr.getResults()[0];
    assertEquals(1, result.getRowCount());
    assertTrue(result.advanceRow());
    // rounding to positive places
    str = result.getString(0);
    // rounding down
    assertEquals(str, "123456.6");
    str = result.getString(1);
    // rounding up
    assertEquals(str, "123456.65");
    str = result.getString(2);
    assertEquals(str, "123456.646");
    str = result.getString(3);
    // banker's rounding: half to nearest even when previous digit is even
    assertEquals(str, "123456.6456");
    // rounding to none-positive places, or say the whole part
    str = result.getString(4);
    // rounding up
    assertEquals(str, "123457");
    cr = client.callProcedure("@AdHoc", "select STR(DEC,15, 1), STR(DEC, 10, 2)," + "STR(DEC,10), STR(DEC) from D1 where id = 2");
    assertEquals(cr.getStatus(), ClientResponse.SUCCESS);
    result = cr.getResults()[0];
    assertEquals(1, result.getRowCount());
    assertTrue(result.advanceRow());
    // rounding to positive places
    str = result.getString(0);
    assertEquals(str, "1123456785.6");
    str = result.getString(1);
    assertEquals(str, "**********");
    str = result.getString(2);
    assertEquals(str, "1123456786");
    str = result.getString(3);
    assertEquals(str, "1123456786");
    // it will go out of the range of int64_t
    verifyStmtFails(client, "select STR(DEC, -19) from D1 where id = 12", "the second parameter should be <= 38 and > 0");
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) BigDecimal(java.math.BigDecimal)

Example 75 with ClientResponse

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

the class TestFunctionsForVoltDBSuite method testFunctionsWithInvalidJSON.

public void testFunctionsWithInvalidJSON() throws Exception {
    Client client = getClient();
    ClientResponse cr;
    cr = client.callProcedure(// OOPS. skipped comma before "bool"
    "JSBAD.insert", // OOPS. skipped comma before "bool"
    1, "{\"id\":1 \"bool\": false}");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure(// OOPS. semi-colon in place of colon before "bool"
    "JSBAD.insert", // OOPS. semi-colon in place of colon before "bool"
    2, "{\"id\":2, \"bool\"; false, \"贾鑫Vo\":\"分かりません分かりません分かりません分かりません分かりません分かりません分かりません分かりません分かりません分かりません分かりません分かりません\"}");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    // OOPS. trailing comma in array
    final String jsTrailingCommaArray = "[ 0, 100, ]";
    final String jsWithTrailingCommaArray = "{\"id\":3, \"trailer\":" + jsTrailingCommaArray + "}";
    cr = client.callProcedure("JSBAD.insert", 3, jsWithTrailingCommaArray);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("JSBAD.insert", 4, jsTrailingCommaArray);
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    String[] jsonProcs = { "BadIdFieldProc", "BadIdArrayProc", "BadIdArrayLengthProc" };
    for (String procname : jsonProcs) {
        try {
            cr = client.callProcedure(procname, 1, "id", "1");
            fail("document validity check failed for " + procname);
        } catch (ProcCallException pcex) {
            assertTrue(pcex.getMessage().contains("Invalid JSON * Line 1, Column 9"));
        }
        try {
            cr = client.callProcedure(procname, 2, "id", "2");
            fail("document validity check failed for " + procname);
        } catch (ProcCallException pcex) {
            assertTrue(pcex.getMessage().contains("Invalid JSON * Line 1, Column 16"));
        }
        try {
            cr = client.callProcedure(procname, 3, "id", "3");
            fail("document validity check failed for " + procname);
        } catch (ProcCallException pcex) {
            assertTrue(pcex.getMessage().contains("Invalid JSON * Line 1, Column 30"));
        }
        try {
            cr = client.callProcedure(procname, 4, "id", "4");
            fail("document validity check failed for " + procname);
        } catch (ProcCallException pcex) {
            assertTrue(pcex.getMessage().contains("Invalid JSON * Line 1, Column 11"));
        }
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Client(org.voltdb.client.Client) ProcCallException(org.voltdb.client.ProcCallException)

Aggregations

ClientResponse (org.voltdb.client.ClientResponse)381 VoltTable (org.voltdb.VoltTable)193 Client (org.voltdb.client.Client)184 ProcCallException (org.voltdb.client.ProcCallException)105 IOException (java.io.IOException)52 NoConnectionsException (org.voltdb.client.NoConnectionsException)33 Test (org.junit.Test)32 ProcedureCallback (org.voltdb.client.ProcedureCallback)32 VoltProjectBuilder (org.voltdb.compiler.VoltProjectBuilder)29 Configuration (org.voltdb.VoltDB.Configuration)28 File (java.io.File)18 Timestamp (java.sql.Timestamp)16 VoltDB (org.voltdb.VoltDB)16 InMemoryJarfile (org.voltdb.utils.InMemoryJarfile)16 VoltCompiler (org.voltdb.compiler.VoltCompiler)15 JSONException (org.json_voltpatches.JSONException)11 BigDecimal (java.math.BigDecimal)10 ExecutionException (java.util.concurrent.ExecutionException)10 ClientResponseImpl (org.voltdb.ClientResponseImpl)10 KeeperException (org.apache.zookeeper_voltpatches.KeeperException)9