Search in sources :

Example 1 with DatasetRuntime

use of org.talend.components.common.dataset.runtime.DatasetRuntime in project components by Talend.

the class RuntimeControllerImpl method useDatasetRuntime.

private <// 
T> // 
T useDatasetRuntime(// 
final DatasetDefinition<DatasetProperties<DatastoreProperties>> datasetDefinition, // 
DatasetProperties datasetProperties, Function<DatasetRuntime<DatasetProperties<DatastoreProperties>>, T> consumer) {
    try (SandboxedInstance instance = RuntimeUtil.createRuntimeClass(datasetDefinition.getRuntimeInfo(datasetProperties), datasetProperties.getClass().getClassLoader())) {
        DatasetRuntime<DatasetProperties<DatastoreProperties>> datasetRuntimeInstance = (DatasetRuntime<DatasetProperties<DatastoreProperties>>) instance.getInstance();
        datasetRuntimeInstance.initialize(null, datasetProperties);
        return consumer.apply(datasetRuntimeInstance);
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) DatastoreProperties(org.talend.components.common.datastore.DatastoreProperties) DatasetRuntime(org.talend.components.common.dataset.runtime.DatasetRuntime) DatasetProperties(org.talend.components.common.dataset.DatasetProperties)

Example 2 with DatasetRuntime

use of org.talend.components.common.dataset.runtime.DatasetRuntime in project components by Talend.

the class SandboxedFixedInputRuntimeTest method testDatasetGetSample.

@Test
public void testDatasetGetSample() throws Exception {
    // The two records to use as values.
    GenericRecord r1 = new GenericData.Record(SampleSchemas.recordSimple());
    r1.put("id", 1);
    r1.put("name", "one");
    GenericRecord r2 = new GenericData.Record(SampleSchemas.recordSimple());
    r2.put("id", 2);
    r2.put("name", "two");
    final FixedDatasetProperties props = createComponentProperties().getDatasetProperties();
    props.format.setValue(FixedDatasetProperties.RecordFormat.AVRO);
    props.schema.setValue(SampleSchemas.recordSimple().toString());
    props.values.setValue(r1.toString() + r2.toString());
    final List<IndexedRecord> consumed = new ArrayList<>();
    RuntimeInfo ri = new FixedDatasetDefinition().getRuntimeInfo(props);
    try (SandboxedInstance si = RuntimeUtil.createRuntimeClass(ri, getClass().getClassLoader())) {
        DatasetRuntime<FixedDatasetProperties> runtime = (DatasetRuntime<FixedDatasetProperties>) si.getInstance();
        runtime.initialize(null, props);
        // The functionality of the runtime is tested in its own module.
        runtime.getSample(100, new Consumer<IndexedRecord>() {

            @Override
            public void accept(IndexedRecord ir) {
                consumed.add(ir);
            }
        });
    }
    assertThat(consumed, hasSize(2));
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) DatasetRuntime(org.talend.components.common.dataset.runtime.DatasetRuntime) ArrayList(java.util.ArrayList) SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) FixedDatasetDefinition(org.talend.components.localio.fixed.FixedDatasetDefinition) GenericRecord(org.apache.avro.generic.GenericRecord) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericRecord(org.apache.avro.generic.GenericRecord) FixedDatasetProperties(org.talend.components.localio.fixed.FixedDatasetProperties) Test(org.junit.Test)

Example 3 with DatasetRuntime

use of org.talend.components.common.dataset.runtime.DatasetRuntime in project components by Talend.

the class JdbcDatasetRuntimeTest method testBasic.

@Test
public void testBasic() throws Exception {
    JDBCDatasetProperties props = createDatasetProperties();
    final List<IndexedRecord> consumed = new ArrayList<>();
    RuntimeInfo ri = def.getRuntimeInfo(props);
    try (SandboxedInstance si = RuntimeUtil.createRuntimeClass(ri, getClass().getClassLoader())) {
        DatasetRuntime runtime = (DatasetRuntime) si.getInstance();
        runtime.initialize(null, props);
        assertThat(runtime, not(nullValue()));
        Schema s = runtime.getSchema();
        assertThat(s, not(nullValue()));
        runtime.getSample(100, new Consumer<IndexedRecord>() {

            @Override
            public void accept(IndexedRecord ir) {
                consumed.add(ir);
            }
        });
    }
    assertThat(consumed, hasSize(2));
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) IndexedRecord(org.apache.avro.generic.IndexedRecord) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) DatasetRuntime(org.talend.components.common.dataset.runtime.DatasetRuntime) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) JDBCDatasetProperties(org.talend.components.jdbc.dataset.JDBCDatasetProperties) Test(org.junit.Test)

