Search in sources :

Example 1 with PatternMatchingIndicator

use of org.talend.dataquality.indicators.PatternMatchingIndicator in project tdq-studio-se by Talend.

the class PatternExplorerRealTest method testGetInvalidValuesStatement_3.

/**
 * Test method for {@link org.talend.dq.analysis.explore.PatternExplorer#getInvalidValuesStatement()}. when the test
 * for indicator is user define indicator
 */
@Test
public void testGetInvalidValuesStatement_3() {
    patternExplorer = new RegexPatternExplorer();
    // mock setEntity
    PatternMatchingIndicator indicator = IndicatorsFactoryImpl.eINSTANCE.createRegexpMatchingIndicator();
    UDIndicatorDefinition indicatorDef = UserdefineFactoryImpl.eINSTANCE.createUDIndicatorDefinition();
    indicator.setIndicatorDefinition(indicatorDef);
    TdExpression udiTdExpression = RelationalFactoryImpl.eINSTANCE.createTdExpression();
    udiTdExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
    udiTdExpression.setBody(ViewInvalidValues);
    indicatorDef.getViewInvalidValuesExpression().add(udiTdExpression);
    // create pattern parameter
    IndicatorParameters createIndicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
    indicator.setParameters(createIndicatorParameters);
    Domain createDomain = DomainFactoryImpl.eINSTANCE.createDomain();
    createIndicatorParameters.setDataValidDomain(createDomain);
    Pattern createPattern = PatternFactoryImpl.eINSTANCE.createPattern();
    createDomain.getPatterns().add(createPattern);
    RegularExpression createPatternComponent = PatternFactoryImpl.eINSTANCE.createRegularExpression();
    createPattern.getComponents().add(createPatternComponent);
    TdExpression createTdExpression = RelationalFactoryImpl.eINSTANCE.createTdExpression();
    createPatternComponent.setExpression(createTdExpression);
    createTdExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
    // $NON-NLS-1$
    createTdExpression.setBody("`su.*`");
    TdColumn element = RelationalFactoryImpl.eINSTANCE.createTdColumn();
    // $NON-NLS-1$
    element.setName("lname");
    TdTable createTdTable = RelationalFactoryImpl.eINSTANCE.createTdTable();
    // $NON-NLS-1$
    createTdTable.setName("table1");
    TableHelper.addColumn(createTdTable, element);
    Catalog createCatalog = orgomg.cwm.resource.relational.impl.RelationalFactoryImpl.eINSTANCE.createCatalog();
    // $NON-NLS-1$
    createCatalog.setName("catalog1");
    List<TdTable> tableList = new ArrayList<TdTable>();
    tableList.add(createTdTable);
    CatalogHelper.addTables(tableList, createCatalog);
    indicator.setAnalyzedElement(element);
    Expression createIndiExpression = CoreFactoryImpl.eINSTANCE.createExpression();
    createIndiExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
    // $NON-NLS-1$
    createIndiExpression.setBody("SELECT *  FROM `tbi`.`customer`  WHERE (customer.lname = \"sunny\")");
    indicator.setInstantiatedExpression(createIndiExpression);
    Analysis analysis = AnalysisFactoryImpl.eINSTANCE.createAnalysis();
    AnalysisContext createAnalysisContext = AnalysisFactoryImpl.eINSTANCE.createAnalysisContext();
    analysis.setContext(createAnalysisContext);
    DatabaseConnection createDatabaseConnection = ConnectionFactoryImpl.eINSTANCE.createDatabaseConnection();
    TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_PRODUCT_NAME, SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
    // $NON-NLS-1$
    TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_PRODUCT_VERSION, "1.0");
    // $NON-NLS-1$
    TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_IDENTIFIER_QUOTE_STRING, "`");
    createAnalysisContext.setConnection(createDatabaseConnection);
    ChartDataEntity cdEntity = new ChartDataEntity();
    cdEntity.setIndicator(indicator);
    Assert.assertTrue(patternExplorer.setAnalysis(analysis));
    patternExplorer.setEnitty(cdEntity);
    String clause = patternExplorer.getInvalidValuesStatement();
    // $NON-NLS-1$
    assertEquals("SELECT `lname` FROM `catalog1`.`table1` WHERE NOT (id>=1) ", clause);
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdTable(org.talend.cwm.relational.TdTable) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) ArrayList(java.util.ArrayList) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) ChartDataEntity(org.talend.dq.indicators.preview.table.ChartDataEntity) Catalog(orgomg.cwm.resource.relational.Catalog) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) TdColumn(org.talend.cwm.relational.TdColumn) TdExpression(org.talend.cwm.relational.TdExpression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Expression(orgomg.cwm.objectmodel.core.Expression) Analysis(org.talend.dataquality.analysis.Analysis) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Domain(org.talend.dataquality.domain.Domain) Test(org.junit.Test)

Example 2 with PatternMatchingIndicator

use of org.talend.dataquality.indicators.PatternMatchingIndicator in project tdq-studio-se by Talend.

the class PatternExplorerRealTest method testGetValidRowsStatement_5.

/**
 * Test method for {@link org.talend.dq.analysis.explore.PatternExplorer#getValidRowsStatement()}. when the test for
 * indicator is user define indicator
 */
@Test
public void testGetValidRowsStatement_5() {
    patternExplorer = new RegexPatternExplorer();
    // mock setEntity
    PatternMatchingIndicator indicator = IndicatorsFactoryImpl.eINSTANCE.createRegexpMatchingIndicator();
    UDIndicatorDefinition indicatorDef = UserdefineFactoryImpl.eINSTANCE.createUDIndicatorDefinition();
    indicator.setIndicatorDefinition(indicatorDef);
    TdExpression udiTdExpression = RelationalFactoryImpl.eINSTANCE.createTdExpression();
    udiTdExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
    udiTdExpression.setBody(ViewValidRows);
    indicatorDef.getViewValidRowsExpression().add(udiTdExpression);
    // create pattern parameter
    IndicatorParameters createIndicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
    indicator.setParameters(createIndicatorParameters);
    Domain createDomain = DomainFactoryImpl.eINSTANCE.createDomain();
    createIndicatorParameters.setDataValidDomain(createDomain);
    Pattern createPattern = PatternFactoryImpl.eINSTANCE.createPattern();
    createDomain.getPatterns().add(createPattern);
    RegularExpression createPatternComponent = PatternFactoryImpl.eINSTANCE.createRegularExpression();
    createPattern.getComponents().add(createPatternComponent);
    TdExpression createTdExpression = RelationalFactoryImpl.eINSTANCE.createTdExpression();
    createPatternComponent.setExpression(createTdExpression);
    createTdExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
    // $NON-NLS-1$
    createTdExpression.setBody("`su.*`");
    TdColumn element = RelationalFactoryImpl.eINSTANCE.createTdColumn();
    // $NON-NLS-1$
    element.setName("lname");
    TdTable createTdTable = RelationalFactoryImpl.eINSTANCE.createTdTable();
    // $NON-NLS-1$
    createTdTable.setName("table1");
    TableHelper.addColumn(createTdTable, element);
    Catalog createCatalog = orgomg.cwm.resource.relational.impl.RelationalFactoryImpl.eINSTANCE.createCatalog();
    // $NON-NLS-1$
    createCatalog.setName("catalog1");
    List<TdTable> tableList = new ArrayList<TdTable>();
    tableList.add(createTdTable);
    CatalogHelper.addTables(tableList, createCatalog);
    indicator.setAnalyzedElement(element);
    Expression createIndiExpression = CoreFactoryImpl.eINSTANCE.createExpression();
    createIndiExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
    // $NON-NLS-1$
    createIndiExpression.setBody("SELECT *  FROM `tbi`.`customer`  WHERE (customer.lname = \"sunny\")");
    indicator.setInstantiatedExpression(createIndiExpression);
    Analysis analysis = AnalysisFactoryImpl.eINSTANCE.createAnalysis();
    AnalysisContext createAnalysisContext = AnalysisFactoryImpl.eINSTANCE.createAnalysisContext();
    analysis.setContext(createAnalysisContext);
    DatabaseConnection createDatabaseConnection = ConnectionFactoryImpl.eINSTANCE.createDatabaseConnection();
    TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_PRODUCT_NAME, SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
    // $NON-NLS-1$
    TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_PRODUCT_VERSION, "1.0");
    // $NON-NLS-1$
    TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_IDENTIFIER_QUOTE_STRING, "`");
    createAnalysisContext.setConnection(createDatabaseConnection);
    ChartDataEntity cdEntity = new ChartDataEntity();
    cdEntity.setIndicator(indicator);
    Assert.assertTrue(patternExplorer.setAnalysis(analysis));
    patternExplorer.setEnitty(cdEntity);
    String clause = patternExplorer.getValidRowsStatement();
    // $NON-NLS-1$
    assertEquals("SELECT * FROM `catalog1`.`table1` ", clause);
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) TdTable(org.talend.cwm.relational.TdTable) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) ArrayList(java.util.ArrayList) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) ChartDataEntity(org.talend.dq.indicators.preview.table.ChartDataEntity) Catalog(orgomg.cwm.resource.relational.Catalog) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) TdColumn(org.talend.cwm.relational.TdColumn) TdExpression(org.talend.cwm.relational.TdExpression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Expression(orgomg.cwm.objectmodel.core.Expression) Analysis(org.talend.dataquality.analysis.Analysis) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Domain(org.talend.dataquality.domain.Domain) Test(org.junit.Test)

Example 3 with PatternMatchingIndicator

use of org.talend.dataquality.indicators.PatternMatchingIndicator in project tdq-studio-se by Talend.

the class AnalysisExecutorHelperTest method testCheckIndicatorWithOutDependencyFiles.

@Test
public void testCheckIndicatorWithOutDependencyFiles() {
    // Load analysis item/property model from test file.
    // $NON-NLS-1$
    String anaPropertyFile = "/data/builtin/indicator_without_dep/TDQ_Data_Profiling/Analyses/patternMatchAna_0.1.properties";
    Resource anaPropertyResource = getPlatformResource(anaPropertyFile);
    Analysis ana = null;
    Property anaProperty = null;
    while (anaPropertyResource.getAllContents().hasNext()) {
        EObject eobj = anaPropertyResource.getAllContents().next();
        if (eobj instanceof Property) {
            anaProperty = (Property) eobj;
            ana = ((TDQAnalysisItem) anaProperty.getItem()).getAnalysis();
            break;
        }
    }
    if (ana == null) {
        Assert.fail("The analysis is null!");
    }
    if (ana.getResults() == null) {
        Assert.fail("The result of analysis is null!");
    }
    if (ana.getResults().getIndicators() == null) {
        Assert.fail("The indicators of analysis is null!");
    }
    for (Indicator indicator : ana.getResults().getIndicators()) {
        if (!(indicator instanceof PatternMatchingIndicator)) {
            // Check system indicator and UDI
            assertTrue(indicator.getIndicatorDefinition().getName() != null);
            assertTrue(indicator.getBuiltInIndicatorDefinition() != null);
            assertTrue(indicator.getBuiltInIndicatorDefinition() == indicator.getIndicatorDefinition());
        }
    }
    ReturnCode rc = AnalysisExecutorHelper.check(ana);
    assertTrue(rc.isOk());
    for (Indicator indicator : ana.getResults().getIndicators()) {
        if (!(indicator instanceof PatternMatchingIndicator)) {
            // Check system indicator and UDI
            assertTrue(indicator.getIndicatorDefinition().getName() != null);
            assertTrue(indicator.getBuiltInIndicatorDefinition() != null);
            assertTrue(indicator.getBuiltInIndicatorDefinition() == indicator.getIndicatorDefinition());
        }
    }
}
Also used : PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) ReturnCode(org.talend.utils.sugars.ReturnCode) Analysis(org.talend.dataquality.analysis.Analysis) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) Property(org.talend.core.model.properties.Property) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) Test(org.junit.Test)

