}
@Test
public void useScalaUDT() {
List<MyLabeledPoint> points = Arrays.asList(
new MyLabeledPoint(1.0, new MyDenseVector(new double[]{0.1, 1.0})),
new MyLabeledPoint(0.0, new MyDenseVector(new double[]{0.2, 2.0})));
JavaRDD<MyLabeledPoint> pointsRDD = javaCtx.parallelize(points);
JavaSchemaRDD schemaRDD = javaSqlCtx.applySchema(pointsRDD, MyLabeledPoint.class);
schemaRDD.registerTempTable("points");
List<Row> actualLabelRows = javaSqlCtx.sql("SELECT label FROM points").collect();
List<Double> actualLabels = new LinkedList<Double>();
for (Row r : actualLabelRows) {
actualLabels.add(r.getDouble(0));
}
for (MyLabeledPoint lp : points) {
Assert.assertTrue(actualLabels.contains(lp.label()));
}
List<Row> actualFeatureRows = javaSqlCtx.sql("SELECT features FROM points").collect();
List<MyDenseVector> actualFeatures = new LinkedList<MyDenseVector>();
for (Row r : actualFeatureRows) {
actualFeatures.add((MyDenseVector)r.get(0));
}
for (MyLabeledPoint lp : points) {
Assert.assertTrue(actualFeatures.contains(lp.features()));
}
List<Row> actual = javaSqlCtx.sql("SELECT label, features FROM points").collect();
List<MyLabeledPoint> actualPoints =
new LinkedList<MyLabeledPoint>();
for (Row r : actual) {
actualPoints.add(new MyLabeledPoint(r.getDouble(0), (MyDenseVector)r.get(1)));
}
for (MyLabeledPoint lp : points) {
Assert.assertTrue(actualPoints.contains(lp));
}
}