Search in sources :

Example 16 with TableOutputMeta

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

the class JobGenerator method generateTimeTransformation.

private TransMeta generateTimeTransformation(DatabaseMeta databaseMeta, LogicalTable logicalTable) throws KettleException {
    // We actually load the transformation from a template and then slightly modify it.
    // 
    String filename = "/org/pentaho/di/resources/Generate time dimension.ktr";
    InputStream inputStream = getClass().getResourceAsStream(filename);
    TransMeta transMeta = new TransMeta(inputStream, Spoon.getInstance().rep, true, new Variables(), null);
    // Find the table output step and inject the target table name and database...
    // 
    StepMeta stepMeta = transMeta.findStep("TARGET");
    if (stepMeta != null) {
        TableOutputMeta meta = (TableOutputMeta) stepMeta.getStepMetaInterface();
        meta.setDatabaseMeta(databaseMeta);
        String phTable = ConceptUtil.getString(logicalTable, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
        meta.setTableName(phTable);
    }
    return transMeta;
}
Also used : Variables(org.pentaho.di.core.variables.Variables) InputStream(java.io.InputStream) TransMeta(org.pentaho.di.trans.TransMeta) TableOutputMeta(org.pentaho.di.trans.steps.tableoutput.TableOutputMeta) StepMeta(org.pentaho.di.trans.step.StepMeta)

Example 17 with TableOutputMeta

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

the class PluginRegistryIT method testPluginRegistry.

public void testPluginRegistry() throws KettlePluginException {
    PluginRegistry registry = PluginRegistry.getInstance();
    assertNotNull("Registry singleton was not found!", registry);
    // PluginRegistry.init() may have already been called, our test path will be different
    // for each case. If it has not been called, try to register the type and plugin. If
    // it has been called, simply verify the plugin type and plugin have been registered.
    Class<? extends PluginTypeInterface> pluginTypeClass = StepPluginType.class;
    Object pluginClass = new TableInputMeta();
    List<PluginInterface> inputPluginsAtTestStart = registry.getPluginsByCategory(pluginTypeClass, PLUGIN_INPUT_CATEGORY);
    int numInputPluginsAtStart = inputPluginsAtTestStart.size();
    List<PluginInterface> outputPluginsAtTestStart = registry.getPluginsByCategory(pluginTypeClass, PLUGIN_OUTPUT_CATEGORY);
    int numOutputPluginsAtStart = outputPluginsAtTestStart.size();
    try {
        registry.getPluginType(pluginTypeClass);
    } catch (KettlePluginException kpe) {
        // Register a new plugin type...
        registry.registerPluginType(pluginTypeClass);
    }
    // See if the plugin is there...
    try {
        registry.getPluginType(pluginTypeClass);
    } catch (KettlePluginException kpe) {
        fail(pluginTypeClass.getName() + " expected in the PluginRegistry but was not found!");
    }
    PluginInterface plugin = registry.getPlugin(pluginTypeClass, pluginClass);
    Map<Class<?>, String> classMap = new HashMap<Class<?>, String>();
    PluginInterface tableInputPlugin = plugin;
    int numInputPluginsRegistered = 0;
    if (plugin == null) {
        // Register a single step plugin
        // 
        classMap.put(StepMetaInterface.class, "org.pentaho.di.trans.steps.tableinput.TableInputMeta");
        tableInputPlugin = new Plugin(new String[] { TABLE_INPUT_PLUGIN_ID }, pluginTypeClass, StepMetaInterface.class, PLUGIN_INPUT_CATEGORY, TABLE_INPUT_PLUGIN_NAME, TABLE_INPUT_PLUGIN_DESCRIPTION, TABLE_INPUT_PLUGIN_IMAGE_FILE_NAME, false, true, classMap, new ArrayList<String>(), // No error help file
        null, // pluginFolder
        null, // documentation URL
        null, // cases URL
        null, // forum URL
        null);
        registry.registerPlugin(pluginTypeClass, tableInputPlugin);
        numInputPluginsRegistered++;
    }
    // Verify the plugin has been registered
    PluginInterface verify = registry.getPlugin(pluginTypeClass, TABLE_INPUT_PLUGIN_ID);
    assertNotNull("A plugin was not found in the plugin registry", verify);
    assertEquals("A different plugin then expected was retrieved from the plugin registry", verify, tableInputPlugin);
    pluginClass = new TableOutputMeta();
    plugin = registry.getPlugin(pluginTypeClass, pluginClass);
    PluginInterface tableOutputPlugin = plugin;
    int numOutputPluginsRegistered = 0;
    if (plugin == null) {
        // Register a second step plugin
        // 
        classMap = new HashMap<Class<?>, String>();
        classMap.put(StepMetaInterface.class, "org.pentaho.di.trans.steps.tableoutput.TableOutputMeta");
        tableOutputPlugin = new Plugin(new String[] { TABLE_OUTPUT_PLUGIN_ID }, pluginTypeClass, StepMetaInterface.class, PLUGIN_OUTPUT_CATEGORY, TABLE_OUTPUT_PLUGIN_NAME, TABLE_OUTPUT_PLUGIN_DESCRIPTION, TABLE_OUTPUT_PLUGIN_IMAGE_FILE_NAME, false, true, classMap, new ArrayList<String>(), // No error help file
        null, // pluginFolder
        null, // documentation URL
        null, // cases URL
        null, // forum URL
        null);
        registry.registerPlugin(pluginTypeClass, tableOutputPlugin);
        numOutputPluginsRegistered++;
    }
    // Verify the plugin has been registered
    verify = registry.getPlugin(pluginTypeClass, TABLE_OUTPUT_PLUGIN_ID);
    assertNotNull("A plugin was not found in the plugin registry", verify);
    assertEquals("A different plugin then expected was retrieved from the plugin registry", verify, tableOutputPlugin);
    // Get a list by category...
    // 
    List<PluginInterface> inputPlugins = registry.getPluginsByCategory(pluginTypeClass, PLUGIN_INPUT_CATEGORY);
    assertEquals("Exactly one plugin expected in the step plugin input category", numInputPluginsAtStart + numInputPluginsRegistered, inputPlugins.size());
    assertTrue("Input plugins list should contain the table input step", inputPlugins.contains(tableInputPlugin));
    assertFalse("Input plugins list should not contain the table output step", inputPlugins.contains(tableOutputPlugin));
    List<PluginInterface> outputPlugins = registry.getPluginsByCategory(pluginTypeClass, PLUGIN_OUTPUT_CATEGORY);
    assertEquals("Exactly one plugin expected in the step plugin output category", numOutputPluginsAtStart + numOutputPluginsRegistered, outputPlugins.size());
    assertTrue("Output plugins list should contain the table output step", outputPlugins.contains(tableOutputPlugin));
    assertFalse("Output plugins list should not contain the table input step", outputPlugins.contains(tableInputPlugin));
    // List the categories...
    // 
    List<String> categories = registry.getCategories(pluginTypeClass);
    assertTrue("The input category was expected in the categories list", categories.contains(PLUGIN_INPUT_CATEGORY));
    assertTrue("The output category was expected in the categories list", categories.contains(PLUGIN_OUTPUT_CATEGORY));
    // Now have a little bit of class loading fun: load the main class of the plugin
    // 
    Object object = registry.loadClass(tableInputPlugin, StepMetaInterface.class);
    assertNotNull(object);
    // The same but now explicitly asking for the main class
    // 
    Object object2 = registry.loadClass(tableOutputPlugin, StepMetaInterface.class);
    assertNotNull(object2);
    try {
        registry.loadClass(tableInputPlugin, String.class);
        fail("A String class type can't be used when loading a step class");
    } catch (Exception e) {
    // OK!
    }
}
Also used : KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) HashMap(java.util.HashMap) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) ArrayList(java.util.ArrayList) TableOutputMeta(org.pentaho.di.trans.steps.tableoutput.TableOutputMeta) TableInputMeta(org.pentaho.di.trans.steps.tableinput.TableInputMeta) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException)

Example 18 with TableOutputMeta

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

the class StagingTransformGenerator method addTableOutputStep.

protected StepMeta addTableOutputStep(TransMeta transMeta, String tableOutputStepName, String modelName) {
    TableOutputMeta tableOutputMeta = new TableOutputMeta();
    tableOutputMeta.setCommitSize(1000);
    tableOutputMeta.setIgnoreErrors(true);
    tableOutputMeta.setPartitioningEnabled(false);
    tableOutputMeta.setSchemaName(AgileHelper.getSchemaName());
    tableOutputMeta.setTableName(getTableName());
    tableOutputMeta.setUseBatchUpdate(false);
    StepMeta tableOutputStepMeta = new StepMeta(tableOutputStepName, tableOutputStepName, tableOutputMeta);
    transMeta.addStep(tableOutputStepMeta);
    return tableOutputStepMeta;
}
Also used : TableOutputMeta(org.pentaho.di.trans.steps.tableoutput.TableOutputMeta) StepMeta(org.pentaho.di.trans.step.StepMeta)

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