Search in sources :

Example 46 with ValueMetaDate

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

the class TextFileInputMeta method getFields.

@Override
public void getFields(RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    if (!isPassingThruFields()) {
        // all incoming fields are not transmitted !
        row.clear();
    } else {
        if (info != null) {
            boolean found = false;
            for (int i = 0; i < info.length && !found; i++) {
                if (info[i] != null) {
                    row.mergeRowMeta(info[i]);
                    found = true;
                }
            }
        }
    }
    for (int i = 0; i < inputFields.length; i++) {
        TextFileInputField field = inputFields[i];
        int type = field.getType();
        if (type == ValueMetaInterface.TYPE_NONE) {
            type = ValueMetaInterface.TYPE_STRING;
        }
        try {
            ValueMetaInterface v = ValueMetaFactory.createValueMeta(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());
            v.setDateFormatLenient(dateFormatLenient);
            v.setDateFormatLocale(dateFormatLocale);
            v.setTrimType(field.getTrimType());
            row.addValueMeta(v);
        } catch (Exception e) {
            throw new KettleStepException(e);
        }
    }
    if (errorIgnored) {
        if (errorCountField != null && errorCountField.length() > 0) {
            ValueMetaInterface v = new ValueMetaInteger(errorCountField);
            v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
            v.setOrigin(name);
            row.addValueMeta(v);
        }
        if (errorFieldsField != null && errorFieldsField.length() > 0) {
            ValueMetaInterface v = new ValueMetaString(errorFieldsField);
            v.setOrigin(name);
            row.addValueMeta(v);
        }
        if (errorTextField != null && errorTextField.length() > 0) {
            ValueMetaInterface v = new ValueMetaString(errorTextField);
            v.setOrigin(name);
            row.addValueMeta(v);
        }
    }
    if (includeFilename) {
        ValueMetaInterface v = new ValueMetaString(filenameField);
        v.setLength(100);
        v.setOrigin(name);
        row.addValueMeta(v);
    }
    if (includeRowNumber) {
        ValueMetaInterface v = new ValueMetaInteger(rowNumberField);
        v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
        v.setOrigin(name);
        row.addValueMeta(v);
    }
    if (getShortFileNameField() != null && getShortFileNameField().length() > 0) {
        ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getShortFileNameField()));
        v.setLength(100, -1);
        v.setOrigin(name);
        row.addValueMeta(v);
    }
    if (getExtensionField() != null && getExtensionField().length() > 0) {
        ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getExtensionField()));
        v.setLength(100, -1);
        v.setOrigin(name);
        row.addValueMeta(v);
    }
    if (getPathField() != null && getPathField().length() > 0) {
        ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getPathField()));
        v.setLength(100, -1);
        v.setOrigin(name);
        row.addValueMeta(v);
    }
    if (getSizeField() != null && getSizeField().length() > 0) {
        ValueMetaInterface v = new ValueMetaInteger(space.environmentSubstitute(getSizeField()));
        v.setOrigin(name);
        v.setLength(9);
        row.addValueMeta(v);
    }
    if (isHiddenField() != null && isHiddenField().length() > 0) {
        ValueMetaInterface v = new ValueMetaBoolean(space.environmentSubstitute(isHiddenField()));
        v.setOrigin(name);
        row.addValueMeta(v);
    }
    if (getLastModificationDateField() != null && getLastModificationDateField().length() > 0) {
        ValueMetaInterface v = new ValueMetaDate(space.environmentSubstitute(getLastModificationDateField()));
        v.setOrigin(name);
        row.addValueMeta(v);
    }
    if (getUriField() != null && getUriField().length() > 0) {
        ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getUriField()));
        v.setLength(100, -1);
        v.setOrigin(name);
        row.addValueMeta(v);
    }
    if (getRootUriField() != null && getRootUriField().length() > 0) {
        ValueMetaInterface v = new ValueMetaString(getRootUriField());
        v.setLength(100, -1);
        v.setOrigin(name);
        row.addValueMeta(v);
    }
}
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) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) 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 47 with ValueMetaDate

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

the class SystemDataMeta method getFields.

