Search in sources :

Example 1 with ValueMetaNone

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);
}
Also used : KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 2 with ValueMetaNone

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;
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) FileObject(org.apache.commons.vfs2.FileObject) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 3 with ValueMetaNone

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;
}
Also used : KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) RowMeta(org.pentaho.di.core.row.RowMeta) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) Database(org.pentaho.di.core.database.Database) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 4 with ValueMetaNone

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;
}
Also used : KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) Iterator(java.util.Iterator) FileObject(org.apache.commons.vfs2.FileObject) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 5 with ValueMetaNone

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));
    }
}
Also used : ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Matchers.anyString(org.mockito.Matchers.anyString) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Aggregations

ValueMetaNone (org.pentaho.di.core.row.value.ValueMetaNone)18 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)17 RowMeta (org.pentaho.di.core.row.RowMeta)12 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)10 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)10 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)8 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)6 KettleException (org.pentaho.di.core.exception.KettleException)5 ArrayList (java.util.ArrayList)4 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)4 FileObject (org.apache.commons.vfs2.FileObject)3 TableItem (org.eclipse.swt.widgets.TableItem)3 SourceToTargetMapping (org.pentaho.di.core.SourceToTargetMapping)3 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)3 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)3 EnterMappingDialog (org.pentaho.di.ui.core.dialog.EnterMappingDialog)3 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)3 List (java.util.List)2 Map (java.util.Map)2 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)2