Search in sources :

Example 1 with DataSetRow

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;
}
Also used : RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow)

Example 2 with DataSetRow

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);
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) List(java.util.List) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow)

Example 3 with DataSetRow

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;
}
Also used : RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow)

Example 4 with DataSetRow

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));
}
Also used : DateCalendarConverter(org.talend.dataprep.transformation.actions.date.DateCalendarConverter) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Example 5 with DataSetRow

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"));
}
Also used : PatternFrequency(org.talend.dataprep.api.dataset.statistics.PatternFrequency) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Aggregations

DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)729 Test (org.junit.Test)688 AbstractMetadataBaseTest (org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)518 HashMap (java.util.HashMap)235 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)111 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)81 LinkedHashMap (java.util.LinkedHashMap)45 RunnableAction (org.talend.dataprep.transformation.actions.common.RunnableAction)21 ActionContext (org.talend.dataprep.transformation.api.action.context.ActionContext)16 TransformationContext (org.talend.dataprep.transformation.api.action.context.TransformationContext)16 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)14 ArrayList (java.util.ArrayList)13 ChangeDatePatternTest (org.talend.dataprep.transformation.actions.date.ChangeDatePatternTest)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 AbstractTransformerWriterTest (org.talend.dataprep.transformation.api.transformer.AbstractTransformerWriterTest)12 List (java.util.List)11 PatternFrequency (org.talend.dataprep.api.dataset.statistics.PatternFrequency)11 DataSet (org.talend.dataprep.api.dataset.DataSet)10 Stream (java.util.stream.Stream)6 TDPException (org.talend.dataprep.exception.TDPException)6