Search in sources :

Example 6 with JDBCDatasetRuntime

use of org.talend.components.jdbc.runtime.dataprep.JDBCDatasetRuntime in project components by Talend.

the class JDBCInputPTransformRuntime method initialize.

@Override
public ValidationResult initialize(RuntimeContainer container, JDBCInputProperties properties) {
    this.properties = properties;
    // In Beam, JdbcIO always has a repartition event, so we are obligated to fetch the schema before any processing
    // occurs in the nodes.
    Schema schema = properties.getDatasetProperties().main.schema.getValue();
    if (schema == null || AvroUtils.isSchemaEmpty(schema) || AvroUtils.isIncludeAllFields(schema)) {
        JDBCDatasetRuntime schemaFetcher = new JDBCDatasetRuntime();
        schemaFetcher.initialize(container, properties.getDatasetProperties());
        schema = schemaFetcher.getSchema();
    }
    this.defaultOutputCoder = AvroCoder.of(schema);
    return ValidationResult.OK;
}
Also used : JDBCDatasetRuntime(org.talend.components.jdbc.runtime.dataprep.JDBCDatasetRuntime) Schema(org.apache.avro.Schema)

Example 7 with JDBCDatasetRuntime

use of org.talend.components.jdbc.runtime.dataprep.JDBCDatasetRuntime in project components by Talend.

the class JDBCDatasetTestIT method testGetSchemaFromTable.

@Test
public void testGetSchemaFromTable() throws IOException {
    JDBCDatasetProperties dataset = createDatasetProperties(false);
    JDBCDatasetRuntime runtime = new JDBCDatasetRuntime();
    runtime.initialize(null, dataset);
    JDBCSourceOrSink jss = new JDBCSourceOrSink();
    jss.initialize(null, dataset);
    Schema schema = jss.getEndpointSchema(null, tablename);
    Assert.assertNotNull(schema);
    DBTestUtils.testMetadata(schema.getFields(), true);
    jss.getEndpointSchema(null, tablename_all_type);
// TODO assert the result
}
Also used : JDBCSourceOrSink(org.talend.components.jdbc.runtime.JDBCSourceOrSink) JDBCDatasetRuntime(org.talend.components.jdbc.runtime.dataprep.JDBCDatasetRuntime) Schema(org.apache.avro.Schema) JDBCDatasetProperties(org.talend.components.jdbc.dataset.JDBCDatasetProperties) Test(org.junit.Test)

Example 8 with JDBCDatasetRuntime

use of org.talend.components.jdbc.runtime.dataprep.JDBCDatasetRuntime in project components by Talend.

the class JDBCDatasetTestIT method updateSchema.

protected void updateSchema(JDBCDatasetProperties dataset) {
    JDBCDatasetRuntime runtime = new JDBCDatasetRuntime();
    runtime.initialize(null, dataset);
    dataset.main.schema.setValue(runtime.getSchema());
}
Also used : JDBCDatasetRuntime(org.talend.components.jdbc.runtime.dataprep.JDBCDatasetRuntime)

Example 9 with JDBCDatasetRuntime

use of org.talend.components.jdbc.runtime.dataprep.JDBCDatasetRuntime in project components by Talend.

the class JDBCDatasetTestIT method getSampleAction.

private void getSampleAction(JDBCDatasetProperties dataset) {
    JDBCDatasetRuntime runtime = new JDBCDatasetRuntime();
    runtime.initialize(null, dataset);
    final IndexedRecord[] record = new IndexedRecord[1];
    Consumer<IndexedRecord> storeTheRecords = new Consumer<IndexedRecord>() {

        @Override
        public void accept(IndexedRecord data) {
            record[0] = data;
        }
    };
    runtime.getSample(1, storeTheRecords);
    Assert.assertEquals("1", record[0].get(0));
    Assert.assertEquals("wangwei", record[0].get(1));
}
Also used : JDBCDatasetRuntime(org.talend.components.jdbc.runtime.dataprep.JDBCDatasetRuntime) IndexedRecord(org.apache.avro.generic.IndexedRecord) Consumer(org.talend.daikon.java8.Consumer)

Example 10 with JDBCDatasetRuntime

use of org.talend.components.jdbc.runtime.dataprep.JDBCDatasetRuntime in project components by Talend.

the class JDBCDatasetOracleTestIT method testGetSchema.

@Ignore
@Test
public void testGetSchema() {
    JDBCDatasetProperties dataset = createDatasetProperties();
    JDBCDatasetRuntime runtime = new JDBCDatasetRuntime();
    runtime.initialize(null, dataset);
    Schema schema = runtime.getSchema();
    Assert.assertNotNull(schema);
    Assert.assertEquals(2, schema.getFields().size());
}
Also used : JDBCDatasetRuntime(org.talend.components.jdbc.runtime.dataprep.JDBCDatasetRuntime) Schema(org.apache.avro.Schema) JDBCDatasetProperties(org.talend.components.jdbc.dataset.JDBCDatasetProperties) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

JDBCDatasetRuntime (org.talend.components.jdbc.runtime.dataprep.JDBCDatasetRuntime)10 Schema (org.apache.avro.Schema)5 Test (org.junit.Test)4 JDBCDatasetProperties (org.talend.components.jdbc.dataset.JDBCDatasetProperties)4 IndexedRecord (org.apache.avro.generic.IndexedRecord)3 Consumer (org.talend.daikon.java8.Consumer)3 BigDecimal (java.math.BigDecimal)1 Ignore (org.junit.Ignore)1 JDBCSourceOrSink (org.talend.components.jdbc.runtime.JDBCSourceOrSink)1