Search in sources :

Example 61 with Variables

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);
}
Also used : Variables(org.pentaho.di.core.variables.Variables) VariableSpace(org.pentaho.di.core.variables.VariableSpace) TransMeta(org.pentaho.di.trans.TransMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) MongoDbMeta(org.pentaho.di.trans.steps.mongodb.MongoDbMeta) Before(org.junit.Before)

Example 62 with Variables

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);
}
Also used : Variables(org.pentaho.di.core.variables.Variables) VariableSpace(org.pentaho.di.core.variables.VariableSpace)

Example 63 with Variables

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")));
}
Also used : Condition(org.pentaho.di.core.Condition) ParameterGenerationTest.newCondition(org.pentaho.di.trans.dataservice.optimization.paramgen.ParameterGenerationTest.newCondition) Variables(org.pentaho.di.core.variables.Variables) RowMeta(org.pentaho.di.core.row.RowMeta) JUnitMatchers.containsString(org.junit.matchers.JUnitMatchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 64 with Variables

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();
    }
}
Also used : Variables(org.pentaho.di.core.variables.Variables) JobMeta(org.pentaho.di.job.JobMeta) TransMeta(org.pentaho.di.trans.TransMeta) Job(org.pentaho.di.job.Job) Trans(org.pentaho.di.trans.Trans) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 65 with Variables

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);
}
Also used : Variables(org.pentaho.di.core.variables.Variables) DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) VariableSpace(org.pentaho.di.core.variables.VariableSpace) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Test(org.junit.Test)

Aggregations

Variables (org.pentaho.di.core.variables.Variables)119 Test (org.junit.Test)67 TransMeta (org.pentaho.di.trans.TransMeta)31 ArrayList (java.util.ArrayList)25 CheckResultInterface (org.pentaho.di.core.CheckResultInterface)20 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)20 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)20 StepMeta (org.pentaho.di.trans.step.StepMeta)18 RowMeta (org.pentaho.di.core.row.RowMeta)17 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)16 VariableSpace (org.pentaho.di.core.variables.VariableSpace)14 Repository (org.pentaho.di.repository.Repository)12 TableView (org.pentaho.di.ui.core.widget.TableView)10 FormAttachment (org.eclipse.swt.layout.FormAttachment)9 FormData (org.eclipse.swt.layout.FormData)9 ColumnInfo (org.pentaho.di.ui.core.widget.ColumnInfo)9 Label (org.eclipse.swt.widgets.Label)8 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)7