Search in sources :

Example 56 with ValueMetaInterface

use of org.pentaho.di.core.row.ValueMetaInterface 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);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 57 with ValueMetaInterface

use of org.pentaho.di.core.row.ValueMetaInterface in project pentaho-kettle by pentaho.

the class GPBulkDataOutput method writeLine.

public void writeLine(RowMetaInterface mi, Object[] row) throws KettleException {
    if (first) {
        first = false;
        enclosure = meta.getEnclosure();
        // Setup up the fields we need to take for each of the rows
        // as this speeds up processing.
        fieldNumbers = new int[meta.getFieldStream().length];
        for (int i = 0; i < fieldNumbers.length; i++) {
            fieldNumbers[i] = mi.indexOfValue(meta.getFieldStream()[i]);
            if (fieldNumbers[i] < 0) {
                throw new KettleException("Could not find field " + meta.getFieldStream()[i] + " in stream");
            }
        }
        sdfDate = new SimpleDateFormat("yyyy-MM-dd");
        sdfDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    }
    // Write the data to the output
    ValueMetaInterface v = null;
    int number = 0;
    for (int i = 0; i < fieldNumbers.length; i++) {
        if (i != 0) {
            output.print(",");
        }
        number = fieldNumbers[i];
        v = mi.getValueMeta(number);
        if (row[number] == null) {
            // TODO (SB): special check for null in case of Strings.
            output.print(enclosure);
            output.print(enclosure);
        } else {
            switch(v.getType()) {
                case ValueMetaInterface.TYPE_STRING:
                    String s = mi.getString(row, number);
                    if (s.indexOf(enclosure) >= 0) {
                        s = createEscapedString(s, enclosure);
                    }
                    output.print(enclosure);
                    output.print(s);
                    output.print(enclosure);
                    break;
                case ValueMetaInterface.TYPE_INTEGER:
                    Long l = mi.getInteger(row, number);
                    output.print(enclosure);
                    output.print(l);
                    output.print(enclosure);
                    break;
                case ValueMetaInterface.TYPE_NUMBER:
                    Double d = mi.getNumber(row, number);
                    output.print(enclosure);
                    output.print(d);
                    output.print(enclosure);
                    break;
                case ValueMetaInterface.TYPE_BIGNUMBER:
                    BigDecimal bd = mi.getBigNumber(row, number);
                    output.print(enclosure);
                    output.print(bd);
                    output.print(enclosure);
                    break;
                case ValueMetaInterface.TYPE_DATE:
                    Date dt = mi.getDate(row, number);
                    output.print(enclosure);
                    String mask = meta.getDateMask()[i];
                    if (GPBulkLoaderMeta.DATE_MASK_DATETIME.equals(mask)) {
                        output.print(sdfDateTime.format(dt));
                    } else {
                        // Default is date format
                        output.print(sdfDate.format(dt));
                    }
                    output.print(enclosure);
                    break;
                case ValueMetaInterface.TYPE_BOOLEAN:
                    Boolean b = mi.getBoolean(row, number);
                    output.print(enclosure);
                    if (b.booleanValue()) {
                        output.print("Y");
                    } else {
                        output.print("N");
                    }
                    output.print(enclosure);
                    break;
                case ValueMetaInterface.TYPE_BINARY:
                    byte[] byt = mi.getBinary(row, number);
                    output.print("<startlob>");
                    output.print(byt);
                    output.print("<endlob>");
                    break;
                default:
                    throw new KettleException("Unsupported type");
            }
        }
    }
    output.print(Const.CR);
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) SimpleDateFormat(java.text.SimpleDateFormat) BigDecimal(java.math.BigDecimal) Date(java.util.Date) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 58 with ValueMetaInterface

use of org.pentaho.di.core.row.ValueMetaInterface in project pentaho-kettle by pentaho.

the class HL7InputMeta method getFields.

