use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.
the class JsonInputMeta method getFields.
@Override
public void getFields(RowMetaInterface rowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
if (inFields && removeSourceField && !Utils.isEmpty(valueField)) {
int index = rowMeta.indexOfValue(valueField);
if (index != -1) {
rowMeta.removeValueMeta(index);
}
}
for (JsonInputField field : getInputFields()) {
try {
rowMeta.addValueMeta(field.toValueMeta(name, space));
} catch (Exception e) {
throw new KettleStepException(e);
}
}
if (includeFilename) {
ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(filenameField));
v.setLength(250);
v.setPrecision(-1);
v.setOrigin(name);
rowMeta.addValueMeta(v);
}
if (includeRowNumber) {
ValueMetaInterface v = new ValueMetaInteger(space.environmentSubstitute(rowNumberField));
v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
v.setOrigin(name);
rowMeta.addValueMeta(v);
}
// Add additional fields
additionalOutputFields.normalize();
additionalOutputFields.getFields(rowMeta, name, info, space, repository, metaStore);
}
use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.
the class JsonInputTest method testBfsMatchOrder.
@Test
public void testBfsMatchOrder() throws Exception {
// streaming will be dfs..ref impl is bfs
String input = "{ \"a\": { \"a\" : { \"b\" :2 } , \"b\":1 } }";
JsonInput jsonInput = createBasicTestJsonInput("$..a.b", new ValueMetaInteger("b"), "in", new Object[] { input });
RowComparatorListener rowComparator = new RowComparatorListener(jsonInput, new Object[] { input, 1L }, new Object[] { input, 2L });
rowComparator.setComparator(0, null);
processRows(jsonInput, 2);
Assert.assertEquals(2, jsonInput.getLinesWritten());
}
use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.
the class JsonOutputTest method createResultRowMetaInterface.
/**
* Creates a row meta interface for the fields that are defined by performing a getFields and by checking "Result
* filenames - Add filenames to result from "Text File Input" dialog.
*
* @return
*/
public RowMetaInterface createResultRowMetaInterface() {
RowMetaInterface rowMetaInterface = new RowMeta();
ValueMetaInterface[] valuesMeta = { new ValueMetaInteger("Id"), new ValueMetaString("State"), new ValueMetaString("City") };
for (int i = 0; i < valuesMeta.length; i++) {
rowMetaInterface.addValueMeta(valuesMeta[i]);
}
return rowMetaInterface;
}
use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.
the class SelectValuesTest method testPDI16368.
@Test
public void testPDI16368() throws Exception {
// This tests that the fix for PDI-16388 doesn't get re-broken.
//
SelectValuesHandler step2 = null;
Object[] inputRow2 = null;
RowMeta inputRowMeta = null;
SelectValuesMeta stepMeta = null;
SelectValuesData stepData = null;
ValueMetaInterface vmi = null;
// First, test current behavior (it's worked this way since 5.x or so)
//
step2 = new SelectValuesHandler(helper.stepMeta, helper.stepDataInterface, 1, helper.transMeta, helper.trans);
step2 = spy(step2);
// Starting with a BigDecimal (no places)
inputRow2 = new Object[] { new BigDecimal("589") };
doReturn(inputRow2).when(step2).getRow();
doNothing().when(step2).putError(any(RowMetaInterface.class), any(Object[].class), anyLong(), anyString(), anyString(), anyString());
inputRowMeta = new RowMeta();
inputRowMeta.addValueMeta(new ValueMetaBigNumber(SELECTED_FIELD));
step2.setInputRowMeta(inputRowMeta);
stepMeta = new SelectValuesMeta();
stepMeta.allocate(1, 0, 1);
stepMeta.getSelectFields()[0] = new SelectField();
stepMeta.getSelectFields()[0].setName(SELECTED_FIELD);
stepMeta.getMeta()[0] = new SelectMetadataChange(stepMeta, SELECTED_FIELD, null, ValueMetaInterface.TYPE_INTEGER, -2, -2, ValueMetaInterface.STORAGE_TYPE_NORMAL, null, false, null, null, false, null, null, // no specified conversion type so should have default conversion mask.
null);
stepData = new SelectValuesData();
stepData.select = true;
stepData.metadata = true;
stepData.firstselect = true;
stepData.firstmetadata = true;
step2.processRow(stepMeta, stepData);
vmi = step2.rowMeta.getValueMeta(0);
assertEquals(ValueMetaBase.DEFAULT_BIG_NUMBER_FORMAT_MASK, vmi.getConversionMask());
step2 = new SelectValuesHandler(helper.stepMeta, helper.stepDataInterface, 1, helper.transMeta, helper.trans);
step2 = spy(step2);
doReturn(inputRow2).when(step2).getRow();
doNothing().when(step2).putError(any(RowMetaInterface.class), any(Object[].class), anyLong(), anyString(), anyString(), anyString());
inputRowMeta = new RowMeta();
inputRowMeta.addValueMeta(new ValueMetaBigNumber(SELECTED_FIELD));
step2.setInputRowMeta(inputRowMeta);
stepMeta = new SelectValuesMeta();
stepMeta.allocate(1, 0, 1);
stepMeta.getSelectFields()[0] = new SelectField();
stepMeta.getSelectFields()[0].setName(SELECTED_FIELD);
stepMeta.getMeta()[0] = new SelectMetadataChange(stepMeta, SELECTED_FIELD, null, ValueMetaInterface.TYPE_NUMBER, -2, -2, ValueMetaInterface.STORAGE_TYPE_NORMAL, null, false, null, null, false, null, null, // no specified conversion type so should have default conversion mask for Double.
null);
stepData = new SelectValuesData();
stepData.select = true;
stepData.metadata = true;
stepData.firstselect = true;
stepData.firstmetadata = true;
step2.processRow(stepMeta, stepData);
vmi = step2.rowMeta.getValueMeta(0);
assertEquals(ValueMetaBase.DEFAULT_BIG_NUMBER_FORMAT_MASK, vmi.getConversionMask());
step2 = new SelectValuesHandler(helper.stepMeta, helper.stepDataInterface, 1, helper.transMeta, helper.trans);
step2 = spy(step2);
// Starting with a Long
inputRow2 = new Object[] { new Long("589") };
doReturn(inputRow2).when(step2).getRow();
doNothing().when(step2).putError(any(RowMetaInterface.class), any(Object[].class), anyLong(), anyString(), anyString(), anyString());
inputRowMeta = new RowMeta();
inputRowMeta.addValueMeta(new ValueMetaInteger(SELECTED_FIELD));
step2.setInputRowMeta(inputRowMeta);
stepMeta = new SelectValuesMeta();
stepMeta.allocate(1, 0, 1);
stepMeta.getSelectFields()[0] = new SelectField();
stepMeta.getSelectFields()[0].setName(SELECTED_FIELD);
// no specified conversion type so should have default conversion mask for BigNumber
stepMeta.getMeta()[0] = new SelectMetadataChange(stepMeta, SELECTED_FIELD, null, ValueMetaInterface.TYPE_BIGNUMBER, -2, -2, ValueMetaInterface.STORAGE_TYPE_NORMAL, null, false, null, null, false, null, null, null);
stepData = new SelectValuesData();
stepData.select = true;
stepData.metadata = true;
stepData.firstselect = true;
stepData.firstmetadata = true;
step2.processRow(stepMeta, stepData);
vmi = step2.rowMeta.getValueMeta(0);
assertEquals(ValueMetaBase.DEFAULT_INTEGER_FORMAT_MASK, vmi.getConversionMask());
// Now, test that setting the variable results in getting the default conversion mask
step2 = new SelectValuesHandler(helper.stepMeta, helper.stepDataInterface, 1, helper.transMeta, helper.trans);
step2.setVariable(Const.KETTLE_COMPATIBILITY_SELECT_VALUES_TYPE_CHANGE_USES_TYPE_DEFAULTS, "Y");
step2 = spy(step2);
// Starting with a BigDecimal (no places)
inputRow2 = new Object[] { new BigDecimal("589") };
doReturn(inputRow2).when(step2).getRow();
doNothing().when(step2).putError(any(RowMetaInterface.class), any(Object[].class), anyLong(), anyString(), anyString(), anyString());
inputRowMeta = new RowMeta();
inputRowMeta.addValueMeta(new ValueMetaBigNumber(SELECTED_FIELD));
step2.setInputRowMeta(inputRowMeta);
stepMeta = new SelectValuesMeta();
stepMeta.allocate(1, 0, 1);
stepMeta.getSelectFields()[0] = new SelectField();
stepMeta.getSelectFields()[0].setName(SELECTED_FIELD);
stepMeta.getMeta()[0] = new SelectMetadataChange(stepMeta, SELECTED_FIELD, null, ValueMetaInterface.TYPE_INTEGER, -2, -2, ValueMetaInterface.STORAGE_TYPE_NORMAL, null, false, null, null, false, null, null, // no specified conversion type so should have default conversion mask.
null);
stepData = new SelectValuesData();
stepData.select = true;
stepData.metadata = true;
stepData.firstselect = true;
stepData.firstmetadata = true;
step2.processRow(stepMeta, stepData);
vmi = step2.rowMeta.getValueMeta(0);
assertEquals(ValueMetaBase.DEFAULT_INTEGER_FORMAT_MASK, vmi.getConversionMask());
step2 = new SelectValuesHandler(helper.stepMeta, helper.stepDataInterface, 1, helper.transMeta, helper.trans);
step2.setVariable(Const.KETTLE_COMPATIBILITY_SELECT_VALUES_TYPE_CHANGE_USES_TYPE_DEFAULTS, "Y");
step2 = spy(step2);
doReturn(inputRow2).when(step2).getRow();
doNothing().when(step2).putError(any(RowMetaInterface.class), any(Object[].class), anyLong(), anyString(), anyString(), anyString());
inputRowMeta = new RowMeta();
inputRowMeta.addValueMeta(new ValueMetaBigNumber(SELECTED_FIELD));
step2.setInputRowMeta(inputRowMeta);
stepMeta = new SelectValuesMeta();
stepMeta.allocate(1, 0, 1);
stepMeta.getSelectFields()[0] = new SelectField();
stepMeta.getSelectFields()[0].setName(SELECTED_FIELD);
stepMeta.getMeta()[0] = new SelectMetadataChange(stepMeta, SELECTED_FIELD, null, ValueMetaInterface.TYPE_NUMBER, -2, -2, ValueMetaInterface.STORAGE_TYPE_NORMAL, null, false, null, null, false, null, null, // no specified conversion type so should have default conversion mask for Double.
null);
stepData = new SelectValuesData();
stepData.select = true;
stepData.metadata = true;
stepData.firstselect = true;
stepData.firstmetadata = true;
step2.processRow(stepMeta, stepData);
vmi = step2.rowMeta.getValueMeta(0);
assertEquals(ValueMetaBase.DEFAULT_NUMBER_FORMAT_MASK, vmi.getConversionMask());
step2 = new SelectValuesHandler(helper.stepMeta, helper.stepDataInterface, 1, helper.transMeta, helper.trans);
step2.setVariable(Const.KETTLE_COMPATIBILITY_SELECT_VALUES_TYPE_CHANGE_USES_TYPE_DEFAULTS, "Y");
step2 = spy(step2);
// Starting with a Long
inputRow2 = new Object[] { new Long("589") };
doReturn(inputRow2).when(step2).getRow();
doNothing().when(step2).putError(any(RowMetaInterface.class), any(Object[].class), anyLong(), anyString(), anyString(), anyString());
inputRowMeta = new RowMeta();
inputRowMeta.addValueMeta(new ValueMetaInteger(SELECTED_FIELD));
step2.setInputRowMeta(inputRowMeta);
stepMeta = new SelectValuesMeta();
stepMeta.allocate(1, 0, 1);
stepMeta.getSelectFields()[0] = new SelectField();
stepMeta.getSelectFields()[0].setName(SELECTED_FIELD);
// no specified conversion type so should have default conversion mask for BigNumber
stepMeta.getMeta()[0] = new SelectMetadataChange(stepMeta, SELECTED_FIELD, null, ValueMetaInterface.TYPE_BIGNUMBER, -2, -2, ValueMetaInterface.STORAGE_TYPE_NORMAL, null, false, null, null, false, null, null, null);
stepData = new SelectValuesData();
stepData.select = true;
stepData.metadata = true;
stepData.firstselect = true;
stepData.firstmetadata = true;
step2.processRow(stepMeta, stepData);
vmi = step2.rowMeta.getValueMeta(0);
assertEquals(ValueMetaBase.DEFAULT_BIG_NUMBER_FORMAT_MASK, vmi.getConversionMask());
}
use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.
the class MappingInputFieldsTest method testOnlySpecifiedFields.
/*
* verifies: If SelectingAndSortingUnspecifiedFields checkbox is not checked, then 1)all fields throw to the next step;
* 2)fields are not resorted;
*/
@Test
public void testOnlySpecifiedFields() throws Exception {
meta.setSelectingAndSortingUnspecifiedFields(false);
MappingInputData sdi = new MappingInputData();
sdi.linked = true;
sdi.valueRenames = new ArrayList<MappingValueRename>();
sdi.valueRenames.add(new MappingValueRename("number2", "n2"));
sdi.valueRenames.add(new MappingValueRename("number4", "n4"));
BlockingRowSet in = new BlockingRowSet(10);
BlockingRowSet out = new BlockingRowSet(10);
RowMeta rm = new RowMeta();
rm.addValueMeta(new ValueMetaString("string"));
rm.addValueMeta(new ValueMetaInteger("number1"));
rm.addValueMeta(new ValueMetaInteger("number2"));
rm.addValueMeta(new ValueMetaInteger("number3"));
rm.addValueMeta(new ValueMetaInteger("number"));
rm.addValueMeta(new ValueMetaInteger("number4"));
rm.addValueMeta(new ValueMetaInteger("number5"));
in.putRow(rm, new Object[] { "str", new Integer(100501), new Integer(100502), new Integer(100503), new Integer(100500), new Integer(100504), new Integer(100505) });
in.putRow(rm, new Object[] { "str_1", new Integer(200501), new Integer(200502), new Integer(200503), new Integer(200500), new Integer(200504), new Integer(200505) });
step.addRowSetToInputRowSets(in);
step.addRowSetToOutputRowSets(out);
assertTrue(step.init(meta, sdi));
assertTrue(step.processRow(meta, sdi));
Object[] outRowData = out.getRow();
RowMetaInterface outMeta = out.getRowMeta();
assertEquals("All fields are expected.", 7, outMeta.size());
int i = 0;
// Check if row-meta is formed according to the step specification
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_STRING, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "string", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "number1", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "n2", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "number3", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "number", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "n4", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "number5", outMeta.getValueMeta(i++).getName());
// Check if row-data corresponds to the row-meta
assertEquals("the field value mismatch.", "str", outRowData[0]);
assertEquals("the field value mismatch.", new Integer(100501), outRowData[1]);
assertEquals("the field value mismatch.", new Integer(100502), outRowData[2]);
assertEquals("the field value mismatch.", new Integer(100503), outRowData[3]);
assertEquals("the field value mismatch.", new Integer(100500), outRowData[4]);
assertEquals("the field value mismatch.", new Integer(100504), outRowData[5]);
assertEquals("the field value mismatch.", new Integer(100505), outRowData[6]);
assertTrue(step.processRow(meta, sdi));
outRowData = out.getRow();
outMeta = out.getRowMeta();
assertEquals("All fields are expected.", 7, outMeta.size());
i = 0;
// Check if row-meta is formed according to the step specification
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_STRING, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "string", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "number1", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "n2", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "number3", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "number", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "n4", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "number5", outMeta.getValueMeta(i++).getName());
// Check if row-data corresponds to the row-meta
assertEquals("the field value mismatch.", "str_1", outRowData[0]);
assertEquals("the field value mismatch.", new Integer(200501), outRowData[1]);
assertEquals("the field value mismatch.", new Integer(200502), outRowData[2]);
assertEquals("the field value mismatch.", new Integer(200503), outRowData[3]);
assertEquals("the field value mismatch.", new Integer(200500), outRowData[4]);
assertEquals("the field value mismatch.", new Integer(200504), outRowData[5]);
assertEquals("the field value mismatch.", new Integer(200505), outRowData[6]);
}
Aggregations