Search in sources :

Example 41 with PigServer

use of org.apache.pig.PigServer in project pigeon by aseldawy.

the class TestConnect method testShouldMakeGeometryCollectionForDisconnectedShapes.

public void testShouldMakeGeometryCollectionForDisconnectedShapes() throws Exception {
    ArrayList<String[]> data = new ArrayList<String[]>();
    data.add(new String[] { "1", "2", "LINESTRING(0 0, 2 0, 3 1)" });
    data.add(new String[] { "2", "3", "LINESTRING(3 1, 2 2)" });
    data.add(new String[] { "3", "1", "LINESTRING(2 2, 1 2, 0 0)" });
    data.add(new String[] { "7", "8", "LINESTRING(10 8, 8 5)" });
    String datafile = TestHelper.createTempFile(data, "\t");
    datafile = datafile.replace("\\", "\\\\");
    PigServer pig = new PigServer(LOCAL);
    String query = "A = LOAD 'file:" + datafile + "' AS (first_point: long, last_point: long, linestring: chararray);\n" + "B = GROUP A ALL;" + "C = FOREACH B GENERATE " + Connect.class.getName() + "(A.first_point, A.last_point, A.linestring);";
    pig.registerQuery(query);
    Iterator<?> it = pig.openIterator("C");
    int count = 0;
    String expectedResult = "GEOMETRYCOLLECTION(LINESTRING(10 8, 8 5), " + "POLYGON((0 0, 2 0, 3 1, 2 2, 1 2, 0 0)))";
    while (it.hasNext()) {
        Tuple tuple = (Tuple) it.next();
        if (tuple == null)
            break;
        TestHelper.assertGeometryEqual(expectedResult, tuple.get(0));
        count++;
    }
    assertEquals(1, count);
}
Also used : PigServer(org.apache.pig.PigServer) ArrayList(java.util.ArrayList) Tuple(org.apache.pig.data.Tuple)

Example 42 with PigServer

use of org.apache.pig.PigServer in project pigeon by aseldawy.

the class TestConvexHull method testShouldWorkWithWKT.

public void testShouldWorkWithWKT() throws Exception {
    ArrayList<String[]> data = new ArrayList<String[]>();
    data.add(new String[] { "0", "POLYGON ((0 0, 6 0, 0 5, 0 0))" });
    data.add(new String[] { "1", "POLYGON ((2 2, 7 2, 2 6, 2 2))" });
    data.add(new String[] { "2", "POLYGON ((3 -2, 8 -1, 8 4, 3 -2))" });
    String datafile = TestHelper.createTempFile(data, "\t");
    datafile = datafile.replace("\\", "\\\\");
    PigServer pig = new PigServer(LOCAL);
    String query = "A = LOAD 'file:" + datafile + "' as (id, geom);\n" + "B = GROUP A ALL;\n" + "C = FOREACH B GENERATE " + ConvexHull.class.getName() + "(A.geom);";
    pig.registerQuery(query);
    Iterator<?> it = pig.openIterator("C");
    // Calculate the convex hull outside Pig
    String true_convex_hull = "POLYGON ((0 0, 3 -2, 8 -1, 8 4, 2 6, 0 5, 0 0))";
    int output_size = 0;
    while (it.hasNext()) {
        Tuple tuple = (Tuple) it.next();
        if (tuple == null)
            break;
        output_size++;
        TestHelper.assertGeometryEqual(true_convex_hull, tuple.get(0));
    }
    assertEquals(1, output_size);
}
Also used : PigServer(org.apache.pig.PigServer) ArrayList(java.util.ArrayList) Tuple(org.apache.pig.data.Tuple)

Example 43 with PigServer

use of org.apache.pig.PigServer in project pigeon by aseldawy.

the class TestCrosses method testShouldWorkWithWKT.

public void testShouldWorkWithWKT() throws Exception {
    ArrayList<String[]> data = new ArrayList<String[]>();
    data.add(new String[] { "0", "LINESTRING (0 0, 3 3)", "LINESTRING (0 3, 3 0)" });
    data.add(new String[] { "1", "LINESTRING (0 0, 0 3)", "LINESTRING (0 3, 3 0)" });
    data.add(new String[] { "2", "LINESTRING (0 0, 3 0)", "LINESTRING (0 3, 3 3)" });
    String datafile = TestHelper.createTempFile(data, "\t");
    datafile = datafile.replace("\\", "\\\\");
    PigServer pig = new PigServer(LOCAL);
    String query = "A = LOAD 'file:" + datafile + "' as (id: int, geom1, geom2);\n" + "B = FILTER A BY " + Crosses.class.getName() + "(geom1, geom2);";
    pig.registerQuery(query);
    Iterator<?> it = pig.openIterator("B");
    ArrayList<Integer> expected_results = new ArrayList<Integer>();
    expected_results.add(0);
    Iterator<Integer> result_ids = expected_results.iterator();
    int count = 0;
    while (it.hasNext() && result_ids.hasNext()) {
        Tuple tuple = (Tuple) it.next();
        count++;
        assertEquals(result_ids.next(), (Integer) tuple.get(0));
    }
    assertFalse(it.hasNext());
    assertEquals(1, count);
}
Also used : PigServer(org.apache.pig.PigServer) ArrayList(java.util.ArrayList) Tuple(org.apache.pig.data.Tuple)

