Search in sources :

Example 66 with DatabaseMeta

use of org.pentaho.di.core.database.DatabaseMeta in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryTransDelegate method loadTransHopMeta.

public TransHopMeta loadTransHopMeta(ObjectId id_trans_hop, List<StepMeta> steps) throws KettleException {
    TransHopMeta hopTransMeta = new TransHopMeta();
    try {
        hopTransMeta.setObjectId(id_trans_hop);
        RowMetaAndData r = getTransHop(id_trans_hop);
        hopTransMeta.setEnabled(r.getBoolean("ENABLED", false));
        long id_step_from = r.getInteger("ID_STEP_FROM", 0);
        long id_step_to = r.getInteger("ID_STEP_TO", 0);
        StepMeta fromStep = StepMeta.findStep(steps, new LongObjectId(id_step_from));
        // 
        if (fromStep == null && id_step_from > 0) {
            // Simply load this, we only want the name, we don't care about the
            // rest...
            // 
            StepMeta stepMeta = repository.stepDelegate.loadStepMeta(new LongObjectId(id_step_from), new ArrayList<DatabaseMeta>(), new ArrayList<PartitionSchema>());
            fromStep = StepMeta.findStep(steps, stepMeta.getName());
        }
        if (fromStep == null) {
            log.logError("Unable to determine source step of transformation hop with ID: " + id_trans_hop);
            // Invalid hop, simply ignore. See: PDI-2446
            return null;
        }
        hopTransMeta.setFromStep(fromStep);
        hopTransMeta.getFromStep().setDraw(true);
        hopTransMeta.setToStep(StepMeta.findStep(steps, new LongObjectId(id_step_to)));
        // 
        if (hopTransMeta.getToStep() == null && id_step_to > 0) {
            // Simply load this, we only want the name, we don't care about
            // the rest...
            StepMeta stepMeta = repository.stepDelegate.loadStepMeta(new LongObjectId(id_step_to), new ArrayList<DatabaseMeta>(), new ArrayList<PartitionSchema>());
            hopTransMeta.setToStep(StepMeta.findStep(steps, stepMeta.getName()));
        }
        if (hopTransMeta.getFromStep() == null) {
            // 
            return null;
        }
        hopTransMeta.getToStep().setDraw(true);
        return hopTransMeta;
    } catch (KettleDatabaseException dbe) {
        throw new KettleException(BaseMessages.getString(PKG, "TransHopMeta.Exception.LoadTransformationHopInfo") + id_trans_hop, dbe);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PartitionSchema(org.pentaho.di.partition.PartitionSchema) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) TransHopMeta(org.pentaho.di.trans.TransHopMeta) LongObjectId(org.pentaho.di.repository.LongObjectId) StepMeta(org.pentaho.di.trans.step.StepMeta) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

Example 67 with DatabaseMeta

use of org.pentaho.di.core.database.DatabaseMeta in project pentaho-kettle by pentaho.

the class JobEntryColumnsExistTest method setUp.

@Before
public void setUp() {
    Job parentJob = new Job(null, new JobMeta());
    jobEntry = spy(new JobEntryColumnsExist(""));
    parentJob.getJobMeta().addJobEntry(new JobEntryCopy(jobEntry));
    parentJob.setStopped(false);
    jobEntry.setParentJob(parentJob);
    parentJob.setLogLevel(LogLevel.NOTHING);
    DatabaseMeta dbMeta = mock(DatabaseMeta.class);
    jobEntry.setDatabase(dbMeta);
    db = spy(new Database(jobEntry, dbMeta));
    jobEntry.setParentJob(parentJob);
    jobEntry.setTablename(TABLENAME);
    jobEntry.setArguments(COLUMNS);
    jobEntry.setSchemaname(SCHEMANAME);
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) Database(org.pentaho.di.core.database.Database) Job(org.pentaho.di.job.Job) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Before(org.junit.Before)

Example 68 with DatabaseMeta

use of org.pentaho.di.core.database.DatabaseMeta in project pentaho-kettle by pentaho.

the class JobEntryCopyFilesTest method saveLoad.

@Test
public void saveLoad() throws Exception {
    String[] srcPath = new String[] { "EMPTY_SOURCE_URL-0-" };
    String[] destPath = new String[] { "EMPTY_DEST_URL-0-" };
    entry.source_filefolder = srcPath;
    entry.destination_filefolder = destPath;
    entry.wildcard = new String[] { EMPTY };
    String xml = "<entry>" + entry.getXML() + "</entry>";
    assertTrue(xml.contains(srcPath[0]));
    assertTrue(xml.contains(destPath[0]));
    JobEntryCopyFiles loadedentry = new JobEntryCopyFiles();
    InputStream is = new ByteArrayInputStream(xml.getBytes());
    loadedentry.loadXML(XMLHandler.getSubNode(XMLHandler.loadXMLFile(is, null, false, false), "entry"), new ArrayList<DatabaseMeta>(), null, null, null);
    assertTrue(loadedentry.destination_filefolder[0].equals(destPath[0]));
    assertTrue(loadedentry.source_filefolder[0].equals(srcPath[0]));
    verify(mockNamedClusterEmbedManager, times(2)).registerUrl(anyString());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Mockito.anyString(org.mockito.Mockito.anyString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Test(org.junit.Test)

Example 69 with DatabaseMeta

use of org.pentaho.di.core.database.DatabaseMeta in project pentaho-kettle by pentaho.

the class SwitchCaseTest method testCreateOutputValueMapping.

/**
 * PDI-6900 Check that SwichCase step can correctly set up input values to output rowsets.
 *
 * @throws KettleException
 * @throws URISyntaxException
 * @throws ParserConfigurationException
 * @throws SAXException
 * @throws IOException
 */
@Test
public void testCreateOutputValueMapping() throws KettleException, URISyntaxException, ParserConfigurationException, SAXException, IOException {
    SwitchCaseCustom krasavez = new SwitchCaseCustom(mockHelper);
    // load step info value-case mapping from xml.
    List<DatabaseMeta> emptyList = new ArrayList<DatabaseMeta>();
    krasavez.meta.loadXML(loadStepXmlMetadata("SwitchCaseTest.xml"), emptyList, mock(IMetaStore.class));
    KeyToRowSetMap expectedNN = new KeyToRowSetMap();
    Set<RowSet> nulls = new HashSet<RowSet>();
    // create real steps for all targets
    List<SwitchCaseTarget> list = krasavez.meta.getCaseTargets();
    for (SwitchCaseTarget item : list) {
        StepMetaInterface smInt = new DummyTransMeta();
        StepMeta stepMeta = new StepMeta(item.caseTargetStepname, smInt);
        item.caseTargetStep = stepMeta;
        // create and put row set for this
        RowSet rw = new QueueRowSet();
        krasavez.map.put(item.caseTargetStepname, rw);
        // null values goes to null rowset
        if (item.caseValue != null) {
            expectedNN.put(item.caseValue, rw);
        } else {
            nulls.add(rw);
        }
    }
    // create default step
    StepMetaInterface smInt = new DummyTransMeta();
    StepMeta stepMeta = new StepMeta(krasavez.meta.getDefaultTargetStepname(), smInt);
    krasavez.meta.setDefaultTargetStep(stepMeta);
    RowSet rw = new QueueRowSet();
    krasavez.map.put(krasavez.meta.getDefaultTargetStepname(), rw);
    krasavez.createOutputValueMapping();
    // inspect step output data:
    Set<RowSet> ones = krasavez.data.outputMap.get("1");
    assertEquals("Output map for 1 values contains 2 row sets", 2, ones.size());
    Set<RowSet> twos = krasavez.data.outputMap.get("2");
    assertEquals("Output map for 2 values contains 1 row sets", 1, twos.size());
    assertEquals("Null row set contains 2 items: ", 2, krasavez.data.nullRowSetSet.size());
    assertEquals("We have at least one default rowset", 1, krasavez.data.defaultRowSetSet.size());
    // check that rowsets data is correct:
    Set<RowSet> rowsets = expectedNN.get("1");
    for (RowSet rowset : rowsets) {
        assertTrue("Output map for 1 values contains expected row set", ones.contains(rowset));
    }
    rowsets = expectedNN.get("2");
    for (RowSet rowset : rowsets) {
        assertTrue("Output map for 2 values contains expected row set", twos.contains(rowset));
    }
    for (RowSet rowset : krasavez.data.nullRowSetSet) {
        assertTrue("Output map for null values contains expected row set", nulls.contains(rowset));
    }
    // we have already check that there is only one item.
    for (RowSet rowset : krasavez.data.defaultRowSetSet) {
        assertTrue("Output map for default case contains expected row set", rowset.equals(rw));
    }
}
Also used : ArrayList(java.util.ArrayList) RowSet(org.pentaho.di.core.RowSet) QueueRowSet(org.pentaho.di.core.QueueRowSet) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) QueueRowSet(org.pentaho.di.core.QueueRowSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 70 with DatabaseMeta

use of org.pentaho.di.core.database.DatabaseMeta in project pentaho-kettle by pentaho.

the class ExecSQLMetaInjectionTest method test.

@Test
public void test() throws Exception {
    check("SQL", () -> meta.getSql());
    check("EXECUTE_FOR_EACH_ROW", () -> meta.isExecutedEachInputRow());
    check("UPDATE_STATS_FIELD", () -> meta.getUpdateField());
    check("INSERT_STATS_FIELD", () -> meta.getInsertField());
    check("DELETE_STATS_FIELD", () -> meta.getDeleteField());
    check("READ_STATS_FIELD", () -> meta.getReadField());
    check("EXECUTE_AS_SINGLE_STATEMENT", () -> meta.isSingleStatement());
    check("REPLACE_VARIABLES", () -> meta.isReplaceVariables());
    check("QUOTE_STRINGS", () -> meta.isQuoteString());
    check("BIND_PARAMETERS", () -> meta.isParams());
    check("PARAMETER_NAME", () -> meta.getArguments()[0]);
    // skip connection name testing, so we can provide our own custom handling
    skipPropertyTest("CONNECTIONNAME");
    // mock the database connections
    final DatabaseMeta db1 = new DatabaseMeta();
    db1.setName("my connection 1");
    final DatabaseMeta db2 = new DatabaseMeta();
    db2.setName("my connection 2");
    final DatabaseMeta db3 = new DatabaseMeta();
    db3.setName("my connection 3");
    final List<SharedObjectInterface> mockDbs = Arrays.asList(new SharedObjectInterface[] { db1, db2, db3 });
    final StepMeta parentStepMeta = Mockito.mock(StepMeta.class);
    final TransMeta parentTransMeta = Mockito.mock(TransMeta.class);
    Mockito.doReturn(mockDbs).when(parentTransMeta).getDatabases();
    Mockito.doReturn(parentTransMeta).when(parentStepMeta).getParentTransMeta();
    meta.setParentStepMeta(parentStepMeta);
    injector.setProperty(meta, "CONNECTIONNAME", setValue(new ValueMetaString("my connection 2"), "my connection 2"), "my connection 2");
    // verify we get back the correct connection
    assertEquals(db2, meta.getDatabaseMeta());
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) TransMeta(org.pentaho.di.trans.TransMeta) SharedObjectInterface(org.pentaho.di.shared.SharedObjectInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Test(org.junit.Test) BaseMetadataInjectionTest(org.pentaho.di.core.injection.BaseMetadataInjectionTest)

Aggregations

DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)522 Test (org.junit.Test)133 KettleException (org.pentaho.di.core.exception.KettleException)131 Database (org.pentaho.di.core.database.Database)88 MessageBox (org.eclipse.swt.widgets.MessageBox)66 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)63 TransMeta (org.pentaho.di.trans.TransMeta)57 StepMeta (org.pentaho.di.trans.step.StepMeta)54 ArrayList (java.util.ArrayList)53 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)48 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)44 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)42 SlaveServer (org.pentaho.di.cluster.SlaveServer)33 IMetaStore (org.pentaho.metastore.api.IMetaStore)30 ObjectId (org.pentaho.di.repository.ObjectId)29 DatabaseExplorerDialog (org.pentaho.di.ui.core.database.dialog.DatabaseExplorerDialog)29 JobMeta (org.pentaho.di.job.JobMeta)26 TransHopMeta (org.pentaho.di.trans.TransHopMeta)26 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)24 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)24