Search in sources :

Example 26 with GeographyPointValue

use of org.voltdb.types.GeographyPointValue in project voltdb by VoltDB.

the class TestGeographyValueQueries method testCaseWhenElseENG9983ENG9984.

// This is mostly a planner test, as the planner had problems recognizing that geo types
// were compatible with themselves in CASE expressions and that geography was a valid
// variable-length type.
public void testCaseWhenElseENG9983ENG9984() throws Exception {
    final double EPSILON = 1.0e-13;
    Client client = getClient();
    fillCheesyTable(client);
    // ENG-9983 CASE WHEN THEN ELSE on geography type.
    VoltTable vt = client.callProcedure("@AdHoc", "select CASE WHEN area(t.poly) < area(alt_t.poly) THEN t.poly ELSE alt_t.poly END" + " from t, t alt_t where t.pk + 1 = alt_t.pk and t.pk >= 100 order by t.pk;").getResults()[0];
    assertEquals("Expected (N-1) rows.", 3, vt.getRowCount());
    assertTrue(vt.advanceRow());
    GeographyValue cheesyRoundTripper1 = vt.getGeographyValue(0);
    vt = client.callProcedure("@AdHoc", "select CASE WHEN area(t.poly) < area(alt_t.poly) THEN t.poly ELSE alt_t.poly END" + " from t, t alt_t where t.pk >= 100 and alt_t.pk >= 100 order by t.pk;").getResults()[0];
    assertEquals("Expected (N^2) rows.", 16, vt.getRowCount());
    assertTrue(vt.advanceRow());
    GeographyValue cheesyRoundTripper2 = vt.getGeographyValue(0);
    assertApproximatelyEquals("Expected Equivalent Round Trip Polygons", cheesyRoundTripper1, cheesyRoundTripper2, EPSILON);
    // ENG-9983 CASE WHEN THEN ELSE on geography point type.
    vt = client.callProcedure("@AdHoc", "select CASE WHEN longitude(l.loc_point) <= longitude(alt_l.loc_point) THEN l.loc_point ELSE alt_l.loc_point END" + " from location l, location alt_l where l.pk + 1 = alt_l.pk and l.pk >= 300 order by l.pk;").getResults()[0];
    assertEquals("Expected (N-1) rows.", 3, vt.getRowCount());
    assertTrue(vt.advanceRow());
    GeographyPointValue cheesyRoundTripper3 = vt.getGeographyPointValue(0);
    vt = client.callProcedure("@AdHoc", "select CASE WHEN longitude(l.loc_point) <= longitude(alt_l.loc_point) THEN l.loc_point ELSE alt_l.loc_point END" + " from location l, location alt_l where l.pk >= 300 and alt_l.pk >= 300 order by l.pk;").getResults()[0];
    assertEquals("Expected (N^2) rows.", 16, vt.getRowCount());
    assertTrue(vt.advanceRow());
    GeographyPointValue cheesyRoundTripper4 = vt.getGeographyPointValue(0);
    assertApproximatelyEquals("Expected Equivalent Round Trip Points", cheesyRoundTripper3, cheesyRoundTripper4, EPSILON);
    // ENG-9984 CASE WHEN THEN no ELSE on geography type.
    vt = client.callProcedure("@AdHoc", "select CASE WHEN area(t.poly) <= area(alt_t.poly) THEN t.poly END" + " from t, t alt_t where t.pk >= 100 and alt_t.pk >= 100 order by t.pk;").getResults()[0];
    assertEquals("Expected (N^2) rows.", 16, vt.getRowCount());
    assertTrue(vt.advanceRow());
    GeographyValue cheesyRoundTripper5 = vt.getGeographyValue(0);
    assertFalse(vt.wasNull());
    assertApproximatelyEquals("Expected Equivalent Round Trip Polygons", cheesyRoundTripper1, cheesyRoundTripper5, EPSILON);
}
Also used : GeographyValue(org.voltdb.types.GeographyValue) Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) GeographyPointValue(org.voltdb.types.GeographyPointValue)