Example 4 with DatasetRuntime

use of org.talend.components.common.dataset.runtime.DatasetRuntime in project components by Talend.

the class KafkaDatasetTestIT method testBasic.

@Test
public void testBasic() throws Exception {
    KafkaDatasetProperties props = createDatasetProperties();
    final List<IndexedRecord> consumed = new ArrayList<>();
    RuntimeInfo ri = def.getRuntimeInfo(props);
    try (SandboxedInstance si = RuntimeUtil.createRuntimeClass(ri, getClass().getClassLoader())) {
        DatasetRuntime runtime = (DatasetRuntime) si.getInstance();
        runtime.initialize(null, props);
        assertThat(runtime, not(nullValue()));
        Schema s = runtime.getSchema();
        assertThat(s, not(nullValue()));
        runtime.getSample(100, new Consumer<IndexedRecord>() {

            @Override
            public void accept(IndexedRecord ir) {
                consumed.add(ir);
            }
        });
    }
    assertThat(consumed, hasSize(0));
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) KafkaDatasetProperties(org.talend.components.kafka.dataset.KafkaDatasetProperties) IndexedRecord(org.apache.avro.generic.IndexedRecord) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) DatasetRuntime(org.talend.components.common.dataset.runtime.DatasetRuntime) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with DatasetRuntime

use of org.talend.components.common.dataset.runtime.DatasetRuntime in project components by Talend.

the class BigQueryDatasetTestIT method testBasic.

@Test
public void testBasic() throws Exception {
    BigQueryDatasetProperties props = createDatasetProperties();
    props.sourceType.setValue(SourceType.QUERY);
    props.query.setValue("SELECT * FROM [bigquery-public-data:samples.shakespeare] LIMIT 1");
    props.useLegacySql.setValue(true);
    final List<IndexedRecord> consumed = new ArrayList<>();
    RuntimeInfo ri = def.getRuntimeInfo(props);
    try (SandboxedInstance si = RuntimeUtil.createRuntimeClass(ri, getClass().getClassLoader())) {
        DatasetRuntime runtime = (DatasetRuntime) si.getInstance();
        runtime.initialize(null, props);
        assertThat(runtime, not(nullValue()));
        Schema s = runtime.getSchema();
        assertThat(s, not(nullValue()));
        runtime.getSample(100, new Consumer<IndexedRecord>() {

            @Override
            public void accept(IndexedRecord ir) {
                consumed.add(ir);
            }
        });
    }
    assertThat(consumed, hasSize(1));
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) IndexedRecord(org.apache.avro.generic.IndexedRecord) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) DatasetRuntime(org.talend.components.common.dataset.runtime.DatasetRuntime) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) BigQueryDatasetProperties(org.talend.components.bigquery.BigQueryDatasetProperties) Test(org.junit.Test)

Aggregations

DatasetRuntime (org.talend.components.common.dataset.runtime.DatasetRuntime)8 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)8 RuntimeInfo (org.talend.daikon.runtime.RuntimeInfo)7 ArrayList (java.util.ArrayList)6 Schema (org.apache.avro.Schema)6 IndexedRecord (org.apache.avro.generic.IndexedRecord)6 Test (org.junit.Test)6 File (java.io.File)2 FileWriter (java.io.FileWriter)2 SimpleFileIODatasetProperties (org.talend.components.simplefileio.SimpleFileIODatasetProperties)2 GenericRecord (org.apache.avro.generic.GenericRecord)1 BigQueryDatasetProperties (org.talend.components.bigquery.BigQueryDatasetProperties)1 DatasetProperties (org.talend.components.common.dataset.DatasetProperties)1 DatastoreProperties (org.talend.components.common.datastore.DatastoreProperties)1 JDBCDatasetProperties (org.talend.components.jdbc.dataset.JDBCDatasetProperties)1 KafkaDatasetProperties (org.talend.components.kafka.dataset.KafkaDatasetProperties)1 FixedDatasetDefinition (org.talend.components.localio.fixed.FixedDatasetDefinition)1 FixedDatasetProperties (org.talend.components.localio.fixed.FixedDatasetProperties)1