Search in sources :

Example 6 with TableOutputMeta

use of org.pentaho.di.trans.steps.tableoutput.TableOutputMeta in project data-access by pentaho.

the class StagingTransformGenerator method loadTable.

/**
 * Stages the data from a CSV file into a database table. As the table is loading, a {@link TransformStats} monitors
 * the progress. This is placed in the supplied {@link IPentahoSession} to allow interrogation under the attribute key
 * <code>FileTransformStats_<em>fileName</em></code>
 *
 * @param truncate
 * @param session
 * @throws CsvTransformGeneratorException
 */
public void loadTable(boolean truncate, IPentahoSession session, boolean async) throws CsvTransformGeneratorException {
    if (session == null) {
        // $NON-NLS-1$
        throw new IllegalArgumentException("IPentahoSession cannot be null");
    }
    if (tableName == null) {
        // $NON-NLS-1$
        throw new IllegalArgumentException("Table name cannot be null");
    }
    if (transformStats != null) {
        transformStats.setRowsFinished(false);
        transformStats.setRowsStarted(true);
        transformStats.setTotalRecords(0);
        transformStats.setRowsRejected(0);
    }
    Trans trans = createTransform(true);
    // the table output is the last step
    StepMeta[] steps = trans.getTransMeta().getStepsArray();
    StepMeta tableStepMeta = steps[steps.length - 1];
    TableOutputMeta meta = (TableOutputMeta) tableStepMeta.getStepMetaInterface();
    meta.setDatabaseMeta(targetDatabaseMeta);
    meta.setTruncateTable(truncate);
    try {
        prepareTransform(trans, session);
    } catch (Exception e) {
        // $NON-NLS-1$
        error("Preview Failed: transformation preparation", e);
        Throwable e2 = e.getCause();
        e2 = e2 == null ? e : e2;
        throw new CsvTransformGeneratorException("Preview Failed: transformation preparation: loadTable", e2, // $NON-NLS-1$
        getStackTraceAsString(e2));
    }
    StepInterface step = trans.findRunThread(TABLE_OUTPUT);
    PdiTransListener listener = new PdiTransListener(trans, step, transformStats);
    // start the listener in a thread
    Thread listenerThread = new Thread(listener);
    listenerThread.start();
    session.setAttribute(TRANS_SESSION_ATTR, trans);
    if (async) {
        executeTransformAsync(trans);
    } else {
        executeTransformSync(trans, null, session);
    }
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) CsvTransformGeneratorException(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException) TableOutputMeta(org.pentaho.di.trans.steps.tableoutput.TableOutputMeta) Trans(org.pentaho.di.trans.Trans) StepMeta(org.pentaho.di.trans.step.StepMeta) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) CsvTransformGeneratorException(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException)

Example 7 with TableOutputMeta

use of org.pentaho.di.trans.steps.tableoutput.TableOutputMeta in project data-access by pentaho.

the class StagingTransformGenerator method createOrModifyTable.

public void createOrModifyTable(IPentahoSession session) throws CsvTransformGeneratorException, IllegalArgumentException {
    if (session == null) {
        // $NON-NLS-1$
        throw new IllegalArgumentException("IPentahoSession cannot be null");
    }
    if (tableName == null) {
        // $NON-NLS-1$
        throw new IllegalArgumentException("Table name cannot be null");
    }
    TransMeta transMeta = createTransMeta(true);
    // the table output is the last step
    StepMeta[] steps = transMeta.getStepsArray();
    StepMeta tableStepMeta = steps[steps.length - 1];
    TableOutputMeta meta = (TableOutputMeta) tableStepMeta.getStepMetaInterface();
    meta.setDatabaseMeta(targetDatabaseMeta);
    try {
        executeSql(meta, tableStepMeta, transMeta);
    } catch (CsvTransformGeneratorException e) {
        if (!e.getMessage().equalsIgnoreCase("No SQL generated")) {
            // $NON-NLS-1$
            error(e.getMessage());
            throw new // $NON-NLS-1$
            CsvTransformGeneratorException(// $NON-NLS-1$
            "Could not create or modify table", // $NON-NLS-1$
            e, getStackTraceAsString(e), null, // $NON-NLS-1$
            Messages.getString("StagingTransformGenerator.ERROR_0001_UNABLE_TO_CREATE_OR_MODIFY_TABLE"));
        }
    }
}
Also used : CsvTransformGeneratorException(org.pentaho.platform.dataaccess.datasource.wizard.models.CsvTransformGeneratorException) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) TableOutputMeta(org.pentaho.di.trans.steps.tableoutput.TableOutputMeta) StepMeta(org.pentaho.di.trans.step.StepMeta)

Example 8 with TableOutputMeta

use of org.pentaho.di.trans.steps.tableoutput.TableOutputMeta in project pentaho-metaverse by pentaho.

the class StepAnalyzerProviderTest method testGetAnalyzersForClass.

