Search in sources :

Example 16 with NoConnectionsException

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

the class SQLCommand method loadStoredProcedures.

private static void loadStoredProcedures(Map<String, Map<Integer, List<String>>> procedures, Map<String, List<Boolean>> classlist) {
    VoltTable procs = null;
    VoltTable params = null;
    VoltTable classes = null;
    try {
        procs = m_client.callProcedure("@SystemCatalog", "PROCEDURES").getResults()[0];
        params = m_client.callProcedure("@SystemCatalog", "PROCEDURECOLUMNS").getResults()[0];
        classes = m_client.callProcedure("@SystemCatalog", "CLASSES").getResults()[0];
    } catch (NoConnectionsException e) {
        e.printStackTrace();
        return;
    } catch (IOException e) {
        e.printStackTrace();
        return;
    } catch (ProcCallException e) {
        e.printStackTrace();
        return;
    }
    Map<String, Integer> proc_param_counts = Collections.synchronizedMap(new HashMap<String, Integer>());
    while (params.advanceRow()) {
        String this_proc = params.getString("PROCEDURE_NAME");
        Integer curr_val = proc_param_counts.get(this_proc);
        if (curr_val == null) {
            curr_val = 1;
        } else {
            ++curr_val;
        }
        proc_param_counts.put(this_proc, curr_val);
    }
    params.resetRowPosition();
    Set<String> userProcs = new HashSet<>();
    while (procs.advanceRow()) {
        String proc_name = procs.getString("PROCEDURE_NAME");
        userProcs.add(proc_name);
        Integer param_count = proc_param_counts.get(proc_name);
        ArrayList<String> this_params = new ArrayList<>();
        // prepopulate it to make sure the size is right
        if (param_count != null) {
            for (int i = 0; i < param_count; i++) {
                this_params.add(null);
            }
        } else {
            param_count = 0;
        }
        HashMap<Integer, List<String>> argLists = new HashMap<>();
        argLists.put(param_count, this_params);
        procedures.put(proc_name, argLists);
    }
    for (String proc_name : new ArrayList<>(procedures.keySet())) {
        if (!proc_name.startsWith("@") && !userProcs.contains(proc_name)) {
            procedures.remove(proc_name);
        }
    }
    classlist.clear();
    while (classes.advanceRow()) {
        String classname = classes.getString("CLASS_NAME");
        boolean isProc = (classes.getLong("VOLT_PROCEDURE") == 1L);
        boolean isActive = (classes.getLong("ACTIVE_PROC") == 1L);
        if (!classlist.containsKey(classname)) {
            List<Boolean> stuff = Collections.synchronizedList(new ArrayList<Boolean>());
            stuff.add(isProc);
            stuff.add(isActive);
            classlist.put(classname, stuff);
        }
    }
    // Retrieve the parameter types.  Note we have to do some special checking
    // for array types.  ENG-3101
    params.resetRowPosition();
    while (params.advanceRow()) {
        Map<Integer, List<String>> argLists = procedures.get(params.getString("PROCEDURE_NAME"));
        assert (argLists.size() == 1);
        List<String> this_params = argLists.values().iterator().next();
        int idx = (int) params.getLong("ORDINAL_POSITION") - 1;
        String param_type = params.getString("TYPE_NAME").toLowerCase();
        // Detect if this parameter is supposed to be an array.  It's kind of clunky, we have to
        // look in the remarks column...
        String param_remarks = params.getString("REMARKS");
        if (null != param_remarks) {
            param_type += (param_remarks.equalsIgnoreCase("ARRAY_PARAMETER") ? "_array" : "");
        }
        this_params.set(idx, param_type);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) VoltTable(org.voltdb.VoltTable) NoConnectionsException(org.voltdb.client.NoConnectionsException) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ProcCallException(org.voltdb.client.ProcCallException) HashSet(java.util.HashSet)

Example 17 with NoConnectionsException

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

the class TestFunctionsSuite method subtestOverlay.

public void subtestOverlay(Client client, String overlayProc, String overlayFullLengthProc) throws NoConnectionsException, IOException, ProcCallException {
    ClientResponse cr;
    VoltTable result;
    String overlayFailed = overlayProc + " got a wrong answer";
    String overlayFullLengthFailed = overlayFullLengthProc + " got a wrong answer";
    cr = client.callProcedure("@AdHoc", "TRUNCATE TABLE P1;");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    cr = client.callProcedure("P1.insert", 1, "Xin@VoltDB", 1, 1.0, new Timestamp(1000000000000L));
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    result = client.callProcedure(overlayProc, "Jia", 4, 7, 1).getResults()[0];
    assertTrue(result.advanceRow());
    assertEquals(overlayFailed, "XinJia", result.getString(1));
    result = client.callProcedure(overlayProc, "Jia_", 4, 1, 1).getResults()[0];
    assertTrue(result.advanceRow());
    assertEquals(overlayFailed, "XinJia_VoltDB", result.getString(1));
    try {
        result = client.callProcedure(overlayProc, "Jia", 4.2, 7, 1).getResults()[0];
    } catch (Exception ex) {
        assertTrue(ex.getMessage().contains("The provided value: (4.2) of type: java.lang.Double " + "is not a match or is out of range for the target parameter type: long"));
    }
    // Test NULL results
    result = client.callProcedure(overlayProc, null, 4, 7, 1).getResults()[0];
    assertTrue(result.advanceRow());
    assertEquals(overlayFailed, null, result.getString(1));
    result = client.callProcedure(overlayProc, "Jia", 4, null, 1).getResults()[0];
    assertTrue(result.advanceRow());
    assertEquals(overlayFailed, null, result.getString(1));
    result = client.callProcedure(overlayProc, "Jia", null, 7, 1).getResults()[0];
    assertTrue(result.advanceRow());
    assertEquals(overlayFailed, null, result.getString(1));
    result = client.callProcedure(overlayFullLengthProc, "Jia", 4, 1).getResults()[0];
    assertTrue(result.advanceRow());
    assertEquals(overlayFullLengthFailed, "XinJialtDB", result.getString(1));
    result = client.callProcedure(overlayFullLengthProc, "J", 4, 1).getResults()[0];
    assertTrue(result.advanceRow());
    assertEquals(overlayFullLengthFailed, "XinJVoltDB", result.getString(1));
    // Test UTF-8 OVERLAY
    cr = client.callProcedure("P1.insert", 2, "贾鑫@VoltDB", 1, 1.0, new Timestamp(1000000000000L));
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    result = client.callProcedure(overlayProc, "XinJia", 1, 2, 2).getResults()[0];
    assertTrue(result.advanceRow());
    assertEquals(overlayFailed, "XinJia@VoltDB", result.getString(1));
    result = client.callProcedure(overlayProc, "XinJia", 8, 2, 2).getResults()[0];
    assertTrue(result.advanceRow());
    assertEquals(overlayFailed, "贾鑫@VoltXinJia", result.getString(1));
    result = client.callProcedure(overlayProc, "XinJia", 1, 9, 2).getResults()[0];
    assertTrue(result.advanceRow());
    assertEquals(overlayFailed, "XinJia", result.getString(1));
    result = client.callProcedure(overlayProc, "XinJia", 2, 7, 2).getResults()[0];
    assertTrue(result.advanceRow());
    assertEquals(overlayFailed, "贾XinJiaB", result.getString(1));
    result = client.callProcedure(overlayProc, "XinJia", 2, 8, 2).getResults()[0];
    assertTrue(result.advanceRow());
    assertEquals(overlayFailed, "贾XinJia", result.getString(1));
    result = client.callProcedure(overlayFullLengthProc, "_", 3, 2).getResults()[0];
    assertTrue(result.advanceRow());
    assertEquals(overlayFullLengthFailed, "贾鑫_VoltDB", result.getString(1));
    result = client.callProcedure(overlayFullLengthProc, " at ", 2, 2).getResults()[0];
    assertTrue(result.advanceRow());
    assertEquals(overlayFullLengthFailed, "贾 at ltDB", result.getString(1));
    result = client.callProcedure(overlayProc, "XinJia", 9, 1, 2).getResults()[0];
    assertTrue(result.advanceRow());
    assertEquals(overlayFailed, "贾鑫@VoltDXinJia", result.getString(1));
    result = client.callProcedure(overlayProc, "石宁", 9, 1, 2).getResults()[0];
    assertTrue(result.advanceRow());
    assertEquals(overlayFailed, "贾鑫@VoltD石宁", result.getString(1));
    // Hsql has bugs on string(substring) index
    if (!isHSQL()) {
        result = client.callProcedure(overlayProc, "XinJia", 9, 2, 2).getResults()[0];
        assertTrue(result.advanceRow());
        assertEquals(overlayFailed, "贾鑫@VoltDXinJia", result.getString(1));
        result = client.callProcedure(overlayProc, "石宁", 9, 2, 2).getResults()[0];
        assertTrue(result.advanceRow());
        assertEquals(overlayFailed, "贾鑫@VoltD石宁", result.getString(1));
        result = client.callProcedure(overlayProc, "XinJia", 10, 2, 2).getResults()[0];
        assertTrue(result.advanceRow());
        assertEquals(overlayFailed, "贾鑫@VoltDBXinJia", result.getString(1));
        result = client.callProcedure(overlayProc, "石宁", 10, 2, 2).getResults()[0];
        assertTrue(result.advanceRow());
        assertEquals(overlayFailed, "贾鑫@VoltDB石宁", result.getString(1));
        // various start argument tests
        // start from 0, not 1, but treat it at least 1
        result = client.callProcedure(overlayProc, "XinJia", 100, 2, 2).getResults()[0];
        assertTrue(result.advanceRow());
        assertEquals(overlayFailed, "贾鑫@VoltDBXinJia", result.getString(1));
        // various length argument
        result = client.callProcedure(overlayProc, "XinJia", 2, 0, 2).getResults()[0];
        assertTrue(result.advanceRow());
        assertEquals(overlayFailed, "贾XinJia鑫@VoltDB", result.getString(1));
        result = client.callProcedure(overlayProc, "XinJia", 1, 10, 2).getResults()[0];
        assertTrue(result.advanceRow());
        assertEquals(overlayFailed, "XinJia", result.getString(1));
        result = client.callProcedure(overlayProc, "XinJia", 1, 100, 2).getResults()[0];
        assertTrue(result.advanceRow());
        assertEquals(overlayFailed, "XinJia", result.getString(1));
        result = client.callProcedure(overlayProc, "XinJia", 2, 100, 2).getResults()[0];
        assertTrue(result.advanceRow());
        assertEquals(overlayFailed, "贾XinJia", result.getString(1));
        // Negative tests
        try {
            result = client.callProcedure(overlayProc, "XinJia", -10, 2, 2).getResults()[0];
            fail();
        } catch (Exception ex) {
            assertTrue(ex.getMessage().contains("data exception -- OVERLAY error, not positive start argument -10"));
        }
        try {
            result = client.callProcedure(overlayProc, "XinJia", 0, 2, 2).getResults()[0];
            fail();
        } catch (Exception ex) {
            assertTrue(ex.getMessage().contains("data exception -- OVERLAY error, not positive start argument 0"));
        }
        try {
            result = client.callProcedure(overlayProc, "XinJia", 1, -1, 2).getResults()[0];
            fail();
        } catch (Exception ex) {
            assertTrue(ex.getMessage().contains("data exception -- OVERLAY error, negative length argument -1"));
        }
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) VoltTable(org.voltdb.VoltTable) Timestamp(java.sql.Timestamp) IOException(java.io.IOException) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException)

Example 18 with NoConnectionsException

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

the class TestInitStartLocalClusterAllOutOfProcess method loadAndAddProcs.

void loadAndAddProcs() throws IOException, NoConnectionsException {
    ClientResponse resp = null;
    long numberOfClasses = 0;
    try {
        resp = client.callProcedure("@SystemCatalog", "CLASSES");
    } catch (ProcCallException excp) {
        assert false : "@SystemCatalogClasses failed";
    }
    numberOfClasses = resp.getResults()[0].getRowCount();
    InMemoryJarfile jarfile = new InMemoryJarfile();
    VoltCompiler comp = new VoltCompiler(false);
    try {
        comp.addClassToJar(jarfile, org.voltdb_testprocs.updateclasses.testImportProc.class);
        comp.addClassToJar(jarfile, org.voltdb_testprocs.updateclasses.testCreateProcFromClassProc.class);
        comp.addClassToJar(jarfile, org.voltdb_testprocs.updateclasses.InnerClassesTestProc.class);
    } catch (Exception e) {
        assert false : "Failed add class to jar: " + e.getMessage();
    }
    try {
        client.callProcedure("@UpdateClasses", jarfile.getFullJarBytes(), null);
    } catch (ProcCallException excp) {
        assert false : "Failed updating the class";
    }
    try {
        resp = client.callProcedure("@SystemCatalog", "CLASSES");
    } catch (ProcCallException excp) {
        assert false : "@SystemCatalogClasses failed";
    }
    assertTrue((numberOfClasses + jarfile.getLoader().getClassNames().size()) == resp.getResults()[0].getRowCount());
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) VoltCompiler(org.voltdb.compiler.VoltCompiler) InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) ProcCallException(org.voltdb.client.ProcCallException) IOException(java.io.IOException) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException)

