Search in sources :

Example 76 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.

the class JobEntrySetVariablesTest method testJobEntrySetVariablesExecute_VARIABLE_TYPE_JVM_VariableNotNull.

@Test
public void testJobEntrySetVariablesExecute_VARIABLE_TYPE_JVM_VariableNotNull() throws Exception {
    List<DatabaseMeta> databases = mock(List.class);
    List<SlaveServer> slaveServers = mock(List.class);
    Repository repository = mock(Repository.class);
    IMetaStore metaStore = mock(IMetaStore.class);
    entry.loadXML(getEntryNode("variableNotNull", "someValue", "JVM"), databases, slaveServers, repository, metaStore);
    assertNull(System.getProperty("variableNotNull"));
    Result result = entry.execute(new Result(), 0);
    assertTrue("Result should be true", result.getResult());
    assertEquals("someValue", System.getProperty("variableNotNull"));
}
Also used : Repository(org.pentaho.di.repository.Repository) SlaveServer(org.pentaho.di.cluster.SlaveServer) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) Result(org.pentaho.di.core.Result) Test(org.junit.Test)

Example 77 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.

the class CombinationLookupIT method testUseDefaultSchemaName.

public void testUseDefaultSchemaName() throws Exception {
    String schemaName = "";
    String tableName = "tableName";
    String schemaTable = "default.tableName";
    String technicalKeyField = "technicalKeyField";
    DatabaseMeta databaseMeta = spy(new DatabaseMeta(databasesXML[0]) {

        @Override
        public String getFieldDefinition(ValueMetaInterface v, String tk, String pk, boolean use_autoinc) {
            return "someValue";
        }
    });
    when(databaseMeta.getQuotedSchemaTableCombination(schemaName, tableName)).thenReturn(schemaTable);
    CombinationLookupMeta clm = new CombinationLookupMeta();
    clm.setTechnicalKeyField(technicalKeyField);
    clm.setKeyLookup(new String[] { "keyLookup1", "keyLookup2" });
    clm.setDatabaseMeta(databaseMeta);
    clm.setTablename(tableName);
    clm.setSchemaName(schemaName);
    StepMeta stepMeta = mock(StepMeta.class);
    RowMetaInterface rowMetaInterface = mock(RowMetaInterface.class);
    when(rowMetaInterface.size()).thenReturn(1);
    Repository repository = mock(Repository.class);
    IMetaStore metaStore = mock(IMetaStore.class);
    SQLStatement sqlStatement = clm.getSQLStatements(new TransMeta(), stepMeta, rowMetaInterface, repository, metaStore);
    String sql = sqlStatement.getSQL();
    Assert.assertTrue(StringUtils.countMatches(sql, schemaTable) == 3);
}
Also used : Repository(org.pentaho.di.repository.Repository) TransMeta(org.pentaho.di.trans.TransMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) SQLStatement(org.pentaho.di.core.SQLStatement) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 78 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.

the class DeleteMetaTest method testReadRepToLoadKeys.

@Test
public void testReadRepToLoadKeys() throws KettleException {
    DeleteMeta deleteMeta = new DeleteMeta();
    Repository rep = mock(Repository.class);
    IMetaStore metaStore = mock(IMetaStore.class);
    ObjectId idStep = mock(ObjectId.class);
    List<DatabaseMeta> databases = new ArrayList<>();
    String keyNameValue = UUID.randomUUID().toString();
    String keyFieldValue = UUID.randomUUID().toString();
    String keyConditionValue = UUID.randomUUID().toString();
    String keyName2Value = UUID.randomUUID().toString();
    when(rep.countNrStepAttributes(idStep, "key_field")).thenReturn(1);
    when(rep.getStepAttributeString(idStep, 0, "key_name")).thenReturn(keyNameValue);
    when(rep.getStepAttributeString(idStep, 0, "key_field")).thenReturn(keyFieldValue);
    when(rep.getStepAttributeString(idStep, 0, "key_condition")).thenReturn(keyConditionValue);
    when(rep.getStepAttributeString(idStep, 0, "key_name2")).thenReturn(keyName2Value);
    deleteMeta.readRep(rep, metaStore, idStep, databases);
    assertEquals(1, ((String[]) getInternalState(deleteMeta, "keyStream")).length);
    assertEquals(keyNameValue, ((String[]) getInternalState(deleteMeta, "keyStream"))[0]);
    assertEquals(1, ((String[]) getInternalState(deleteMeta, "keyLookup")).length);
    assertEquals(keyFieldValue, ((String[]) getInternalState(deleteMeta, "keyLookup"))[0]);
    assertEquals(1, ((String[]) getInternalState(deleteMeta, "keyCondition")).length);
    assertEquals(keyConditionValue, ((String[]) getInternalState(deleteMeta, "keyCondition"))[0]);
    assertEquals(1, ((String[]) getInternalState(deleteMeta, "keyStream2")).length);
    assertEquals(keyName2Value, ((String[]) getInternalState(deleteMeta, "keyStream2"))[0]);
}
Also used : Repository(org.pentaho.di.repository.Repository) ObjectId(org.pentaho.di.repository.ObjectId) ArrayList(java.util.ArrayList) IMetaStore(org.pentaho.metastore.api.IMetaStore) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) Test(org.junit.Test)

