Search in sources :

Example 11 with TableInputMeta

use of org.pentaho.di.trans.steps.tableinput.TableInputMeta in project pentaho-kettle by pentaho.

the class PurRepositoryIT method testExport.

@Test
public void testExport() throws Exception {
    // $NON-NLS-1$
    final String exportFileName = new File("test.export").getAbsolutePath();
    RepositoryDirectoryInterface rootDir = initRepo();
    String uniqueTransName = EXP_TRANS_NAME.concat(EXP_DBMETA_NAME);
    TransMeta transMeta = createTransMeta(EXP_DBMETA_NAME);
    // Create a database association
    DatabaseMeta dbMeta = createDatabaseMeta(EXP_DBMETA_NAME);
    repository.save(dbMeta, VERSION_COMMENT_V1, null);
    TableInputMeta tableInputMeta = new TableInputMeta();
    tableInputMeta.setDatabaseMeta(dbMeta);
    transMeta.addStep(new StepMeta(EXP_TRANS_STEP_1_NAME, tableInputMeta));
    RepositoryDirectoryInterface transDir = rootDir.findDirectory(DIR_TRANSFORMATIONS);
    repository.save(transMeta, VERSION_COMMENT_V1, null);
    // So this transformation is cleaned up afterward
    deleteStack.push(transMeta);
    assertNotNull(transMeta.getObjectId());
    ObjectRevision version = transMeta.getObjectRevision();
    assertNotNull(version);
    assertTrue(hasVersionWithComment(transMeta, VERSION_COMMENT_V1));
    assertTrue(repository.exists(uniqueTransName, transDir, RepositoryObjectType.TRANSFORMATION));
    JobMeta jobMeta = createJobMeta(EXP_JOB_NAME);
    RepositoryDirectoryInterface jobsDir = rootDir.findDirectory(DIR_JOBS);
    repository.save(jobMeta, VERSION_COMMENT_V1, null);
    deleteStack.push(jobMeta);
    assertNotNull(jobMeta.getObjectId());
    version = jobMeta.getObjectRevision();
    assertNotNull(version);
    assertTrue(hasVersionWithComment(jobMeta, VERSION_COMMENT_V1));
    assertTrue(repository.exists(EXP_JOB_NAME, jobsDir, RepositoryObjectType.JOB));
    LogListener errorLogListener = new LogListener(LogLevel.ERROR);
    KettleLogStore.getAppender().addLoggingEventListener(errorLogListener);
    try {
        // $NON-NLS-1$
        repository.getExporter().exportAllObjects(new MockProgressMonitorListener(), exportFileName, null, "all");
        FileObject exportFile = KettleVFS.getFileObject(exportFileName);
        assertFalse("file left open", exportFile.getContent().isOpen());
        assertNotNull(exportFile);
        MockRepositoryExportParser parser = new MockRepositoryExportParser();
        SAXParserFactory.newInstance().newSAXParser().parse(KettleVFS.getInputStream(exportFile), parser);
        if (parser.getFatalError() != null) {
            throw parser.getFatalError();
        }
        // $NON-NLS-1$
        assertNotNull("No nodes found in export", parser.getNodeNames());
        // $NON-NLS-1$
        assertTrue("No nodes found in export", !parser.getNodeNames().isEmpty());
        // $NON-NLS-1$
        assertEquals("Incorrect number of nodes", 5, parser.getNodeNames().size());
        // $NON-NLS-1$ //$NON-NLS-2$
        assertEquals("Incorrect number of transformations", 1, parser.getNodesWithName("transformation").size());
        // $NON-NLS-1$ //$NON-NLS-2$
        assertEquals("Incorrect number of jobs", 1, parser.getNodesWithName("job").size());
        assertTrue("log error", errorLogListener.getEvents().isEmpty());
    } finally {
        KettleVFS.getFileObject(exportFileName).delete();
        KettleLogStore.getAppender().removeLoggingEventListener(errorLogListener);
    }
}
Also used : ObjectRevision(org.pentaho.di.repository.ObjectRevision) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) JobMeta(org.pentaho.di.job.JobMeta) TransMeta(org.pentaho.di.trans.TransMeta) Matchers.anyString(org.mockito.Matchers.anyString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) TableInputMeta(org.pentaho.di.trans.steps.tableinput.TableInputMeta) FileObject(org.apache.commons.vfs2.FileObject) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Test(org.junit.Test)

