Search in sources :

Example 6 with RowMetadata

use of org.talend.dataprep.api.dataset.RowMetadata 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 7 with RowMetadata

use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.

the class ClearMatching method toClear.

@Override
public boolean toClear(DataSetRow dataSetRow, String columnId, ActionContext actionContext) {
    final Map<String, String> parameters = actionContext.getParameters();
    final RowMetadata rowMetadata = actionContext.getRowMetadata();
    final ColumnMetadata columnMetadata = rowMetadata.getById(columnId);
    final String value = dataSetRow.get(columnId);
    final String equalsValue = parameters.get(VALUE_PARAMETER);
    if (Type.get(columnMetadata.getType()) == Type.BOOLEAN) {
        // for boolean we can accept True equalsIgnoreCase true
        return StringUtils.equalsIgnoreCase(value, equalsValue);
    } else {
        ReplaceOnValueHelper replaceOnValueHelper = new ReplaceOnValueHelper().build(equalsValue, true);
        return replaceOnValueHelper.matches(value);
    }
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) ReplaceOnValueHelper(org.talend.dataprep.transformation.actions.common.ReplaceOnValueHelper) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata)

Example 8 with RowMetadata

use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.

the class DataSetRow method filter.

public DataSetRow filter(List<ColumnMetadata> filteredColumns) {
    final Set<String> columnsToKeep = filteredColumns.stream().map(ColumnMetadata::getId).collect(Collectors.toSet());
    final Set<String> columnsToDelete = values.entrySet().stream().filter(// 
    e -> !columnsToKeep.contains(e.getKey())).map(Map.Entry::getKey).collect(Collectors.toSet());
    final RowMetadata rowMetadataClone = rowMetadata.clone();
    final LinkedHashMap<String, String> filteredValues = new LinkedHashMap<>(this.values);
    for (String columnId : columnsToDelete) {
        filteredValues.remove(columnId);
        rowMetadataClone.deleteColumnById(columnId);
    }
    final DataSetRow filteredDataSetRow = new DataSetRow(rowMetadataClone, filteredValues);
    filteredDataSetRow.invalidColumnIds.addAll(invalidColumnIds);
    return filteredDataSetRow;
}
Also used : RowMetadata(org.talend.dataprep.api.dataset.RowMetadata)

Example 9 with RowMetadata

use of org.talend.dataprep.api.dataset.RowMetadata 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 10 with RowMetadata

use of org.talend.dataprep.api.dataset.RowMetadata 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)

Aggregations

RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)199 Test (org.junit.Test)130 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)112 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)87 AbstractMetadataBaseTest (org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)68 HashMap (java.util.HashMap)48 ActionContext (org.talend.dataprep.transformation.api.action.context.ActionContext)21 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)20 RunnableAction (org.talend.dataprep.transformation.actions.common.RunnableAction)19 TransformationContext (org.talend.dataprep.transformation.api.action.context.TransformationContext)18 ArrayList (java.util.ArrayList)16 DataSet (org.talend.dataprep.api.dataset.DataSet)11 List (java.util.List)9 Statistics (org.talend.dataprep.api.dataset.statistics.Statistics)9 Before (org.junit.Before)7 SemanticDomain (org.talend.dataprep.api.dataset.statistics.SemanticDomain)6 Preparation (org.talend.dataprep.api.preparation.Preparation)6 Response (com.jayway.restassured.response.Response)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Logger (org.slf4j.Logger)5