Search in sources :

Example 31 with StepField

use of org.pentaho.metaverse.api.StepField in project pentaho-metaverse by pentaho.

the class FilterRowsStepAnalyzerTest method testGetUsedFields.

@Test
public void testGetUsedFields() throws Exception {
    StepNodes inputNodes = new StepNodes();
    inputNodes.addNode("input", "height", node);
    inputNodes.addNode("input", "width", node);
    inputNodes.addNode("input", "radius", node);
    inputNodes.addNode("input", "pi", node);
    inputNodes.addNode("input", "two", node);
    when(analyzer.getInputs()).thenReturn(inputNodes);
    Set<StepField> usedFields = analyzer.getUsedFields(meta);
    assertNotNull(usedFields);
    assertEquals(conditionFields.length, usedFields.size());
}
Also used : StepField(org.pentaho.metaverse.api.StepField) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) Test(org.junit.Test)

Example 32 with StepField

use of org.pentaho.metaverse.api.StepField in project pentaho-metaverse by pentaho.

the class GroupByStepAnalyzerTest method testGetUsedFields.

@Test
public void testGetUsedFields() throws Exception {
    Set<StepField> fields = new HashSet<>();
    fields.add(new StepField("prev", "member"));
    fields.add(new StepField("prev", "donation"));
    fields.add(new StepField("prev", "state"));
    fields.add(new StepField("prev", "country"));
    doReturn(fields).when(analyzer).createStepFields(anyString(), any(StepNodes.class));
    Set<StepField> usedFields = analyzer.getUsedFields(meta);
    int expectedUsedFieldCount = mockAggregateFields.length + mockSubjectFields.length;
    assertEquals(expectedUsedFieldCount, usedFields.size());
    verify(analyzer, times(expectedUsedFieldCount)).createStepFields(anyString(), any(StepNodes.class));
}
Also used : StepField(org.pentaho.metaverse.api.StepField) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 33 with StepField

use of org.pentaho.metaverse.api.StepField in project pentaho-metaverse by pentaho.

the class NumberRangeStepAnalyzerTest method testGetUsedFields.

@Test
public void testGetUsedFields() throws Exception {
    Set<StepField> fields = new HashSet<>();
    fields.add(new StepField("prev", "inField"));
    doReturn(fields).when(analyzer).createStepFields(anyString(), any(StepNodes.class));
    Set<StepField> usedFields = analyzer.getUsedFields(meta);
    int expectedUsedFieldCount = 1;
    assertEquals(expectedUsedFieldCount, usedFields.size());
    verify(analyzer, times(expectedUsedFieldCount)).createStepFields(anyString(), any(StepNodes.class));
}
Also used : StepField(org.pentaho.metaverse.api.StepField) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 34 with StepField

use of org.pentaho.metaverse.api.StepField in project pentaho-metaverse by pentaho.

the class SelectValuesStepAnalyzerTest method testIsPassthrough.

@Test
public void testIsPassthrough() throws Exception {
    String[] deleted = new String[] { "first, last" };
    String[] selected = new String[] { "age" };
    SelectMetadataChange[] changed = new SelectMetadataChange[] { testChange1, testChange2 };
    when(selectValuesMeta.getDeleteName()).thenReturn(deleted);
    when(selectValuesMeta.getSelectName()).thenReturn(selected);
    when(selectValuesMeta.getMeta()).thenReturn(changed);
    StepField stepField = new StepField("previousStep", "first");
    assertFalse(analyzer.isPassthrough(stepField));
    stepField.setFieldName("last");
    assertFalse(analyzer.isPassthrough(stepField));
    stepField.setFieldName("age");
    assertFalse(analyzer.isPassthrough(stepField));
    // birthday should not be a passthrough, there are fields "selected"
    stepField.setFieldName("birthday");
    assertFalse(analyzer.isPassthrough(stepField));
}
Also used : StepField(org.pentaho.metaverse.api.StepField) SelectMetadataChange(org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange) Test(org.junit.Test)

Example 35 with StepField

use of org.pentaho.metaverse.api.StepField in project pentaho-metaverse by pentaho.

the class SelectValuesStepAnalyzerTest method testIsPassthrough_deleteAndMeta.

@Test
public void testIsPassthrough_deleteAndMeta() throws Exception {
    String[] deleted = new String[] { "first", "age" };
    String[] selected = new String[0];
    SelectMetadataChange[] changed = new SelectMetadataChange[] { testChange1, testChange2 };
    when(selectValuesMeta.getDeleteName()).thenReturn(deleted);
    when(selectValuesMeta.getSelectName()).thenReturn(selected);
    when(selectValuesMeta.getMeta()).thenReturn(changed);
    StepField stepField = new StepField("previousStep", "first");
    // first was deleted, not a passthrough
    assertFalse(analyzer.isPassthrough(stepField));
    stepField.setFieldName("last");
    // last not deleted but it is meta-modified, not a passthrough
    assertFalse(analyzer.isPassthrough(stepField));
    stepField.setFieldName("age");
    // age was deleted, it is NOT passthrough
    assertFalse(analyzer.isPassthrough(stepField));
    stepField.setFieldName("birthday");
    // birthday was NOT deleted and not meta-modified, it is a passthrough
    assertTrue(analyzer.isPassthrough(stepField));
}
Also used : StepField(org.pentaho.metaverse.api.StepField) SelectMetadataChange(org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange) Test(org.junit.Test)

Aggregations

StepField (org.pentaho.metaverse.api.StepField)53 Test (org.junit.Test)33 HashSet (java.util.HashSet)23 StepNodes (org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes)11 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)10 ComponentDerivationRecord (org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord)10 Matchers.anyString (org.mockito.Matchers.anyString)6 Before (org.junit.Before)4 SelectMetadataChange (org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange)4 Set (java.util.Set)3 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)3 MetaverseObjectFactory (org.pentaho.metaverse.api.MetaverseObjectFactory)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)2 IAnalysisContext (org.pentaho.metaverse.api.IAnalysisContext)2 IExternalResourceInfo (org.pentaho.metaverse.api.model.IExternalResourceInfo)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Graph (com.tinkerpop.blueprints.Graph)1 Vertex (com.tinkerpop.blueprints.Vertex)1