Search in sources :

Example 81 with ValueMetaInteger

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

the class DatabaseLookupUTest method getRowInCacheTest.

@Test
public void getRowInCacheTest() throws KettleException {
    when(mockHelper.logChannelInterfaceFactory.create(any(), any(LoggingObjectInterface.class))).thenReturn(mockHelper.logChannelInterface);
    DatabaseLookup look = new DatabaseLookup(mockHelper.stepMeta, mockHelper.stepDataInterface, 0, mockHelper.transMeta, mockHelper.trans);
    DatabaseLookupData lookData = new DatabaseLookupData();
    lookData.cache = DefaultCache.newCache(lookData, 0);
    lookData.lookupMeta = new RowMeta();
    look.init(new DatabaseLookupMeta(), lookData);
    ValueMetaInterface valueMeta = new ValueMetaInteger("fieldTest");
    RowMeta lookupMeta = new RowMeta();
    lookupMeta.setValueMetaList(Collections.singletonList(valueMeta));
    Object[] kgsRow1 = new Object[1];
    kgsRow1[0] = 1L;
    Object[] kgsRow2 = new Object[1];
    kgsRow2[0] = 2L;
    Object[] add1 = new Object[1];
    add1[0] = 10L;
    Object[] add2 = new Object[1];
    add2[0] = 20L;
    lookData.cache.storeRowInCache(mockHelper.processRowsStepMetaInterface, lookupMeta, kgsRow1, add1);
    lookData.cache.storeRowInCache(mockHelper.processRowsStepMetaInterface, lookupMeta, kgsRow2, add2);
    Object[] rowToCache = new Object[1];
    rowToCache[0] = 0L;
    lookData.conditions = new int[1];
    lookData.conditions[0] = DatabaseLookupMeta.CONDITION_GE;
    Object[] dataFromCache = lookData.cache.getRowFromCache(lookupMeta, rowToCache);
    assertArrayEquals(dataFromCache, add1);
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 82 with ValueMetaInteger

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

the class DatabaseLookupUTest method getCreatedData.

private DatabaseLookupData getCreatedData(boolean allEquals) throws Exception {
    Database db = mock(Database.class);
    when(db.getRows(anyString(), anyInt())).thenReturn(Collections.singletonList(new Object[] { 1L }));
    RowMeta returnRowMeta = new RowMeta();
    returnRowMeta.addValueMeta(new ValueMetaInteger());
    when(db.getReturnRowMeta()).thenReturn(returnRowMeta);
    DatabaseLookupMeta meta = createTestMeta();
    DatabaseLookupData data = new DatabaseLookupData();
    DatabaseLookup step = createSpiedStep(db, mockHelper, meta);
    step.init(meta, data);
    data.db = db;
    data.keytypes = new int[] { ValueMetaInterface.TYPE_INTEGER };
    if (allEquals) {
        data.allEquals = true;
        data.conditions = new int[] { DatabaseLookupMeta.CONDITION_EQ };
    } else {
        data.allEquals = false;
        data.conditions = new int[] { DatabaseLookupMeta.CONDITION_LT };
    }
    step.processRow(meta, data);
    return data;
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) Database(org.pentaho.di.core.database.Database) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger)

Example 83 with ValueMetaInteger

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

the class IndexTestBase method testFindsNothing.

void testFindsNothing(long value) {
    assertFalse(context.isEmpty());
    index.applyRestrictionsTo(context, new ValueMetaInteger(), value);
    assertTrue("Expected not to find anything matching " + value, context.isEmpty());
}
Also used : ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger)

Example 84 with ValueMetaInteger

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

the class IsNullIndexTest method testFindsCorrectly.

private void testFindsCorrectly(IsNullIndex index, boolean isLookingForNull) {
    final int expectedAmount = isLookingForNull ? amountOfNulls : 5 - amountOfNulls;
    assertFalse(context.isEmpty());
    // the index ignores lookup value - pass null there
    index.applyRestrictionsTo(context, new ValueMetaInteger(), null);
    if (expectedAmount == 0) {
        assertTrue(context.isEmpty());
        return;
    }
    assertFalse(String.format("Expected to find %d values", expectedAmount), context.isEmpty());
    BitSet actual = context.getCandidates();
    int cnt = expectedAmount;
    int lastSetBit = 0;
    while (cnt > 0) {
        lastSetBit = actual.nextSetBit(lastSetBit);
        if (lastSetBit < 0) {
            fail("Expected to find " + expectedAmount + " values, but got: " + actual.toString());
        }
        Long actualValue = rows[lastSetBit][0];
        if (isLookingForNull) {
            assertNull(actualValue);
        } else {
            assertEquals(Long.valueOf(1), actualValue);
        }
        lastSetBit++;
        cnt--;
    }
}
Also used : BitSet(java.util.BitSet) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger)

Example 85 with ValueMetaInteger

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

the class ReadAllCacheTest method lookup_DoesNotFind_WithBetweenOperator.

@Test
public void lookup_DoesNotFind_WithBetweenOperator() throws Exception {
    RowMeta meta = keysMeta.clone();
    meta.setValueMeta(3, new ValueMetaDate());
    meta.addValueMeta(new ValueMetaInteger());
    ReadAllCache cache = buildCache("<>,IS NOT NULL,BETWEEN,IS NULL");
    Object[] found = cache.getRowFromCache(meta, new Object[] { -1L, null, new Date(1000), new Date(2000), null });
    assertNull("(1000 <= keys[2] <= 2000) --> none", found);
}
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) Date(java.util.Date) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Test(org.junit.Test)

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