use of org.pentaho.di.core.variables.Variables in project pentaho-metaverse by pentaho.
the class MongoDbResourceInfoTest method setUp.
@Before
public void setUp() throws Exception {
meta = mock(MongoDbMeta.class);
when(meta.getDbName()).thenReturn(null);
when(meta.getPort()).thenReturn(null);
when(meta.getHostnames()).thenReturn(null);
when(meta.getAuthenticationUser()).thenReturn(null);
when(meta.getAuthenticationPassword()).thenReturn(null);
when(meta.getUseAllReplicaSetMembers()).thenReturn(false);
when(meta.getUseKerberosAuthentication()).thenReturn(false);
when(meta.getConnectTimeout()).thenReturn(null);
when(meta.getSocketTimeout()).thenReturn(null);
when(meta.getCollection()).thenReturn(null);
StepMeta stepMeta = new StepMeta();
TransMeta transMeta = new TransMeta();
stepMeta.setParentTransMeta(transMeta);
VariableSpace variables = new Variables();
when(meta.getParentStepMeta()).thenReturn(stepMeta);
info = new MongoDbResourceInfo(meta);
}
use of org.pentaho.di.core.variables.Variables in project pdi-dataservice-server-plugin by pentaho.
the class ParameterGeneration method setQueryParameter.
protected String setQueryParameter(String query, String parameterValue) {
VariableSpace varSpace = new Variables();
varSpace.setVariable(getParameterName(), parameterValue);
return varSpace.environmentSubstitute(query);
}
use of org.pentaho.di.core.variables.Variables in project pdi-dataservice-server-plugin by pentaho.
the class TableInputParameterGenerationTest method testPushDown.
@Test
public void testPushDown() throws Exception {
// Add filters to both WHERE and GROUP by converting original query to a prepared statement...
String originalQuery = "SELECT DepartmentName, COUNT(*) as EmployeeCount " + "FROM Department, Employee " + "WHERE Employee.DepartmentId = Department.DepartmentId AND ${EMPLOYEE_FILTER} ";
ParameterGeneration employeeFilterParamGen = factory.createPushDown();
employeeFilterParamGen.setParameterName("EMPLOYEE_FILTER");
// Employee.Grade = "G7"
Condition employeeFilter = newCondition("Employee.Grade", "G7");
// Push Down condition
service.pushDown(employeeFilter, employeeFilterParamGen, stepInterface);
// Verify that the database for this step is now 'wrapped'
assertThat(data.db, is(instanceOf(DatabaseWrapper.class)));
final DatabaseWrapper databaseWrapper = (DatabaseWrapper) data.db;
// The employee filter variable should now be set
ArgumentCaptor<String> varCaptor = ArgumentCaptor.forClass(String.class);
verify(stepInterface).setVariable(eq(employeeFilterParamGen.getParameterName()), varCaptor.capture());
// Verify stored data for runtime injection
final List<String> fragmentIds = varCaptor.getAllValues();
assertThat(fragmentIds.size(), is(1));
assertTrue(databaseWrapper.pushDownMap.keySet().containsAll(fragmentIds));
// Update original query with variable values
Variables variables = new Variables();
variables.setVariable(employeeFilterParamGen.getParameterName(), fragmentIds.get(0));
String runtimeQuery = variables.environmentSubstitute(originalQuery);
for (String fragment : fragmentIds) {
assertThat(runtimeQuery, containsString(fragment));
}
// During trans runtime, values and sql fragments will be injected
RowMeta rowMeta = new RowMeta();
List<Object> values = new LinkedList<Object>();
String resultQuery = databaseWrapper.injectRuntime(databaseWrapper.pushDownMap, runtimeQuery, rowMeta, values);
String expectedQuery = "SELECT DepartmentName, COUNT(*) as EmployeeCount " + "FROM Department, Employee " + "WHERE Employee.DepartmentId = Department.DepartmentId AND Employee.Grade = ? ";
assertThat(resultQuery, equalTo(expectedQuery));
assertThat(rowMeta.getValueMetaList(), equalTo(Arrays.asList(resolvedValueMeta)));
assertThat(values, equalTo(Arrays.<Object>asList("G7")));
}
use of org.pentaho.di.core.variables.Variables in project pentaho-metaverse by pentaho.
the class ExternalResourceConsumerIT method testExternalResourceConsumer.
@Test
public void testExternalResourceConsumer() throws Exception {
FileInputStream xmlStream = new FileInputStream(transOrJobPath);
Variables vars = new Variables();
for (String key : variables.keySet()) {
vars.setVariable(key, variables.get(key));
}
// run the trans or job
if (transOrJobPath.endsWith(".ktr")) {
KettleClientEnvironment.getInstance().setClient(KettleClientEnvironment.ClientType.PAN);
TransMeta tm = new TransMeta(xmlStream, null, true, vars, null);
tm.setFilename(tm.getName());
Trans trans = new Trans(tm, null, tm.getName(), REPO_PATH, transOrJobPath);
for (String var : vars.listVariables()) {
trans.setVariable(var, vars.getVariable(var));
}
trans.execute(null);
trans.waitUntilFinished();
} else {
KettleClientEnvironment.getInstance().setClient(KettleClientEnvironment.ClientType.KITCHEN);
JobMeta jm = new JobMeta(new Variables(), transOrJobPath, null, null, null);
jm.setFilename(jm.getName());
Job job = new Job(null, jm);
Variables variables = new Variables();
variables.initializeVariablesFrom(job.getParentJob());
jm.setInternalKettleVariables(variables);
for (String var : vars.listVariables()) {
jm.setVariable(var, vars.getVariable(var));
}
job.copyParametersFrom(jm);
job.copyVariablesFrom(jm);
job.activateParameters();
// We have to call the extension point ourselves -- don't ask :(
ExtensionPointHandler.callExtensionPoint(job.getLogChannel(), KettleExtensionPoint.JobStart.id, job);
job.execute(0, null);
job.fireJobFinishListeners();
}
}
use of org.pentaho.di.core.variables.Variables in project pentaho-metaverse by pentaho.
the class JdbcResourceInfoTest method testDbMetaVarPort.
@Test
public void testDbMetaVarPort() throws Exception {
DatabaseMeta dbMeta = mock(DatabaseMeta.class);
DatabaseInterface dbInterface = mock(DatabaseInterface.class);
when(dbMeta.getDatabaseInterface()).thenReturn(dbInterface);
when(dbMeta.getAccessTypeDesc()).thenReturn("Native");
final VariableSpace vs = new Variables();
when(dbMeta.getDatabasePortNumberString()).thenReturn("${port_var}");
when(dbMeta.environmentSubstitute(any(String.class))).thenAnswer(new Answer<String>() {
public String answer(InvocationOnMock invocation) throws Throwable {
return vs.environmentSubstitute((String) invocation.getArguments()[0]);
}
});
// check if var replaced
vs.setVariable("port_var", "4321");
JdbcResourceInfo jdbcResourceInfo = new JdbcResourceInfo(dbMeta);
assertEquals(jdbcResourceInfo.getPort(), new Integer(4321));
// check no exception when empty
vs.setVariable("port_var", "");
jdbcResourceInfo = new JdbcResourceInfo(dbMeta);
}
Aggregations