use of org.apache.pig.PigServer in project pigeon by aseldawy.
the class TestConnect method testShouldWorkWithSomeReversedSegments.
public void testShouldWorkWithSomeReversedSegments() 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[] { "3", "2", "LINESTRING(2 2, 3 1)" });
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);
}
use of org.apache.pig.PigServer in project pigeon by aseldawy.
the class TestConvexHull method testShouldWorkAsUnaryOperation.
public void testShouldWorkAsUnaryOperation() 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 ((0 0, 0 2, 1 1, 2 2, 2 0, 0 0))" });
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 = FOREACH A GENERATE " + ConvexHull.class.getName() + "(geom);";
pig.registerQuery(query);
Iterator<?> it = pig.openIterator("B");
int output_size = 0;
ArrayList<String> expected_results = new ArrayList<String>();
expected_results.add("POLYGON ((0 0, 6 0, 0 5, 0 0))");
expected_results.add("POLYGON ((0 0, 0 2, 2 2, 2 0, 0 0))");
expected_results.add("POLYGON ((3 -2, 8 -1, 8 4, 3 -2))");
Iterator<String> geoms = expected_results.iterator();
while (it.hasNext()) {
Tuple tuple = (Tuple) it.next();
if (tuple == null)
break;
output_size++;
TestHelper.assertGeometryEqual(geoms.next(), tuple.get(0));
}
assertEquals(3, output_size);
}
use of org.apache.pig.PigServer in project pigeon by aseldawy.
the class TestConvexHull method testShouldWorkWithOneObject.
public void testShouldWorkWithOneObject() throws Exception {
ArrayList<String[]> data = new ArrayList<String[]>();
data.add(new String[] { "1", "POLYGON ((0 0, 0 2, 1 1, 2 2, 2 0, 0 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 = 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, 0 2, 2 2, 2 0, 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);
}
use of org.apache.pig.PigServer in project pigeon by aseldawy.
the class TestDifference method testShouldWorkWithWKT.
public void testShouldWorkWithWKT() throws Exception {
ArrayList<String[]> data = new ArrayList<String[]>();
data.add(new String[] { "0", "POLYGON ((0 0, 3 0, 3 3, 0 3, 0 0))", "POLYGON ((4 2, 4 4, 2 4, 4 2))" });
data.add(new String[] { "1", "POLYGON ((0 0, 3 0, 3 3, 0 3, 0 0))", "POLYGON ((4 0, 4 2, 2 2, 4 0))" });
String datafile = TestHelper.createTempFile(data, "\t");
datafile = datafile.replace("\\", "\\\\");
PigServer pig = new PigServer(LOCAL);
String query = "A = LOAD 'file:" + datafile + "' as (id, geom1, geom2);\n" + "B = FOREACH A GENERATE " + Difference.class.getName() + "(geom1, geom2);";
pig.registerQuery(query);
Iterator<?> it = pig.openIterator("B");
ArrayList<String> expected_results = new ArrayList<String>();
expected_results.add("POLYGON ((0 0, 3 0, 3 3, 0 3, 0 0))");
expected_results.add("POLYGON ((0 0, 3 0, 3 1, 2 2, 3 2, 3 3, 0 3, 0 0))");
Iterator<String> geom = expected_results.iterator();
while (it.hasNext() && geom.hasNext()) {
Tuple tuple = (Tuple) it.next();
if (tuple == null)
break;
TestHelper.assertGeometryEqual(geom.next(), tuple.get(0));
}
}
use of org.apache.pig.PigServer in project pigeon by aseldawy.
the class TestExtent 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[] { "0", "LINESTRING (2 2, 7 2, 2 6)" });
data.add(new String[] { "0", "POINT (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 " + Extent.class.getName() + "(A.geom);";
pig.registerQuery(query);
Iterator<?> it = pig.openIterator("C");
// Calculate the union outside Pig
String true_mbr = "POLYGON ((0 -2, 7 -2, 7 6, 0 6, 0 -2))";
int output_size = 0;
while (it.hasNext()) {
Tuple tuple = (Tuple) it.next();
if (tuple == null)
break;
output_size++;
TestHelper.assertGeometryEqual(true_mbr, tuple.get(0));
}
assertEquals(1, output_size);
}
Aggregations