Search in sources :

Example 66 with ProcCallException

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

the class TestGeospatialFunctions method testPolygonPointDistance.

public void testPolygonPointDistance() throws Exception {
    // The distances we consider are all in the thousands of
    // meters.  We expect 1.0e-12 precision, so that's 1.0e-8 relative
    // precision.  Note that we have determined empirically that
    // 1.0e-9 fails.
    final double DISTANCE_EPSILON = 1.0e-8;
    Client client = getClient();
    populateTables(client);
    client.callProcedure("places.Insert", 50, "San Jose", GeographyPointValue.fromWKT("POINT(-121.903692 37.325464)"));
    client.callProcedure("places.Insert", 51, "Boston", GeographyPointValue.fromWKT("POINT(-71.069862 42.338100)"));
    VoltTable vt;
    String sql;
    // distance of all points with respect to a specific polygon
    sql = "select borders.name, places.name, distance(borders.region, places.loc) as distance " + "from borders, places where borders.pk = 1" + "order by distance, places.pk";
    vt = client.callProcedure("@AdHoc", sql).getResults()[0];
    assertApproximateContentOfTable(new Object[][] { { "Wyoming", "Neverwhere", Double.MIN_VALUE }, { "Wyoming", "Cheyenne", 0.0 }, { "Wyoming", "Point on N Wyoming Border", 0.0 }, { "Wyoming", "Point on E Wyoming Border", 0.0 }, { "Wyoming", "Point On S Wyoming Border", 0.0 }, { "Wyoming", "Point On W Wyoming Border", 0.0 }, { "Wyoming", "East Point Not On Wyoming Border", 1.9770308670798656E-10 }, { "Wyoming", "West Point Not on Wyoming Border", 495.81208205561956 }, { "Wyoming", "Point near N Colorado border", 2382.072566994318 }, { "Wyoming", "North Point Not On Colorado Border", 4045.11696044222 }, { "Wyoming", "North Point Not On Wyoming Border", 12768.354425089678 }, { "Wyoming", "Fort Collins", 48820.514427535185 }, { "Wyoming", "Denver", 146450.5648140179 }, { "Wyoming", "South Point Not On Colorado Border", 453546.1064887051 }, { "Wyoming", "Albuquerque", 659770.3125551793 }, { "Wyoming", "San Jose", 1020359.8369329285 }, { "Wyoming", "Boston", 2651698.17837178 } }, vt, DISTANCE_EPSILON);
    // Validate result set obtained using distance between point and polygon is same as
    // distance between polygon and point
    sql = "select borders.name, places.name, distance(borders.region, places.loc) as distance " + "from borders, places where not contains(borders.region, places.loc) " + "order by borders.pk";
    vt = client.callProcedure("@AdHoc", sql).getResults()[0];
    // distance between point and polygon
    sql = "select borders.name, places.name, distance(places.loc, borders.region) as distance " + "from borders, places where not contains(borders.region, places.loc) " + "order by borders.pk";
    VoltTable vt1 = client.callProcedure("@AdHoc", sql).getResults()[0];
    assertEquals(vt1, vt);
    // get distance of points contained in a polygon to polygon's centroid
    sql = "select borders.name as State, places.name as Location, " + "distance(centroid(borders.region), places.loc) as distance " + "from borders, places where contains(borders.region, places.loc) " + "order by distance";
    vt = client.callProcedure("@AdHoc", sql).getResults()[0];
    assertApproximateContentOfTable(new Object[][] { { "Colorado", "Denver", 90126.44134902404 }, { "Colorado", "Fort Collins", 177132.68582044652 }, { "Colorado with a hole around Denver", "Fort Collins", 182956.55626884513 }, { "Colorado", "Point near N Colorado border", 223104.00553344024 }, { "Colorado with a hole around Denver", "Point near N Colorado border", 228833.82026300067 }, { "Wyoming", "Point On W Wyoming Border", 280064.27022410504 }, { "Wyoming", "Point on E Wyoming Border", 282622.1083568741 }, { "Wyoming", "Point on N Wyoming Border", 295384.0984736869 }, { "Wyoming", "Cheyenne", 308378.91700889106 }, { "Wyoming", "Point On S Wyoming Border", 355574.4468866087 } }, vt, DISTANCE_EPSILON);
    sql = "select distance(A.loc, B.loc) as distance " + "from places A, places B where A.name = 'Boston' and B.name = 'San Jose' " + "order by distance;";
    vt = client.callProcedure("@AdHoc", sql).getResults()[0];
    assertApproximateContentOfTable(new Object[][] { { 4311575.515808559 } }, vt, DISTANCE_EPSILON);
    // distance between polygon and polygon - currently not supported and should generate
    // exception saying incompatible data type supplied
    ProcCallException exception = null;
    try {
        sql = "select places.name, distance(borders.region, borders.region) " + "from borders, places where borders.pk = places.pk " + "order by borders.pk";
        vt = client.callProcedure("@AdHoc", sql).getResults()[0];
    } catch (ProcCallException excp) {
        exception = excp;
        assertTrue(exception.getMessage().contains("incompatible data type in operation"));
        assertTrue(exception.getMessage().contains("DISTANCE between two POLYGONS not supported"));
    } finally {
        assertNotNull(exception);
    }
    // distance between types others than point and poygon not supported
    exception = null;
    try {
        sql = "select places.name, distance(borders.region, borders.pk) " + "from borders, places where borders.pk = places.pk " + "order by borders.pk";
        vt = client.callProcedure("@AdHoc", sql).getResults()[0];
    } catch (ProcCallException excp) {
        exception = excp;
        assertTrue(exception.getMessage().contains("Error compiling query"));
        assertTrue(exception.getMessage().contains("incompatible data type in operation"));
    } finally {
        assertNotNull(exception);
    }
}
Also used : Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) ProcCallException(org.voltdb.client.ProcCallException)

