Search in sources :

Example 11 with NoConnectionsException

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

the class VoltDBOsmSink method process.

public void process(NodeContainer nodeContainer) {
    Node node;
    node = nodeContainer.getEntity();
    double lat = node.getLatitude();
    double lng = node.getLongitude();
    String pointText = "POINT(" + lng + " " + lat + ")";
    // keep track of the nodes so we can build polygons later
    if (enableBboxBuilder || enableLinestringBuilder) {
        wayGeometryBuilder.addNodeLocation(node);
    }
    try {
        client.callProcedure(new InsertCallback(), INS_NODE_PROC, node.getId(), node.getVersion(), node.getUser().getId(), new TimestampType(node.getTimestamp().getTime()), node.getChangesetId(), pointText);
    } catch (NoConnectionsException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Collection<Tag> tags = node.getTags();
    for (Tag tag : tags) {
        // System.out.println(INS_NODE_TAG_PROC+","+node.getId()+","+tag.getKey()+","+tag.getValue());
        try {
            client.callProcedure(new InsertCallback(), INS_NODE_TAG_PROC, node.getId(), tag.getKey(), tag.getValue());
        } catch (NoConnectionsException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : NoConnectionsException(org.voltdb.client.NoConnectionsException) WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) TimestampType(org.voltdb.types.TimestampType) LineString(org.postgis.LineString) IOException(java.io.IOException) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag)

Example 12 with NoConnectionsException

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

the class TestFunctionsForVoltDBSuite method testTO_TIMESTAMP.

public void testTO_TIMESTAMP() throws NoConnectionsException, IOException, ProcCallException {
    System.out.println("STARTING TO_TIMESTAMP");
    Client client = getClient();
    ClientResponse cr;
    VoltTable result;
    cr = client.callProcedure("P2.insert", 0, new Timestamp(0L));
    cr = client.callProcedure("P2.insert", 1, new Timestamp(1L));
    cr = client.callProcedure("P2.insert", 2, new Timestamp(1000L));
    cr = client.callProcedure("P2.insert", 3, new Timestamp(-1000L));
    // Test AdHoc
    cr = client.callProcedure("@AdHoc", "select to_timestamp(second, 1372640523) from P2 limit 1");
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    result = cr.getResults()[0];
    assertEquals(1, result.getRowCount());
    assertTrue(result.advanceRow());
    assertEquals(1372640523 * 1000000L, result.getTimestampAsLong(0));
    // Test string input number, expect error
    try {
        cr = client.callProcedure("@AdHoc", "select to_timestamp(second, '1372640523') from P2 limit 1");
        fail();
    } catch (Exception ex) {
        assertTrue(ex.getMessage().contains("PlanningErrorException"));
        assertTrue(ex.getMessage().contains("incompatible data type"));
    }
    String[] procedures = { "FROM_UNIXTIME", "TO_TIMESTAMP_SECOND", "TO_TIMESTAMP_MILLIS", "TO_TIMESTAMP_MILLISECOND", "TO_TIMESTAMP_MICROS", "TO_TIMESTAMP_MICROSECOND" };
    for (int i = 0; i < procedures.length; i++) {
        String proc = procedures[i];
        cr = client.callProcedure(proc, 0L, 0);
        assertEquals(ClientResponse.SUCCESS, cr.getStatus());
        result = cr.getResults()[0];
        assertEquals(1, result.getRowCount());
        assertTrue(result.advanceRow());
        if (proc == "TO_TIMESTAMP_SECOND" || proc == "FROM_UNIXTIME") {
            assertEquals(0L, result.getTimestampAsLong(0));
        } else if (proc == "TO_TIMESTAMP_MILLIS" || proc == "TO_TIMESTAMP_MILLISECOND") {
            assertEquals(0L, result.getTimestampAsLong(0));
        } else if (proc == "TO_TIMESTAMP_MICROS" || proc == "TO_TIMESTAMP_MICROSECOND") {
            assertEquals(0L, result.getTimestampAsLong(0));
        } else {
            fail();
        }
        cr = client.callProcedure(proc, 1L, 1);
        assertEquals(ClientResponse.SUCCESS, cr.getStatus());
        result = cr.getResults()[0];
        assertEquals(1, result.getRowCount());
        assertTrue(result.advanceRow());
        if (proc == "TO_TIMESTAMP_SECOND" || proc == "FROM_UNIXTIME") {
            assertEquals(1000000L, result.getTimestampAsLong(0));
        } else if (proc == "TO_TIMESTAMP_MILLIS" || proc == "TO_TIMESTAMP_MILLISECOND") {
            assertEquals(1000L, result.getTimestampAsLong(0));
        } else if (proc == "TO_TIMESTAMP_MICROS" || proc == "TO_TIMESTAMP_MICROSECOND") {
            assertEquals(1L, result.getTimestampAsLong(0));
        } else {
            fail();
        }
        cr = client.callProcedure(proc, 1000L, 1);
        assertEquals(ClientResponse.SUCCESS, cr.getStatus());
        result = cr.getResults()[0];
        assertEquals(1, result.getRowCount());
        assertTrue(result.advanceRow());
        if (proc == "TO_TIMESTAMP_SECOND" || proc == "FROM_UNIXTIME") {
            assertEquals(1000000000L, result.getTimestampAsLong(0));
        } else if (proc == "TO_TIMESTAMP_MILLIS" || proc == "TO_TIMESTAMP_MILLISECOND") {
            assertEquals(1000000L, result.getTimestampAsLong(0));
        } else if (proc == "TO_TIMESTAMP_MICROS" || proc == "TO_TIMESTAMP_MICROSECOND") {
            assertEquals(1000L, result.getTimestampAsLong(0));
        } else {
            fail();
        }
        cr = client.callProcedure(proc, -1000, 1);
        assertEquals(ClientResponse.SUCCESS, cr.getStatus());
        result = cr.getResults()[0];
        assertEquals(1, result.getRowCount());
        assertTrue(result.advanceRow());
        if (proc == "TO_TIMESTAMP_SECOND" || proc == "FROM_UNIXTIME") {
            assertEquals(-1000000000L, result.getTimestampAsLong(0));
        } else if (proc == "TO_TIMESTAMP_MILLIS" || proc == "TO_TIMESTAMP_MILLISECOND") {
            assertEquals(-1000000L, result.getTimestampAsLong(0));
        } else if (proc == "TO_TIMESTAMP_MICROS" || proc == "TO_TIMESTAMP_MICROSECOND") {
            assertEquals(-1000L, result.getTimestampAsLong(0));
        } else {
            fail();
        }
        final long maxSec = GREGORIAN_EPOCH / 1000000;
        cr = client.callProcedure(proc, maxSec, 1);
        assertEquals(ClientResponse.SUCCESS, cr.getStatus());
        result = cr.getResults()[0];
        assertEquals(1, result.getRowCount());
        assertTrue(result.advanceRow());
        if (proc == "TO_TIMESTAMP_SECOND" || proc == "FROM_UNIXTIME") {
            assertEquals(maxSec * 1000000, result.getTimestampAsLong(0));
        } else if (proc == "TO_TIMESTAMP_MILLIS" || proc == "TO_TIMESTAMP_MILLISECOND") {
            assertEquals(maxSec * 1000, result.getTimestampAsLong(0));
        } else if (proc == "TO_TIMESTAMP_MICROS" || proc == "TO_TIMESTAMP_MICROSECOND") {
            assertEquals(maxSec, result.getTimestampAsLong(0));
        } else {
            fail();
        }
    }
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) BadParamTypesForTimestamp(org.voltdb_testprocs.regressionsuites.failureprocs.BadParamTypesForTimestamp) Timestamp(java.sql.Timestamp) IOException(java.io.IOException) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException)

Example 13 with NoConnectionsException

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

the class TestFunctionsForVoltDBSuite method testBitwiseShift.

public void testBitwiseShift() throws NoConnectionsException, IOException, ProcCallException {
    System.out.println("STARTING test bitwise shifting tests");
    bitwiseShiftChecker(1, 1, 1);
    bitwiseShiftChecker(2, -1, 1);
    bitwiseShiftChecker(3, 3, 60);
    bitwiseShiftChecker(4, -3, 60);
    bitwiseShiftChecker(5, 3, 64);
    bitwiseShiftChecker(6, -3, 64);
    bitwiseShiftChecker(7, 3, 65);
    bitwiseShiftChecker(8, -3, 65);
    bitwiseShiftChecker(9, 3, 127);
    bitwiseShiftChecker(10, -3, 127);
    bitwiseShiftChecker(11, 3, 128);
    bitwiseShiftChecker(12, -3, 128);
    bitwiseShiftChecker(13, 3, 129);
    bitwiseShiftChecker(14, -3, 129);
    bitwiseShiftChecker(15, 8, 63);
    bitwiseShiftChecker(16, -8, 63);
    bitwiseShiftChecker(17, 8, 0);
    bitwiseShiftChecker(18, -8, 0);
    // Min/MAX
    bitwiseShiftChecker(50, Long.MAX_VALUE, 3);
    bitwiseShiftChecker(51, 3, Long.MAX_VALUE);
    bitwiseShiftChecker(52, Long.MAX_VALUE, -3);
    bitwiseShiftChecker(53, -3, Long.MAX_VALUE);
    bitwiseShiftChecker(54, Long.MIN_VALUE + 1, 6);
    bitwiseShiftChecker(55, 6, Long.MIN_VALUE + 1);
    bitwiseShiftChecker(56, Long.MIN_VALUE + 1, -6);
    bitwiseShiftChecker(57, -6, Long.MIN_VALUE + 1);
    try {
        bitwiseShiftChecker(19, 3, 63);
        fail();
    } catch (Exception ex) {
        assertTrue(ex.getMessage().contains("would produce INT64_MIN, which is reserved for SQL NULL values"));
    }
    try {
        bitwiseShiftChecker(20, -3, 63);
        fail();
    } catch (Exception ex) {
        assertTrue(ex.getMessage().contains("would produce INT64_MIN, which is reserved for SQL NULL values"));
    }
    Client client = getClient();
    // out of range tests
    verifyStmtFails(client, "select BIT_SHIFT_LEFT(big, 9223372036854775809) from R3;", "numeric value out of range");
    verifyStmtFails(client, "select BIT_SHIFT_LEFT(big, 0.5) from R3;", "incompatible data type in conversion");
    verifyStmtFails(client, "select BIT_SHIFT_RIGHT(3.6, 2) from R3;", "incompatible data type in conversion");
    // negative shifting tests
    verifyStmtFails(client, "select BIT_SHIFT_LEFT(big, -1) from R3;", "unsupported negative value for bit shifting");
    verifyStmtFails(client, "select BIT_SHIFT_RIGHT(big, -1) from R3;", "unsupported negative value for bit shifting");
    VoltTable vt;
    // NULL tests: null in null out
    client.callProcedure("@AdHoc", "insert into R3(id, big) values (100, null)");
    vt = client.callProcedure("BITWISE_SHIFT_PARAM_1", 2, 2, 100).getResults()[0];
    validateRowOfLongs(vt, new long[] { Long.MIN_VALUE, Long.MIN_VALUE });
    vt = client.callProcedure("BITWISE_SHIFT_PARAM_2", 2, 2, 100).getResults()[0];
    validateRowOfLongs(vt, new long[] { Long.MIN_VALUE, Long.MIN_VALUE });
}
Also used : Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) IOException(java.io.IOException) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException)

