Search in sources :

Example 51 with DataSetMetadata

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

the class SchemaAnalysisTest method initializeDataSetMetadata.

/**
 * Initialize a dataset with the given content. Perform the format and the schema analysis.
 *
 * @param content the dataset content.
 * @return the analyzed dataset metadata.
 */
private DataSetMetadata initializeDataSetMetadata(InputStream content) {
    String id = UUID.randomUUID().toString();
    final DataSetMetadata metadata = metadataBuilder.metadata().id(id).build();
    dataSetMetadataRepository.save(metadata);
    contentStore.storeAsRaw(metadata, content);
    formatAnalysis.analyze(id);
    contentAnalysis.analyze(id);
    // Analyze schema
    schemaAnalysis.analyze(id);
    final DataSetMetadata analyzed = dataSetMetadataRepository.get(id);
    assertNotNull(analyzed);
    assertNotNull(analyzed.getLifecycle());
    assertThat(analyzed.getLifecycle().schemaAnalyzed(), is(true));
    return analyzed;
}
Also used : DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata)

Example 52 with DataSetMetadata

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

the class SchemaAnalysisTest method testTDP_471.

/**
 * See <a href="https://jira.talendforge.org/browse/TDP-471">https://jira.talendforge.org/browse/TDP-471</a>.
 *
 * @throws Exception
 */
@Test
public void testTDP_471() {
    final DataSetMetadata actual = initializeDataSetMetadata(DataSetServiceTest.class.getResourceAsStream("../semantic_type_threshold.csv"));
    assertThat(actual.getLifecycle().schemaAnalyzed(), is(true));
    String[] expectedNames = { "gender_column" };
    Type[] expectedTypes = { Type.INTEGER };
    String[] expectedDomains = { "" };
    int i = 0;
    for (ColumnMetadata column : actual.getRowMetadata().getColumns()) {
        assertThat(column.getName(), is(expectedNames[i]));
        assertThat(column.getType(), is(expectedTypes[i].getName()));
        assertThat(column.getDomain(), is(expectedDomains[i++]));
        assertThat(column.getSemanticDomains()).isNotNull().isNotEmpty().hasSize(2).contains(// 
        new SemanticDomain("GENDER", "Gender", (float) 35), new SemanticDomain("CIVILITY", "Civility", (float) 20.833334));
    }
}
Also used : Type(org.talend.dataprep.api.type.Type) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) DataSetServiceTest(org.talend.dataprep.dataset.service.DataSetServiceTest) SemanticDomain(org.talend.dataprep.api.dataset.statistics.SemanticDomain) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test) DataSetBaseTest(org.talend.dataprep.dataset.DataSetBaseTest) DataSetServiceTest(org.talend.dataprep.dataset.service.DataSetServiceTest)

Example 53 with DataSetMetadata

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

the class SchemaAnalysisTest method testTDP_855.

/**
 * See <a href="https://jira.talendforge.org/browse/TDP-855">TDP-855_movie_title_detected_as_city</a>.
 */
@Test
public void testTDP_855() {
    final DataSetMetadata actual = initializeDataSetMetadata(DataSetServiceTest.class.getResourceAsStream("../TDP-855_movie_title_detected_as_city.csv"));
    assertThat(actual.getLifecycle().schemaAnalyzed(), is(true));
    ColumnMetadata column = actual.getRowMetadata().getColumns().get(0);
    String expectedName = "Genre: (Movie, Program, show)";
    Type expectedType = Type.STRING;
    assertThat(expectedName, is(column.getName()));
    assertThat(expectedType.getName(), is(column.getType()));
    assertThat("", is(column.getDomainLabel()));
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) Type(org.talend.dataprep.api.type.Type) DataSetServiceTest(org.talend.dataprep.dataset.service.DataSetServiceTest) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test) DataSetBaseTest(org.talend.dataprep.dataset.DataSetBaseTest) DataSetServiceTest(org.talend.dataprep.dataset.service.DataSetServiceTest)

Example 54 with DataSetMetadata

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

the class SchemaAnalysisTest method testAnalysis.

@Test
public void testAnalysis() {
    final DataSetMetadata actual = initializeDataSetMetadata(DataSetServiceTest.class.getResourceAsStream("../avengers.csv"));
    assertThat(actual.getLifecycle().schemaAnalyzed(), is(true));
    String[] expectedNames = { "nickname", "secret firstname", "secret lastname", "date of birth", "city" };
    Type[] expectedTypes = { Type.STRING, Type.STRING, Type.STRING, Type.DATE, Type.STRING };
    int i = 0;
    int j = 0;
    for (ColumnMetadata column : actual.getRowMetadata().getColumns()) {
        assertThat(column.getName(), is(expectedNames[i++]));
        assertThat(column.getType(), is(expectedTypes[j++].getName()));
    }
}
Also used : Type(org.talend.dataprep.api.type.Type) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) DataSetServiceTest(org.talend.dataprep.dataset.service.DataSetServiceTest) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) Test(org.junit.Test) DataSetBaseTest(org.talend.dataprep.dataset.DataSetBaseTest) DataSetServiceTest(org.talend.dataprep.dataset.service.DataSetServiceTest)

