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);
}
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;
}
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());
}
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--;
}
}
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);
}
Aggregations