Example 14 with NoConnectionsException

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

the class TestMaterializedViewNonemptyTablesSuite method testCreateView.

/**
     * Test to see if we can create a view.  The view name is
     * necessary because we drop the view after creation.
     *
     * @param client The Client object.
     * @param sql The sql string.  This should start "create view name ",
     *            where "name" is the view name.
     * @param expectedDiagnostic The expected diagnostic string.  This
     *                           should be null if the creation is
     *                           expected to succeed.
     * @throws IOException
     * @throws NoConnectionsException
     * @throws ProcCallException
     */
private void testCreateView(Client client, String sql, String expectedDiagnostic) throws IOException, NoConnectionsException, ProcCallException {
    ClientResponse cr = null;
    assertTrue("SQL string should start with \"create view \"", sql.startsWith("create view "));
    int pos = sql.indexOf(" ", 12);
    String viewName = sql.substring(12, pos);
    // Try to drop the view.  Even if it doesn't
    // exist, this should succeed.
    dropView(client, viewName);
    // Truncate all the tables.
    truncateTables(client, TABLE_NAMES);
    // This should always succeed.
    try {
        cr = client.callProcedure("@AdHoc", sql);
    } catch (Exception ex) {
        fail("Unexpected exception: \"" + ex.getMessage() + "\"");
    }
    assertEquals(ClientResponse.SUCCESS, cr.getStatus());
    // Drop the view and populate the tables.
    dropView(client, viewName);
    populateTables(client);
    // Try the view creation again.  This may or may
    // not succeed.
    boolean expectedSuccess = (expectedDiagnostic == null);
    try {
        cr = client.callProcedure("@AdHoc", sql);
        if (!expectedSuccess) {
            fail("Unexpected SQL compilation success");
        }
    } catch (ProcCallException ex) {
        cr = ex.getClientResponse();
        if (expectedSuccess) {
            fail(String.format("Unexpected SQL compilation failure:\n%s", cr.getStatusString()));
        }
        assertTrue(String.format("Did not find \"%s\" in diagnostic message \"%s\"", expectedDiagnostic, cr.getStatusString()), cr.getStatusString().contains(expectedDiagnostic));
    }
    // Drop the view..
    dropView(client, viewName);
    truncateTables(client, TABLE_NAMES);
    // Try creating the view again.  Sometimes after a
    // population and then truncation things go awry.
    // Again, this should always succeed.
    cr = client.callProcedure("@AdHoc", sql);
    assertEquals("View creation on empty tables should always succeed.", ClientResponse.SUCCESS, cr.getStatus());
    dropView(client, viewName);
}
Also used : ClientResponse(org.voltdb.client.ClientResponse) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException) IOException(java.io.IOException) ProcCallException(org.voltdb.client.ProcCallException)

