Search in sources :

Example 46 with ValueMetaBoolean

use of org.pentaho.di.core.row.value.ValueMetaBoolean 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;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) KettleException(org.pentaho.di.core.exception.KettleException) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) DBFField(com.linuxense.javadbf.DBFField) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) DBFException(com.linuxense.javadbf.DBFException) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 47 with ValueMetaBoolean

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

the class UpdateMeta 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 = RowMetaUtils.getRowMetaForUpdate(prev, keyLookup, keyStream, updateLookup, updateStream);
            if (!Utils.isEmpty(tableName)) {
                String schemaTable = databaseMeta.getQuotedSchemaTableCombination(schemaName, tableName);
                Database db = new Database(loggingObject, databaseMeta);
                db.shareVariablesWith(transMeta);
                try {
                    db.connect();
                    if (getIgnoreFlagField() != null && getIgnoreFlagField().length() > 0) {
                        prev.addValueMeta(new ValueMetaBoolean(getIgnoreFlagField()));
                    }
                    String cr_table = db.getDDL(schemaTable, tableFields, null, false, null, true);
                    String cr_index = "";
                    String[] idx_fields = null;
                    if (keyLookup != null && keyLookup.length > 0) {
                        idx_fields = new String[keyLookup.length];
                        for (int i = 0; i < keyLookup.length; i++) {
                            idx_fields[i] = keyLookup[i];
                        }
                    } else {
                        retval.setError(BaseMessages.getString(PKG, "UpdateMeta.CheckResult.MissingKeyFields"));
                    }
                    // Key lookup dimensions...
                    if (idx_fields != null && idx_fields.length > 0 && !db.checkIndexExists(schemaTable, idx_fields)) {
                        String indexname = "idx_" + tableName + "_lookup";
                        cr_index = db.getCreateIndexStatement(schemaTable, indexname, idx_fields, false, false, false, true);
                    }
                    String sql = cr_table + cr_index;
                    if (sql.length() == 0) {
                        retval.setSQL(null);
                    } else {
                        retval.setSQL(sql);
                    }
                } catch (KettleException e) {
                    retval.setError(BaseMessages.getString(PKG, "UpdateMeta.ReturnValue.ErrorOccurred") + e.getMessage());
                }
            } else {
                retval.setError(BaseMessages.getString(PKG, "UpdateMeta.ReturnValue.NoTableDefinedOnConnection"));
            }
        } else {
            retval.setError(BaseMessages.getString(PKG, "UpdateMeta.ReturnValue.NotReceivingAnyFields"));
        }
    } else {
        retval.setError(BaseMessages.getString(PKG, "UpdateMeta.ReturnValue.NoConnectionDefined"));
    }
    return retval;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) Database(org.pentaho.di.core.database.Database) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) SQLStatement(org.pentaho.di.core.SQLStatement)

Example 48 with ValueMetaBoolean

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

the class MailInputMeta method getFields.

