Search in sources :

Example 1 with ValueMetaDate

use of org.apache.hop.core.row.value.ValueMetaDate in project hop by apache.

the class ResultFile method getRow.

/**
 * @return an output Row for this Result File object.
 */
@JsonIgnore
public RowMetaAndData getRow() {
    RowMetaAndData row = new RowMetaAndData();
    // First the type
    row.addValue(new ValueMetaString("type"), getTypeDesc());
    // The filename
    row.addValue(new ValueMetaString("filename"), file.getName().getBaseName());
    // The path
    row.addValue(new ValueMetaString("path"), file.getName().getURI());
    // The origin parent
    row.addValue(new ValueMetaString("parentorigin"), originParent);
    // The origin
    row.addValue(new ValueMetaString("origin"), origin);
    // The comment
    row.addValue(new ValueMetaString("comment"), comment);
    // The timestamp
    row.addValue(new ValueMetaDate("timestamp"), timestamp);
    return row;
}
Also used : ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) ValueMetaDate(org.apache.hop.core.row.value.ValueMetaDate) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore)

Example 2 with ValueMetaDate

use of org.apache.hop.core.row.value.ValueMetaDate in project hop by apache.

the class InsertUpdateTestLazyConversion method testDateLazyConversion.

@Test
public void testDateLazyConversion() throws HopException {
    Database db = mock(Database.class);
    RowMeta returnRowMeta = new RowMeta();
    doReturn(new Object[] { new Timestamp(System.currentTimeMillis()) }).when(db).getLookup(any(PreparedStatement.class));
    returnRowMeta.addValueMeta(new ValueMetaDate("TimeStamp"));
    doReturn(returnRowMeta).when(db).getReturnRowMeta();
    ValueMetaString storageMetadata = new ValueMetaString("Date");
    storageMetadata.setConversionMask("yyyy-MM-dd");
    ValueMetaDate valueMeta = new ValueMetaDate("Date");
    valueMeta.setStorageType(IValueMeta.STORAGE_TYPE_BINARY_STRING);
    valueMeta.setStorageMetadata(storageMetadata);
    RowMeta inputRowMeta = new RowMeta();
    inputRowMeta.addValueMeta(valueMeta);
    InsertUpdateMeta transformMeta = smh.iTransformMeta;
    InsertUpdateLookupField mockedIulf = mock(InsertUpdateLookupField.class);
    List<InsertUpdateValue> items = mock(ArrayList.class);
    when(transformMeta.getInsertUpdateLookupField()).thenReturn(mockedIulf);
    when(transformMeta.getInsertUpdateLookupField().getValueFields()).thenReturn(items);
    when(items.get(0)).thenReturn(mock(InsertUpdateValue.class));
    when(items.get(0).isUpdate()).thenReturn(true);
    InsertUpdateData transformData = smh.iTransformData;
    transformData.lookupParameterRowMeta = inputRowMeta;
    transformData.db = db;
    transformData.keynrs = transformData.valuenrs = new int[] { 0 };
    transformData.keynrs2 = new int[] { -1 };
    transformData.updateParameterRowMeta = when(mock(RowMeta.class).size()).thenReturn(2).getMock();
    InsertUpdate transform = new InsertUpdate(smh.transformMeta, smh.iTransformMeta, smh.iTransformData, 0, smh.pipelineMeta, smh.pipeline);
    transform.setInputRowMeta(inputRowMeta);
    transform.addRowSetToInputRowSets(smh.getMockInputRowSet(new Object[] { "2013-12-20".getBytes() }));
    transform.init();
    transform.first = false;
    transform.processRow();
}
Also used : ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) RowMeta(org.apache.hop.core.row.RowMeta) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp) Database(org.apache.hop.core.database.Database) ILoggingObject(org.apache.hop.core.logging.ILoggingObject) ValueMetaDate(org.apache.hop.core.row.value.ValueMetaDate) Test(org.junit.Test)

Example 3 with ValueMetaDate

use of org.apache.hop.core.row.value.ValueMetaDate in project hop by apache.

the class PipelineLoggingMeta method getFields.