@Override
public void getFields(RowMetaInterface rowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    ValueMetaInterface valueMeta = new ValueMetaString("ParentGroup");
    valueMeta.setOrigin(origin);
    rowMeta.addValueMeta(valueMeta);
    valueMeta = new ValueMetaString("Group");
    valueMeta.setOrigin(origin);
    rowMeta.addValueMeta(valueMeta);
    valueMeta = new ValueMetaString("HL7Version");
    valueMeta.setOrigin(origin);
    rowMeta.addValueMeta(valueMeta);
    valueMeta = new ValueMetaString("StructureName");
    valueMeta.setOrigin(origin);
    rowMeta.addValueMeta(valueMeta);
    valueMeta = new ValueMetaString("StructureNumber");
    valueMeta.setOrigin(origin);
    rowMeta.addValueMeta(valueMeta);
    valueMeta = new ValueMetaString("FieldName");
    valueMeta.setOrigin(origin);
    rowMeta.addValueMeta(valueMeta);
    valueMeta = new ValueMetaString("Coordinates");
    valueMeta.setOrigin(origin);
    rowMeta.addValueMeta(valueMeta);
    valueMeta = new ValueMetaString("HL7DataType");
    valueMeta.setOrigin(origin);
    rowMeta.addValueMeta(valueMeta);
    valueMeta = new ValueMetaString("FieldDescription");
    valueMeta.setOrigin(origin);
    rowMeta.addValueMeta(valueMeta);
    valueMeta = new ValueMetaString("Value");
    valueMeta.setOrigin(origin);
    rowMeta.addValueMeta(valueMeta);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 59 with ValueMetaInterface

use of org.pentaho.di.core.row.ValueMetaInterface in project pentaho-kettle by pentaho.

the class GPBulkLoaderMeta method getSQLStatements.

@Override
public SQLStatement getSQLStatements(TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, Repository repository, IMetaStore metaStore) throws KettleStepException {
    // default: nothing to do!
    SQLStatement retval = new SQLStatement(stepMeta.getName(), databaseMeta, null);
    if (databaseMeta != null) {
        if (prev != null && prev.size() > 0) {
            // Copy the row
            RowMetaInterface tableFields = new RowMeta();
            // Now change the field names
            for (int i = 0; i < fieldTable.length; i++) {
                ValueMetaInterface v = prev.searchValueMeta(fieldStream[i]);
                if (v != null) {
                    ValueMetaInterface tableField = v.clone();
                    tableField.setName(fieldTable[i]);
                    tableFields.addValueMeta(tableField);
                } else {
                    throw new KettleStepException("Unable to find field [" + fieldStream[i] + "] in the input rows");
                }
            }
            if (!Utils.isEmpty(tableName)) {
                Database db = new Database(loggingObject, databaseMeta);
                db.shareVariablesWith(transMeta);
                try {
                    db.connect();
                    String schemaTable = databaseMeta.getQuotedSchemaTableCombination(transMeta.environmentSubstitute(schemaName), transMeta.environmentSubstitute(tableName));
                    String sql = db.getDDL(schemaTable, tableFields, null, false, null, true);
                    if (sql.length() == 0) {
                        retval.setSQL(null);
                    } else {
                        retval.setSQL(sql);
                    }
                } catch (KettleException e) {
                    retval.setError(BaseMessages.getString(PKG, "GPBulkLoaderMeta.GetSQL.ErrorOccurred") + e.getMessage());
                }
            } else {
                retval.setError(BaseMessages.getString(PKG, "GPBulkLoaderMeta.GetSQL.NoTableDefinedOnConnection"));
            }
        } else {
            retval.setError(BaseMessages.getString(PKG, "GPBulkLoaderMeta.GetSQL.NotReceivingAnyFields"));
        }
    } else {
        retval.setError(BaseMessages.getString(PKG, "GPBulkLoaderMeta.GetSQL.NoConnectionDefined"));
    }
    return retval;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) Database(org.pentaho.di.core.database.Database) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) SQLStatement(org.pentaho.di.core.SQLStatement) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 60 with ValueMetaInterface

use of org.pentaho.di.core.row.ValueMetaInterface in project pentaho-kettle by pentaho.

the class GPLoadMeta method getSQLStatements.

public SQLStatement getSQLStatements(TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, Repository repository, IMetaStore metaStore) throws KettleStepException {
    // default: nothing to do!
    SQLStatement retval = new SQLStatement(stepMeta.getName(), databaseMeta, null);
    if (databaseMeta != null) {
        if (prev != null && prev.size() > 0) {
            // Copy the row
            RowMetaInterface tableFields = new RowMeta();
            // Now change the field names
            for (int i = 0; i < fieldTable.length; i++) {
                ValueMetaInterface v = prev.searchValueMeta(fieldStream[i]);
                if (v != null) {
                    ValueMetaInterface tableField = v.clone();
                    tableField.setName(fieldTable[i]);
                    tableFields.addValueMeta(tableField);
                } else {
                    throw new KettleStepException("Unable to find field [" + fieldStream[i] + "] in the input rows");
                }
            }
            if (!Utils.isEmpty(tableName)) {
                Database db = new Database(loggingObject, databaseMeta);
                db.shareVariablesWith(transMeta);
                try {
                    db.connect();
                    String schemaTable = databaseMeta.getQuotedSchemaTableCombination(transMeta.environmentSubstitute(schemaName), transMeta.environmentSubstitute(tableName));
                    String sql = db.getDDL(schemaTable, tableFields, null, false, null, true);
                    if (sql.length() == 0) {
                        retval.setSQL(null);
                    } else {
                        retval.setSQL(sql);
                    }
                } catch (KettleException e) {
                    retval.setError(BaseMessages.getString(PKG, "GPLoadMeta.GetSQL.ErrorOccurred") + e.getMessage());
                }
            } else {
                retval.setError(BaseMessages.getString(PKG, "GPLoadMeta.GetSQL.NoTableDefinedOnConnection"));
            }
        } else {
            retval.setError(BaseMessages.getString(PKG, "GPLoadMeta.GetSQL.NotReceivingAnyFields"));
        }
    } else {
        retval.setError(BaseMessages.getString(PKG, "GPLoadMeta.GetSQL.NoConnectionDefined"));
    }
    return retval;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) Database(org.pentaho.di.core.database.Database) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) SQLStatement(org.pentaho.di.core.SQLStatement) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)908 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)345 KettleException (org.pentaho.di.core.exception.KettleException)269 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)243 RowMeta (org.pentaho.di.core.row.RowMeta)232 Test (org.junit.Test)212 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)146 KettleStepException (org.pentaho.di.core.exception.KettleStepException)120 ArrayList (java.util.ArrayList)111 TableItem (org.eclipse.swt.widgets.TableItem)78 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)76 KettleValueException (org.pentaho.di.core.exception.KettleValueException)58 FileObject (org.apache.commons.vfs2.FileObject)55 Date (java.util.Date)49 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)48 StepMeta (org.pentaho.di.trans.step.StepMeta)47 Database (org.pentaho.di.core.database.Database)46 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)46 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)44 TableItemInsertListener (org.pentaho.di.ui.trans.step.TableItemInsertListener)43