Example 44 with PigServer

use of org.apache.pig.PigServer in project pigeon by aseldawy.

the class TestEnvelope method testShouldWorkWithWKT.

public void testShouldWorkWithWKT() throws Exception {
    ArrayList<String[]> data = new ArrayList<String[]>();
    data.add(new String[] { "0", "LINESTRING (0 0, 0 3, 4 5, 10 0)" });
    String datafile = TestHelper.createTempFile(data, "\t");
    datafile = datafile.replace("\\", "\\\\");
    PigServer pig = new PigServer(LOCAL);
    String query = "A = LOAD 'file:" + datafile + "' as (id, geom);\n" + "B = FOREACH A GENERATE " + Envelope.class.getName() + "(geom);";
    pig.registerQuery(query);
    Iterator<?> it = pig.openIterator("B");
    ArrayList<String> geometries = new ArrayList<String>();
    geometries.add("POLYGON ((0 0, 10 0, 10 5, 0 5, 0 0))");
    Iterator<String> geoms = geometries.iterator();
    while (it.hasNext() && geoms.hasNext()) {
        String expected_result = geoms.next();
        Tuple tuple = (Tuple) it.next();
        if (tuple == null)
            break;
        TestHelper.assertGeometryEqual(expected_result, tuple.get(0));
    }
}
Also used : PigServer(org.apache.pig.PigServer) ArrayList(java.util.ArrayList) Tuple(org.apache.pig.data.Tuple)

Example 45 with PigServer

use of org.apache.pig.PigServer in project pigeon by aseldawy.

the class TestMakeBox method testShouldWorkWithWKT.

public void testShouldWorkWithWKT() throws Exception {
    ArrayList<String[]> data = new ArrayList<String[]>();
    data.add(new String[] { "0" });
    String datafile = TestHelper.createTempFile(data, "\t");
    datafile = datafile.replace("\\", "\\\\");
    PigServer pig = new PigServer(LOCAL);
    String query = "A = LOAD 'file:" + datafile + "' as (dummy);\n" + "B = FOREACH A GENERATE " + MakeBox.class.getName() + "(1, 2, 5, 7);";
    pig.registerQuery(query);
    Iterator<?> it = pig.openIterator("B");
    Vector<String> expectedResult = new Vector<String>();
    expectedResult.add("POLYGON((1 2, 5 2, 5 7, 1 7, 1 2))");
    Iterator<String> geoms = expectedResult.iterator();
    int count = 0;
    while (it.hasNext() && geoms.hasNext()) {
        Tuple tuple = (Tuple) it.next();
        String expected_result = geoms.next();
        if (tuple == null)
            break;
        TestHelper.assertGeometryEqual(expected_result, tuple.get(0));
        count++;
    }
    assertEquals(expectedResult.size(), count);
}
Also used : PigServer(org.apache.pig.PigServer) ArrayList(java.util.ArrayList) Vector(java.util.Vector) Tuple(org.apache.pig.data.Tuple)

Aggregations

PigServer (org.apache.pig.PigServer)114 Tuple (org.apache.pig.data.Tuple)74 ArrayList (java.util.ArrayList)68 Test (org.junit.Test)57 HCatBaseTest (org.apache.hive.hcatalog.mapreduce.HCatBaseTest)28 File (java.io.File)16 Data (org.apache.pig.builtin.mock.Storage.Data)15 Schema (org.apache.pig.impl.logicalLayer.schema.Schema)14 FieldSchema (org.apache.pig.impl.logicalLayer.schema.Schema.FieldSchema)9 Properties (java.util.Properties)8 Vector (java.util.Vector)8 HCatFieldSchema (org.apache.hive.hcatalog.data.schema.HCatFieldSchema)6 CommandProcessorResponse (org.apache.hadoop.hive.ql.processors.CommandProcessorResponse)5 FileWriter (java.io.FileWriter)3 IOException (java.io.IOException)3 List (java.util.List)3 Map (java.util.Map)3 Path (org.apache.hadoop.fs.Path)3 Admin (org.apache.hadoop.hbase.client.Admin)3 Connection (org.apache.hadoop.hbase.client.Connection)3