Example 19 with NoConnectionsException

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

the class TestSQLTypesSuite method testDeleteNulls.

public void testDeleteNulls() throws NoConnectionsException, ProcCallException, IOException {
    final Client client = this.getClient();
    // Insert a NULL value for each column. For the first
    // row, insert null 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
        // Fill the row with diagonal null data and insert
        params[0] = "ALLOW_NULLS";
        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);
        }
        client.callProcedure("Insert", params);
        VoltTable[] result = client.callProcedure("Select", "ALLOW_NULLS", pkey.get()).getResults();
        System.out.println(result[0]);
        try {
            client.callProcedure("Delete", "ALLOW_NULLS", pkey.get());
        } catch (final ProcCallException e) {
            e.printStackTrace();
            fail();
        } catch (final NoConnectionsException e) {
            e.printStackTrace();
            fail();
        }
        // verify that the row was deleted
        result = client.callProcedure("Select", "ALLOW_NULLS", pkey.get()).getResults();
        assertEquals(0, result[0].getRowCount());
    }
}
Also used : NoConnectionsException(org.voltdb.client.NoConnectionsException) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) ProcCallException(org.voltdb.client.ProcCallException)

Example 20 with NoConnectionsException

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

the class TestSQLTypesSuite method testMissingAttributeInsert_With_Defaults.