Example 27 with GeographyPointValue

use of org.voltdb.types.GeographyPointValue in project voltdb by VoltDB.

the class TestGeographyValueQueries method fillCheesyTable.

private void fillCheesyTable(Client client) throws Exception {
    GeographyValue cheesyPolygon = GeographyValue.fromWKT(cheesyWKT);
    GeographyValue cheesyShellPolygon = GeographyValue.fromWKT(cheesyShellWKT);
    //
    // Get the holes from the cheesy polygon, and make them
    // into polygons in their own right.  This means we need
    // to reverse them.
    //
    List<GeographyValue> cheesyHoles = new ArrayList<>();
    List<List<GeographyPointValue>> loops = cheesyPolygon.getRings();
    for (int idx = 1; idx < loops.size(); idx += 1) {
        List<GeographyPointValue> oneHole = loops.get(idx);
        List<GeographyPointValue> rev = new ArrayList<>();
        rev.addAll(oneHole);
        Collections.reverse(rev);
        List<List<GeographyPointValue>> holeLoops = new ArrayList<>();
        holeLoops.add(rev);
        cheesyHoles.add(new GeographyValue(holeLoops));
    }
    String cheesyOrigin = "POINT(0.0 0.0)";
    String cheesyInHole = "POINT(15  15)";
    List<String> exteriorPoints = Arrays.asList("POINT( 60  60)", "POINT( 60 -60)", "POINT(-60 -60)", "POINT(-60  60)");
    List<String> centers = Arrays.asList("POINT( 11  11)", "POINT( 11 -11)", "POINT(-11 -11)", "POINT(-11  11)");
    client.callProcedure("T.INSERT", 0, "SHELL", cheesyShellPolygon);
    client.callProcedure("T.INSERT", 1, "Formaggio", cheesyPolygon);
    for (int idx = 0; idx < cheesyHoles.size(); idx += 1) {
        GeographyValue hole = cheesyHoles.get(idx);
        client.callProcedure("T.INSERT", idx + 100, "hole" + idx + 100, hole);
    }
    client.callProcedure("LOCATION.INSERT", 0, "ORIGIN", GeographyPointValue.fromWKT(cheesyOrigin));
    client.callProcedure("LOCATION.INSERT", 1, "INHOLE", GeographyPointValue.fromWKT(cheesyInHole));
    for (int idx = 0; idx < exteriorPoints.size(); idx += 1) {
        String exPt = exteriorPoints.get(idx);
        client.callProcedure("LOCATION.INSERT", idx + 200, exPt, GeographyPointValue.fromWKT(exPt));
        idx += 1;
    }
    for (int idx = 0; idx < centers.size(); idx += 1) {
        String ctrPt = centers.get(idx);
        client.callProcedure("LOCATION.INSERT", idx + 300, ctrPt, GeographyPointValue.fromWKT(ctrPt));
    }
    // Make sure that all the polygons
    // are valid.
    VoltTable vt = client.callProcedure("@AdHoc", "select t.pk from t where not isValid(t.poly) order by t.pk").getResults()[0];
    assertTrue("fillCheesyTable: " + vt.getRowCount() + " invalid polygons.", vt.getRowCount() == 0);
}
Also used : GeographyValue(org.voltdb.types.GeographyValue) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) GeographyPointValue(org.voltdb.types.GeographyPointValue) VoltTable(org.voltdb.VoltTable)

Example 28 with GeographyPointValue

use of org.voltdb.types.GeographyPointValue in project voltdb by VoltDB.

the class TestGeographyPointValue method testPointFromText.

