Search in sources :

Example 1 with SnowflakeWriter

use of org.talend.components.snowflake.runtime.SnowflakeWriter in project components by Talend.

the class SnowflakeWritersTestIT method testOutputFeedback.

@Test
public void testOutputFeedback() throws Throwable {
    TSnowflakeOutputProperties props = (TSnowflakeOutputProperties) getComponentService().getComponentProperties(TSnowflakeOutputDefinition.COMPONENT_NAME);
    setupProps(props.getConnectionProperties());
    setupTableWithStaticValues(props);
    props.outputAction.setStoredValue(TSnowflakeOutputProperties.OutputAction.INSERT);
    DefaultComponentRuntimeContainerImpl container = new DefaultComponentRuntimeContainerImpl();
    // Initialize the Sink, WriteOperation and Writer
    SnowflakeSink sfSink = new SnowflakeSink();
    sfSink.initialize(container, props);
    sfSink.validate(container);
    SnowflakeWriteOperation sfWriteOp = sfSink.createWriteOperation();
    sfWriteOp.initialize(container);
    SnowflakeWriter sfWriter = sfSink.createWriteOperation().createWriter(container);
    sfWriter.open("uid1");
    List<IndexedRecord> rows = makeRows(2);
    IndexedRecord r = rows.get(0);
    r.put(0, "badId");
    r.put(2, "badBoolean");
    r.put(4, "badDate");
    r.put(5, "badTime");
    r.put(6, "badTimestamp");
    sfWriter.write(r);
    sfWriter.write(rows.get(1));
    Result wr1 = sfWriter.close();
    // The rejected writes would come in here
    Iterable<IndexedRecord> rejected = sfWriter.getRejectedWrites();
    Iterator<IndexedRecord> it = rejected.iterator();
    IndexedRecord rej;
    rej = it.next();
    // row
    assertEquals("1", rej.get(1));
    // character
    assertEquals("1", rej.get(3));
    assertThat((String) rej.get(4), containsString("Numeric value 'badId'"));
    // byte offset
    assertEquals("0", rej.get(5));
    // line
    assertEquals("1", rej.get(6));
    // code
    assertEquals("100038", rej.get(8));
    rej = it.next();
    // row
    assertEquals("1", rej.get(1));
    // character
    assertEquals("13", rej.get(3));
    assertThat((String) rej.get(4), containsString("Boolean value 'badBoolean'"));
    // byte offset
    assertEquals("12", rej.get(5));
    // line
    assertEquals("1", rej.get(6));
    // code
    assertEquals("100037", rej.get(8));
    rej = it.next();
    // row
    assertEquals("1", rej.get(1));
    // character
    assertEquals("32", rej.get(3));
    assertThat((String) rej.get(4), containsString("Date 'badDate'"));
    // byte offset
    assertEquals("31", rej.get(5));
    // line
    assertEquals("1", rej.get(6));
    // code
    assertEquals("100040", rej.get(8));
    rej = it.next();
    // row
    assertEquals("1", rej.get(1));
    // character
    assertEquals("40", rej.get(3));
    assertThat((String) rej.get(4), containsString("Time 'badTime'"));
    // byte offset
    assertEquals("39", rej.get(5));
    // line
    assertEquals("1", rej.get(6));
    // code
    assertEquals("100108", rej.get(8));
    rej = it.next();
    // row
    assertEquals("1", rej.get(1));
    // character
    assertEquals("48", rej.get(3));
    assertThat((String) rej.get(4), containsString("Timestamp 'badTimestamp'"));
    // byte offset
    assertEquals("47", rej.get(5));
    // line
    assertEquals("1", rej.get(6));
    // code
    assertEquals("100035", rej.get(8));
    assertFalse(it.hasNext());
    assertEquals(1, wr1.getSuccessCount());
    assertEquals(1, wr1.getRejectCount());
    assertEquals(2, wr1.getTotalCount());
    sfWriteOp.finalize(Arrays.asList(wr1), container);
}
Also used : TSnowflakeOutputProperties(org.talend.components.snowflake.tsnowflakeoutput.TSnowflakeOutputProperties) SnowflakeWriteOperation(org.talend.components.snowflake.runtime.SnowflakeWriteOperation) IndexedRecord(org.apache.avro.generic.IndexedRecord) DefaultComponentRuntimeContainerImpl(org.talend.components.api.container.DefaultComponentRuntimeContainerImpl) SnowflakeWriter(org.talend.components.snowflake.runtime.SnowflakeWriter) SnowflakeSink(org.talend.components.snowflake.runtime.SnowflakeSink) ValidationResult(org.talend.daikon.properties.ValidationResult) Result(org.talend.components.api.component.runtime.Result) Test(org.junit.Test)

Aggregations

IndexedRecord (org.apache.avro.generic.IndexedRecord)1 Test (org.junit.Test)1 Result (org.talend.components.api.component.runtime.Result)1 DefaultComponentRuntimeContainerImpl (org.talend.components.api.container.DefaultComponentRuntimeContainerImpl)1 SnowflakeSink (org.talend.components.snowflake.runtime.SnowflakeSink)1 SnowflakeWriteOperation (org.talend.components.snowflake.runtime.SnowflakeWriteOperation)1 SnowflakeWriter (org.talend.components.snowflake.runtime.SnowflakeWriter)1 TSnowflakeOutputProperties (org.talend.components.snowflake.tsnowflakeoutput.TSnowflakeOutputProperties)1 ValidationResult (org.talend.daikon.properties.ValidationResult)1