use of org.apache.pig.PigServer in project pigeon by aseldawy.
the class TestBreak method testShouldWorkWithGeometryCollection.
public void testShouldWorkWithGeometryCollection() throws Exception {
ArrayList<String[]> data = new ArrayList<String[]>();
data.add(new String[] { "1", "GEOMETRYCOLLECTION (POLYGON ((0 0, 0 1, 1 0, 0 0)))" });
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[] { "1", "0", "0", "0", "0", "1" });
expectedResults.add(new String[] { "1", "1", "0", "1", "1", "0" });
expectedResults.add(new String[] { "1", "2", "1", "0", "0", "0" });
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);
}
use of org.apache.pig.PigServer in project pigeon by aseldawy.
the class TestBreak method testShouldWorkWithPolygon.
public void testShouldWorkWithPolygon() throws Exception {
ArrayList<String[]> data = new ArrayList<String[]>();
data.add(new String[] { "1", "POLYGON ((0 0, 0 1, 1 0, 0 0))" });
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[] { "1", "0", "0", "0", "0", "1" });
expectedResults.add(new String[] { "1", "1", "0", "1", "1", "0" });
expectedResults.add(new String[] { "1", "2", "1", "0", "0", "0" });
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);
}
use of org.apache.pig.PigServer in project pigeon by aseldawy.
the class TestBreak method testShouldSkipPoints.
public void testShouldSkipPoints() throws Exception {
ArrayList<String[]> data = new ArrayList<String[]>();
data.add(new String[] { "1", "GEOMETRYCOLLECTION (POLYGON ((0 0, 0 1, 1 0, 0 0)), POINT (5 5))" });
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[] { "1", "0", "0", "0", "0", "1" });
expectedResults.add(new String[] { "1", "1", "0", "1", "1", "0" });
expectedResults.add(new String[] { "1", "2", "1", "0", "0", "0" });
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);
}
use of org.apache.pig.PigServer in project pigeon by aseldawy.
the class TestBuffer method testShouldWorkWithDoubleBuffer.
public void testShouldWorkWithDoubleBuffer() 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.0);";
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));
}
}
use of org.apache.pig.PigServer in project pigeon by aseldawy.
the class TestConnect method testShouldWorkWithDirectPolygon.
public void testShouldWorkWithDirectPolygon() 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)" });
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");
String expectedResult = "Polygon((0 0, 2 0, 3 1, 2 2, 1 2, 0 0))";
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);
}
Aggregations