public void testPointFromText() throws Exception {
    Client client = getClient();
    validateTableOfScalarLongs(client, "insert into t (pk) values (1);", new long[] { 1 });
    VoltTable vt = client.callProcedure("@AdHoc", "select pointfromtext('point (-71.2767 42.4906)') from t;").getResults()[0];
    assertTrue(vt.advanceRow());
    GeographyPointValue pt = vt.getGeographyPointValue(0);
    assertFalse(vt.wasNull());
    assertEquals(42.4906, pt.getLatitude(), EPSILON);
    assertEquals(-71.2767, pt.getLongitude(), EPSILON);
}
Also used : Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) GeographyPointValue(org.voltdb.types.GeographyPointValue)

Example 29 with GeographyPointValue

use of org.voltdb.types.GeographyPointValue in project voltdb by VoltDB.

the class TestGeographyPointValue method testPointIn.

public void testPointIn() throws Exception {
    Client client = getClient();
    fillTable(client, 0);
    Object listParam = new GeographyPointValue[] { SANTA_CLARA_PT, null, LOWELL_PT };
    VoltTable vt = client.callProcedure("sel_in", listParam).getResults()[0];
    assertApproximateContentOfTable(new Object[][] { { 1, SANTA_CLARA_PT } }, vt, EPSILON);
    try {
        vt = client.callProcedure("sel_in", (Object) (new Object[] { SANTA_CLARA_PT, null, LOWELL_PT })).getResults()[0];
        fail("Expected an exception to be thrown");
    } catch (RuntimeException rte) {
        // When ENG-9311 is fixed, then we shouldn't get this error and
        // the procedure call should succeed.
        assertTrue(rte.getMessage().contains("GeographyPointValue or GeographyValue instances " + "are not yet supported in Object arrays passed as parameters"));
    }
}
Also used : Client(org.voltdb.client.Client) GeographyPointValue(org.voltdb.types.GeographyPointValue) VoltTable(org.voltdb.VoltTable)

Example 30 with GeographyPointValue

use of org.voltdb.types.GeographyPointValue in project voltdb by VoltDB.

the class TestGeographyPointValue method testPointNotNull.

public void testPointNotNull() throws Exception {
    Client client = getClient();
    verifyStmtFails(client, "insert into t_not_null (pk, name) values (0, 'Westchester')", "Column PT has no default and is not nullable");
    verifyStmtFails(client, "insert into t_not_null (pk, name, pt) values (0, 'Westchester', null)", "CONSTRAINT VIOLATION");
    validateTableOfScalarLongs(client, "insert into t_not_null (pk, name, pt) values (0, 'Singapore', pointfromtext('point(103.8521 1.2905)'))", new long[] { 1 });
    VoltTable vt = client.callProcedure("@AdHoc", "select pk, name, pt from t_not_null order by pk").getResults()[0];
    assertApproximateContentOfTable(new Object[][] { { 0, "Singapore", new GeographyPointValue(103.8521, 1.2905) } }, vt, EPSILON);
}
Also used : Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) GeographyPointValue(org.voltdb.types.GeographyPointValue)

Aggregations

GeographyPointValue (org.voltdb.types.GeographyPointValue)38 GeographyValue (org.voltdb.types.GeographyValue)23 VoltTable (org.voltdb.VoltTable)11 BigDecimal (java.math.BigDecimal)10 TimestampType (org.voltdb.types.TimestampType)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Client (org.voltdb.client.Client)7 IOException (java.io.IOException)5 JSONString (org.json_voltpatches.JSONString)3 VoltType (org.voltdb.VoltType)3 ByteBuffer (java.nio.ByteBuffer)2 ColumnInfo (org.voltdb.VoltTable.ColumnInfo)2 NullCallback (org.voltdb.client.NullCallback)2 File (java.io.File)1 BigInteger (java.math.BigInteger)1 InetSocketAddress (java.net.InetSocketAddress)1 ServerSocketChannel (java.nio.channels.ServerSocketChannel)1 SocketChannel (java.nio.channels.SocketChannel)1 SimpleDateFormat (java.text.SimpleDateFormat)1