@Override
public void getFields(IRowMeta inputRowMeta, String name, IRowMeta[] info, TransformMeta nextTransform, IVariables variables, IHopMetadataProvider metadataProvider) throws HopTransformException {
    inputRowMeta.clear();
    // Logging date
    inputRowMeta.addValueMeta(new ValueMetaDate("loggingDate"));
    // Logging date
    inputRowMeta.addValueMeta(new ValueMetaString("loggingPhase"));
    // Name of the pipeline
    inputRowMeta.addValueMeta(new ValueMetaString("pipelineName", 255, -1));
    // Filename of the pipeline
    inputRowMeta.addValueMeta(new ValueMetaString("pipelineFilename", 255, -1));
    // Start date of the pipeline
    inputRowMeta.addValueMeta(new ValueMetaDate("pipelineStart"));
    // End date of the pipeline
    inputRowMeta.addValueMeta(new ValueMetaDate("pipelineEnd"));
    // Pipeline log channel ID
    inputRowMeta.addValueMeta(new ValueMetaString("pipelineLogChannelId", 32, -1));
    // Parent log channel ID
    inputRowMeta.addValueMeta(new ValueMetaString("parentLogChannelId", 32, -1));
    // Logging text of the pipeline
    inputRowMeta.addValueMeta(new ValueMetaString("pipelineLogging", 1000000, -1));
    // Number of errors
    inputRowMeta.addValueMeta(new ValueMetaInteger("pipelineErrorCount", 3, 0));
    // Pipeline status description
    inputRowMeta.addValueMeta(new ValueMetaString("pipelineStatusDescription", 32, -1));
    if (loggingTransforms) {
        // Name of the transform
        inputRowMeta.addValueMeta(new ValueMetaString("transformName"));
        // Copy number of the transform
        inputRowMeta.addValueMeta(new ValueMetaInteger("transformCopyNr"));
        // Copy number of the transform
        inputRowMeta.addValueMeta(new ValueMetaString("transformStatusDescription", 100, -1));
        // Transform log channel ID
        inputRowMeta.addValueMeta(new ValueMetaString("transformLogChannelId", 32, -1));
        // Transform logging text
        inputRowMeta.addValueMeta(new ValueMetaString("transformLoggingText", 1000000, -1));
        // Number of lines read
        inputRowMeta.addValueMeta(new ValueMetaInteger("transformLinesRead", 12, 0));
        // Number of lines written
        inputRowMeta.addValueMeta(new ValueMetaInteger("transformLinesWritten", 12, 0));
        // Number of lines input
        inputRowMeta.addValueMeta(new ValueMetaInteger("transformLinesInput", 12, 0));
        // Number of lines output
        inputRowMeta.addValueMeta(new ValueMetaInteger("transformLinesOutput", 12, 0));
        // Number of lines updated
        inputRowMeta.addValueMeta(new ValueMetaInteger("transformLinesUpdated", 12, 0));
        // Number of lines rejected
        inputRowMeta.addValueMeta(new ValueMetaInteger("transformLinesRejected", 12, 0));
        // Number of errors
        inputRowMeta.addValueMeta(new ValueMetaInteger("transformErrors", 3, 0));
        // Execution start
        inputRowMeta.addValueMeta(new ValueMetaDate("transformStart"));
        // Execution end
        inputRowMeta.addValueMeta(new ValueMetaDate("transformEnd"));
        // Execution duration in ms
        inputRowMeta.addValueMeta(new ValueMetaInteger("transformDuration", 12, 0));
    }
}
Also used : ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) ValueMetaInteger(org.apache.hop.core.row.value.ValueMetaInteger) ValueMetaDate(org.apache.hop.core.row.value.ValueMetaDate)

Example 4 with ValueMetaDate

use of org.apache.hop.core.row.value.ValueMetaDate in project hop by apache.

the class CombinationLookup method combiInsert.

/**
 * This inserts new record into a junk dimension
 */