@Override
public void getFields(RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
    for (int i = 0; i < fieldName.length; i++) {
        ValueMetaInterface v;
        switch(fieldType[i]) {
            // All date values...
            case TYPE_SYSTEM_INFO_SYSTEM_START:
            case TYPE_SYSTEM_INFO_SYSTEM_DATE:
            case TYPE_SYSTEM_INFO_TRANS_DATE_FROM:
            case TYPE_SYSTEM_INFO_TRANS_DATE_TO:
            case TYPE_SYSTEM_INFO_JOB_DATE_FROM:
            case TYPE_SYSTEM_INFO_JOB_DATE_TO:
            case TYPE_SYSTEM_INFO_PREV_DAY_START:
            case TYPE_SYSTEM_INFO_PREV_DAY_END:
            case TYPE_SYSTEM_INFO_THIS_DAY_START:
            case TYPE_SYSTEM_INFO_THIS_DAY_END:
            case TYPE_SYSTEM_INFO_NEXT_DAY_START:
            case TYPE_SYSTEM_INFO_NEXT_DAY_END:
            case TYPE_SYSTEM_INFO_PREV_MONTH_START:
            case TYPE_SYSTEM_INFO_PREV_MONTH_END:
            case TYPE_SYSTEM_INFO_THIS_MONTH_START:
            case TYPE_SYSTEM_INFO_THIS_MONTH_END:
            case TYPE_SYSTEM_INFO_NEXT_MONTH_START:
            case TYPE_SYSTEM_INFO_NEXT_MONTH_END:
            case TYPE_SYSTEM_INFO_MODIFIED_DATE:
            case TYPE_SYSTEM_INFO_KETTLE_BUILD_DATE:
            case TYPE_SYSTEM_INFO_PREV_WEEK_START:
            case TYPE_SYSTEM_INFO_PREV_WEEK_END:
            case TYPE_SYSTEM_INFO_PREV_WEEK_OPEN_END:
            case TYPE_SYSTEM_INFO_PREV_WEEK_START_US:
            case TYPE_SYSTEM_INFO_PREV_WEEK_END_US:
            case TYPE_SYSTEM_INFO_THIS_WEEK_START:
            case TYPE_SYSTEM_INFO_THIS_WEEK_END:
            case TYPE_SYSTEM_INFO_THIS_WEEK_OPEN_END:
            case TYPE_SYSTEM_INFO_THIS_WEEK_START_US:
            case TYPE_SYSTEM_INFO_THIS_WEEK_END_US:
            case TYPE_SYSTEM_INFO_NEXT_WEEK_START:
            case TYPE_SYSTEM_INFO_NEXT_WEEK_END:
            case TYPE_SYSTEM_INFO_NEXT_WEEK_OPEN_END:
            case TYPE_SYSTEM_INFO_NEXT_WEEK_START_US:
            case TYPE_SYSTEM_INFO_NEXT_WEEK_END_US:
            case TYPE_SYSTEM_INFO_PREV_QUARTER_START:
            case TYPE_SYSTEM_INFO_PREV_QUARTER_END:
            case TYPE_SYSTEM_INFO_THIS_QUARTER_START:
            case TYPE_SYSTEM_INFO_THIS_QUARTER_END:
            case TYPE_SYSTEM_INFO_NEXT_QUARTER_START:
            case TYPE_SYSTEM_INFO_NEXT_QUARTER_END:
            case TYPE_SYSTEM_INFO_PREV_YEAR_START:
            case TYPE_SYSTEM_INFO_PREV_YEAR_END:
            case TYPE_SYSTEM_INFO_THIS_YEAR_START:
            case TYPE_SYSTEM_INFO_THIS_YEAR_END:
            case TYPE_SYSTEM_INFO_NEXT_YEAR_START:
            case TYPE_SYSTEM_INFO_NEXT_YEAR_END:
                v = new ValueMetaDate(fieldName[i]);
                break;
            case TYPE_SYSTEM_INFO_TRANS_NAME:
            case TYPE_SYSTEM_INFO_FILENAME:
            case TYPE_SYSTEM_INFO_ARGUMENT_01:
            case TYPE_SYSTEM_INFO_ARGUMENT_02:
            case TYPE_SYSTEM_INFO_ARGUMENT_03:
            case TYPE_SYSTEM_INFO_ARGUMENT_04:
            case TYPE_SYSTEM_INFO_ARGUMENT_05:
            case TYPE_SYSTEM_INFO_ARGUMENT_06:
            case TYPE_SYSTEM_INFO_ARGUMENT_07:
            case TYPE_SYSTEM_INFO_ARGUMENT_08:
            case TYPE_SYSTEM_INFO_ARGUMENT_09:
            case TYPE_SYSTEM_INFO_ARGUMENT_10:
            case TYPE_SYSTEM_INFO_MODIFIED_USER:
            case TYPE_SYSTEM_INFO_HOSTNAME:
            case TYPE_SYSTEM_INFO_HOSTNAME_REAL:
            case TYPE_SYSTEM_INFO_IP_ADDRESS:
            case TYPE_SYSTEM_INFO_KETTLE_VERSION:
            case TYPE_SYSTEM_INFO_KETTLE_BUILD_VERSION:
            case TYPE_SYSTEM_INFO_PREVIOUS_RESULT_LOG_TEXT:
                v = new ValueMetaString(fieldName[i]);
                break;
            case TYPE_SYSTEM_INFO_COPYNR:
            case TYPE_SYSTEM_INFO_TRANS_BATCH_ID:
            case TYPE_SYSTEM_INFO_JOB_BATCH_ID:
            case TYPE_SYSTEM_INFO_CURRENT_PID:
            case TYPE_SYSTEM_INFO_JVM_TOTAL_MEMORY:
            case TYPE_SYSTEM_INFO_JVM_FREE_MEMORY:
            case TYPE_SYSTEM_INFO_JVM_MAX_MEMORY:
            case TYPE_SYSTEM_INFO_JVM_AVAILABLE_MEMORY:
            case TYPE_SYSTEM_INFO_AVAILABLE_PROCESSORS:
            case TYPE_SYSTEM_INFO_JVM_CPU_TIME:
            case TYPE_SYSTEM_INFO_TOTAL_PHYSICAL_MEMORY_SIZE:
            case TYPE_SYSTEM_INFO_TOTAL_SWAP_SPACE_SIZE:
            case TYPE_SYSTEM_INFO_COMMITTED_VIRTUAL_MEMORY_SIZE:
            case TYPE_SYSTEM_INFO_FREE_PHYSICAL_MEMORY_SIZE:
            case TYPE_SYSTEM_INFO_FREE_SWAP_SPACE_SIZE:
            case TYPE_SYSTEM_INFO_PREVIOUS_RESULT_EXIT_STATUS:
            case TYPE_SYSTEM_INFO_PREVIOUS_RESULT_ENTRY_NR:
            case TYPE_SYSTEM_INFO_PREVIOUS_RESULT_NR_ERRORS:
            case TYPE_SYSTEM_INFO_PREVIOUS_RESULT_NR_FILES:
            case TYPE_SYSTEM_INFO_PREVIOUS_RESULT_NR_FILES_RETRIEVED:
            case TYPE_SYSTEM_INFO_PREVIOUS_RESULT_NR_LINES_DELETED:
            case TYPE_SYSTEM_INFO_PREVIOUS_RESULT_NR_LINES_INPUT:
            case TYPE_SYSTEM_INFO_PREVIOUS_RESULT_NR_LINES_OUTPUT:
            case TYPE_SYSTEM_INFO_PREVIOUS_RESULT_NR_LINES_READ:
            case TYPE_SYSTEM_INFO_PREVIOUS_RESULT_NR_LINES_REJETED:
            case TYPE_SYSTEM_INFO_PREVIOUS_RESULT_NR_LINES_UPDATED:
            case TYPE_SYSTEM_INFO_PREVIOUS_RESULT_NR_LINES_WRITTEN:
                v = new ValueMetaInteger(fieldName[i]);
                v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
                break;
            case TYPE_SYSTEM_INFO_PREVIOUS_RESULT_RESULT:
            case TYPE_SYSTEM_INFO_PREVIOUS_RESULT_IS_STOPPED:
                v = new ValueMetaBoolean(fieldName[i]);
                break;
            default:
                v = new ValueMetaNone(fieldName[i]);
                break;
        }
        v.setOrigin(name);
        row.addValueMeta(v);
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaNone(org.pentaho.di.core.row.value.ValueMetaNone) 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 48 with ValueMetaDate

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

the class PropertyInputMeta method getFields.

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++) {
        PropertyInputField field = inputFields[i];
        int type = field.getType();
        if (type == ValueMetaInterface.TYPE_NONE) {
            type = ValueMetaInterface.TYPE_STRING;
        }
        try {
            ValueMetaInterface v = ValueMetaFactory.createValueMeta(space.environmentSubstitute(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 KettleStepException(e);
        }
    }
    String realFilenameField = space.environmentSubstitute(filenameField);
    if (includeFilename && !Utils.isEmpty(realFilenameField)) {
        ValueMetaInterface v = new ValueMetaString(realFilenameField);
        v.setLength(500);
        v.setPrecision(-1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    String realRowNumberField = space.environmentSubstitute(rowNumberField);
    if (includeRowNumber && !Utils.isEmpty(realRowNumberField)) {
        ValueMetaInterface v = new ValueMetaInteger(realRowNumberField);
        v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    String realSectionField = space.environmentSubstitute(iniSectionField);
    if (includeIniSection && !Utils.isEmpty(realSectionField)) {
        ValueMetaInterface v = new ValueMetaString(realSectionField);
        v.setLength(500);
        v.setPrecision(-1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (getShortFileNameField() != null && getShortFileNameField().length() > 0) {
        ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getShortFileNameField()));
        v.setLength(100, -1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (getExtensionField() != null && getExtensionField().length() > 0) {
        ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getExtensionField()));
        v.setLength(100, -1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (getPathField() != null && getPathField().length() > 0) {
        ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getPathField()));
        v.setLength(100, -1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (getSizeField() != null && getSizeField().length() > 0) {
        ValueMetaInterface v = new ValueMetaInteger(space.environmentSubstitute(getSizeField()));
        v.setOrigin(name);
        v.setLength(9);
        r.addValueMeta(v);
    }
    if (isHiddenField() != null && isHiddenField().length() > 0) {
        ValueMetaInterface v = new ValueMetaBoolean(space.environmentSubstitute(isHiddenField()));
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (getLastModificationDateField() != null && getLastModificationDateField().length() > 0) {
        ValueMetaInterface v = new ValueMetaDate(space.environmentSubstitute(getLastModificationDateField()));
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (getUriField() != null && getUriField().length() > 0) {
        ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getUriField()));
        v.setLength(100, -1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
    if (getRootUriField() != null && getRootUriField().length() > 0) {
        ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getRootUriField()));
        v.setLength(100, -1);
        v.setOrigin(name);
        r.addValueMeta(v);
    }
}
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) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) 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 49 with ValueMetaDate

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

the class RowGenerator method buildRow.

public static final RowMetaAndData buildRow(RowGeneratorMeta meta, List<CheckResultInterface> remarks, String origin) throws KettlePluginException {
    RowMetaInterface rowMeta = new RowMeta();
    Object[] rowData = RowDataUtil.allocateRowData(meta.getFieldName().length + 2);
    int index = 0;
    if (meta.isNeverEnding()) {
        if (!Utils.isEmpty(meta.getRowTimeField())) {
            rowMeta.addValueMeta(new ValueMetaDate(meta.getRowTimeField()));
            rowData[index++] = null;
        }
        if (!Utils.isEmpty(meta.getLastTimeField())) {
            rowMeta.addValueMeta(new ValueMetaDate(meta.getLastTimeField()));
            rowData[index++] = null;
        }
    }
    for (int i = 0; i < meta.getFieldName().length; i++) {
        int valtype = ValueMetaFactory.getIdForValueMeta(meta.getFieldType()[i]);
        if (meta.getFieldName()[i] != null) {
            // build a
            ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta(meta.getFieldName()[i], valtype);
            // value!
            valueMeta.setLength(meta.getFieldLength()[i]);
            valueMeta.setPrecision(meta.getFieldPrecision()[i]);
            valueMeta.setConversionMask(meta.getFieldFormat()[i]);
            valueMeta.setCurrencySymbol(meta.getCurrency()[i]);
            valueMeta.setGroupingSymbol(meta.getGroup()[i]);
            valueMeta.setDecimalSymbol(meta.getDecimal()[i]);
            valueMeta.setOrigin(origin);
            ValueMetaInterface stringMeta = ValueMetaFactory.cloneValueMeta(valueMeta, ValueMetaInterface.TYPE_STRING);
            if (meta.isSetEmptyString() != null && meta.isSetEmptyString()[i]) {
                // Set empty string
                rowData[index] = StringUtil.EMPTY_STRING;
            } else {
                String stringValue = meta.getValue()[i];
                // If the value is empty: consider it to be NULL.
                if (Utils.isEmpty(stringValue)) {
                    rowData[index] = null;
                    if (valueMeta.getType() == ValueMetaInterface.TYPE_NONE) {
                        String message = BaseMessages.getString(PKG, "RowGenerator.CheckResult.SpecifyTypeError", valueMeta.getName(), stringValue);
                        remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
                    }
                } else {
                    // 
                    try {
                        rowData[index] = valueMeta.convertData(stringMeta, stringValue);
                    } catch (KettleValueException e) {
                        switch(valueMeta.getType()) {
                            case ValueMetaInterface.TYPE_NUMBER:
                                String message = BaseMessages.getString(PKG, "RowGenerator.BuildRow.Error.Parsing.Number", valueMeta.getName(), stringValue, e.toString());
                                remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
                                break;
                            case ValueMetaInterface.TYPE_DATE:
                                message = BaseMessages.getString(PKG, "RowGenerator.BuildRow.Error.Parsing.Date", valueMeta.getName(), stringValue, e.toString());
                                remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
                                break;
                            case ValueMetaInterface.TYPE_INTEGER:
                                message = BaseMessages.getString(PKG, "RowGenerator.BuildRow.Error.Parsing.Integer", valueMeta.getName(), stringValue, e.toString());
                                remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
                                break;
                            case ValueMetaInterface.TYPE_BIGNUMBER:
                                message = BaseMessages.getString(PKG, "RowGenerator.BuildRow.Error.Parsing.BigNumber", valueMeta.getName(), stringValue, e.toString());
                                remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
                                break;
                            case ValueMetaInterface.TYPE_TIMESTAMP:
                                message = BaseMessages.getString(PKG, "RowGenerator.BuildRow.Error.Parsing.Timestamp", valueMeta.getName(), stringValue, e.toString());
                                remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
                                break;
                            default:
                                // Boolean and binary don't throw errors normally, so it's probably an unspecified error problem...
                                message = BaseMessages.getString(PKG, "RowGenerator.CheckResult.SpecifyTypeError", valueMeta.getName(), stringValue);
                                remarks.add(new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, message, null));
                                break;
                        }
                    }
                }
            }
            // Now add value to the row!
            // This is in fact a copy from the fields row, but now with data.
            rowMeta.addValueMeta(valueMeta);
            index++;
        }
    }
    return new RowMetaAndData(rowMeta, rowData);
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) RowMeta(org.pentaho.di.core.row.RowMeta) CheckResult(org.pentaho.di.core.CheckResult) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) KettleValueException(org.pentaho.di.core.exception.KettleValueException) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 50 with ValueMetaDate

use of org.pentaho.di.core.row.value.ValueMetaDate in project pdi-dataservice-server-plugin by pentaho.

the class DataServiceExecutorTest method testConditionResolution.

@Test
public void testConditionResolution() throws Exception {
    RowMeta rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("aString"));
    rowMeta.addValueMeta(new ValueMetaInteger("anInt"));
    rowMeta.addValueMeta(new ValueMetaDate("aDate"));
    String query = "SELECT COUNT(aString), aString FROM " + DATA_SERVICE_NAME + " WHERE anInt = 2 AND aDate IN ('2014-12-05','2008-01-01')" + " GROUP BY aString HAVING COUNT(aString) > 2";
    when(transMeta.getStepFields(DATA_SERVICE_STEP)).thenReturn(rowMeta);
    DataServiceExecutor executor = new DataServiceExecutor.Builder(new SQL(query), dataService, context).serviceTrans(transMeta).prepareExecution(false).build();
    Condition condition = executor.getSql().getWhereCondition().getCondition();
    Calendar calendar = Calendar.getInstance();
    calendar.clear();
    calendar.set(2014, Calendar.DECEMBER, 5);
    assertThat(condition.evaluate(rowMeta, new Object[] { "value", 2L, calendar.getTime() }), is(true));
    assertThat(condition.evaluate(rowMeta, new Object[] { "value", 2L, new Date() }), is(false));
}
Also used : Condition(org.pentaho.di.core.Condition) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) Calendar(java.util.Calendar) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Matchers.anyString(org.mockito.Matchers.anyString) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Date(java.util.Date) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Aggregations

ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)104 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)63 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)59 Test (org.junit.Test)50 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)44 RowMeta (org.pentaho.di.core.row.RowMeta)43 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)34 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)33 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)25 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)23 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)21 Calendar (java.util.Calendar)17 Date (java.util.Date)17 KettleException (org.pentaho.di.core.exception.KettleException)15 ValueMetaInternetAddress (org.pentaho.di.core.row.value.ValueMetaInternetAddress)15 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)14 ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)13 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)10 KettleStepException (org.pentaho.di.core.exception.KettleStepException)10 SQLException (java.sql.SQLException)8