Example 67 with ProcCallException

use of org.voltdb.client.ProcCallException 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 68 with ProcCallException

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

the class TestInitStartLocalClusterAllOutOfProcess method testGetClasses.

public void testGetClasses() throws IOException {
    InMemoryJarfile jarFile = null;
    org.voltdb.client.ClientResponse resp = null;
    // fetch the java procs classes currently in catalog
    try {
        resp = client.callProcedure("@SystemCatalog", "CLASSES");
    } catch (ProcCallException excp) {
        assert false : "@SystemCatalogClasses failed";
    }
    jarFile = getProcJarFromCatalog();
    assertTrue(!TestInitStartLocalClusterInProcess.anyCatalogDefaultArtifactsExists(jarFile));
    assertTrue(jarFile.getLoader().getClassNames().size() == resp.getResults()[0].getRowCount());
    // load some additional java stored proc classes and verify the retrieved classes count
    loadAndAddProcs();
    jarFile = getProcJarFromCatalog();
    assertTrue(!TestInitStartLocalClusterInProcess.anyCatalogDefaultArtifactsExists(jarFile));
    try {
        resp = client.callProcedure("@SystemCatalog", "CLASSES");
    } catch (ProcCallException excp) {
        assert false : "@SystemCatalogClasses failed";
    }
    assertTrue(jarFile.getLoader().getClassNames().size() == resp.getResults()[0].getRowCount());
}
Also used : InMemoryJarfile(org.voltdb.utils.InMemoryJarfile) ClientResponse(org.voltdb.client.ClientResponse) ProcCallException(org.voltdb.client.ProcCallException)

Example 69 with ProcCallException

use of org.voltdb.client.ProcCallException 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 70 with ProcCallException

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

the class TestSQLTypesSuite method testInsertViolatesStringLength.

//
// Insert strings that violate the VARCHAR size limit.
//
public void testInsertViolatesStringLength() throws IOException, ProcCallException {
    final Client client = this.getClient();
    boolean caught = false;
    // by looping twice and setting params[0] differently each time.
    for (int i = 0; i < 2; ++i) {
        final Object[] params = new Object[COLS + 2];
        params[0] = (i == 0) ? "NO_NULLS" : "ALLOW_NULLS";
        // varchar to the too-big value each time.
        for (int stringcount = 0; stringcount < 3; ++stringcount) {
            int curr_string = 0;
            params[1] = pkey.incrementAndGet();
            for (int k = 0; k < COLS; ++k) {
                if ((m_types[k] == VoltType.STRING) && (stringcount == curr_string)) {
                    params[k + 2] = ReallyLongString;
                } else {
                    params[k + 2] = m_midValues[k];
                }
                if (m_types[k] == VoltType.STRING)
                    curr_string++;
            }
            try {
                caught = false;
                client.callProcedure("Insert", params);
            } catch (final ProcCallException e) {
                caught = true;
            }
            assertTrue(caught);
        }
    }
}
Also used : Client(org.voltdb.client.Client) ProcCallException(org.voltdb.client.ProcCallException)

Aggregations

ProcCallException (org.voltdb.client.ProcCallException)240 Client (org.voltdb.client.Client)151 VoltTable (org.voltdb.VoltTable)120 ClientResponse (org.voltdb.client.ClientResponse)92 IOException (java.io.IOException)82 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