Search in sources :

Example 6 with KyloCatalogClient

use of com.thinkbiganalytics.kylo.catalog.api.KyloCatalogClient in project kylo by Teradata.

the class AbstractJdbcDataSetProviderTest method createHighWaterMark.

/**
 * Verify creating a high water mark.
 */
@Test
public void createHighWaterMark() {
    final KyloCatalogClient client = Mockito.mock(KyloCatalogClient.class);
    // Test creating high water mark
    final MockJdbcDataSetProvider provider = new MockJdbcDataSetProvider();
    final JdbcHighWaterMark highWaterMark = provider.createHighWaterMark("mockWaterMark", client);
    Assert.assertEquals("mockWaterMark", highWaterMark.getName());
    Assert.assertNull("Expected initial value to be null", highWaterMark.getValue());
    // Test adding a value
    highWaterMark.accumulate(1525014303000L);
    Mockito.verify(client).setHighWaterMarks(Collections.singletonMap("mockWaterMark", "2018-04-29T15:05:03"));
}
Also used : JdbcHighWaterMark(com.thinkbiganalytics.kylo.catalog.spark.sources.jdbc.JdbcHighWaterMark) KyloCatalogClient(com.thinkbiganalytics.kylo.catalog.api.KyloCatalogClient) Test(org.junit.Test)

Example 7 with KyloCatalogClient

use of com.thinkbiganalytics.kylo.catalog.api.KyloCatalogClient in project kylo by Teradata.

the class AbstractJdbcDataSetProviderTest method updateHighWaterMarkWithTimestamp.

/**
 * Verify updating a high water mark for a timestamp column.
 */
@Test
public void updateHighWaterMarkWithTimestamp() {
    // Mock data set
    final DataFrame dataSet = Mockito.mock(DataFrame.class);
    Mockito.when(dataSet.col("mockField")).thenReturn(new Column("mockField"));
    final StructField field = DataTypes.createStructField("mockField", DataTypes.TimestampType, true);
    Mockito.when(dataSet.schema()).thenReturn(DataTypes.createStructType(Collections.singletonList(field)));
    final DataFrame mapDataSet = Mockito.mock(DataFrame.class);
    Mockito.when(dataSet.withColumn(Mockito.eq("mockField"), Mockito.any(Column.class))).thenReturn(mapDataSet);
    // Test updating high water mark
    final KyloCatalogClient client = Mockito.mock(KyloCatalogClient.class);
    final JdbcHighWaterMark highWaterMark = new JdbcHighWaterMark("mockWaterMark", client);
    final MockJdbcDataSetProvider provider = new MockJdbcDataSetProvider();
    final DataFrame newDataSet = provider.updateHighWaterMark(dataSet, "mockField", highWaterMark, client);
    Assert.assertEquals(mapDataSet, newDataSet);
    // Test replaced column
    final ArgumentCaptor<Column> newColumn = ArgumentCaptor.forClass(Column.class);
    Mockito.verify(dataSet).withColumn(Mockito.eq("mockField"), newColumn.capture());
    Assert.assertTrue("Expected new column to be a UDF", newColumn.getValue().expr() instanceof ScalaUDF);
}
Also used : StructField(org.apache.spark.sql.types.StructField) JdbcHighWaterMark(com.thinkbiganalytics.kylo.catalog.spark.sources.jdbc.JdbcHighWaterMark) Column(org.apache.spark.sql.Column) KyloCatalogClient(com.thinkbiganalytics.kylo.catalog.api.KyloCatalogClient) DataFrame(org.apache.spark.sql.DataFrame) ScalaUDF(org.apache.spark.sql.catalyst.expressions.ScalaUDF) Test(org.junit.Test)

Aggregations

KyloCatalogClient (com.thinkbiganalytics.kylo.catalog.api.KyloCatalogClient)7 Test (org.junit.Test)7 JdbcHighWaterMark (com.thinkbiganalytics.kylo.catalog.spark.sources.jdbc.JdbcHighWaterMark)4 DataFrame (org.apache.spark.sql.DataFrame)4 DataSetOptions (com.thinkbiganalytics.kylo.catalog.spi.DataSetOptions)2 File (java.io.File)2 Configuration (org.apache.hadoop.conf.Configuration)2 Column (org.apache.spark.sql.Column)2 ScalaUDF (org.apache.spark.sql.catalyst.expressions.ScalaUDF)2 StructField (org.apache.spark.sql.types.StructField)2 ArrayList (java.util.ArrayList)1