use of org.talend.dataprep.api.dataset.row.DataSetRow in project data-prep by Talend.
the class DefaultLookupRowMatcher method getEmptyRow.
/**
* Returns an empty default row based on the given dataset metadata.
*
* @param columns the list of column metadata of rows within the data set
* @return an empty default row based on the given list of column metadata.
*/
private DataSetRow getEmptyRow(List<ColumnMetadata> columns) {
RowMetadata rowMetadata = new RowMetadata(columns);
DataSetRow defaultRow = new DataSetRow(rowMetadata);
columns.forEach(column -> defaultRow.set(column.getId(), EMPTY));
return defaultRow;
}
use of org.talend.dataprep.api.dataset.row.DataSetRow in project data-prep by Talend.
the class DataSetRowStreamDeserializer method deserialize.
@Override
public Stream<DataSetRow> deserialize(JsonParser jp, DeserializationContext context) {
final List<ColumnMetadata> columns = (List<ColumnMetadata>) context.getAttribute(ColumnContextDeserializer.class.getName());
final RowMetadata rowMetadata;
if (columns == null) {
rowMetadata = new RowMetadata();
} else {
rowMetadata = new RowMetadata(columns);
}
final Iterable<DataSetRow> rowIterable = () -> new DataSetRowIterator(jp, rowMetadata);
return StreamSupport.stream(rowIterable.spliterator(), false);
}
use of org.talend.dataprep.api.dataset.row.DataSetRow in project data-prep by Talend.
the class DataSetLookupRowMatcher method getEmptyRow.
/**
* Return an empty default row based on the given dataset metadata.
*
* @param columns the dataset to get build the row from.
* @return an empty default row based on the given dataset metadata.
*/
private DataSetRow getEmptyRow(List<ColumnMetadata> columns) {
RowMetadata rowMetadata = new RowMetadata(columns);
DataSetRow defaultRow = new DataSetRow(rowMetadata);
columns.forEach(column -> defaultRow.set(column.getId(), EMPTY));
return defaultRow;
}
use of org.talend.dataprep.api.dataset.row.DataSetRow in project data-prep by Talend.
the class DateCalendarConverterTest method testCompileShouldComputeToAndFromInternalContextParameters.
@Test
public void testCompileShouldComputeToAndFromInternalContextParameters() {
// Given
final DateCalendarConverter calendarConverter = new DateCalendarConverter();
final DataSetRow row = builder().with(value("toto").type(Type.STRING).name("recipe")).with(value("10/29/1996").type(Type.DATE).name("last update").statistics(getDateTestJsonAsStream("statistics_MM_dd_yyyy.json"))).with(//
value("tata").type(Type.STRING).name("who")).build();
final ActionContext context = new ActionContext(new TransformationContext(), row.getRowMetadata());
context.setActionStatus(ActionContext.ActionStatus.OK);
final Map<String, String> parameters = new HashMap<>();
parameters.put(ImplicitParameters.SCOPE.getKey().toLowerCase(), "column");
parameters.put(COLUMN_ID.getKey(), "0001");
parameters.put(FROM_CALENDAR_TYPE_PARAMETER, DateCalendarConverter.CalendarUnit.ISO.name());
parameters.put(TO_CALENDAR_TYPE_PARAMETER, CalendarUnit.JULIAN_DAY.name());
context.setParameters(parameters);
// When
calendarConverter.compile(context);
// Then
assertTrue(context.get(IS_FROM_CHRONOLOGY_INTERNAL_KEY));
assertFalse(context.get(IS_TO_CHRONOLOGY_INTERNAL_KEY));
}
use of org.talend.dataprep.api.dataset.row.DataSetRow in project data-prep by Talend.
the class DateCalendarConverterTest method testConversionJapaneseToISO_InvalidDateWithEra.
@Test
public void testConversionJapaneseToISO_InvalidDateWithEra() {
// given
Map<String, String> rowContent = new HashMap<>();
rowContent.put("0000", "Lucy");
rowContent.put("0001", "0008/02/30 平成");
final DataSetRow row = new DataSetRow(rowContent);
row.getRowMetadata().getColumns().get(1).getStatistics().getPatternFrequencies().add(new PatternFrequency("yyyy/MM/dd G", 1));
final Map<String, String> parameters = new HashMap<>();
parameters.put(ImplicitParameters.SCOPE.getKey().toLowerCase(), "column");
parameters.put(COLUMN_ID.getKey(), "0001");
parameters.put(FROM_CALENDAR_TYPE_PARAMETER, DateCalendarConverter.CalendarUnit.JAPANESE.name());
parameters.put(TO_CALENDAR_TYPE_PARAMETER, DateCalendarConverter.CalendarUnit.ISO.name());
// when
ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
// then
// February 30 does not exist, can not parse even the Era part exists.
// invalid date
assertEquals("0008/02/30 平成", row.get("0001"));
}
Aggregations