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);
}
}
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"));
}
}
}
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);
}
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));
}
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());
}
Aggregations