Search in sources :

Example 21 with GeographyPointValue

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

the class TestCSVLoader method testGeographyStringRoundTrip.

@Test
public void testGeographyStringRoundTrip() throws Exception {
    String[] myOptions = { "-f" + path_csv, "--reportdir=" + reportDir, "BLAH" };
    String[] myData = { "1,,,,,,,,,\"POLYGON((1.1 1.1, -1.1 1.1, -1.1 -1.1, 1.1 -1.1, 1.1 1.1))\"", "2,,,,,,,,,\"POLYGON((1.1 1.1, -1.1 1.1, -1.1 -1.1, 1.1 -1.1, 1.1 1.1))\"", "3,,,,,,,,,\"POLYGON((2.2 2.2, -2.2 2.2, -2.2 -2.2, 2.2 -2.2, 2.2 2.2),(1.1 1.1, 1.1 -1.1, -1.1 -1.1, -1.1 1.1, 1.1 1.1))\"", "4,,,,,,,,,\"POLYGON((2.2 2.2, -2.2 2.2, -2.2 -2.2, 2.2 -2.2, 2.2 2.2),(1.1 1.1, 1.1 -1.1, -1.1 -1.1, -1.1 1.1, 1.1 1.1))\"" };
    int invalidLineCnt = 0;
    int validLineCnt = myData.length - invalidLineCnt;
    test_Interface(myOptions, myData, invalidLineCnt, validLineCnt);
    VoltTable ts_table = client.callProcedure("@AdHoc", "SELECT * FROM BLAH ORDER BY clm_integer;").getResults()[0];
    while (ts_table.advanceRow()) {
        GeographyPointValue pt1 = ts_table.getGeographyPointValue(8);
        if (ts_table.advanceRow()) {
            GeographyPointValue pt2 = ts_table.getGeographyPointValue(8);
            assertEquals(pt1, pt2);
            continue;
        }
    }
}
Also used : VoltTable(org.voltdb.VoltTable) GeographyPointValue(org.voltdb.types.GeographyPointValue) Test(org.junit.Test)

Example 22 with GeographyPointValue

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

the class TestGeospatialIndexes method populateGeoTables.

// function generates and fills table with polygon and points. For each generated polygon, there are corresponding points
// generated such that:
// - n points that are inside polygon's (this number is equal to number of vertex the polygon has)
// - 8 random points (4 in valgrind env) that are inside polygon's outer shell and along the axis line of vertex
// - 4 points that are outside polygon and near cell covering polygon
// - another one that is outside the bounding box of polygon.
// All the generated data is populated in (indexed/non-indexed) borders and places tables.
// Polygons are generated along horizontal grid
// Generated data is cached in m_polygonPoints list and used in data verification later
private void populateGeoTables(Client client) throws NoConnectionsException, IOException, ProcCallException {
    final int polygonRadius = 3;
    final int numberOfPolygonPointsForEachShape;
    if (isValgrind()) {
        // limit the data for valgrind environment as IPC can't handle data beyond 5000 rows.
        // Not Contains query hangs otherwise in valgrind environment
        numberOfPolygonPointsForEachShape = 2;
    } else {
        numberOfPolygonPointsForEachShape = 10;
    }
    // generate latitude and longitudes for somewhere in north-west hemisphere
    // generate longitude between -178 to -168
    final int longitude = m_random.nextInt(10) - 178;
    // generate latitude between 82 to 72
    final int latitude = m_random.nextInt(10) + 72;
    GeographyPointValue center = new GeographyPointValue(longitude, latitude);
    // offset to use for generating new center of polygon. this is not randomized, it will generate polygons in same order
    // in horizontal grid running along latitude line
    final GeographyPointValue centerShiftOffset = new GeographyPointValue(0.33 * polygonRadius, 0);
    // triangles without holes
    center = generatePolygonPointData(center, centerShiftOffset, polygonRadius, 3, 0, numberOfPolygonPointsForEachShape);
    // triangles with holes
    center = generatePolygonPointData(center, centerShiftOffset, polygonRadius, 3, 0.33, numberOfPolygonPointsForEachShape);
    // pentagons without holes
    center = generatePolygonPointData(center, centerShiftOffset, polygonRadius, 5, 0, numberOfPolygonPointsForEachShape);
    // pentagons with holes
    center = generatePolygonPointData(center, centerShiftOffset, polygonRadius, 5, 0.33, numberOfPolygonPointsForEachShape);
    // octagon without holes
    center = generatePolygonPointData(center, centerShiftOffset, polygonRadius, 8, 0, numberOfPolygonPointsForEachShape);
    // octagons with holes
    center = generatePolygonPointData(center, centerShiftOffset, polygonRadius, 8, 0.33, numberOfPolygonPointsForEachShape);
    int polygonEntries = 0;
    int pointEntries = 0;
    List<GeographyPointValue> listOfPoints;
    for (PolygonPoints polygonPoints : m_generatedPolygonPoints) {
        listOfPoints = polygonPoints.getPoints();
        for (GeographyPointValue point : listOfPoints) {
            client.callProcedure("PLACES.Insert", pointEntries, point);
            pointEntries++;
        }
        client.callProcedure("BORDERS.Insert", polygonEntries, polygonPoints.getPolygon());
        client.callProcedure("INDEXED_BORDERS.Insert", polygonEntries, polygonPoints.getPolygon());
        polygonEntries++;
    }
}
Also used : GeographyPointValue(org.voltdb.types.GeographyPointValue)

