Search in sources :

Example 11 with DataSetOptions

use of com.thinkbiganalytics.kylo.catalog.spi.DataSetOptions in project kylo by Teradata.

the class SparkDataSetContextTest method isFileFormat.

/**
 * Verify determining if a format reads files.
 */
@Test
@SuppressWarnings("unchecked")
public void isFileFormat() {
    // Mock delegate
    final SparkDataSetDelegate<DataFrame> delegate = Mockito.mock(SparkDataSetDelegate.class);
    Mockito.when(delegate.isFileFormat(Mockito.any(Class.class))).then(new Answer<Boolean>() {

        @Nonnull
        @Override
        public Boolean answer(@Nonnull final InvocationOnMock invocation) {
            final Class<?> clazz = invocation.getArgumentAt(0, Class.class);
            return HadoopFsRelationProvider.class.isAssignableFrom(clazz);
        }
    });
    // Test invalid format
    final DataSetOptions options = new DataSetOptions();
    options.setFormat("invalid");
    final KyloCatalogClient<DataFrame> client = Mockito.mock(KyloCatalogClient.class);
    SparkDataSetContext<DataFrame> context = new SparkDataSetContext<>(options, client, delegate);
    Assert.assertFalse("Expected 'invalid' to not be a file format", context.isFileFormat());
    // Test non-file format
    options.setFormat("jdbc");
    context = new SparkDataSetContext<>(options, client, delegate);
    Assert.assertFalse("Expected 'jdbc' to not be a file format", context.isFileFormat());
    // Test short name
    options.setFormat("text");
    context = new SparkDataSetContext<>(options, client, delegate);
    Assert.assertTrue("Expected 'text' to be a file format", context.isFileFormat());
    // Test class name
    options.setFormat("org.apache.spark.sql.execution.datasources.text.DefaultSource");
    context = new SparkDataSetContext<>(options, client, delegate);
    Assert.assertTrue("Expected 'org.apache.spark.sql.execution.datasources.text.DefaultSource' to be a file format", context.isFileFormat());
    // Test package name
    options.setFormat("org.apache.spark.sql.execution.datasources.text");
    context = new SparkDataSetContext<>(options, client, delegate);
    Assert.assertTrue("Expected 'org.apache.spark.sql.execution.datasources.text' to be a file format", context.isFileFormat());
}
Also used : HadoopFsRelationProvider(org.apache.spark.sql.sources.HadoopFsRelationProvider) Nonnull(javax.annotation.Nonnull) DataSetOptions(com.thinkbiganalytics.kylo.catalog.spi.DataSetOptions) DataFrame(org.apache.spark.sql.DataFrame) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.Test)

Example 12 with DataSetOptions

use of com.thinkbiganalytics.kylo.catalog.spi.DataSetOptions in project kylo by Teradata.

the class SparkDataSetContextTest method getOptionsFileFormat.

/**
 * Verify retrieving options for file data sources.
 */
@Test
@SuppressWarnings("unchecked")
public void getOptionsFileFormat() {
    // Mock options
    final DataSetOptions options = new DataSetOptions();
    options.setFormat("text");
    options.setOption(KyloCatalogConstants.PATH_OPTION, "/mock/path/file.txt");
    // Mock delegate
    final SparkDataSetDelegate<DataFrame> delegate = Mockito.mock(SparkDataSetDelegate.class);
    Mockito.when(delegate.isFileFormat(Mockito.any(Class.class))).thenReturn(true);
    // Test getting path
    final SparkDataSetContext<DataFrame> context = new SparkDataSetContext<>(options, Mockito.mock(KyloCatalogClient.class), delegate);
    Assert.assertTrue("Expected path option to be empty", context.getOption(KyloCatalogConstants.PATH_OPTION).isEmpty());
}
Also used : KyloCatalogClient(com.thinkbiganalytics.kylo.catalog.api.KyloCatalogClient) DataSetOptions(com.thinkbiganalytics.kylo.catalog.spi.DataSetOptions) DataFrame(org.apache.spark.sql.DataFrame) Test(org.junit.Test)

Example 13 with DataSetOptions

use of com.thinkbiganalytics.kylo.catalog.spi.DataSetOptions in project kylo by Teradata.

the class SparkDataSetContextTest method getOptions.

/**
 * Verify retrieving options.
 */
