Search in sources :

Example 51 with ValueMetaDate

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

the class SqlTransGeneratorTest method testDataFormatting.

@Test
public void testDataFormatting() throws Exception {
    SQL sql = new SQL("SELECT * FROM table");
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("str"));
    rowMeta.addValueMeta(new ValueMetaDate("time"));
    rowMeta.addValueMeta(new ValueMetaInteger("long"));
    sql.parse(new ValueMetaResolver(rowMeta).getRowMeta());
    SqlTransGenerator generator = new SqlTransGenerator(sql, -1);
    TransMeta transMeta = generator.generateTransMeta();
    RowMetaInterface outputFields = transMeta.getStepFields(generator.getResultStepName());
    Calendar calendar = Calendar.getInstance();
    calendar.clear();
    calendar.set(2016, Calendar.FEBRUARY, 12, 13, 20);
    Object[] row = { "value", calendar.getTime(), 42L };
    assertThat(outputFields.getFieldNames(), arrayContaining("str", "time", "long"));
    assertThat(outputFields.getString(row, 0), is("value"));
    assertThat(outputFields.getString(row, 1), is("2016-02-12"));
    assertThat(outputFields.getString(row, 2), is("42"));
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) Calendar(java.util.Calendar) TransMeta(org.pentaho.di.trans.TransMeta) ValueMetaResolver(org.pentaho.di.trans.dataservice.optimization.ValueMetaResolver) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) SQL(org.pentaho.di.core.sql.SQL) Test(org.junit.Test)

Example 52 with ValueMetaDate

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

the class DriverCQLRowHandlerTest method testQueryRowsTimestamp.

@Test
public void testQueryRowsTimestamp() {
    Row row = mock(Row.class);
    when(row.getLong(0)).thenReturn(1L);
    when(row.getTimestamp(1)).thenReturn(new Date(1520538054000L));
    when(row.getDate(2)).thenReturn(LocalDate.fromYearMonthDay(2018, 03, 12));
    assertEquals(1L, DriverCQLRowHandler.readValue(new ValueMetaInteger("row"), row, 0));
    assertEquals(new Date(1520538054000L), DriverCQLRowHandler.readValue(new ValueMetaTimestamp("timestamp"), row, 1));
    assertEquals(LocalDate.fromYearMonthDay(2018, 03, 12), DriverCQLRowHandler.readValue(new ValueMetaDate("datestamp"), row, 2));
}
Also used : ValueMetaTimestamp(org.pentaho.di.core.row.value.ValueMetaTimestamp) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) Row(com.datastax.driver.core.Row) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Date(java.util.Date) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) LocalDate(com.datastax.driver.core.LocalDate) Test(org.junit.Test)

Example 53 with ValueMetaDate

use of org.pentaho.di.core.row.value.ValueMetaDate 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 54 with ValueMetaDate

use of org.pentaho.di.core.row.value.ValueMetaDate 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 55 with ValueMetaDate

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

the class BaseStep method buildLog.

/**
 * Builds the log.
 *
 * @param sname         the sname
 * @param copynr        the copynr
 * @param lines_read    the lines_read
 * @param lines_written the lines_written
 * @param lines_updated the lines_updated
 * @param lines_skipped the lines_skipped
 * @param errors        the errors
 * @param start_date    the start_date
 * @param end_date      the end_date
 * @return the row meta and data
 */
public RowMetaAndData buildLog(String sname, int copynr, long lines_read, long lines_written, long lines_updated, long lines_skipped, long errors, Date start_date, Date end_date) {
    RowMetaInterface r = new RowMeta();
    Object[] data = new Object[9];
    int nr = 0;
    r.addValueMeta(new ValueMetaString(BaseMessages.getString(PKG, "BaseStep.ColumnName.Stepname")));
    data[nr] = sname;
    nr++;
    r.addValueMeta(new ValueMetaNumber(BaseMessages.getString(PKG, "BaseStep.ColumnName.Copy")));
    data[nr] = new Double(copynr);
    nr++;
    r.addValueMeta(new ValueMetaNumber(BaseMessages.getString(PKG, "BaseStep.ColumnName.LinesReaded")));
    data[nr] = new Double(lines_read);
    nr++;
    r.addValueMeta(new ValueMetaNumber(BaseMessages.getString(PKG, "BaseStep.ColumnName.LinesWritten")));
    data[nr] = new Double(lines_written);
    nr++;
    r.addValueMeta(new ValueMetaNumber(BaseMessages.getString(PKG, "BaseStep.ColumnName.LinesUpdated")));
    data[nr] = new Double(lines_updated);
    nr++;
    r.addValueMeta(new ValueMetaNumber(BaseMessages.getString(PKG, "BaseStep.ColumnName.LinesSkipped")));
    data[nr] = new Double(lines_skipped);
    nr++;
    r.addValueMeta(new ValueMetaNumber(BaseMessages.getString(PKG, "BaseStep.ColumnName.Errors")));
    data[nr] = new Double(errors);
    nr++;
    r.addValueMeta(new ValueMetaDate("start_date"));
    data[nr] = start_date;
    nr++;
    r.addValueMeta(new ValueMetaDate("end_date"));
    data[nr] = end_date;
    nr++;
    return new RowMetaAndData(r, data);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate)

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