Search in sources :

Example 1 with Catalog

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

the class AbstractHiveDataSetProviderTest method createDataFrameWriter.

/**
 * Creates a {@code DataFrameWriter} that creates tables using the specified answer.
 */
@Nonnull
private DataFrameWriter createDataFrameWriter(@Nonnull final Answer<Void> executePlanAnswer) {
    final DataFrame df = Mockito.mock(DataFrame.class);
    Mockito.when(df.sqlContext()).thenReturn(sqlContext);
    final Catalog catalog = Mockito.mock(Catalog.class);
    Mockito.when(catalog.tableExists(Mockito.any(TableIdentifier.class))).thenReturn(false);
    Mockito.when(sqlContext.catalog()).thenReturn(catalog);
    final QueryExecution queryExecution = Mockito.mock(QueryExecution.class);
    Mockito.when(sqlContext.executePlan(Mockito.any(LogicalPlan.class))).then(new Answer<QueryExecution>() {

        @Override
        public QueryExecution answer(InvocationOnMock invocation) throws Throwable {
            executePlanAnswer.answer(invocation);
            return queryExecution;
        }
    });
    return new DataFrameWriter(df);
}
Also used : TableIdentifier(org.apache.spark.sql.catalyst.TableIdentifier) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DataFrameWriter(org.apache.spark.sql.DataFrameWriter) LogicalPlan(org.apache.spark.sql.catalyst.plans.logical.LogicalPlan) DataFrame(org.apache.spark.sql.DataFrame) Catalog(org.apache.spark.sql.catalyst.analysis.Catalog) QueryExecution(org.apache.spark.sql.execution.QueryExecution) Nonnull(javax.annotation.Nonnull)

Aggregations

Nonnull (javax.annotation.Nonnull)1 DataFrame (org.apache.spark.sql.DataFrame)1 DataFrameWriter (org.apache.spark.sql.DataFrameWriter)1 TableIdentifier (org.apache.spark.sql.catalyst.TableIdentifier)1 Catalog (org.apache.spark.sql.catalyst.analysis.Catalog)1 LogicalPlan (org.apache.spark.sql.catalyst.plans.logical.LogicalPlan)1 QueryExecution (org.apache.spark.sql.execution.QueryExecution)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1