Search in sources :

Example 1 with SimpleFileIODatasetProperties

use of org.talend.components.simplefileio.SimpleFileIODatasetProperties in project components by Talend.

the class SimpleFileIODatasetRuntimeTest method createDatasetProperties.

/**
 * @return the properties for this dataset, fully initialized with the default values.
 */
public static SimpleFileIODatasetProperties createDatasetProperties() {
    // Configure the dataset.
    SimpleFileIODatasetProperties datasetProps = new SimpleFileIODatasetProperties(null);
    datasetProps.init();
    datasetProps.setDatastoreProperties(SimpleFileIODatastoreRuntimeTest.createDatastoreProperties());
    return datasetProps;
}
Also used : SimpleFileIODatasetProperties(org.talend.components.simplefileio.SimpleFileIODatasetProperties)

Example 2 with SimpleFileIODatasetProperties

use of org.talend.components.simplefileio.SimpleFileIODatasetProperties in project components by Talend.

the class SimpleFileIODatasetRuntimeTest method testGetSchema.

@Test
public void testGetSchema() throws Exception {
    writeRandomAvroFile(mini.getFs(), "/user/test/input.avro", getSimpleTestData(0));
    String fileSpec = mini.getFs().getUri().resolve("/user/test/input.avro").toString();
    // Configure the component.
    SimpleFileIODatasetProperties props = createDatasetProperties();
    props.format.setValue(SimpleFileIOFormat.AVRO);
    props.path.setValue(fileSpec);
    // Create the runtime.
    SimpleFileIODatasetRuntime runtime = new SimpleFileIODatasetRuntime();
    runtime.initialize(null, props);
    // Attempt to get a sample using the runtime methods.
    Schema actual = runtime.getSchema();
    assertThat(actual, notNullValue());
// TODO(rskraba): check the schema with the input file.
}
Also used : Schema(org.apache.avro.Schema) SimpleFileIODatasetProperties(org.talend.components.simplefileio.SimpleFileIODatasetProperties) Test(org.junit.Test)

Example 3 with SimpleFileIODatasetProperties

use of org.talend.components.simplefileio.SimpleFileIODatasetProperties in project components by Talend.

the class SandboxedSimpleFileIODatasetRuntimeTest method createDatasetProperties.

/**
 * @return the properties for this dataset, fully initialized with the default values.
 */
public static SimpleFileIODatasetProperties createDatasetProperties() {
    // Configure the dataset.
    SimpleFileIODatastoreProperties datastoreProps = new SimpleFileIODatastoreProperties(null);
    datastoreProps.init();
    SimpleFileIODatasetProperties datasetProps = new SimpleFileIODatasetProperties(null);
    datasetProps.init();
    datasetProps.setDatastoreProperties(datastoreProps);
    return datasetProps;
}
Also used : SimpleFileIODatastoreProperties(org.talend.components.simplefileio.SimpleFileIODatastoreProperties) SimpleFileIODatasetProperties(org.talend.components.simplefileio.SimpleFileIODatasetProperties)

Example 4 with SimpleFileIODatasetProperties

use of org.talend.components.simplefileio.SimpleFileIODatasetProperties in project components by Talend.

the class SimpleFileIODatasetRuntimeTest method createDatasetProperties.

/**
 * @return the properties for this dataset, fully initialized with the default values.
 */
public static SimpleFileIODatasetProperties createDatasetProperties() {
    // Configure the dataset.
    SimpleFileIODatastoreProperties datastoreProps = new SimpleFileIODatastoreProperties(null);
    datastoreProps.init();
    SimpleFileIODatasetProperties datasetProps = new SimpleFileIODatasetProperties(null);
    datasetProps.init();
    datasetProps.setDatastoreProperties(datastoreProps);
    return datasetProps;
}
Also used : SimpleFileIODatastoreProperties(org.talend.components.simplefileio.SimpleFileIODatastoreProperties) SimpleFileIODatasetProperties(org.talend.components.simplefileio.SimpleFileIODatasetProperties)

Example 5 with SimpleFileIODatasetProperties

use of org.talend.components.simplefileio.SimpleFileIODatasetProperties in project components by Talend.

the class SandboxedSimpleFileIODatasetRuntimeTest method testBasic.

@Test
public void testBasic() throws Exception {
    File input = folder.newFile("stuff.csv");
    try (FileWriter fw = new FileWriter(input)) {
        fw.write("1;one");
    }
    SimpleFileIODatasetProperties props = createDatasetProperties();
    props.path.setValue(input.toURI().toString());
    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));
    assertThat(consumed.get(0).get(0), is((Object) "1"));
    assertThat(consumed.get(0).get(1), is((Object) "one"));
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) DatasetRuntime(org.talend.components.common.dataset.runtime.DatasetRuntime) FileWriter(java.io.FileWriter) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) File(java.io.File) SimpleFileIODatasetProperties(org.talend.components.simplefileio.SimpleFileIODatasetProperties) Test(org.junit.Test)

Aggregations

SimpleFileIODatasetProperties (org.talend.components.simplefileio.SimpleFileIODatasetProperties)10 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 IndexedRecord (org.apache.avro.generic.IndexedRecord)5 Schema (org.apache.avro.Schema)3 SimpleFileIODatastoreProperties (org.talend.components.simplefileio.SimpleFileIODatastoreProperties)3 RecordSet (org.talend.components.test.RecordSet)3 File (java.io.File)2 FileWriter (java.io.FileWriter)2 DatasetRuntime (org.talend.components.common.dataset.runtime.DatasetRuntime)2 RuntimeInfo (org.talend.daikon.runtime.RuntimeInfo)2 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)2 List (java.util.List)1 Before (org.junit.Before)1 Consumer (org.talend.daikon.java8.Consumer)1