public void testMissingAttributeInsert_With_Defaults() throws NoConnectionsException, ProcCallException, IOException {
    Client client = this.getClient();
    Object[] params = new Object[COLS + 2];
    params[0] = "WITH_DEFAULTS";
    params[1] = pkey.incrementAndGet();
    for (int i = 0; i < COLS; i++) {
        params[i + 2] = m_defaultValues[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_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]);
        if (m_types[i] == VoltType.GEOGRAPHY || m_types[i] == VoltType.GEOGRAPHY_POINT) {
            // Default values are not supported for these types (yet?)
            assertNull(obj);
        } else {
            assertTrue("Expected to be equal: (" + obj + ", " + params[i + 2] + ")", comparisonHelper(obj, params[i + 2], m_types[i]));
        }
    }
}
Also used : NoConnectionsException(org.voltdb.client.NoConnectionsException) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) VoltTableRow(org.voltdb.VoltTableRow) ProcCallException(org.voltdb.client.ProcCallException)

Aggregations

NoConnectionsException (org.voltdb.client.NoConnectionsException)50 IOException (java.io.IOException)41 ProcCallException (org.voltdb.client.ProcCallException)38 VoltTable (org.voltdb.VoltTable)27 ClientResponse (org.voltdb.client.ClientResponse)21 Client (org.voltdb.client.Client)19 Date (java.util.Date)7 VoltTableRow (org.voltdb.VoltTableRow)6 ProcedureCallback (org.voltdb.client.ProcedureCallback)5 Timestamp (java.sql.Timestamp)4 File (java.io.File)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 Tag (org.openstreetmap.osmosis.core.domain.v0_6.Tag)3 ClientResponseImpl (org.voltdb.ClientResponseImpl)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)2 LineString (org.postgis.LineString)2 VoltCompiler (org.voltdb.compiler.VoltCompiler)2