Example 23 with GeographyPointValue

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

the class TestGeospatialIndexes method subTestParameterizedContains.

private void subTestParameterizedContains(Client client, Boolean testContains) throws NoConnectionsException, IOException, ProcCallException {
    VoltTable resultsUsingGeoIndex, resultsFromNonGeoIndex;
    String indexedProcName, nonIndexProcName, predicate;
    String prefixMsg;
    if (testContains) {
        indexedProcName = "P_CONTAINS_INDEXED";
        nonIndexProcName = "P_CONTAINS";
        predicate = "Contains";
    } else {
        indexedProcName = "P_NOT_CONTAINS_INDEXED";
        nonIndexProcName = "P_NOT_CONTAINS";
        predicate = "Not Contains";
    }
    int maxPolygonsContainSamePoint = 0;
    prefixMsg = "Assertion failed comparing results of " + predicate + " on indexed with non-indexed tables: ";
    List<GeographyPointValue> points;
    for (PolygonPoints polygonPoints : m_generatedPolygonPoints) {
        points = polygonPoints.getPoints();
        for (GeographyPointValue point : points) {
            resultsUsingGeoIndex = client.callProcedure(indexedProcName, point).getResults()[0];
            resultsFromNonGeoIndex = client.callProcedure(nonIndexProcName, point).getResults()[0];
            assertTablesAreEqual(prefixMsg, resultsFromNonGeoIndex, resultsUsingGeoIndex);
            maxPolygonsContainSamePoint = (maxPolygonsContainSamePoint < resultsUsingGeoIndex.getRowCount()) ? resultsUsingGeoIndex.getRowCount() : maxPolygonsContainSamePoint;
        }
    }
    System.out.println("Max polygons for predicate '" + predicate + "': " + maxPolygonsContainSamePoint);
}
Also used : VoltTable(org.voltdb.VoltTable) GeographyPointValue(org.voltdb.types.GeographyPointValue)

Example 24 with GeographyPointValue

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

the class TestGeospatialFunctions method testPointAsText.

public void testPointAsText() throws Exception {
    Client client = getClient();
    populateTables(client);
    // test for border case of rounding up the decimal number
    client.callProcedure("places.Insert", 50, "Someplace1", GeographyPointValue.fromWKT("POINT(13.4999999999995 17)"));
    // test for border case of rounding up the decimal number
    client.callProcedure("places.Insert", 51, "Someplace2", GeographyPointValue.fromWKT("POINT(-13.499999999999999995 -17)"));
    // get WKT representation using asText()
    VoltTable asTextVT = client.callProcedure("@AdHoc", "select loc, asText(loc) from places order by pk").getResults()[0];
    // get WKT representation using cast(point as varchar)
    VoltTable castVT = client.callProcedure("@AdHoc", "select loc, cast(loc as VARCHAR) from places order by pk").getResults()[0];
    // verify results of asText from EE matches WKT format defined in frontend/java
    while (asTextVT.advanceRow()) {
        GeographyPointValue gpv = asTextVT.getGeographyPointValue(0);
        if (gpv == null) {
            assertEquals(null, asTextVT.getString(1));
        } else {
            assertEquals(gpv.toString(), asTextVT.getString(1));
        }
    }
    // verify WKT from asText and cast(point as varchar) results in same result WKT.
    assertEquals(asTextVT, castVT);
}
Also used : Client(org.voltdb.client.Client) VoltTable(org.voltdb.VoltTable) GeographyPointValue(org.voltdb.types.GeographyPointValue)

Example 25 with GeographyPointValue

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

the class TestPolygonFactory method testStarPolygon.

public void testStarPolygon() throws Exception {
    for (int idx = 3; idx < 10; idx += 1) {
        GeographyValue star = PolygonFactory.CreateStar(origin, y.mul(20.0), idx, 0.5, 0.0);
        List<List<GeographyPointValue>> loops = star.getRings();
        assertEquals(1, loops.size());
        List<GeographyPointValue> shell = loops.get(0);
        assertEquals(2 * idx + 1, shell.size());
        star = PolygonFactory.CreateStar(origin, y.mul(20).add(x.mul(20)), idx, 0.5, 0.1);
        loops = star.getRings();
        assertEquals(2, loops.size());
        shell = loops.get(0);
        List<GeographyPointValue> hole = loops.get(1);
        assertEquals(2 * idx + 1, shell.size());
        assertEquals(2 * idx + 1, hole.size());
    }
}
Also used : GeographyValue(org.voltdb.types.GeographyValue) List(java.util.List) ArrayList(java.util.ArrayList) 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