@Test
public void testGetAnalyzersForClass() throws Exception {
    Set<IStepAnalyzer> baseStepAnalyzerSet = Sets.newSet(mock(IStepAnalyzer.class));
    Set<IStepAnalyzer> tableOutputStepAnalyzerSet = Sets.newSet(mock(IStepAnalyzer.class));
    // Return the baseStepAnalyzer set if BaseStepMeta analyzers are requested
    provider.analyzerTypeMap.put(BaseStepMeta.class, baseStepAnalyzerSet);
    // Return the tableOutputStepAnalyzerSet set if TableOutputMeta analyzers are requested
    provider.analyzerTypeMap.put(TableOutputMeta.class, tableOutputStepAnalyzerSet);
    List<IStepAnalyzer> analyzers = provider.getAnalyzers(new ArrayList() {

        {
            add(BaseStepMeta.class);
            add(TableOutputMeta.class);
        }
    });
    assertEquals(analyzers.size(), 2);
    analyzers = provider.getAnalyzers(new HashSet() {

        {
            add(TableOutputMeta.class);
        }
    });
    assertEquals(analyzers.size(), 1);
}
Also used : IStepAnalyzer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepAnalyzer) ArrayList(java.util.ArrayList) TableOutputMeta(org.pentaho.di.trans.steps.tableoutput.TableOutputMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with TableOutputMeta

use of org.pentaho.di.trans.steps.tableoutput.TableOutputMeta in project pentaho-metaverse by pentaho.

the class TableOutputExternalResourceConsumerTest method testGetResourcesFromMeta_runtime.

@Test
public void testGetResourcesFromMeta_runtime() throws Exception {
    TableOutputMeta meta = mock(TableOutputMeta.class);
    DatabaseMeta dbMeta = mock(DatabaseMeta.class);
    DatabaseInterface dbi = mock(DatabaseInterface.class);
    when(meta.getDatabaseMeta()).thenReturn(dbMeta);
    when(meta.getTableName()).thenReturn("tableName");
    when(meta.getSchemaName()).thenReturn("schemaName");
    when(meta.getParentStepMeta()).thenReturn(parentStepMeta);
    when(parentStepMeta.getParentTransMeta()).thenReturn(parentTransMeta);
    when(parentTransMeta.environmentSubstitute("tableName")).thenReturn("tableName");
    when(parentTransMeta.environmentSubstitute("schemaName")).thenReturn("schemaName");
    when(dbMeta.getAccessTypeDesc()).thenReturn("JNDI");
    when(dbMeta.getName()).thenReturn("TestConnection");
    when(dbMeta.getDescription()).thenReturn("my conn description");
    when(dbMeta.getDatabaseInterface()).thenReturn(dbi);
    when(dbi.getPluginId()).thenReturn("POSTGRESQL");
    Collection<IExternalResourceInfo> resources = consumer.getResourcesFromMeta(meta, new AnalysisContext(DictionaryConst.CONTEXT_RUNTIME));
    assertEquals(1, resources.size());
    IExternalResourceInfo res = resources.iterator().next();
    assertEquals("TestConnection", res.getName());
    assertEquals("tableName", res.getAttributes().get(DictionaryConst.PROPERTY_TABLE));
    assertEquals("schemaName", res.getAttributes().get(DictionaryConst.PROPERTY_SCHEMA));
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) TableOutputMeta(org.pentaho.di.trans.steps.tableoutput.TableOutputMeta) AnalysisContext(org.pentaho.metaverse.api.AnalysisContext) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Test(org.junit.Test)

Example 10 with TableOutputMeta

use of org.pentaho.di.trans.steps.tableoutput.TableOutputMeta in project pentaho-metaverse by pentaho.

the class TableOutputStepMetaJsonSerializerTest method setUp.

@Before
public void setUp() throws Exception {
    repo = new LineageRepository();
    serializer = new TableOutputStepMetaJsonSerializer(TableOutputMeta.class, repo);
    meta = spy(new TableOutputMeta());
}
Also used : LineageRepository(org.pentaho.metaverse.impl.model.kettle.LineageRepository) TableOutputMeta(org.pentaho.di.trans.steps.tableoutput.TableOutputMeta) Before(org.junit.Before)

Aggregations

TableOutputMeta (org.pentaho.di.trans.steps.tableoutput.TableOutputMeta)18 StepMeta (org.pentaho.di.trans.step.StepMeta)9 KettleException (org.pentaho.di.core.exception.KettleException)6 TransMeta (org.pentaho.di.trans.TransMeta)6 Test (org.junit.Test)4 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)4 ArrayList (java.util.ArrayList)3 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)3 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)3 TableInputMeta (org.pentaho.di.trans.steps.tableinput.TableInputMeta)3 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)3 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 NotePadMeta (org.pentaho.di.core.NotePadMeta)2 SQLStatement (org.pentaho.di.core.SQLStatement)2 DatabaseInterface (org.pentaho.di.core.database.DatabaseInterface)2 KettleStepException (org.pentaho.di.core.exception.KettleStepException)2 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)2 Variables (org.pentaho.di.core.variables.Variables)2 TransHopMeta (org.pentaho.di.trans.TransHopMeta)2