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