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"));
}
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));
}
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;
}
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);
}
}
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);
}
Aggregations