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);
}
}
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);
}
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));
}
}
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));
}
}
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);
}
Aggregations