use of org.pentaho.di.core.row.value.ValueMetaNone in project pentaho-kettle by pentaho.
the class RowMetaAndData method addValue.
public void addValue(String valueName, int valueType, Object valueData) {
ValueMetaInterface v;
try {
v = ValueMetaFactory.createValueMeta(valueName, valueType);
} catch (KettlePluginException e) {
v = new ValueMetaNone(valueName);
}
addValue(v, valueData);
}
use of org.pentaho.di.core.row.value.ValueMetaNone in project pentaho-kettle by pentaho.
the class GroupBy method newAggregate.
/**
* used for junits in GroupByAggregationNullsTest
*
* @param r
*/
void newAggregate(Object[] r) {
// Put all the counters at 0
for (int i = 0; i < data.counts.length; i++) {
data.counts[i] = 0;
}
data.distinctObjs = null;
data.agg = new Object[data.subjectnrs.length];
// sets all doubles to 0.0
data.mean = new double[data.subjectnrs.length];
data.aggMeta = new RowMeta();
for (int i = 0; i < data.subjectnrs.length; i++) {
ValueMetaInterface subjMeta = data.inputRowMeta.getValueMeta(data.subjectnrs[i]);
Object v = null;
ValueMetaInterface vMeta = null;
int aggType = meta.getAggregateType()[i];
switch(aggType) {
case GroupByMeta.TYPE_GROUP_SUM:
case GroupByMeta.TYPE_GROUP_AVERAGE:
case GroupByMeta.TYPE_GROUP_CUMULATIVE_SUM:
case GroupByMeta.TYPE_GROUP_CUMULATIVE_AVERAGE:
if (subjMeta.isNumeric()) {
try {
vMeta = ValueMetaFactory.createValueMeta(meta.getAggregateField()[i], subjMeta.getType());
} catch (KettlePluginException e) {
vMeta = new ValueMetaNone(meta.getAggregateField()[i]);
}
} else {
vMeta = new ValueMetaNumber(meta.getAggregateField()[i]);
}
break;
case GroupByMeta.TYPE_GROUP_MEDIAN:
case GroupByMeta.TYPE_GROUP_PERCENTILE:
case GroupByMeta.TYPE_GROUP_PERCENTILE_NEAREST_RANK:
vMeta = new ValueMetaNumber(meta.getAggregateField()[i]);
v = new ArrayList<Double>();
break;
case GroupByMeta.TYPE_GROUP_STANDARD_DEVIATION:
case GroupByMeta.TYPE_GROUP_STANDARD_DEVIATION_SAMPLE:
vMeta = new ValueMetaNumber(meta.getAggregateField()[i]);
break;
case GroupByMeta.TYPE_GROUP_COUNT_DISTINCT:
case GroupByMeta.TYPE_GROUP_COUNT_ANY:
case GroupByMeta.TYPE_GROUP_COUNT_ALL:
vMeta = new ValueMetaInteger(meta.getAggregateField()[i]);
break;
case GroupByMeta.TYPE_GROUP_FIRST:
case GroupByMeta.TYPE_GROUP_LAST:
case GroupByMeta.TYPE_GROUP_FIRST_INCL_NULL:
case GroupByMeta.TYPE_GROUP_LAST_INCL_NULL:
case GroupByMeta.TYPE_GROUP_MIN:
case GroupByMeta.TYPE_GROUP_MAX:
vMeta = subjMeta.clone();
vMeta.setName(meta.getAggregateField()[i]);
v = r == null ? null : r[data.subjectnrs[i]];
break;
case GroupByMeta.TYPE_GROUP_CONCAT_COMMA:
vMeta = new ValueMetaString(meta.getAggregateField()[i]);
v = new StringBuilder();
break;
case GroupByMeta.TYPE_GROUP_CONCAT_STRING:
vMeta = new ValueMetaString(meta.getAggregateField()[i]);
v = new StringBuilder();
break;
default:
// TODO raise an error here because we cannot continue successfully maybe the UI should validate this
break;
}
if ((subjMeta != null) && (aggType != GroupByMeta.TYPE_GROUP_COUNT_ALL && aggType != GroupByMeta.TYPE_GROUP_COUNT_DISTINCT && aggType != GroupByMeta.TYPE_GROUP_COUNT_ANY)) {
vMeta.setLength(subjMeta.getLength(), subjMeta.getPrecision());
}
data.agg[i] = v;
data.aggMeta.addValueMeta(vMeta);
}
//
for (int i = 0; i < data.previousSums.length; i++) {
data.previousSums[i] = null;
}
for (int i = 0; i < data.previousAvgCount.length; i++) {
data.previousAvgCount[i] = 0L;
data.previousAvgSum[i] = null;
}
}
use of org.pentaho.di.core.row.value.ValueMetaNone in project pentaho-kettle by pentaho.
the class DatabaseJoinMeta method getTableFields.
@Override
public RowMetaInterface getTableFields() {
// Build a dummy parameter row...
//
RowMetaInterface param = new RowMeta();
for (int i = 0; i < parameterField.length; i++) {
ValueMetaInterface v;
try {
v = ValueMetaFactory.createValueMeta(parameterField[i], parameterType[i]);
} catch (KettlePluginException e) {
v = new ValueMetaNone(parameterField[i]);
}
param.addValueMeta(v);
}
RowMetaInterface fields = null;
if (databaseMeta != null) {
Database db = new Database(loggingObject, databaseMeta);
// Keep track of this one for cancelQuery
databases = new Database[] { db };
try {
db.connect();
fields = db.getQueryFields(databaseMeta.environmentSubstitute(sql), true, param, new Object[param.size()]);
} catch (KettleDatabaseException dbe) {
logError(BaseMessages.getString(PKG, "DatabaseJoinMeta.Log.DatabaseErrorOccurred") + dbe.getMessage());
} finally {
db.disconnect();
}
}
return fields;
}
use of org.pentaho.di.core.row.value.ValueMetaNone in project pentaho-kettle by pentaho.
the class YamlReader method getFields.
@SuppressWarnings({ "rawtypes", "unchecked" })
public RowMeta getFields() {
RowMeta rowMeta = new RowMeta();
Iterator<Object> ito = documents.iterator();
while (ito.hasNext()) {
Object data = ito.next();
if (data instanceof Map) {
// First check if we deals with a map
Map<Object, Object> map = (Map<Object, Object>) data;
Iterator it = map.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry) it.next();
String valueName = pairs.getKey().toString();
ValueMetaInterface valueMeta;
try {
valueMeta = ValueMetaFactory.createValueMeta(valueName, getType(pairs.getValue()));
} catch (KettlePluginException e) {
valueMeta = new ValueMetaNone(valueName);
}
rowMeta.addValueMeta(valueMeta);
}
} else if (data instanceof List) {
rowMeta = new RowMeta();
// Maybe we deals with List
List<Object> list = (List<Object>) data;
Iterator<Object> it = list.iterator();
Object value = it.next();
if (list.size() == 1) {
Map<Object, Object> map = (Map<Object, Object>) value;
Iterator its = map.entrySet().iterator();
while (its.hasNext()) {
Map.Entry pairs = (Map.Entry) its.next();
String valueName = pairs.getKey().toString();
ValueMetaInterface valueMeta;
try {
valueMeta = ValueMetaFactory.createValueMeta(valueName, getType(pairs.getValue()));
} catch (KettlePluginException e) {
valueMeta = new ValueMetaNone(valueName);
}
rowMeta.addValueMeta(valueMeta);
}
} else {
ValueMetaInterface valueMeta;
try {
valueMeta = ValueMetaFactory.createValueMeta(DEFAULT_LIST_VALUE_NAME, getType(value));
} catch (KettlePluginException e) {
valueMeta = new ValueMetaNone(DEFAULT_LIST_VALUE_NAME);
}
rowMeta.addValueMeta(valueMeta);
}
}
}
return rowMeta;
}
use of org.pentaho.di.core.row.value.ValueMetaNone in project pentaho-kettle by pentaho.
the class DatabaseMetaTest method testQuoteReservedWords.
@Test
public void testQuoteReservedWords() {
DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
doCallRealMethod().when(databaseMeta).quoteReservedWords(any(RowMetaInterface.class));
doCallRealMethod().when(databaseMeta).quoteField(anyString());
doCallRealMethod().when(databaseMeta).setDatabaseInterface(any(DatabaseInterface.class));
doReturn("\"").when(databaseMeta).getStartQuote();
doReturn("\"").when(databaseMeta).getEndQuote();
final DatabaseInterface databaseInterface = mock(DatabaseInterface.class);
doReturn(true).when(databaseInterface).isQuoteAllFields();
databaseMeta.setDatabaseInterface(databaseInterface);
final RowMeta fields = new RowMeta();
for (int i = 0; i < 10; i++) {
final ValueMetaInterface valueMeta = new ValueMetaNone("test_" + i);
fields.addValueMeta(valueMeta);
}
for (int i = 0; i < 10; i++) {
databaseMeta.quoteReservedWords(fields);
}
for (int i = 0; i < 10; i++) {
databaseMeta.quoteReservedWords(fields);
final String name = fields.getValueMeta(i).getName();
// check valueMeta index in list
assertTrue(name.contains("test_" + i));
// check valueMeta is found by quoted name
assertNotNull(fields.searchValueMeta(name));
}
}
Aggregations