Search in sources :

Example 1 with Person

use of io.cdap.cdap.spark.app.Person in project cdap by caskdata.

the class SparkTest method testDatasetSQL.

@Test
@Ignore("For this to work in spark 2 and later DefaultSource should implement" + "org.apache.spark.sql.execution.datasources.FileFormat")
public void testDatasetSQL() throws Exception {
    ApplicationManager appManager = deploy(TestSparkApp.class);
    DataSetManager<ObjectMappedTable<Person>> tableManager = getDataset("PersonTable");
    ObjectMappedTable<Person> table = tableManager.get();
    table.write("1", new Person("Bob", 10));
    table.write("2", new Person("Bill", 20));
    table.write("3", new Person("Berry", 30));
    tableManager.flush();
    SparkManager sparkManager = appManager.getSparkManager(DatasetSQLSpark.class.getSimpleName());
    sparkManager.startAndWaitForGoodRun(ProgramRunStatus.COMPLETED, 2, TimeUnit.MINUTES);
    // The program executes "SELECT * FROM Person WHERE age > 10", hence expected two new entries for Bill and Berry.
    tableManager.flush();
    Person person = table.read("new:2");
    Assert.assertEquals("Bill", person.name());
    Assert.assertEquals(20, person.age());
    person = table.read("new:3");
    Assert.assertEquals("Berry", person.name());
    Assert.assertEquals(30, person.age());
    // Shouldn't have new Bob
    Assert.assertNull(table.read("new:1"));
}
Also used : ApplicationManager(io.cdap.cdap.test.ApplicationManager) SparkManager(io.cdap.cdap.test.SparkManager) ObjectMappedTable(io.cdap.cdap.api.dataset.lib.ObjectMappedTable) Person(io.cdap.cdap.spark.app.Person) DatasetSQLSpark(io.cdap.cdap.spark.app.DatasetSQLSpark) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ObjectMappedTable (io.cdap.cdap.api.dataset.lib.ObjectMappedTable)1 DatasetSQLSpark (io.cdap.cdap.spark.app.DatasetSQLSpark)1 Person (io.cdap.cdap.spark.app.Person)1 ApplicationManager (io.cdap.cdap.test.ApplicationManager)1 SparkManager (io.cdap.cdap.test.SparkManager)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1