Search in sources :

Example 71 with ValueMetaInteger

use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.

the class GroupByMetaGetFieldsTest method setup.

@Before
public void setup() throws KettlePluginException {
    rowMeta = spy(new RowMeta());
    groupByMeta = spy(new GroupByMeta());
    mockStatic(ValueMetaFactory.class);
    when(ValueMetaFactory.createValueMeta(anyInt())).thenCallRealMethod();
    when(ValueMetaFactory.createValueMeta(anyString(), anyInt())).thenCallRealMethod();
    when(ValueMetaFactory.createValueMeta("maxDate", 3, -1, -1)).thenReturn(new ValueMetaDate("maxDate"));
    when(ValueMetaFactory.createValueMeta("minDate", 3, -1, -1)).thenReturn(new ValueMetaDate("minDate"));
    when(ValueMetaFactory.createValueMeta("countDate", 5, -1, -1)).thenReturn(new ValueMetaInteger("countDate"));
    when(ValueMetaFactory.getValueMetaName(3)).thenReturn("Date");
    when(ValueMetaFactory.getValueMetaName(5)).thenReturn("Integer");
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Before(org.junit.Before)

Example 72 with ValueMetaInteger

use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.

the class GroupByNewAggregateTest method setUp.

@Before
public void setUp() throws Exception {
    data = new GroupByData();
    data.subjectnrs = new int[18];
    int[] arr = new int[18];
    String[] arrF = new String[18];
    data.previousSums = new Object[18];
    data.previousAvgCount = new long[18];
    data.previousAvgSum = new Object[18];
    for (int i = 0; i < arr.length; i++) {
        // set aggregation types (hardcoded integer values from 1 to 18)
        arr[i] = i + 1;
        data.subjectnrs[i] = i;
    }
    Arrays.fill(arrF, "x");
    Arrays.fill(data.previousSums, 11);
    Arrays.fill(data.previousAvgCount, 12);
    Arrays.fill(data.previousAvgSum, 13);
    GroupByMeta meta = new GroupByMeta();
    meta.setAggregateType(arr);
    meta.setAggregateField(arrF);
    ValueMetaInterface vmi = new ValueMetaInteger();
    when(mockHelper.stepMeta.getStepMetaInterface()).thenReturn(meta);
    RowMetaInterface rmi = Mockito.mock(RowMetaInterface.class);
    data.inputRowMeta = rmi;
    when(rmi.getValueMeta(Mockito.anyInt())).thenReturn(vmi);
    data.aggMeta = rmi;
    data.agg = new Object[] { def };
    data.counts = new long[] { 1 };
    data.previousSums = new Object[] { 18 };
    step = new GroupBy(mockHelper.stepMeta, data, 0, mockHelper.transMeta, mockHelper.trans);
}
Also used : ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Before(org.junit.Before)

Example 73 with ValueMetaInteger

use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.

the class GroupByNullInputTest method testNullInputDataForStandardDeviation.

/**
 * PMD-1037 NPE error appears when user uses "Data Profile" feature to some tables in Hive 2.
 */
@Test
public void testNullInputDataForStandardDeviation() throws KettleValueException {
    setAggregationTypesAndInitData(new int[] { 15 });
    ValueMetaInterface vmi = new ValueMetaInteger();
    when(rowMetaInterfaceMock.getValueMeta(Mockito.anyInt())).thenReturn(vmi);
    Object[] row1 = new Object[NUMBER_OF_COLUMNS];
    Arrays.fill(row1, null);
    step.newAggregate(row1);
    step.calcAggregate(row1);
    Object[] aggregateResult = step.getAggregateResult();
    Assert.assertNull("Returns null if aggregation is null", aggregateResult[0]);
}
Also used : ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 74 with ValueMetaInteger

use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.

the class GroupByTest method testProcessRow.

@Test
public void testProcessRow() throws KettleException {
    GroupByMeta groupByMeta = mock(GroupByMeta.class);
    GroupByData groupByData = mock(GroupByData.class);
    GroupBy groupBySpy = Mockito.spy(new GroupBy(mockHelper.stepMeta, mockHelper.stepDataInterface, 0, mockHelper.transMeta, mockHelper.trans));
    doReturn(null).when(groupBySpy).getRow();
    doReturn(null).when(groupBySpy).getInputRowMeta();
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaInteger("ROWNR"));
    List<RowSet> outputRowSets = new ArrayList<RowSet>();
    BlockingRowSet rowSet = new BlockingRowSet(1);
    rowSet.putRow(rowMeta, new Object[] { new Long(0) });
    outputRowSets.add(rowSet);
    groupBySpy.setOutputRowSets(outputRowSets);
    final String[] sub = { "b" };
    doReturn(sub).when(groupByMeta).getSubjectField();
    final String[] groupField = { "a" };
    doReturn(groupField).when(groupByMeta).getGroupField();
    final String[] aggFields = { "b_g" };
    doReturn(aggFields).when(groupByMeta).getAggregateField();
    final int[] aggType = { GroupByMeta.TYPE_GROUP_CONCAT_COMMA };
    doReturn(aggType).when(groupByMeta).getAggregateType();
    when(mockHelper.transMeta.getPrevStepFields(mockHelper.stepMeta)).thenReturn(new RowMeta());
    groupBySpy.processRow(groupByMeta, groupByData);
    assertTrue(groupBySpy.getOutputRowSets().get(0).isDone());
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) RowSet(org.pentaho.di.core.RowSet) BlockingRowSet(org.pentaho.di.core.BlockingRowSet) ArrayList(java.util.ArrayList) BlockingRowSet(org.pentaho.di.core.BlockingRowSet) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Matchers.anyString(org.mockito.Matchers.anyString) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) Test(org.junit.Test)

Example 75 with ValueMetaInteger

use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryTest method getNullIntegerRow.

private RowMetaAndData getNullIntegerRow() {
    RowMeta rm = new RowMeta();
    rm.addValueMeta(new ValueMetaInteger());
    return new RowMetaAndData(rm, new Object[] { null });
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger)

Aggregations

ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)291 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)198 RowMeta (org.pentaho.di.core.row.RowMeta)132 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)124 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)110 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)89 Test (org.junit.Test)72 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)63 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)60 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)52 KettleException (org.pentaho.di.core.exception.KettleException)39 LongObjectId (org.pentaho.di.repository.LongObjectId)38 ObjectId (org.pentaho.di.repository.ObjectId)33 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)31 KettleStepException (org.pentaho.di.core.exception.KettleStepException)25 ArrayList (java.util.ArrayList)21 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)20 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)19 Date (java.util.Date)17 SQLException (java.sql.SQLException)16