public Long combiInsert(IRowMeta rowMeta, Object[] row, Long valKey, Long valCrc) throws HopDatabaseException {
    String debug = "Combination insert";
    DatabaseMeta databaseMeta = meta.getDatabaseMeta();
    try {
        if (data.prepStatementInsert == null) {
            // first time: construct prepared statement
            debug = "First: construct prepared statement";
            data.insertRowMeta = new RowMeta();
            /*
         * Construct the SQL statement...
         *
         * INSERT INTO d_test(keyfield, [crcfield,] keylookup[]) VALUES(val_key, [val_crc], row values with keynrs[])
         */
            String sql = "";
            sql += "INSERT INTO " + data.schemaTable + ("( ");
            boolean comma = false;
            if (!isAutoIncrement()) {
                // NO AUTOINCREMENT
                sql += databaseMeta.quoteField(meta.getTechnicalKeyField());
                data.insertRowMeta.addValueMeta(new ValueMetaInteger(meta.getTechnicalKeyField()));
                comma = true;
            } else if (databaseMeta.needsPlaceHolder()) {
                // placeholder on informix! Will be replaced in table by real autoinc value.
                sql += "0";
                data.insertRowMeta.addValueMeta(new ValueMetaInteger(meta.getTechnicalKeyField()));
                comma = true;
            }
            if (meta.useHash()) {
                if (comma) {
                    sql += ", ";
                }
                sql += databaseMeta.quoteField(meta.getHashField());
                data.insertRowMeta.addValueMeta(new ValueMetaInteger(meta.getHashField()));
                comma = true;
            }
            if (!Utils.isEmpty(meta.getLastUpdateField())) {
                if (comma) {
                    sql += ", ";
                }
                sql += databaseMeta.quoteField(meta.getLastUpdateField());
                data.insertRowMeta.addValueMeta(new ValueMetaDate(meta.getLastUpdateField()));
                comma = true;
            }
            for (int i = 0; i < meta.getKeyLookup().length; i++) {
                if (comma) {
                    sql += ", ";
                }
                sql += databaseMeta.quoteField(meta.getKeyLookup()[i]);
                data.insertRowMeta.addValueMeta(rowMeta.getValueMeta(data.keynrs[i]));
                comma = true;
            }
            sql += ") VALUES (";
            comma = false;
            if (!isAutoIncrement()) {
                sql += '?';
                comma = true;
            }
            if (meta.useHash()) {
                if (comma) {
                    sql += ',';
                }
                sql += '?';
                comma = true;
            }
            if (!Utils.isEmpty(meta.getLastUpdateField())) {
                if (comma) {
                    sql += ',';
                }
                sql += '?';
                comma = true;
            }
            for (int i = 0; i < meta.getKeyLookup().length; i++) {
                if (comma) {
                    sql += ',';
                } else {
                    comma = true;
                }
                sql += '?';
            }
            sql += " )";
            String sqlStatement = sql;
            try {
                debug = "First: prepare statement";
                if (isAutoIncrement() && databaseMeta.supportsAutoGeneratedKeys()) {
                    logDetailed("SQL with return keys: " + sqlStatement);
                    data.prepStatementInsert = data.db.getConnection().prepareStatement(databaseMeta.stripCR(sqlStatement), Statement.RETURN_GENERATED_KEYS);
                } else {
                    logDetailed("SQL without return keys: " + sqlStatement);
                    data.prepStatementInsert = data.db.getConnection().prepareStatement(databaseMeta.stripCR(sqlStatement));
                }
            } catch (SQLException ex) {
                throw new HopDatabaseException("Unable to prepare combi insert statement : " + Const.CR + sqlStatement, ex);
            } catch (Exception ex) {
                throw new HopDatabaseException("Unable to prepare combi insert statement : " + Const.CR + sqlStatement, ex);
            }
        }
        debug = "Create new insert row rins";
        Object[] insertRow = new Object[data.insertRowMeta.size()];
        int insertIndex = 0;
        if (!isAutoIncrement()) {
            insertRow[insertIndex] = valKey;
            insertIndex++;
        }
        if (meta.useHash()) {
            insertRow[insertIndex] = valCrc;
            insertIndex++;
        }
        if (!Utils.isEmpty(meta.getLastUpdateField())) {
            insertRow[insertIndex] = new Date();
            insertIndex++;
        }
        for (int i = 0; i < data.keynrs.length; i++) {
            insertRow[insertIndex] = row[data.keynrs[i]];
            insertIndex++;
        }
        if (isRowLevel()) {
            logRowlevel("rins=" + data.insertRowMeta.getString(insertRow));
        }
        debug = "Set values on insert";
        // INSERT NEW VALUE!
        data.db.setValues(data.insertRowMeta, insertRow, data.prepStatementInsert);
        debug = "Insert row";
        data.db.insertRow(data.prepStatementInsert);
        debug = "Retrieve key";
        if (isAutoIncrement() && databaseMeta.supportsAutoGeneratedKeys()) {
            ResultSet keys = null;
            try {
                // 1 key
                keys = data.prepStatementInsert.getGeneratedKeys();
                if (keys.next()) {
                    valKey = Long.valueOf(keys.getLong(1));
                } else {
                    throw new HopDatabaseException("Unable to retrieve auto-increment of combi insert key : " + meta.getTechnicalKeyField() + ", no fields in resultset");
                }
            } catch (SQLException ex) {
                throw new HopDatabaseException("Unable to retrieve auto-increment of combi insert key : " + meta.getTechnicalKeyField(), ex);
            } finally {
                try {
                    if (keys != null) {
                        keys.close();
                    }
                } catch (SQLException ex) {
                    throw new HopDatabaseException("Unable to retrieve auto-increment of combi insert key : " + meta.getTechnicalKeyField(), ex);
                }
            }
        }
    } catch (Exception e) {
        logError(Const.getStackTracker(e));
        throw new HopDatabaseException("Unexpected error in combination insert in part [" + debug + "] : " + e.toString(), e);
    }
    return valKey;
}
Also used : IRowMeta(org.apache.hop.core.row.IRowMeta) RowMeta(org.apache.hop.core.row.RowMeta) SQLException(java.sql.SQLException) DatabaseMeta(org.apache.hop.core.database.DatabaseMeta) SQLException(java.sql.SQLException) ValueMetaDate(org.apache.hop.core.row.value.ValueMetaDate) ResultSet(java.sql.ResultSet) ValueMetaInteger(org.apache.hop.core.row.value.ValueMetaInteger) ValueMetaDate(org.apache.hop.core.row.value.ValueMetaDate)