Example 4 with PatternMatchingIndicator

use of org.talend.dataquality.indicators.PatternMatchingIndicator in project tdq-studio-se by Talend.

the class AnalysisExecutorHelperTest method testCheckIndicatorWithOutDependencyFilesAndBuiltIn.

@Test
public void testCheckIndicatorWithOutDependencyFilesAndBuiltIn() {
    // Load analysis item/property model from test file.
    // $NON-NLS-1$
    String anaPropertyFile = "/data/builtin/indicator_without_dep_builtin/TDQ_Data_Profiling/Analyses/patternMatchAna_0.1.properties";
    Resource anaPropertyResource = getPlatformResource(anaPropertyFile);
    Analysis ana = null;
    Property anaProperty = null;
    while (anaPropertyResource.getAllContents().hasNext()) {
        EObject eobj = anaPropertyResource.getAllContents().next();
        if (eobj instanceof Property) {
            anaProperty = (Property) eobj;
            ana = ((TDQAnalysisItem) anaProperty.getItem()).getAnalysis();
            break;
        }
    }
    if (ana == null) {
        Assert.fail("The analysis is null!");
    }
    if (ana.getResults() == null) {
        Assert.fail("The result of analysis is null!");
    }
    if (ana.getResults().getIndicators() == null) {
        Assert.fail("The indicators of analysis is null!");
    }
    for (Indicator indicator : ana.getResults().getIndicators()) {
        if (!(indicator instanceof PatternMatchingIndicator)) {
            // Check system indicator and UDI
            assertTrue(indicator.getIndicatorDefinition().getName() == null);
            assertTrue(indicator.getBuiltInIndicatorDefinition() == null);
        }
    }
    ReturnCode rc = AnalysisExecutorHelper.check(ana);
    assertFalse(rc.isOk());
}
Also used : PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) ReturnCode(org.talend.utils.sugars.ReturnCode) Analysis(org.talend.dataquality.analysis.Analysis) EObject(org.eclipse.emf.ecore.EObject) Resource(org.eclipse.emf.ecore.resource.Resource) Property(org.talend.core.model.properties.Property) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) Test(org.junit.Test)

