use of org.pentaho.di.core.row.value.ValueMetaNumber in project pentaho-kettle by pentaho.
the class Formula2IT method testIsText_EmptyStringIsNotNull.
@Test
public void testIsText_EmptyStringIsNotNull() throws KettleException {
FieldAccessorUtl.ensureEmptyStringIsNotNull(true);
final String fIsText = "ISTEXT([" + KEY_ARG + "])";
assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaString(KEY_ARG)), new Object[] { "1" }, true);
assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaString(KEY_ARG)), new Object[] { "a" }, true);
assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaString(KEY_ARG)), new Object[] { null }, false);
assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaString(KEY_ARG)), new Object[] { "" }, true);
assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaString(KEY_ARG)), new Object[] { " " }, true);
assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaNumber(KEY_ARG)), new Object[] { 1 }, false);
assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaNumber(KEY_ARG)), new Object[] { 0 }, false);
assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaNumber(KEY_ARG)), new Object[] { -1.0 }, false);
assertBooleanFormula(fIsText, buildRowMeta(new ValueMetaNumber(KEY_ARG)), new Object[] { null }, false);
}
use of org.pentaho.di.core.row.value.ValueMetaNumber in project pentaho-kettle by pentaho.
the class UnivariateStatsMeta method getValueMetas.
/**
* Returns an array of ValueMetaInterface that contains the meta data for each value computed by the supplied
* UnivariateStatsMetaFunction
*
* @param fn
* the <code>UnivariateStatsMetaFunction</code> to construct meta data for
* @param origin
* the origin
* @return an array of meta data
*/
private ValueMetaInterface[] getValueMetas(UnivariateStatsMetaFunction fn, String origin) {
ValueMetaInterface[] v = new ValueMetaInterface[fn.numberOfMetricsRequested()];
int index = 0;
if (fn.getCalcN()) {
v[index] = new ValueMetaNumber(fn.getSourceFieldName() + "(N)");
v[index].setOrigin(origin);
index++;
}
if (fn.getCalcMean()) {
v[index] = new ValueMetaNumber(fn.getSourceFieldName() + "(mean)");
v[index].setOrigin(origin);
index++;
}
if (fn.getCalcStdDev()) {
v[index] = new ValueMetaNumber(fn.getSourceFieldName() + "(stdDev)");
v[index].setOrigin(origin);
index++;
}
if (fn.getCalcMin()) {
v[index] = new ValueMetaNumber(fn.getSourceFieldName() + "(min)");
v[index].setOrigin(origin);
index++;
}
if (fn.getCalcMax()) {
v[index] = new ValueMetaNumber(fn.getSourceFieldName() + "(max)");
v[index].setOrigin(origin);
index++;
}
if (fn.getCalcMedian()) {
v[index] = new ValueMetaNumber(fn.getSourceFieldName() + "(median)");
v[index].setOrigin(origin);
index++;
}
if (fn.getCalcPercentile() >= 0) {
double percent = fn.getCalcPercentile();
// NumberFormat pF = NumberFormat.getPercentInstance();
NumberFormat pF = NumberFormat.getInstance();
pF.setMaximumFractionDigits(2);
String res = pF.format(percent * 100);
v[index] = new ValueMetaNumber(fn.getSourceFieldName() + "(" + res + "th percentile)");
v[index].setOrigin(origin);
index++;
}
return v;
}
use of org.pentaho.di.core.row.value.ValueMetaNumber in project pdi-dataservice-server-plugin by pentaho.
the class SqlTransGeneratorTest method testTypeHandlingWithAvg.
@Test
public void testTypeHandlingWithAvg() throws KettleException {
SQL sql = new SQL("SELECT avg( intVal ), avg( numericVal ), avg( bigNumber) FROM table");
RowMetaInterface rowMeta = new RowMeta();
rowMeta.addValueMeta(new ValueMetaInteger("intVal"));
rowMeta.addValueMeta(new ValueMetaNumber("numericVal"));
rowMeta.addValueMeta(new ValueMetaBigNumber("bigNumber"));
sql.parse(rowMeta);
SqlTransGenerator generator = new SqlTransGenerator(sql, 0);
SelectValuesMeta meta = (SelectValuesMeta) getStepByName(generator.generateTransMeta(), "Set Conversion");
assertThat(meta.getMeta().length, is(3));
// Integer should be converted to TYPE_NUMBER
assertThat(meta.getMeta()[0].getType(), is(TYPE_NUMBER));
// Other types should be left alone ( SelectMetadataChange.getType remains TYPE_NONE )
assertThat(meta.getMeta()[1].getType(), is(TYPE_NONE));
assertThat(meta.getMeta()[2].getType(), is(TYPE_NONE));
}
use of org.pentaho.di.core.row.value.ValueMetaNumber in project pentaho-cassandra-plugin by pentaho.
the class DriverCQLRowHandlerTest method testExpandCollection.
@Test
public void testExpandCollection() throws Exception {
List<Object[]> rowList = new ArrayList<Object[]>();
ArrayList<Long> numList = new ArrayList<Long>();
numList.add(1L);
numList.add(2L);
numList.add(3L);
rowList.add(new Object[] { 1L, numList });
rowList.add(new Object[] { 2L, new ArrayList<Long>() });
Iterator<Object[]> it = rowList.iterator();
DriverKeyspace keyspace = mock(DriverKeyspace.class);
Session session = mock(Session.class);
ResultSet rs = mock(ResultSet.class);
when(session.execute(anyString())).thenReturn(rs);
when(rs.isExhausted()).then(invoc -> {
return !it.hasNext();
});
when(rs.one()).then(invocation -> {
Object[] rowArr = it.next();
Row row = mock(Row.class);
when(row.getObject(anyInt())).then(invoc -> {
return rowArr[(int) invoc.getArguments()[0]];
});
when(row.getLong(0)).thenReturn((long) rowArr[0]);
return row;
});
mockColumnDefinitions(rs, DataType.bigint(), DataType.list(DataType.bigint()));
DriverCQLRowHandler rowHandler = new DriverCQLRowHandler(keyspace, session, true);
RowMetaInterface rowMeta = new RowMeta();
rowMeta.addValueMeta(new ValueMetaInteger("id"));
rowMeta.addValueMeta(new ValueMetaNumber("nums"));
rowHandler.newRowQuery(mock(StepInterface.class), "tab", "select * from tab", null, null, mock(LogChannelInterface.class));
List<Object[]> resultRows = getNextOutputRows(rowHandler, rowMeta);
assertEquals(4, resultRows.size());
assertEquals(1L, resultRows.get(0)[1]);
assertEquals(2L, resultRows.get(3)[0]);
assertNull(resultRows.get(3)[1]);
}
use of org.pentaho.di.core.row.value.ValueMetaNumber in project pentaho-kettle by pentaho.
the class XBase method getFields.
@SuppressWarnings("fallthrough")
public RowMetaInterface getFields() throws KettleException {
String debug = "get fields from XBase file";
RowMetaInterface row = new RowMeta();
try {
// Fetch all field information
//
debug = "allocate data types";
datatype = new byte[reader.getFieldCount()];
for (int i = 0; i < reader.getFieldCount(); i++) {
if (log.isDebug()) {
debug = "get field #" + i;
}
DBFField field = reader.getField(i);
ValueMetaInterface value = null;
datatype[i] = field.getDataType();
switch(datatype[i]) {
case // Memo
DBFField.FIELD_TYPE_M:
debug = "memo field";
if ((log != null) && log.isDebug()) {
log.logDebug("Field #" + i + " is a memo-field! (" + field.getName() + ")");
}
case // Character
DBFField.FIELD_TYPE_C:
// case DBFField.FIELD_TYPE_P: // Picture
debug = "character field";
value = new ValueMetaString(field.getName());
value.setLength(field.getFieldLength());
break;
// Integer
case FIELD_TYPE_I:
// Numeric
case DBFField.FIELD_TYPE_N:
case // Float
DBFField.FIELD_TYPE_F:
debug = "Number field";
value = new ValueMetaNumber(field.getName());
value.setLength(field.getFieldLength(), field.getDecimalCount());
break;
case // Logical
DBFField.FIELD_TYPE_L:
debug = "Logical field";
value = new ValueMetaBoolean(field.getName());
value.setLength(-1, -1);
break;
case // Date
DBFField.FIELD_TYPE_D:
debug = "Date field";
value = new ValueMetaDate(field.getName());
value.setLength(-1, -1);
break;
default:
if ((log != null) && (log.isDebug())) {
log.logDebug("Unknown Datatype" + datatype[i]);
}
}
if (value != null) {
row.addValueMeta(value);
}
}
} catch (Exception e) {
throw new KettleException("Error reading DBF metadata (in part " + debug + ")", e);
}
return row;
}
Aggregations