Example 79 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.

the class BaseStreamStepMeta method check.

public void check(List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore) {
    long duration = Long.MIN_VALUE;
    try {
        duration = Long.parseLong(space.environmentSubstitute(getBatchDuration()));
    } catch (NumberFormatException e) {
        remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, NOT_A_NUMBER, "Duration"), stepMeta));
    }
    long size = Long.MIN_VALUE;
    try {
        size = Long.parseLong(space.environmentSubstitute(getBatchSize()));
    } catch (NumberFormatException e) {
        remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, NOT_A_NUMBER, "Number of records"), stepMeta));
    }
    if (duration == 0 && size == 0) {
        remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "BaseStreamStepMeta.CheckResult.NoBatchDefined"), stepMeta));
    }
    try {
        int prefetch = Integer.parseInt(space.environmentSubstitute(getPrefetchCount()));
        if (prefetch <= 0) {
            remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "BaseStreamStepMeta.CheckResult.PrefetchZeroOrLess", prefetch, size), stepMeta));
        }
        if (prefetch < size) {
            remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "BaseStreamStepMeta.CheckResult.PrefetchLessThanBatch", prefetch, size), stepMeta));
        }
    } catch (NumberFormatException e) {
        remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, NOT_A_NUMBER, "Message prefetch limit"), stepMeta));
    }
    try {
        TransMeta subMeta = mappingMetaRetriever.get(this, repository, metaStore, space);
        if (!StringUtil.isEmpty(getSubStep())) {
            String realSubStepName = space.environmentSubstitute(getSubStep());
            if (!subMeta.getSteps().stream().anyMatch(subStepMeta -> subStepMeta.getName().equals(realSubStepName))) {
                remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "BaseStreamStepMeta.CheckResult.ResultStepMissing", subMeta.getName(), realSubStepName), stepMeta));
            }
        }
    } catch (KettleException e) {
        getLog().logDebug("Error loading subtrans meta", e);
    }
}
Also used : StepMeta(org.pentaho.di.trans.step.StepMeta) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) CheckResultInterface(org.pentaho.di.core.CheckResultInterface) RowMeta(org.pentaho.di.core.row.RowMeta) Repository(org.pentaho.di.repository.Repository) KettleException(org.pentaho.di.core.exception.KettleException) ResourceEntry(org.pentaho.di.resource.ResourceEntry) Injection(org.pentaho.di.core.injection.Injection) TransExecutorMeta(org.pentaho.di.trans.steps.transexecutor.TransExecutorMeta) Utils(org.pentaho.di.core.util.Utils) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ISubTransAwareMeta(org.pentaho.di.trans.ISubTransAwareMeta) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) ResourceReference(org.pentaho.di.resource.ResourceReference) StepWithMappingMeta(org.pentaho.di.trans.StepWithMappingMeta) List(java.util.List) TransMeta(org.pentaho.di.trans.TransMeta) CheckResult(org.pentaho.di.core.CheckResult) KettleStepException(org.pentaho.di.core.exception.KettleStepException) IMetaStore(org.pentaho.metastore.api.IMetaStore) VariableSpace(org.pentaho.di.core.variables.VariableSpace) BaseMessages(org.pentaho.di.i18n.BaseMessages) StringUtil(org.pentaho.di.core.util.StringUtil) KettleException(org.pentaho.di.core.exception.KettleException) CheckResult(org.pentaho.di.core.CheckResult) TransMeta(org.pentaho.di.trans.TransMeta)

Example 80 with IMetaStore

use of org.pentaho.metastore.api.IMetaStore in project pentaho-kettle by pentaho.

the class SystemDataMetaTest method testLoadXML.

@Test
public void testLoadXML() throws Exception {
    SystemDataMeta systemDataMeta = new SystemDataMeta();
    DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
    Document document = documentBuilder.parse(new InputSource(new StringReader(expectedXML)));
    Node node = document;
    IMetaStore store = null;
    systemDataMeta.loadXML(node, null, store);
    assertEquals(expectedSystemDataMeta, systemDataMeta);
}
Also used : InputSource(org.xml.sax.InputSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Node(org.w3c.dom.Node) StringReader(java.io.StringReader) Document(org.w3c.dom.Document) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Aggregations

IMetaStore (org.pentaho.metastore.api.IMetaStore)86 Test (org.junit.Test)62 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)25 Repository (org.pentaho.di.repository.Repository)25 SQL (org.pentaho.di.core.sql.SQL)17 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)12 TransMeta (org.pentaho.di.trans.TransMeta)12 Matchers.anyString (org.mockito.Matchers.anyString)11 StepMeta (org.pentaho.di.trans.step.StepMeta)11 KettleException (org.pentaho.di.core.exception.KettleException)10 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)10 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)10 ArrayList (java.util.ArrayList)9 IMetaStoreElementType (org.pentaho.metastore.api.IMetaStoreElementType)9 Node (org.w3c.dom.Node)9 Variables (org.pentaho.di.core.variables.Variables)7 StringObjectId (org.pentaho.di.repository.StringObjectId)7 PushDownOptimizationMeta (org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta)7 CheckResultInterface (org.pentaho.di.core.CheckResultInterface)6 IMetaStoreElement (org.pentaho.metastore.api.IMetaStoreElement)6