@Test
@SuppressWarnings("unchecked")
public void getOptions() {
    final DataSetOptions options = new DataSetOptions();
    options.setFormat("text");
    options.setOption(KyloCatalogConstants.PATH_OPTION, "/mock/path/file.txt");
    final SparkDataSetContext<DataFrame> context = new SparkDataSetContext<>(options, Mockito.mock(KyloCatalogClient.class), Mockito.mock(SparkDataSetDelegate.class));
    Assert.assertEquals("/mock/path/file.txt", context.getOption(KyloCatalogConstants.PATH_OPTION).get());
}
Also used : KyloCatalogClient(com.thinkbiganalytics.kylo.catalog.api.KyloCatalogClient) DataSetOptions(com.thinkbiganalytics.kylo.catalog.spi.DataSetOptions) DataFrame(org.apache.spark.sql.DataFrame) Test(org.junit.Test)

Example 14 with DataSetOptions

use of com.thinkbiganalytics.kylo.catalog.spi.DataSetOptions in project kylo by Teradata.

the class SparkDataSetContextTest method getPathsFileFormatEmpty.

/**
 * Verify retrieving {@code null} paths.
 */
@Test
@SuppressWarnings("unchecked")
public void getPathsFileFormatEmpty() {
    // Mock options
    final DataSetOptions options = new DataSetOptions();
    options.setFormat("text");
    // Mock delegate
    final SparkDataSetDelegate<DataFrame> delegate = Mockito.mock(SparkDataSetDelegate.class);
    Mockito.when(delegate.isFileFormat(Mockito.any(Class.class))).thenReturn(true);
    // Test getting paths
    final SparkDataSetContext<DataFrame> context = new SparkDataSetContext<>(options, Mockito.mock(KyloCatalogClient.class), delegate);
    Assert.assertNull(context.getPaths());
}
Also used : KyloCatalogClient(com.thinkbiganalytics.kylo.catalog.api.KyloCatalogClient) DataSetOptions(com.thinkbiganalytics.kylo.catalog.spi.DataSetOptions) DataFrame(org.apache.spark.sql.DataFrame) Test(org.junit.Test)

Example 15 with DataSetOptions

use of com.thinkbiganalytics.kylo.catalog.spi.DataSetOptions in project kylo by Teradata.

the class AbstractJdbcDataSetProviderTest method read.

/**
 * Verify reading from a JDBC table.
 */
@Test
public void read() {
    final DataSetOptions options = new DataSetOptions();
    options.setFormat("jdbc");
    // Test reading
    final MockJdbcDataSetProvider provider = new MockJdbcDataSetProvider();
    provider.read(Mockito.mock(KyloCatalogClient.class), options);
    Mockito.verify(reader).format(JdbcRelationProvider.class.getName());
}
Also used : JdbcRelationProvider(com.thinkbiganalytics.kylo.catalog.spark.sources.jdbc.JdbcRelationProvider) KyloCatalogClient(com.thinkbiganalytics.kylo.catalog.api.KyloCatalogClient) DataSetOptions(com.thinkbiganalytics.kylo.catalog.spi.DataSetOptions) Test(org.junit.Test)

Aggregations

DataSetOptions (com.thinkbiganalytics.kylo.catalog.spi.DataSetOptions)21 Test (org.junit.Test)21 KyloCatalogClient (com.thinkbiganalytics.kylo.catalog.api.KyloCatalogClient)17 DataFrame (org.apache.spark.sql.DataFrame)16 File (java.io.File)2 Configuration (org.apache.hadoop.conf.Configuration)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 JdbcRelationProvider (com.thinkbiganalytics.kylo.catalog.spark.sources.jdbc.JdbcRelationProvider)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 Nonnull (javax.annotation.Nonnull)1 Column (org.apache.spark.sql.Column)1 SQLConf (org.apache.spark.sql.SQLConf)1 SQLContext (org.apache.spark.sql.SQLContext)1 UnresolvedRelation (org.apache.spark.sql.catalyst.analysis.UnresolvedRelation)1 ScalaUDF (org.apache.spark.sql.catalyst.expressions.ScalaUDF)1 InsertIntoTable (org.apache.spark.sql.catalyst.plans.logical.InsertIntoTable)1 LogicalPlan (org.apache.spark.sql.catalyst.plans.logical.LogicalPlan)1