Search in sources :

Example 41 with VoltTable

use of org.voltdb.VoltTable in project voltdb by VoltDB.

the class TestUpdateClasses method testRoleControl.

@Test
public void testRoleControl() throws Exception {
    System.out.println("\n\n-----\n testRoleControl \n-----\n\n");
    String pathToCatalog = Configuration.getPathToCatalogForTest("updateclasses.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("updateclasses.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("-- Don't care");
    builder.setUseDDLSchema(true);
    RoleInfo[] groups = new RoleInfo[] { new RoleInfo("adhoc", true, false, false, false, false, false) };
    UserInfo[] users = new UserInfo[] { new UserInfo("adhocuser", "adhocuser", new String[] { "adhoc" }), new UserInfo("sysuser", "sysuser", new String[] { "ADMINISTRATOR" }) };
    builder.addRoles(groups);
    builder.addUsers(users);
    // Test defines its own ADMIN user
    builder.setSecurityEnabled(true, false);
    boolean success = builder.compile(pathToCatalog, 2, 1, 0);
    assertTrue("Schema compilation failed", success);
    MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
    // This is maybe cheating a little bit?
    InMemoryJarfile jarfile = new InMemoryJarfile();
    for (Class<?> clazz : PROC_CLASSES) {
        VoltCompiler comp = new VoltCompiler(false);
        comp.addClassToJar(jarfile, clazz);
    }
    for (Class<?> clazz : EXTRA_CLASSES) {
        VoltCompiler comp = new VoltCompiler(false);
        comp.addClassToJar(jarfile, clazz);
    }
    Client auth_client = null;
    try {
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToCatalog = pathToCatalog;
        config.m_pathToDeployment = pathToDeployment;
        // Default client auth is going to fail, catch and keep chugging
        try {
            startSystem(config);
        } catch (IOException ioe) {
            assertTrue(ioe.getMessage().contains("Authentication rejected"));
        }
        m_client.close();
        // reconnect m_client with auth that will connect but no sysproc powers
        ClientConfig bad_config = new ClientConfig("adhocuser", "adhocuser");
        m_client = ClientFactory.createClient(bad_config);
        m_client.createConnection("localhost");
        // Need a client with the right auth
        ClientConfig auth_config = new ClientConfig("sysuser", "sysuser");
        auth_client = ClientFactory.createClient(auth_config);
        auth_client.createConnection("localhost");
        ClientResponse resp;
        resp = auth_client.callProcedure("@SystemCatalog", "CLASSES");
        System.out.println(resp.getResults()[0]);
        // New cluster, you're like summer vacation...
        assertEquals(0, resp.getResults()[0].getRowCount());
        assertFalse(VoltTableTestHelpers.moveToMatchingRow(resp.getResults()[0], "CLASS_NAME", PROC_CLASSES[0].getCanonicalName()));
        boolean threw = false;
        try {
            resp = auth_client.callProcedure(PROC_CLASSES[0].getSimpleName());
        } catch (ProcCallException pce) {
            assertTrue(pce.getMessage().contains("was not found"));
            threw = true;
        }
        assertTrue(threw);
        threw = false;
        try {
            resp = m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
        } catch (ProcCallException pce) {
            assertTrue(pce.getMessage().contains("does not have admin permission"));
            threw = true;
        }
        assertTrue(threw);
        resp = auth_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
        assertEquals(ClientResponse.SUCCESS, resp.getStatus());
        // Are we still like summer vacation?
        resp = auth_client.callProcedure("@SystemCatalog", "CLASSES");
        VoltTable results = resp.getResults()[0];
        System.out.println(results);
        assertEquals(3, results.getRowCount());
        assertTrue(VoltTableTestHelpers.moveToMatchingRow(results, "CLASS_NAME", PROC_CLASSES[0].getCanonicalName()));
        assertEquals(1L, results.getLong("VOLT_PROCEDURE"));
        assertEquals(0L, results.getLong("ACTIVE_PROC"));
    } finally {
        if (auth_client != null) {
            auth_client.close();
        }
        teardownSystem();
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Configuration(org.voltdb.VoltDB.Configuration) UserInfo(org.voltdb.compiler.VoltProjectBuilder.UserInfo) IOException(java.io.IOException) VoltTable(org.voltdb.VoltTable) VoltDB(org.voltdb.VoltDB) VoltCompiler(org.voltdb.compiler.VoltCompiler) RoleInfo(org.voltdb.compiler.VoltProjectBuilder.RoleInfo) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) Configuration(org.voltdb.VoltDB.Configuration) Client(org.voltdb.client.Client) ClientConfig(org.voltdb.client.ClientConfig) ProcCallException(org.voltdb.client.ProcCallException) Test(org.junit.Test)

Example 42 with VoltTable

use of org.voltdb.VoltTable in project voltdb by VoltDB.

the class TestUpdateClasses method testBasic.

@Test
public void testBasic() throws Exception {
    System.out.println("\n\n-----\n testBasic \n-----\n\n");
    String pathToCatalog = Configuration.getPathToCatalogForTest("updateclasses.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("updateclasses.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("-- Don't care");
    builder.setUseDDLSchema(true);
    boolean success = builder.compile(pathToCatalog, 2, 1, 0);
    assertTrue("Schema compilation failed", success);
    MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
    // This is maybe cheating a little bit?
    InMemoryJarfile jarfile = new InMemoryJarfile();
    for (Class<?> clazz : PROC_CLASSES) {
        VoltCompiler comp = new VoltCompiler(false);
        comp.addClassToJar(jarfile, clazz);
    }
    for (Class<?> clazz : EXTRA_CLASSES) {
        VoltCompiler comp = new VoltCompiler(false);
        comp.addClassToJar(jarfile, clazz);
    }
    // Add a deployment file just to have something other than classes in the jar
    jarfile.put("deployment.xml", new File(pathToDeployment));
    try {
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToCatalog = pathToCatalog;
        config.m_pathToDeployment = pathToDeployment;
        startSystem(config);
        ClientResponse resp;
        resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
        System.out.println(resp.getResults()[0]);
        // New cluster, you're like summer vacation...
        assertEquals(0, resp.getResults()[0].getRowCount());
        assertFalse(VoltTableTestHelpers.moveToMatchingRow(resp.getResults()[0], "CLASS_NAME", PROC_CLASSES[0].getCanonicalName()));
        boolean threw = false;
        try {
            resp = m_client.callProcedure(PROC_CLASSES[0].getSimpleName());
        } catch (ProcCallException pce) {
            assertTrue(pce.getMessage().contains("was not found"));
            threw = true;
        }
        assertTrue(threw);
        // First, some tests of incorrect parameters
        // only 1 param
        threw = false;
        try {
            resp = m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes());
        } catch (ProcCallException pce) {
            assertTrue(pce.getMessage().contains("UpdateClasses system procedure requires exactly two parameters"));
            threw = true;
        }
        assertTrue(threw);
        // wrong jarfile param type
        threw = false;
        try {
            resp = m_client.callProcedure("@UpdateClasses", 10L, null);
        } catch (ProcCallException pce) {
            assertTrue(pce.getMessage().contains("UpdateClasses system procedure takes the jarfile bytes as a byte array"));
            threw = true;
        }
        assertTrue(threw);
        // wrong delete string param type
        threw = false;
        try {
            resp = m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), 10L);
        } catch (ProcCallException pce) {
            assertTrue(pce.getMessage().contains("UpdateClasses system procedure takes the list of classes"));
            threw = true;
        }
        assertTrue(threw);
        resp = m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
        System.out.println(((ClientResponseImpl) resp).toJSONString());
        // Are we still like summer vacation?
        resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
        VoltTable results = resp.getResults()[0];
        System.out.println(results);
        assertEquals(3, results.getRowCount());
        assertTrue(VoltTableTestHelpers.moveToMatchingRow(results, "CLASS_NAME", PROC_CLASSES[0].getCanonicalName()));
        assertEquals(1L, results.getLong("VOLT_PROCEDURE"));
        assertEquals(0L, results.getLong("ACTIVE_PROC"));
        // Can we turn it into a procedure?
        resp = m_client.callProcedure("@AdHoc", "create procedure from class " + PROC_CLASSES[0].getCanonicalName() + ";");
        System.out.println(((ClientResponseImpl) resp).toJSONString());
        resp = m_client.callProcedure(PROC_CLASSES[0].getSimpleName());
        assertEquals(ClientResponse.SUCCESS, resp.getStatus());
        results = resp.getResults()[0];
        assertEquals(10L, results.asScalarLong());
    } finally {
        teardownSystem();
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Configuration(org.voltdb.VoltDB.Configuration) VoltTable(org.voltdb.VoltTable) VoltDB(org.voltdb.VoltDB) VoltCompiler(org.voltdb.compiler.VoltCompiler) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) Configuration(org.voltdb.VoltDB.Configuration) File(java.io.File) ProcCallException(org.voltdb.client.ProcCallException) Test(org.junit.Test)

Example 43 with VoltTable

use of org.voltdb.VoltTable in project voltdb by VoltDB.

the class TestUpdateClasses method testCollidingClasses.

@Test
public void testCollidingClasses() throws Exception {
    System.out.println("\n\n-----\n testCollidingProc \n-----\n\n");
    String pathToCatalog = Configuration.getPathToCatalogForTest("updateclasses.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("updateclasses.xml");
    VoltProjectBuilder builder = new VoltProjectBuilder();
    builder.addLiteralSchema("-- Don't care");
    builder.setUseDDLSchema(true);
    boolean success = builder.compile(pathToCatalog, 2, 1, 0);
    assertTrue("Schema compilation failed", success);
    MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
    // This is maybe cheating a little bit?
    InMemoryJarfile jarfile = new InMemoryJarfile();
    for (Class<?> clazz : PROC_CLASSES) {
        VoltCompiler comp = new VoltCompiler(false);
        comp.addClassToJar(jarfile, clazz);
    }
    for (Class<?> clazz : EXTRA_CLASSES) {
        VoltCompiler comp = new VoltCompiler(false);
        comp.addClassToJar(jarfile, clazz);
    }
    try {
        VoltDB.Configuration config = new VoltDB.Configuration();
        config.m_pathToCatalog = pathToCatalog;
        config.m_pathToDeployment = pathToDeployment;
        startSystem(config);
        ClientResponse resp;
        resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
        System.out.println(resp.getResults()[0]);
        // New cluster, you're like summer vacation...
        assertEquals(0, resp.getResults()[0].getRowCount());
        assertFalse(VoltTableTestHelpers.moveToMatchingRow(resp.getResults()[0], "CLASS_NAME", PROC_CLASSES[0].getCanonicalName()));
        boolean threw = false;
        try {
            resp = m_client.callProcedure(PROC_CLASSES[0].getSimpleName());
        } catch (ProcCallException pce) {
            assertTrue(pce.getMessage().contains("was not found"));
            threw = true;
        }
        assertTrue(threw);
        resp = m_client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
        System.out.println(((ClientResponseImpl) resp).toJSONString());
        // Are we still like summer vacation?
        resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
        VoltTable results = resp.getResults()[0];
        System.out.println(results);
        assertEquals(3, results.getRowCount());
        assertTrue(VoltTableTestHelpers.moveToMatchingRow(results, "CLASS_NAME", PROC_CLASSES[0].getCanonicalName()));
        assertEquals(1L, results.getLong("VOLT_PROCEDURE"));
        assertEquals(0L, results.getLong("ACTIVE_PROC"));
        // Can we turn it into a procedure?
        resp = m_client.callProcedure("@AdHoc", "create procedure from class " + PROC_CLASSES[0].getCanonicalName() + ";");
        System.out.println(((ClientResponseImpl) resp).toJSONString());
        resp = m_client.callProcedure(PROC_CLASSES[0].getSimpleName());
        assertEquals(ClientResponse.SUCCESS, resp.getStatus());
        results = resp.getResults()[0];
        assertEquals(10L, results.asScalarLong());
        // now, let's collide identically simpleName'd classes
        InMemoryJarfile boom = new InMemoryJarfile();
        for (Class<?> clazz : COLLIDING_CLASSES) {
            VoltCompiler comp = new VoltCompiler(false);
            comp.addClassToJar(boom, clazz);
        }
        resp = m_client.callProcedure("@UpdateClasses", boom.getFullJarBytes(), null);
        System.out.println(((ClientResponseImpl) resp).toJSONString());
        // should be okay to have classnames with same simplename
        resp = m_client.callProcedure("@SystemCatalog", "CLASSES");
        results = resp.getResults()[0];
        System.out.println(results);
        assertEquals(5, results.getRowCount());
        assertTrue(VoltTableTestHelpers.moveToMatchingRow(results, "CLASS_NAME", COLLIDING_CLASSES[0].getCanonicalName()));
        assertEquals(1L, results.getLong("VOLT_PROCEDURE"));
        assertEquals(0L, results.getLong("ACTIVE_PROC"));
    } finally {
        teardownSystem();
    }
}
Also used : VoltDB(org.voltdb.VoltDB) ClientResponse(org.voltdb.client.ClientResponse) VoltCompiler(org.voltdb.compiler.VoltCompiler) Configuration(org.voltdb.VoltDB.Configuration) VoltProjectBuilder(org.voltdb.compiler.VoltProjectBuilder) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) Configuration(org.voltdb.VoltDB.Configuration) VoltTable(org.voltdb.VoltTable) ProcCallException(org.voltdb.client.ProcCallException) Test(org.junit.Test)

Example 44 with VoltTable

use of org.voltdb.VoltTable in project voltdb by VoltDB.

the class TestSubQueriesSuite method subTestScalarSubqueryWithNonIntegerType.

private void subTestScalarSubqueryWithNonIntegerType(Client client) throws Exception {
    client.callProcedure("@AdHoc", "truncate table R4");
    client.callProcedure("R4.insert", 1, "foo1", -1, 1.1);
    client.callProcedure("R4.insert", 2, "foo2", -1, 2.2);
    VoltTable vt;
    String sql;
    // test FLOAT
    sql = "select ID, (select SUM(RATIO) from R4) " + "from R4 " + "order by ID;";
    vt = client.callProcedure("@AdHoc", sql).getResults()[0];
    assertEquals(2, vt.getRowCount());
    assertTrue(vt.advanceRow());
    assertEquals(1, vt.getLong(0));
    assertEquals(3.3, vt.getDouble(1), 0.0001);
    assertTrue(vt.advanceRow());
    assertEquals(2, vt.getLong(0));
    assertEquals(3.3, vt.getDouble(1), 0.0001);
    // test VARCHAR
    sql = "select ID, (select MIN(DESC) from R4) from R4 " + "order by ID;";
    vt = client.callProcedure("@AdHoc", sql).getResults()[0];
    assertEquals(2, vt.getRowCount());
    assertTrue(vt.advanceRow());
    assertEquals(1, vt.getLong(0));
    assertEquals("foo1", vt.getString(1));
    assertTrue(vt.advanceRow());
    assertEquals(2, vt.getLong(0));
    assertEquals("foo1", vt.getString(1));
}
Also used : VoltTable(org.voltdb.VoltTable)

Example 45 with VoltTable

use of org.voltdb.VoltTable in project voltdb by VoltDB.

the class TestSubQueriesSuite method subTestScalarSubqueryWithParentOrderByOrGroupBy.

private void subTestScalarSubqueryWithParentOrderByOrGroupBy(Client client) throws Exception {
    String sql;
    int len = 100;
    if (isValgrind()) {
        // valgrind is too slow with 100 rows, use a small number
        len = 10;
    }
    long[][] expected = new long[len][1];
    for (int i = 0; i < len; ++i) {
        client.callProcedure("@AdHoc", "insert into R_ENG8145_1 values (?, ?);", i, i * 2);
        client.callProcedure("@AdHoc", "insert into R_ENG8145_2 values (?, ?);", i, i * 2);
        long val = len - ((i * 2) + 1);
        if (val < 0)
            val = 0;
        expected[i][0] = val;
    }
    sql = "select (select count(*) from R_ENG8145_1 where ID > parent.num) " + "from R_ENG8145_2 parent " + "order by id;";
    validateTableOfLongs(client, sql, expected);
    // has to have order by ID to be deterministic
    sql = "select (select count(*) from R_ENG8145_1 where ID > parent.num) " + "from R_ENG8145_2 parent " + "group by id " + "order by id;";
    validateTableOfLongs(client, sql, expected);
    // ENG-8173
    client.callProcedure("@AdHoc", "insert into R_ENG8173_1 values (0, 'foo', 50);");
    client.callProcedure("@AdHoc", "insert into R_ENG8173_1 values (1, 'goo', 25);");
    // These queries were failing because we weren't calling "resolveColumnIndexes"
    // for subqueries that appeared on the select list (as part of a projection node).
    VoltTable vt = client.callProcedure("@AdHoc", "select *, (select SUM(NUM) from R_ENG8173_1) " + "from R_ENG8173_1 A1 " + "order by DESC;").getResults()[0];
    assertTrue(vt.advanceRow());
    assertEquals(0, vt.getLong(0));
    assertEquals("foo", vt.getString(1));
    assertEquals(50, vt.getLong(2));
    assertEquals(75, vt.getLong(3));
    assertTrue(vt.advanceRow());
    assertEquals(1, vt.getLong(0));
    assertEquals("goo", vt.getString(1));
    assertEquals(25, vt.getLong(2));
    assertEquals(75, vt.getLong(3));
    assertFalse(vt.advanceRow());
    sql = "select (select SUM(NUM) + SUM(ID) from R_ENG8173_1) " + "from R_ENG8173_1 A1 order by DESC;";
    validateTableOfLongs(client, sql, new long[][] { { 76 }, { 76 } });
    // Similar queries from ENG-8174
    client.callProcedure("@AdHoc", "truncate table R4");
    client.callProcedure("@AdHoc", "insert into R4 values (0,null,null,null);");
    client.callProcedure("@AdHoc", "insert into R4 values (1,'foo1',-1,1.1);");
    vt = client.callProcedure("@AdHoc", "select NUM V, (select SUM(RATIO) from R4) " + "from R4 " + "order by V;").getResults()[0];
    assertTrue(vt.advanceRow());
    vt.getLong(0);
    assertTrue(vt.wasNull());
    assertEquals(1.1, vt.getDouble(1));
    assertTrue(vt.advanceRow());
    assertEquals(-1, vt.getLong(0));
    assertEquals(1.1, vt.getDouble(1));
    assertFalse(vt.advanceRow());
    vt = client.callProcedure("@AdHoc", "select RATIO V, (select SUM(NUM) from R4) " + "from R4 " + "order by V;").getResults()[0];
    assertTrue(vt.advanceRow());
    vt.getDouble(0);
    assertTrue(vt.wasNull());
    assertEquals(-1, vt.getLong(1));
    assertTrue(vt.advanceRow());
    assertEquals(1.1, vt.getDouble(0));
    assertEquals(-1, vt.getLong(1));
    assertFalse(vt.advanceRow());
    vt = client.callProcedure("@AdHoc", "select NUM V, (select MAX(DESC) from R4) " + "from R4 " + "order by V;").getResults()[0];
    assertTrue(vt.advanceRow());
    vt.getLong(0);
    assertTrue(vt.wasNull());
    assertEquals("foo1", vt.getString(1));
    assertTrue(vt.advanceRow());
    assertEquals(-1, vt.getLong(0));
    assertEquals("foo1", vt.getString(1));
    assertFalse(vt.advanceRow());
}
Also used : VoltTable(org.voltdb.VoltTable)

Aggregations

VoltTable (org.voltdb.VoltTable)887 Client (org.voltdb.client.Client)497 ClientResponse (org.voltdb.client.ClientResponse)193 ProcCallException (org.voltdb.client.ProcCallException)144 IOException (java.io.IOException)100 VoltTableRow (org.voltdb.VoltTableRow)57 NoConnectionsException (org.voltdb.client.NoConnectionsException)52 ColumnInfo (org.voltdb.VoltTable.ColumnInfo)42 TimestampType (org.voltdb.types.TimestampType)37 BigDecimal (java.math.BigDecimal)30 ArrayList (java.util.ArrayList)27 Test (org.junit.Test)26 File (java.io.File)25 HashMap (java.util.HashMap)21 ClientResponseImpl (org.voltdb.ClientResponseImpl)20 Timestamp (java.sql.Timestamp)15 Date (java.util.Date)15 VoltDB (org.voltdb.VoltDB)15 DependencyPair (org.voltdb.DependencyPair)14 Configuration (org.voltdb.VoltDB.Configuration)14