Search in sources :

Example 1 with JDBCInputProperties

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

the class JdbcInputOutputRuntimeTest method testBasic.

@Test
public void testBasic() {
    JDBCInputProperties inputProperties = new JDBCInputProperties("input");
    inputProperties.init();
    inputProperties.setDatasetProperties(JdbcDatasetRuntimeTest.createDatasetProperties());
    JDBCInputDefinition inputDefinition = new JDBCInputDefinition();
    RuntimeInfo inputRI = inputDefinition.getRuntimeInfo(ExecutionEngine.BEAM, inputProperties, ConnectorTopology.OUTGOING);
    try (SandboxedInstance si = RuntimeUtil.createRuntimeClass(inputRI, getClass().getClassLoader())) {
        assertThat(si.getInstance().getClass().getCanonicalName(), is(JDBCInputDefinition.BEAM_RUNTIME));
    }
    inputRI = inputDefinition.getRuntimeInfo(ExecutionEngine.DI, inputProperties, ConnectorTopology.OUTGOING);
    try (SandboxedInstance si = RuntimeUtil.createRuntimeClass(inputRI, getClass().getClassLoader())) {
        assertThat(si.getInstance().getClass().getCanonicalName(), is(JDBCInputDefinition.DI_RUNTIME));
    }
    JDBCOutputProperties outputProperties = new JDBCOutputProperties("output");
    outputProperties.init();
    outputProperties.setDatasetProperties(JdbcDatasetRuntimeTest.createDatasetProperties());
    JDBCOutputDefinition outputDefinition = new JDBCOutputDefinition();
    RuntimeInfo outputRI = outputDefinition.getRuntimeInfo(ExecutionEngine.BEAM, outputProperties, ConnectorTopology.INCOMING);
    try (SandboxedInstance si = RuntimeUtil.createRuntimeClass(outputRI, getClass().getClassLoader())) {
        assertThat(si.getInstance().getClass().getCanonicalName(), is(JDBCOutputDefinition.BEAM_RUNTIME));
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) JDBCInputDefinition(org.talend.components.jdbc.dataprep.JDBCInputDefinition) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) JDBCOutputProperties(org.talend.components.jdbc.datastream.JDBCOutputProperties) JDBCInputProperties(org.talend.components.jdbc.dataprep.JDBCInputProperties) JDBCOutputDefinition(org.talend.components.jdbc.datastream.JDBCOutputDefinition) Test(org.junit.Test)

Example 2 with JDBCInputProperties

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

the class JDBCBeamRuntimeTest method testPipeline.

@Test
public void testPipeline() throws Exception {
    JDBCDatastoreProperties jdbcDatastoreProperties;
    jdbcDatastoreProperties = new JDBCDatastoreProperties("datastore");
    jdbcDatastoreProperties.init();
    jdbcDatastoreProperties.dbTypes.setValue("DERBY");
    jdbcDatastoreProperties.jdbcUrl.setValue(JDBC_URL);
    JDBCDatasetProperties inputDatasetProperties = new JDBCDatasetProperties("inputDataset");
    inputDatasetProperties.init();
    inputDatasetProperties.setDatastoreProperties(jdbcDatastoreProperties);
    inputDatasetProperties.sql.setValue("select * from " + TABLE_IN);
    // Schema inputSchema =
    // SchemaBuilder.record("DYNAMIC").fields().name("ID").type(SchemaBuilder.builder().stringType())
    // .noDefault().name("NAME").type(SchemaBuilder.builder().stringType()).noDefault().endRecord();
    // inputDatasetProperties.main.schema.setValue(inputSchema);
    JDBCInputProperties inputProperties = new JDBCInputProperties("input");
    inputProperties.init();
    inputProperties.setDatasetProperties(inputDatasetProperties);
    JDBCDatasetProperties outputDatasetProperties = new JDBCDatasetProperties("outputDataset");
    outputDatasetProperties.init();
    outputDatasetProperties.setDatastoreProperties(jdbcDatastoreProperties);
    outputDatasetProperties.sourceType.setValue(JDBCDatasetProperties.SourceType.TABLE_NAME);
    outputDatasetProperties.tableName.setValue(TABLE_OUT);
    Schema outputSchema = SchemaBuilder.record("DYNAMIC").fields().name("ID").prop(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "ID").type(SchemaBuilder.builder().intType()).noDefault().name("NAME").prop(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME, "NAME").type(SchemaBuilder.builder().stringType()).noDefault().endRecord();
    outputDatasetProperties.main.schema.setValue(outputSchema);
    JDBCOutputProperties outputProperties = new JDBCOutputProperties("output");
    outputProperties.init();
    outputProperties.setDatasetProperties(outputDatasetProperties);
    outputProperties.dataAction.setValue(JDBCOutputProperties.DataAction.INSERT);
    JDBCInputPTransformRuntime inputRuntime = new JDBCInputPTransformRuntime();
    inputRuntime.initialize(null, inputProperties);
    JDBCOutputPTransformRuntime outputRuntime = new JDBCOutputPTransformRuntime();
    outputRuntime.initialize(null, outputProperties);
    pipeline.apply(inputRuntime).apply(outputRuntime);
    PipelineResult pipelineResult = pipeline.run();
    Map<Integer, String> results = new HashMap<>();
    try (Connection connection = dataSource.getConnection()) {
        try (Statement statement = connection.createStatement()) {
            try (ResultSet resultSet = statement.executeQuery("select * from " + TABLE_OUT)) {
                while (resultSet.next()) {
                    results.put(resultSet.getInt(1), resultSet.getString(2));
                }
            }
        }
    }
    assertEquals(assertRows, results);
}
Also used : HashMap(java.util.HashMap) JDBCOutputProperties(org.talend.components.jdbc.datastream.JDBCOutputProperties) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Schema(org.apache.avro.Schema) Connection(java.sql.Connection) PipelineResult(org.apache.beam.sdk.PipelineResult) JDBCDatasetProperties(org.talend.components.jdbc.dataset.JDBCDatasetProperties) JDBCDatastoreProperties(org.talend.components.jdbc.datastore.JDBCDatastoreProperties) JDBCInputProperties(org.talend.components.jdbc.dataprep.JDBCInputProperties) ResultSet(java.sql.ResultSet) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 JDBCInputProperties (org.talend.components.jdbc.dataprep.JDBCInputProperties)2 JDBCOutputProperties (org.talend.components.jdbc.datastream.JDBCOutputProperties)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 HashMap (java.util.HashMap)1 Schema (org.apache.avro.Schema)1 PipelineResult (org.apache.beam.sdk.PipelineResult)1 JDBCInputDefinition (org.talend.components.jdbc.dataprep.JDBCInputDefinition)1 JDBCDatasetProperties (org.talend.components.jdbc.dataset.JDBCDatasetProperties)1 JDBCDatastoreProperties (org.talend.components.jdbc.datastore.JDBCDatastoreProperties)1 JDBCOutputDefinition (org.talend.components.jdbc.datastream.JDBCOutputDefinition)1 RuntimeInfo (org.talend.daikon.runtime.RuntimeInfo)1 SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)1