Search in sources :

Example 36 with PigServer

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

the class TestAsText method testShouldWorkWithWKT.

public void testShouldWorkWithWKT() throws Exception {
    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 " + AsText.class.getName() + "(geom);";
    pig.registerQuery(query);
    Iterator<?> it = pig.openIterator("B");
    Iterator<OGCGeometry> geoms = geometries.iterator();
    while (it.hasNext() && geoms.hasNext()) {
        Tuple tuple = (Tuple) it.next();
        OGCGeometry geom = geoms.next();
        if (tuple == null)
            break;
        String wkt = (String) tuple.get(0);
        assertEquals(geom.asText(), wkt);
    }
}
Also used : OGCGeometry(com.esri.core.geometry.ogc.OGCGeometry) PigServer(org.apache.pig.PigServer) Tuple(org.apache.pig.data.Tuple)

Example 37 with PigServer

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

the class TestBreak method testShouldWorkWithLinestring.

public void testShouldWorkWithLinestring() throws Exception {
    ArrayList<String[]> data = new ArrayList<String[]>();
    data.add(new String[] { "0", "LINESTRING (0 0, 0 1, 1 3)" });
    String datafile = TestHelper.createTempFile(data, "\t");
    datafile = datafile.replace("\\", "\\\\");
    PigServer pig = new PigServer(LOCAL);
    String query = "A = LOAD 'file:" + datafile + "' as (geom_id: int, geom);\n" + "B = FOREACH A GENERATE geom_id, FLATTEN(" + Break.class.getName() + "(geom));";
    pig.registerQuery(query);
    Iterator<?> it = pig.openIterator("B");
    Vector<String[]> expectedResults = new Vector<String[]>();
    expectedResults.add(new String[] { "0", "0", "0", "0", "0", "1" });
    expectedResults.add(new String[] { "0", "1", "0", "1", "1", "3" });
    Iterator<String[]> expected = expectedResults.iterator();
    int count = 0;
    while (it.hasNext() && expected.hasNext()) {
        Tuple tuple = (Tuple) it.next();
        String[] expectedResult = expected.next();
        if (tuple == null)
            break;
        assertEquals(Integer.parseInt(expectedResult[0]), tuple.get(0));
        assertEquals(Integer.parseInt(expectedResult[1]), tuple.get(1));
        assertEquals(Double.parseDouble(expectedResult[2]), tuple.get(2));
        assertEquals(Double.parseDouble(expectedResult[3]), tuple.get(3));
        assertEquals(Double.parseDouble(expectedResult[4]), tuple.get(4));
        assertEquals(Double.parseDouble(expectedResult[5]), tuple.get(5));
        count++;
    }
    assertEquals(expectedResults.size(), count);
}
Also used : PigServer(org.apache.pig.PigServer) ArrayList(java.util.ArrayList) Vector(java.util.Vector) Tuple(org.apache.pig.data.Tuple)

Example 38 with PigServer

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

the class TestBuffer method testShouldWorkWithIntegerBuffer.

public void testShouldWorkWithIntegerBuffer() throws Exception {
    ArrayList<String[]> data = new ArrayList<String[]>();
    data.add(new String[] { "1", "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 " + Buffer.class.getName() + "(geom, 1);";
    pig.registerQuery(query);
    Iterator<?> it = pig.openIterator("B");
    ArrayList<String> geometries = new ArrayList<String>();
    geometries.add(OGCGeometry.fromText("LINESTRING (0 0, 0 3, 4 5, 10 0)").buffer(1.0).asText());
    Iterator<String> geoms = geometries.iterator();
    while (it.hasNext() && geoms.hasNext()) {
        Tuple tuple = (Tuple) it.next();
        if (tuple == null)
            break;
        String exptected_result = geoms.next();
        TestHelper.assertGeometryEqual(exptected_result, tuple.get(0));
    }
}
Also used : PigServer(org.apache.pig.PigServer) ArrayList(java.util.ArrayList) Tuple(org.apache.pig.data.Tuple)

Example 39 with PigServer

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

the class TestBuffer method testShouldWorkWithUntypedColumn.

public void testShouldWorkWithUntypedColumn() throws Exception {
    ArrayList<String[]> data = new ArrayList<String[]>();
    data.add(new String[] { "1", "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 " + Buffer.class.getName() + "(geom, id);";
    pig.registerQuery(query);
    Iterator<?> it = pig.openIterator("B");
    ArrayList<String> geometries = new ArrayList<String>();
    geometries.add(OGCGeometry.fromText("LINESTRING (0 0, 0 3, 4 5, 10 0)").buffer(1.0).asText());
    Iterator<String> geoms = geometries.iterator();
    while (it.hasNext() && geoms.hasNext()) {
        Tuple tuple = (Tuple) it.next();
        if (tuple == null)
            break;
        String exptected_result = geoms.next();
        TestHelper.assertGeometryEqual(exptected_result, tuple.get(0));
    }
}
Also used : PigServer(org.apache.pig.PigServer) ArrayList(java.util.ArrayList) Tuple(org.apache.pig.data.Tuple)

Example 40 with PigServer

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

the class TestConnect method testShouldWorkWithEntriesOfTypePolygon.

public void testShouldWorkWithEntriesOfTypePolygon() throws Exception {
    ArrayList<String[]> data = new ArrayList<String[]>();
    data.add(new String[] { "1", "1", "POLYGON((0 0, 2 0, 3 1, 0 0))" });
    data.add(new String[] { "2", "2", "POLYGON((5 5, 5 6, 6 5, 5 5))" });
    data.add(new String[] { "7", "8", "LINESTRING(10 8, 8 5)" });
    String expectedResult = "GeometryCollection(LineString(10 8, 8 5), " + "Polygon((0 0, 2 0, 3 1, 0 0)), Polygon((5 5, 5 6, 6 5, 5 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;
    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)

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