Example 12 with TableInputMeta

use of org.pentaho.di.trans.steps.tableinput.TableInputMeta in project pentaho-kettle by pentaho.

the class TableInputDialog method preview.

/**
 * Preview the data generated by this step. This generates a transformation using this step & a dummy and previews it.
 */
private void preview() {
    // Create the table input reader step...
    TableInputMeta oneMeta = new TableInputMeta();
    getInfo(oneMeta, true);
    TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText());
    EnterNumberDialog numberDialog = new EnterNumberDialog(shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "TableInputDialog.EnterPreviewSize"), BaseMessages.getString(PKG, "TableInputDialog.NumberOfRowsToPreview"));
    int previewSize = numberDialog.open();
    if (previewSize > 0) {
        TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(shell, previewMeta, new String[] { wStepname.getText() }, new int[] { previewSize });
        progressDialog.open();
        Trans trans = progressDialog.getTrans();
        String loggingText = progressDialog.getLoggingText();
        if (!progressDialog.isCancelled()) {
            if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) {
                EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true);
                etd.setReadOnly();
                etd.open();
            } else {
                PreviewRowsDialog prd = new PreviewRowsDialog(shell, transMeta, SWT.NONE, wStepname.getText(), progressDialog.getPreviewRowsMeta(wStepname.getText()), progressDialog.getPreviewRows(wStepname.getText()), loggingText);
                prd.open();
            }
        }
    }
}
Also used : TransPreviewProgressDialog(org.pentaho.di.ui.trans.dialog.TransPreviewProgressDialog) TransMeta(org.pentaho.di.trans.TransMeta) EnterTextDialog(org.pentaho.di.ui.core.dialog.EnterTextDialog) PreviewRowsDialog(org.pentaho.di.ui.core.dialog.PreviewRowsDialog) EnterNumberDialog(org.pentaho.di.ui.core.dialog.EnterNumberDialog) Trans(org.pentaho.di.trans.Trans) TableInputMeta(org.pentaho.di.trans.steps.tableinput.TableInputMeta)

Example 13 with TableInputMeta

use of org.pentaho.di.trans.steps.tableinput.TableInputMeta in project pentaho-kettle by pentaho.

the class TransDialog method get.

// Get the dependencies
private void get() {
    Table table = wFields.table;
    for (int i = 0; i < transMeta.nrSteps(); i++) {
        StepMeta stepMeta = transMeta.getStep(i);
        String con = null;
        String tab = null;
        TableItem item = null;
        StepMetaInterface sii = stepMeta.getStepMetaInterface();
        if (sii instanceof TableInputMeta) {
            TableInputMeta tii = (TableInputMeta) stepMeta.getStepMetaInterface();
            if (tii.getDatabaseMeta() == null) {
                MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
                mb.setMessage(BaseMessages.getString(PKG, "TransDialog.DatabaseMetaNotSet.Text"));
                mb.open();
                return;
            }
            con = tii.getDatabaseMeta().getName();
            tab = getTableFromSQL(tii.getSQL());
            if (tab == null) {
                tab = stepMeta.getName();
            }
        }
        if (sii instanceof DatabaseLookupMeta) {
            DatabaseLookupMeta dvli = (DatabaseLookupMeta) stepMeta.getStepMetaInterface();
            con = dvli.getDatabaseMeta().getName();
            tab = dvli.getTablename();
            if (tab == null) {
                tab = stepMeta.getName();
            }
            break;
        }
        if (tab != null || con != null) {
            item = new TableItem(table, SWT.NONE);
            if (con != null) {
                item.setText(1, con);
            }
            if (tab != null) {
                item.setText(2, tab);
            }
        }
    }
    wFields.setRowNums();
}
Also used : DatabaseLookupMeta(org.pentaho.di.trans.steps.databaselookup.DatabaseLookupMeta) PerformanceLogTable(org.pentaho.di.core.logging.PerformanceLogTable) ChannelLogTable(org.pentaho.di.core.logging.ChannelLogTable) StepLogTable(org.pentaho.di.core.logging.StepLogTable) MetricsLogTable(org.pentaho.di.core.logging.MetricsLogTable) Table(org.eclipse.swt.widgets.Table) TransLogTable(org.pentaho.di.core.logging.TransLogTable) TableItem(org.eclipse.swt.widgets.TableItem) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) TableInputMeta(org.pentaho.di.trans.steps.tableinput.TableInputMeta) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 14 with TableInputMeta