Example 55 with DataSetMetadata

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

the class TransformationService method getSemanticDomains.

/**
 * Return the semantic domains for the given parameters.
 *
 * @param metadata the dataset metadata.
 * @param columnId the column id to analyze.
 * @param records the dataset records.
 * @return the semantic domains for the given parameters.
 * @throws IOException can happen...
 */
private List<SemanticDomain> getSemanticDomains(DataSetMetadata metadata, String columnId, InputStream records) throws IOException {
    // copy the column metadata and set the semantic domain forced flag to false to make sure the statistics adapter set all
    // available domains
    final ColumnMetadata columnMetadata = // 
    column().copy(// 
    metadata.getRowMetadata().getById(columnId)).semanticDomainForce(// 
    false).build();
    final Analyzer<Analyzers.Result> analyzer = analyzerService.build(columnMetadata, SEMANTIC);
    analyzer.init();
    try (final JsonParser parser = mapper.getFactory().createParser(new InputStreamReader(records, UTF_8))) {
        final DataSet dataSet = mapper.readerFor(DataSet.class).readValue(parser);
        dataSet.getRecords().map(// 
        r -> r.get(columnId)).forEach(analyzer::analyze);
        analyzer.end();
    }
    final List<Analyzers.Result> analyzerResult = analyzer.getResult();
    statisticsAdapter.adapt(singletonList(columnMetadata), analyzerResult);
    return columnMetadata.getSemanticDomains();
}
Also used : VolumeMetered(org.talend.dataprep.metrics.VolumeMetered) LocaleContextHolder(org.springframework.context.i18n.LocaleContextHolder) StringUtils(org.apache.commons.lang.StringUtils) ContentCacheKey(org.talend.dataprep.cache.ContentCacheKey) TdqCategories(org.talend.dataquality.semantic.broadcast.TdqCategories) Autowired(org.springframework.beans.factory.annotation.Autowired) ApiParam(io.swagger.annotations.ApiParam) PreviewParameters(org.talend.dataprep.transformation.preview.api.PreviewParameters) ExportFormatMessage(org.talend.dataprep.format.export.ExportFormatMessage) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) Collections.singletonList(java.util.Collections.singletonList) ScopeCategory(org.talend.dataprep.transformation.actions.category.ScopeCategory) Valid(javax.validation.Valid) SemanticDomain(org.talend.dataprep.api.dataset.statistics.SemanticDomain) BeanConversionService(org.talend.dataprep.conversions.BeanConversionService) GetPrepMetadataAsyncCondition(org.talend.dataprep.async.conditional.GetPrepMetadataAsyncCondition) TaskExecutor(org.springframework.core.task.TaskExecutor) DataSet(org.talend.dataprep.api.dataset.DataSet) ExportParametersUtil(org.talend.dataprep.api.export.ExportParametersUtil) StepDiff(org.talend.dataprep.api.preparation.StepDiff) PreparationDetailsGet(org.talend.dataprep.command.preparation.PreparationDetailsGet) HEAD(org.talend.dataprep.api.export.ExportParameters.SourceType.HEAD) APPLICATION_OCTET_STREAM_VALUE(org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE) Resource(javax.annotation.Resource) StreamingResponseBody(org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody) JSON(org.talend.dataprep.transformation.format.JsonFormat.JSON) PreparationGetContentUrlGenerator(org.talend.dataprep.async.result.PreparationGetContentUrlGenerator) SecurityProxy(org.talend.dataprep.security.SecurityProxy) Stream(java.util.stream.Stream) Builder.column(org.talend.dataprep.api.dataset.ColumnMetadata.Builder.column) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) GZIPOutputStream(java.util.zip.GZIPOutputStream) DynamicType(org.talend.dataprep.transformation.api.action.dynamic.DynamicType) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) Analyzers(org.talend.dataquality.common.inference.Analyzers) java.util(java.util) TransformationErrorCodes(org.talend.dataprep.exception.error.TransformationErrorCodes) GenericParameter(org.talend.dataprep.transformation.api.action.dynamic.GenericParameter) Configuration(org.talend.dataprep.transformation.api.transformer.configuration.Configuration) PreviewConfiguration(org.talend.dataprep.transformation.api.transformer.configuration.PreviewConfiguration) AnalyzerService(org.talend.dataprep.quality.AnalyzerService) TransformationMetadataCacheKey(org.talend.dataprep.cache.TransformationMetadataCacheKey) PrepMetadataExecutionIdGenerator(org.talend.dataprep.async.generator.PrepMetadataExecutionIdGenerator) PREPARATION_DOES_NOT_EXIST(org.talend.dataprep.exception.error.PreparationErrorCodes.PREPARATION_DOES_NOT_EXIST) Api(io.swagger.annotations.Api) Preparation(org.talend.dataprep.api.preparation.Preparation) ActionRegistry(org.talend.dataprep.transformation.pipeline.ActionRegistry) GetPrepContentAsyncCondition(org.talend.dataprep.async.conditional.GetPrepContentAsyncCondition) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) AggregationService(org.talend.dataprep.transformation.aggregation.AggregationService) NullOutputStream(org.apache.commons.io.output.NullOutputStream) StatisticsAdapter(org.talend.dataprep.dataset.StatisticsAdapter) DataSetGetMetadata(org.talend.dataprep.command.dataset.DataSetGetMetadata) Timed(org.talend.dataprep.metrics.Timed) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) DataSetGet(org.talend.dataprep.command.dataset.DataSetGet) AggregationResult(org.talend.dataprep.transformation.aggregation.api.AggregationResult) LoggerFactory(org.slf4j.LoggerFactory) Flag(org.talend.dataprep.api.dataset.row.Flag) SEMANTIC(org.talend.dataprep.quality.AnalyzerService.Analysis.SEMANTIC) ActionParser(org.talend.dataprep.transformation.api.action.ActionParser) CacheKeyGenerator(org.talend.dataprep.cache.CacheKeyGenerator) ApiOperation(io.swagger.annotations.ApiOperation) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) ExportParameters(org.talend.dataprep.api.export.ExportParameters) PrepMetadataGetContentUrlGenerator(org.talend.dataprep.async.result.PrepMetadataGetContentUrlGenerator) MediaType(org.springframework.http.MediaType) PublicAPI(org.talend.dataprep.security.PublicAPI) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) Collectors(java.util.stream.Collectors) ContentCache(org.talend.dataprep.cache.ContentCache) UNEXPECTED_EXCEPTION(org.talend.dataprep.exception.error.TransformationErrorCodes.UNEXPECTED_EXCEPTION) TransformerFactory(org.talend.dataprep.transformation.api.transformer.TransformerFactory) CommonErrorCodes(org.talend.dataprep.exception.error.CommonErrorCodes) Analyzer(org.talend.dataquality.common.inference.Analyzer) ActionDefinition(org.talend.dataprep.api.action.ActionDefinition) PreparationExportStrategy(org.talend.dataprep.transformation.service.export.PreparationExportStrategy) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) ExportFormat(org.talend.dataprep.format.export.ExportFormat) TDPException(org.talend.dataprep.exception.TDPException) JsonErrorCodeDescription(org.talend.dataprep.exception.json.JsonErrorCodeDescription) ExceptionContext.build(org.talend.daikon.exception.ExceptionContext.build) ExportParametersExecutionIdGenerator(org.talend.dataprep.async.generator.ExportParametersExecutionIdGenerator) ExceptionContext(org.talend.daikon.exception.ExceptionContext) org.talend.dataprep.async(org.talend.dataprep.async) Suggestion(org.talend.dataprep.transformation.api.transformer.suggestion.Suggestion) SuggestionEngine(org.talend.dataprep.transformation.api.transformer.suggestion.SuggestionEngine) Logger(org.slf4j.Logger) LocaleContextHolder.getLocale(org.springframework.context.i18n.LocaleContextHolder.getLocale) JsonParser(com.fasterxml.jackson.core.JsonParser) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Step(org.talend.dataprep.api.preparation.Step) APPLICATION_JSON_VALUE(org.springframework.http.MediaType.APPLICATION_JSON_VALUE) ApplicationContext(org.springframework.context.ApplicationContext) ActionForm(org.talend.dataprep.api.action.ActionForm) AggregationParameters(org.talend.dataprep.transformation.aggregation.api.AggregationParameters) java.io(java.io) TdqCategoriesFactory(org.talend.dataquality.semantic.broadcast.TdqCategoriesFactory) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) DataSet(org.talend.dataprep.api.dataset.DataSet) AggregationResult(org.talend.dataprep.transformation.aggregation.api.AggregationResult) JsonParser(com.fasterxml.jackson.core.JsonParser)

Aggregations

DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)192 Test (org.junit.Test)126 DataSetBaseTest (org.talend.dataprep.dataset.DataSetBaseTest)63 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)48 InputStream (java.io.InputStream)45 Matchers.containsString (org.hamcrest.Matchers.containsString)28 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)28 TDPException (org.talend.dataprep.exception.TDPException)26 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)20 DataSetServiceTest (org.talend.dataprep.dataset.service.DataSetServiceTest)20 ApiOperation (io.swagger.annotations.ApiOperation)18 DataSet (org.talend.dataprep.api.dataset.DataSet)18 Type (org.talend.dataprep.api.type.Type)17 Timed (org.talend.dataprep.metrics.Timed)17 DistributedLock (org.talend.dataprep.lock.DistributedLock)16 Autowired (org.springframework.beans.factory.annotation.Autowired)14 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)14 IOException (java.io.IOException)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 ArrayList (java.util.ArrayList)12