Example 15 with NoConnectionsException

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

the class TestMaterializedViewSuite method truncateBeforeTest.

private void truncateBeforeTest(Client client) {
    // TODO Auto-generated method stub
    VoltTable[] results = null;
    try {
        results = client.callProcedure("TruncateMatViewDataMP").getResults();
    } catch (NoConnectionsException e) {
        e.printStackTrace();
        fail("Unexpected:" + e);
    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected:" + e);
    } catch (ProcCallException e) {
        e.printStackTrace();
        fail("Unexpected:" + e);
    }
    int nStatement = 0;
    for (VoltTable countTable : results) {
        ++nStatement;
        try {
            long count = countTable.asScalarLong();
            assertEquals("COUNT statement " + nStatement + "/" + results.length + " should have found no undeleted rows.", 0, count);
        } catch (Exception exc) {
            System.out.println("validation query " + nStatement + " got a bad result: " + exc);
            throw exc;
        }
    }
}
Also used : NoConnectionsException(org.voltdb.client.NoConnectionsException) IOException(java.io.IOException) VoltTable(org.voltdb.VoltTable) ProcCallException(org.voltdb.client.ProcCallException) IOException(java.io.IOException) ProcCallException(org.voltdb.client.ProcCallException) NoConnectionsException(org.voltdb.client.NoConnectionsException)

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