use of org.pentaho.di.trans.steps.tableinput.TableInputMeta 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 15 with TableInputMeta

use of org.pentaho.di.trans.steps.tableinput.TableInputMeta in project pentaho-kettle by pentaho.

the class CombinationLookupIT method testCombinationLookup.

/**
 * Test case for Combination lookup/update.
 */
public void testCombinationLookup() throws Exception {
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("transname");
    // Add the database connections
    for (int i = 0; i < databasesXML.length; i++) {
        DatabaseMeta databaseMeta = new DatabaseMeta(databasesXML[i]);
        transMeta.addDatabase(databaseMeta);
    }
    DatabaseMeta lookupDBInfo = transMeta.findDatabase("lookup");
    // Execute our setup SQLs in the database.
    Database lookupDatabase = new Database(transMeta, lookupDBInfo);
    lookupDatabase.connect();
    createTables(lookupDatabase);
    createData(lookupDatabase);
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // create the source step...
    // 
    String fromstepname = "read from [" + source_table + "]";
    TableInputMeta tii = new TableInputMeta();
    tii.setDatabaseMeta(transMeta.findDatabase("lookup"));
    String selectSQL = "SELECT " + Const.CR;
    selectSQL += "DLR_CD, DLR_NM, DLR_DESC ";
    selectSQL += "FROM " + source_table + " ORDER BY ORDNO;";
    tii.setSQL(selectSQL);
    String fromstepid = registry.getPluginId(StepPluginType.class, tii);
    StepMeta fromstep = new StepMeta(fromstepid, fromstepname, tii);
    fromstep.setLocation(150, 100);
    fromstep.setDraw(true);
    fromstep.setDescription("Reads information from table [" + source_table + "] on database [" + lookupDBInfo + "]");
    transMeta.addStep(fromstep);
    // 
    // create the combination lookup/update step...
    // 
    String lookupstepname = "lookup from [lookup]";
    CombinationLookupMeta clm = new CombinationLookupMeta();
    String[] lookupKey = { "DLR_CD" };
    clm.setTablename(target_table);
    clm.setKeyField(lookupKey);
    clm.setKeyLookup(lookupKey);
    clm.setTechnicalKeyField("ID");
    clm.setTechKeyCreation(CombinationLookupMeta.CREATION_METHOD_TABLEMAX);
    clm.setDatabaseMeta(lookupDBInfo);
    String lookupstepid = registry.getPluginId(StepPluginType.class, clm);
    StepMeta lookupstep = new StepMeta(lookupstepid, lookupstepname, clm);
    lookupstep.setDescription("Looks up information from table [lookup] on database [" + lookupDBInfo + "]");
    transMeta.addStep(lookupstep);
    TransHopMeta hi = new TransHopMeta(fromstep, lookupstep);
    transMeta.addTransHop(hi);
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.execute(null);
    trans.waitUntilFinished();
    checkResults(lookupDatabase);
}
Also used : PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransMeta(org.pentaho.di.trans.TransMeta) Database(org.pentaho.di.core.database.Database) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) TransHopMeta(org.pentaho.di.trans.TransHopMeta) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Trans(org.pentaho.di.trans.Trans) TableInputMeta(org.pentaho.di.trans.steps.tableinput.TableInputMeta)

Aggregations

TableInputMeta (org.pentaho.di.trans.steps.tableinput.TableInputMeta)18 StepMeta (org.pentaho.di.trans.step.StepMeta)14 TransMeta (org.pentaho.di.trans.TransMeta)8 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)6 Test (org.junit.Test)5 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)4 TransHopMeta (org.pentaho.di.trans.TransHopMeta)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 MessageBox (org.eclipse.swt.widgets.MessageBox)2 Matchers.anyString (org.mockito.Matchers.anyString)2 NotePadMeta (org.pentaho.di.core.NotePadMeta)2 Database (org.pentaho.di.core.database.Database)2 KettleException (org.pentaho.di.core.exception.KettleException)2 Point (org.pentaho.di.core.gui.Point)2 StepPluginType (org.pentaho.di.core.plugins.StepPluginType)2 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)2 Trans (org.pentaho.di.trans.Trans)2 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)2