@Override
public void getFields(RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    int i;
    for (i = 0; i < inputFields.length; i++) {
        MailInputField field = inputFields[i];
        ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(field.getName()));
        switch(field.getColumn()) {
            case MailInputField.COLUMN_MESSAGE_NR:
            case MailInputField.COLUMN_SIZE:
            case MailInputField.COLUMN_ATTACHED_FILES_COUNT:
                v = new ValueMetaInteger(space.environmentSubstitute(field.getName()));
                v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
                break;
            case MailInputField.COLUMN_RECEIVED_DATE:
            case MailInputField.COLUMN_SENT_DATE:
                v = new ValueMetaDate(space.environmentSubstitute(field.getName()));
                break;
            case MailInputField.COLUMN_FLAG_DELETED:
            case MailInputField.COLUMN_FLAG_DRAFT:
            case MailInputField.COLUMN_FLAG_FLAGGED:
            case MailInputField.COLUMN_FLAG_NEW:
            case MailInputField.COLUMN_FLAG_READ:
                v = new ValueMetaBoolean(space.environmentSubstitute(field.getName()));
                break;
            default:
                // STRING
                v.setLength(250);
                v.setPrecision(-1);
                break;
        }
        v.setOrigin(name);
        r.addValueMeta(v);
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 49 with ValueMetaBoolean

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

the class MailValidatorMeta method getFields.

public void getFields(RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    String realResultFieldName = space.environmentSubstitute(resultfieldname);
    if (ResultAsString) {
        ValueMetaInterface v = new ValueMetaString(realResultFieldName);
        v.setLength(100, -1);
        v.setOrigin(name);
        r.addValueMeta(v);
    } else {
        ValueMetaInterface v = new ValueMetaBoolean(realResultFieldName);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    String realErrorsFieldName = space.environmentSubstitute(errorsFieldName);
    if (!Utils.isEmpty(realErrorsFieldName)) {
        ValueMetaInterface v = new ValueMetaString(realErrorsFieldName);
        v.setLength(100, -1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 50 with ValueMetaBoolean

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

the class DimensionLookupMeta method getSQLStatements.

@Override
public SQLStatement getSQLStatements(TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, Repository repository, IMetaStore metaStore) {
    // default: nothing to do!
    SQLStatement retval = new SQLStatement(stepMeta.getName(), databaseMeta, null);
    if (update) {
        // Only bother in case of update, not lookup!
        logDebug(BaseMessages.getString(PKG, "DimensionLookupMeta.Log.Update"));
        if (databaseMeta != null) {
            if (prev != null && prev.size() > 0) {
                String schemaTable = databaseMeta.getQuotedSchemaTableCombination(schemaName, tableName);
                if (!Utils.isEmpty(schemaTable)) {
                    Database db = createDatabaseObject();
                    db.shareVariablesWith(transMeta);
                    try {
                        db.connect();
                        String sql = "";
                        // How does the table look like?
                        // 
                        RowMetaInterface fields = new RowMeta();
                        // First the technical key
                        // 
                        ValueMetaInterface vkeyfield = new ValueMetaInteger(keyField);
                        vkeyfield.setLength(10);
                        fields.addValueMeta(vkeyfield);
                        // The the version
                        // 
                        ValueMetaInterface vversion = new ValueMetaInteger(versionField);
                        vversion.setLength(5);
                        fields.addValueMeta(vversion);
                        // The date from
                        // 
                        ValueMetaInterface vdatefrom = new ValueMetaDate(dateFrom);
                        fields.addValueMeta(vdatefrom);
                        // The date to
                        // 
                        ValueMetaInterface vdateto = new ValueMetaDate(dateTo);
                        fields.addValueMeta(vdateto);
                        String errors = "";
                        // 
                        for (int i = 0; i < keyLookup.length; i++) {
                            ValueMetaInterface vprev = prev.searchValueMeta(keyStream[i]);
                            if (vprev != null) {
                                ValueMetaInterface field = vprev.clone();
                                field.setName(keyLookup[i]);
                                fields.addValueMeta(field);
                            } else {
                                if (errors.length() > 0) {
                                    errors += ", ";
                                }
                                errors += keyStream[i];
                            }
                        }
                        // 
                        for (int i = 0; i < fieldLookup.length; i++) {
                            ValueMetaInterface vprev = prev.searchValueMeta(fieldStream[i]);
                            if (vprev != null) {
                                ValueMetaInterface field = vprev.clone();
                                field.setName(fieldLookup[i]);
                                fields.addValueMeta(field);
                            } else {
                                if (errors.length() > 0) {
                                    errors += ", ";
                                }
                                errors += fieldStream[i];
                            }
                        }
                        // 
                        for (int i = 0; i < fieldUpdate.length; i++) {
                            ValueMetaInterface valueMeta = null;
                            switch(fieldUpdate[i]) {
                                case TYPE_UPDATE_DATE_INSUP:
                                case TYPE_UPDATE_DATE_INSERTED:
                                case TYPE_UPDATE_DATE_UPDATED:
                                    valueMeta = new ValueMetaDate(fieldLookup[i]);
                                    break;
                                case TYPE_UPDATE_LAST_VERSION:
                                    valueMeta = new ValueMetaBoolean(fieldLookup[i]);
                                    break;
                                default:
                                    break;
                            }
                            if (valueMeta != null) {
                                fields.addValueMeta(valueMeta);
                            }
                        }
                        if (errors.length() > 0) {
                            retval.setError(BaseMessages.getString(PKG, "DimensionLookupMeta.ReturnValue.UnableToFindFields") + errors);
                        }
                        logDebug(BaseMessages.getString(PKG, "DimensionLookupMeta.Log.GetDDLForTable") + schemaTable + "] : " + fields.toStringMeta());
                        sql += db.getDDL(schemaTable, fields, (sequenceName != null && sequenceName.length() != 0) ? null : keyField, autoIncrement, null, true);
                        logDebug("sql =" + sql);
                        String[] idx_fields = null;
                        // Key lookup dimensions...
                        if (!Utils.isEmpty(keyLookup)) {
                            idx_fields = new String[keyLookup.length];
                            for (int i = 0; i < keyLookup.length; i++) {
                                idx_fields[i] = keyLookup[i];
                            }
                        } else {
                            retval.setError(BaseMessages.getString(PKG, "DimensionLookupMeta.ReturnValue.NoKeyFieldsSpecified"));
                        }
                        if (!Utils.isEmpty(idx_fields) && !db.checkIndexExists(schemaTable, idx_fields)) {
                            String indexname = "idx_" + tableName + "_lookup";
                            sql += db.getCreateIndexStatement(schemaTable, indexname, idx_fields, false, false, false, true);
                        }
                        // (Bitmap) index on technical key
                        idx_fields = new String[] { keyField };
                        if (!Utils.isEmpty(keyField)) {
                            if (!db.checkIndexExists(schemaTable, idx_fields)) {
                                String indexname = "idx_" + tableName + "_tk";
                                sql += db.getCreateIndexStatement(schemaTable, indexname, idx_fields, true, false, true, true);
                            }
                        } else {
                            retval.setError(BaseMessages.getString(PKG, "DimensionLookupMeta.ReturnValue.TechnicalKeyFieldRequired"));
                        }
                        // The optional Oracle sequence
                        if (CREATION_METHOD_SEQUENCE.equals(getTechKeyCreation()) && !Utils.isEmpty(sequenceName)) {
                            if (!db.checkSequenceExists(schemaName, sequenceName)) {
                                sql += db.getCreateSequenceStatement(schemaName, sequenceName, 1L, 1L, -1L, true);
                            }
                        }
                        if (sql.length() == 0) {
                            retval.setSQL(null);
                        } else {
                            retval.setSQL(transMeta.environmentSubstitute(sql));
                        }
                    } catch (KettleDatabaseException dbe) {
                        retval.setError(BaseMessages.getString(PKG, "DimensionLookupMeta.ReturnValue.ErrorOccurred") + dbe.getMessage());
                    } finally {
                        db.disconnect();
                    }
                } else {
                    retval.setError(BaseMessages.getString(PKG, "DimensionLookupMeta.ReturnValue.NoTableDefinedOnConnection"));
                }
            } else {
                retval.setError(BaseMessages.getString(PKG, "DimensionLookupMeta.ReturnValue.NotReceivingAnyFields"));
            }
        } else {
            retval.setError(BaseMessages.getString(PKG, "DimensionLookupMeta.ReturnValue.NoConnectionDefiendInStep"));
        }
    }
    return retval;
}
Also used : 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) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) SQLStatement(org.pentaho.di.core.SQLStatement) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)84 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)68 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)60 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)46 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)44 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)32 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)25 RowMeta (org.pentaho.di.core.row.RowMeta)22 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)20 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)20 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)18 Test (org.junit.Test)16 ValueMetaInternetAddress (org.pentaho.di.core.row.value.ValueMetaInternetAddress)15 KettleException (org.pentaho.di.core.exception.KettleException)13 ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)13 ObjectId (org.pentaho.di.repository.ObjectId)12 LongObjectId (org.pentaho.di.repository.LongObjectId)9 KettleStepException (org.pentaho.di.core.exception.KettleStepException)8 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)7 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)6