Example 5 with ValueMetaDate

use of org.apache.hop.core.row.value.ValueMetaDate in project hop by apache.

the class SalesforceInputMeta method getFields.

@Override
public void getFields(IRowMeta r, String name, IRowMeta[] info, TransformMeta nextTransform, IVariables variables, IHopMetadataProvider metadataProvider) throws HopTransformException {
    int i;
    for (i = 0; i < inputFields.length; i++) {
        SalesforceInputField field = inputFields[i];
        int type = field.getType();
        if (type == IValueMeta.TYPE_NONE) {
            type = IValueMeta.TYPE_STRING;
        }
        try {
            IValueMeta v = ValueMetaFactory.createValueMeta(variables.resolve(field.getName()), type);
            v.setLength(field.getLength());
            v.setPrecision(field.getPrecision());
            v.setOrigin(name);
            v.setConversionMask(field.getFormat());
            v.setDecimalSymbol(field.getDecimalSymbol());
            v.setGroupingSymbol(field.getGroupSymbol());
            v.setCurrencySymbol(field.getCurrencySymbol());
            r.addValueMeta(v);
        } catch (Exception e) {
            throw new HopTransformException(e);
        }
    }
    if (includeTargetURL && !Utils.isEmpty(targetURLField)) {
        IValueMeta v = new ValueMetaString(variables.resolve(targetURLField));
        v.setLength(250);
        v.setPrecision(-1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (includeModule && !Utils.isEmpty(moduleField)) {
        IValueMeta v = new ValueMetaString(variables.resolve(moduleField));
        v.setLength(250);
        v.setPrecision(-1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (includeSQL && !Utils.isEmpty(sqlField)) {
        IValueMeta v = new ValueMetaString(variables.resolve(sqlField));
        v.setLength(250);
        v.setPrecision(-1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (includeTimestamp && !Utils.isEmpty(timestampField)) {
        IValueMeta v = new ValueMetaDate(variables.resolve(timestampField));
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (includeRowNumber && !Utils.isEmpty(rowNumberField)) {
        IValueMeta v = new ValueMetaInteger(variables.resolve(rowNumberField));
        v.setLength(IValueMeta.DEFAULT_INTEGER_LENGTH, 0);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (includeDeletionDate && !Utils.isEmpty(deletionDateField)) {
        IValueMeta v = new ValueMetaDate(variables.resolve(deletionDateField));
        v.setOrigin(name);
        r.addValueMeta(v);
    }
}
Also used : IValueMeta(org.apache.hop.core.row.IValueMeta) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) ValueMetaInteger(org.apache.hop.core.row.value.ValueMetaInteger) HopTransformException(org.apache.hop.core.exception.HopTransformException) ValueMetaDate(org.apache.hop.core.row.value.ValueMetaDate) HopXmlException(org.apache.hop.core.exception.HopXmlException) HopTransformException(org.apache.hop.core.exception.HopTransformException)

Aggregations

ValueMetaDate (org.apache.hop.core.row.value.ValueMetaDate)53 Test (org.junit.Test)24 RowMeta (org.apache.hop.core.row.RowMeta)22 ValueMetaInteger (org.apache.hop.core.row.value.ValueMetaInteger)22 Calendar (java.util.Calendar)15 IValueMeta (org.apache.hop.core.row.IValueMeta)14 ValueMetaString (org.apache.hop.core.row.value.ValueMetaString)14 IRowMeta (org.apache.hop.core.row.IRowMeta)13 Date (java.util.Date)9 ValueMetaBoolean (org.apache.hop.core.row.value.ValueMetaBoolean)6 SQLException (java.sql.SQLException)5 RowMetaAndData (org.apache.hop.core.RowMetaAndData)5 ArrayList (java.util.ArrayList)4 Database (org.apache.hop.core.database.Database)4 DatabaseMeta (org.apache.hop.core.database.DatabaseMeta)4 HopDatabaseException (org.apache.hop.core.exception.HopDatabaseException)4 HopException (org.apache.hop.core.exception.HopException)4 ILoggingObject (org.apache.hop.core.logging.ILoggingObject)4 ValueMetaNumber (org.apache.hop.core.row.value.ValueMetaNumber)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3