Search in sources :

Example 1 with SQLConf

use of org.apache.spark.sql.SQLConf in project kylo by Teradata.

the class AbstractHiveDataSetProviderTest method beforeEach.

/**
 * Set up tests.
 */
@Before
public void beforeEach() {
    sqlContext = Mockito.mock(SQLContext.class);
    Mockito.when(sqlContext.conf()).thenReturn(new SQLConf());
}
Also used : SQLContext(org.apache.spark.sql.SQLContext) SQLConf(org.apache.spark.sql.SQLConf) Before(org.junit.Before)

Example 2 with SQLConf

use of org.apache.spark.sql.SQLConf in project kylo by Teradata.

the class AbstractJdbcDataSetProviderTest method write.

/**
 * Verify writing to a JDBC table.
 */
@Test
public void write() throws Exception {
    // Mock data set
    final DataFrame dataFrame = Mockito.mock(DataFrame.class);
    final SQLContext sqlContext = Mockito.mock(SQLContext.class);
    Mockito.when(sqlContext.conf()).thenReturn(new SQLConf());
    Mockito.when(dataFrame.sqlContext()).thenReturn(sqlContext);
    final StructField field1 = DataTypes.createStructField("col1", DataTypes.IntegerType, true);
    final StructField field2 = DataTypes.createStructField("col2", DataTypes.StringType, true);
    Mockito.when(dataFrame.schema()).thenReturn(DataTypes.createStructType(Arrays.asList(field1, field2)));
    // Mock options
    final DataSetOptions options = new DataSetOptions();
    options.setOption("dbtable", "mytable");
    options.setOption("url", "jdbc:h2:mem:spark");
    // Test writing
    try (final Connection conn = DriverManager.getConnection("jdbc:h2:mem:spark")) {
        final MockJdbcDataSetProvider provider = new MockJdbcDataSetProvider();
        provider.write(Mockito.mock(KyloCatalogClient.class), options, dataFrame);
        try (final Statement stmt = conn.createStatement();
            final ResultSet rs = stmt.executeQuery("SHOW COLUMNS FROM mytable")) {
            Assert.assertTrue("Expected 2 rows; found 0 rows", rs.next());
            Assert.assertEquals("COL1", rs.getString(1));
            Assert.assertEquals("INTEGER(10)", rs.getString(2));
            Assert.assertTrue("Expected 2 rows; found 1 row", rs.next());
            Assert.assertEquals("COL2", rs.getString(1));
            Assert.assertEquals("CLOB(2147483647)", rs.getString(2));
            Assert.assertFalse("Expected 2 rows; fonud 3 rows", rs.next());
        }
    }
}
Also used : StructField(org.apache.spark.sql.types.StructField) Statement(java.sql.Statement) Connection(java.sql.Connection) KyloCatalogClient(com.thinkbiganalytics.kylo.catalog.api.KyloCatalogClient) ResultSet(java.sql.ResultSet) DataSetOptions(com.thinkbiganalytics.kylo.catalog.spi.DataSetOptions) DataFrame(org.apache.spark.sql.DataFrame) SQLContext(org.apache.spark.sql.SQLContext) SQLConf(org.apache.spark.sql.SQLConf) Test(org.junit.Test)

Aggregations

SQLConf (org.apache.spark.sql.SQLConf)2 SQLContext (org.apache.spark.sql.SQLContext)2 KyloCatalogClient (com.thinkbiganalytics.kylo.catalog.api.KyloCatalogClient)1 DataSetOptions (com.thinkbiganalytics.kylo.catalog.spi.DataSetOptions)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 DataFrame (org.apache.spark.sql.DataFrame)1 StructField (org.apache.spark.sql.types.StructField)1 Before (org.junit.Before)1 Test (org.junit.Test)1