Search in sources :

Example 1 with UnresolvedRelation

use of org.apache.spark.sql.catalyst.analysis.UnresolvedRelation in project kylo by Teradata.

the class AbstractHiveDataSetProviderTest method write.

/**
 * Verify writing to a Hive table.
 */
@Test
public void write() {
    // Mock writer
    writer = createDataFrameWriter(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) {
            final InsertIntoTable plan = invocation.getArgumentAt(0, InsertIntoTable.class);
            final UnresolvedRelation relation = (UnresolvedRelation) plan.table();
            Assert.assertEquals("default", relation.tableIdentifier().database().get());
            Assert.assertEquals("mytable", relation.tableIdentifier().table());
            return null;
        }
    });
    // Create options
    final DataSetOptions options = new DataSetOptions();
    options.addJar("http://example.com/serde.jar");
    options.setOption(KyloCatalogConstants.PATH_OPTION, "default.mytable");
    // Test writing
    final MockHiveDataSetProvider provider = new MockHiveDataSetProvider();
    provider.write(Mockito.mock(KyloCatalogClient.class), options, Mockito.mock(DataFrame.class));
    Mockito.verify(sqlContext).sql("ADD JAR http://example.com/serde.jar");
    Mockito.verify(sqlContext).executePlan(Mockito.any(LogicalPlan.class));
}
Also used : Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) InsertIntoTable(org.apache.spark.sql.catalyst.plans.logical.InsertIntoTable) KyloCatalogClient(com.thinkbiganalytics.kylo.catalog.api.KyloCatalogClient) UnresolvedRelation(org.apache.spark.sql.catalyst.analysis.UnresolvedRelation) DataSetOptions(com.thinkbiganalytics.kylo.catalog.spi.DataSetOptions) LogicalPlan(org.apache.spark.sql.catalyst.plans.logical.LogicalPlan) DataFrame(org.apache.spark.sql.DataFrame) Test(org.junit.Test)

Aggregations

KyloCatalogClient (com.thinkbiganalytics.kylo.catalog.api.KyloCatalogClient)1 DataSetOptions (com.thinkbiganalytics.kylo.catalog.spi.DataSetOptions)1 DataFrame (org.apache.spark.sql.DataFrame)1 UnresolvedRelation (org.apache.spark.sql.catalyst.analysis.UnresolvedRelation)1 InsertIntoTable (org.apache.spark.sql.catalyst.plans.logical.InsertIntoTable)1 LogicalPlan (org.apache.spark.sql.catalyst.plans.logical.LogicalPlan)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1