Example 5 with PatternMatchingIndicator

use of org.talend.dataquality.indicators.PatternMatchingIndicator in project tdq-studio-se by Talend.

the class AnalysisColumnNominalIntervalTreeViewer method createTreeMenu.

/**
 * DOC xzhao Comment method "createTreeMenu".
 *
 * @param newTree
 * @param containEdit
 */
private void createTreeMenu(final Tree newTree, boolean containEdit) {
    Menu oldMenu = newTree.getMenu();
    if (oldMenu != null && !oldMenu.isDisposed()) {
        oldMenu.dispose();
    }
    menu = new Menu(newTree);
    MenuItem deleteMenuItem = new MenuItem(menu, SWT.CASCADE);
    // $NON-NLS-1$
    deleteMenuItem.setText(DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.removeElement"));
    deleteMenuItem.setImage(ImageLib.getImage(ImageLib.DELETE_ACTION));
    deleteMenuItem.addSelectionListener(new SelectionAdapter() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse .swt.events.SelectionEvent)
             */
        @Override
        public void widgetSelected(SelectionEvent e) {
            removeSelectedElements(newTree);
        // MOD mzhao 2005-05-05 bug 6587.
        // MOD mzhao 2009-06-8, bug 5887.
        // updateBindConnection(masterPage, tree);
        }
    });
    // ADD 2009-01-07 mzhao for feature:0005664
    MenuItem showMenuItem = new MenuItem(menu, SWT.CASCADE);
    // $NON-NLS-1$
    showMenuItem.setText(DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.showDQElement"));
    showMenuItem.setImage(ImageLib.getImage(ImageLib.EXPLORE_IMAGE));
    showMenuItem.addSelectionListener(new SelectionAdapter() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse .swt.events.SelectionEvent)
             */
        @Override
        public void widgetSelected(SelectionEvent e) {
            TreeItem[] selection = newTree.getSelection();
            if (selection.length > 0) {
                // if DqRepository view is not openning we will not do anything
                DQRespositoryView dqview = CorePlugin.getDefault().findAndOpenRepositoryView();
                if (dqview == null) {
                    return;
                }
                // TdColumn tdColumn = (TdColumn) selection[0].getData(COLUMN_INDICATOR_KEY);
                dqview.showSelectedElements(selection[0].getData(COLUMN_INDICATOR_KEY));
            }
        }
    });
    if (containEdit) {
        editPatternMenuItem = new MenuItem(menu, SWT.CASCADE);
        // $NON-NLS-1$
        editPatternMenuItem.setText(DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.editPattern"));
        editPatternMenuItem.setImage(ImageLib.getImage(ImageLib.PATTERN_REG));
        editPatternMenuItem.addSelectionListener(new SelectionAdapter() {

            /*
                 * (non-Javadoc)
                 * 
                 * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org .eclipse.swt.events.SelectionEvent)
                 */
            @Override
            public void widgetSelected(SelectionEvent e) {
                TreeItem[] selection = tree.getSelection();
                if (selection.length > 0) {
                    TreeItem treeItem = selection[0];
                    IndicatorUnit indicatorUnit = (IndicatorUnit) treeItem.getData(INDICATOR_UNIT_KEY);
                    PatternMatchingIndicator indicator = (PatternMatchingIndicator) indicatorUnit.getIndicator();
                    Pattern pattern = indicator.getParameters().getDataValidDomain().getPatterns().get(0);
                    // MOD mzhao 2009-03-13 Feature 6066 Move all folders
                    // into one project.
                    IFile file = ResourceFileMap.findCorrespondingFile(pattern);
                    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
                    try {
                        activePage.openEditor(new FileEditorInput(file), // $NON-NLS-1$
                        "org.talend.dataprofiler.core.ui.editor.pattern.PatternEditor");
                    } catch (PartInitException e1) {
                        log.error(e1, e1);
                    }
                }
            }
        });
    }
    newTree.setMenu(menu);
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) IFile(org.eclipse.core.resources.IFile) TreeItem(org.eclipse.swt.widgets.TreeItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) IndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit) MenuItem(org.eclipse.swt.widgets.MenuItem) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) FileEditorInput(org.eclipse.ui.part.FileEditorInput) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) Menu(org.eclipse.swt.widgets.Menu) PartInitException(org.eclipse.ui.PartInitException) DQRespositoryView(org.talend.dataprofiler.core.ui.views.DQRespositoryView)

Aggregations

PatternMatchingIndicator (org.talend.dataquality.indicators.PatternMatchingIndicator)18 Pattern (org.talend.dataquality.domain.pattern.Pattern)12 ArrayList (java.util.ArrayList)8 Analysis (org.talend.dataquality.analysis.Analysis)8 Indicator (org.talend.dataquality.indicators.Indicator)8 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)8 Expression (orgomg.cwm.objectmodel.core.Expression)7 Test (org.junit.Test)6 TdExpression (org.talend.cwm.relational.TdExpression)6 Domain (org.talend.dataquality.domain.Domain)6 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)6 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)5 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)5 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)5 TdColumn (org.talend.cwm.relational.TdColumn)4 TdTable (org.talend.cwm.relational.TdTable)4 IndicatorUnit (org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit)4 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)4 UserDefIndicator (org.talend.dataquality.indicators.sql.UserDefIndicator)4 Catalog (orgomg.cwm.resource.relational.Catalog)4