Search in sources :

Example 1 with WhereRuleIndicator

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

the class DQRuleUtilities method createIndicatorUnit.

/**
 * DOC xqliu Comment method "createIndicatorUnit".
 *
 * @param fe
 * @param tableIndicator
 * @param analysis
 * @return
 */
public static TableIndicatorUnit createIndicatorUnit(RuleRepNode ruleRepNode, TableIndicator tableIndicator, Analysis analysis) {
    IndicatorDefinition whereRule = ruleRepNode.getRule();
    for (Indicator indicator : tableIndicator.getIndicators()) {
        if (whereRule.getName().equals(indicator.getName())) {
            return null;
        }
    }
    WhereRuleIndicator[] compositeWhereRuleIndicator = createCompositeWhereRuleIndicator(tableIndicator.getColumnSet(), whereRule);
    IndicatorEnum type = IndicatorEnum.findIndicatorEnum(compositeWhereRuleIndicator[0].eClass());
    TableIndicatorUnit addIndicatorUnit = tableIndicator.addSpecialIndicator(whereRule, type, compositeWhereRuleIndicator[0]);
    DependenciesHandler.getInstance().setUsageDependencyOn(analysis, whereRule);
    return addIndicatorUnit;
}
Also used : WhereRuleIndicator(org.talend.dataquality.indicators.sql.WhereRuleIndicator) IndicatorEnum(org.talend.dq.nodes.indicator.type.IndicatorEnum) TableIndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.TableIndicatorUnit) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) TableIndicator(org.talend.dataprofiler.core.model.TableIndicator) Indicator(org.talend.dataquality.indicators.Indicator) WhereRuleIndicator(org.talend.dataquality.indicators.sql.WhereRuleIndicator)

Example 2 with WhereRuleIndicator

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

the class IndicatorHelper method getIndicatorValue.

/**
 * DOC bZhou Comment method "getIndicatorValue".
 *
 * @param indicator
 * @return
 */
public static String getIndicatorValue(Indicator indicator) {
    IndicatorsSwitch<String> mySwitch = new IndicatorsSwitch<String>() {

        @Override
        public String caseAverageLengthIndicator(AverageLengthIndicator object) {
            return createStandardNumber(object.getAverageLength());
        }

        @Override
        public String caseBlankCountIndicator(BlankCountIndicator object) {
            return String.valueOf(object.getBlankCount());
        }

        @Override
        public String caseDefValueCountIndicator(DefValueCountIndicator object) {
            return String.valueOf(object.getDefaultValCount());
        }

        @Override
        public String caseDistinctCountIndicator(DistinctCountIndicator object) {
            return String.valueOf(object.getDistinctValueCount());
        }

        @Override
        public String caseDuplicateCountIndicator(DuplicateCountIndicator object) {
            return String.valueOf(object.getDuplicateValueCount());
        }

        @Override
        public String caseMaxLengthIndicator(MaxLengthIndicator object) {
            return String.valueOf(object.getLength());
        }

        @Override
        public String caseMeanIndicator(MeanIndicator object) {
            return createStandardNumber(object.getMean());
        }

        @Override
        public String caseMedianIndicator(MedianIndicator object) {
            return createStandardNumber(object.getMedian());
        }

        @Override
        public String caseMinLengthIndicator(MinLengthIndicator object) {
            return String.valueOf(object.getLength());
        }

        @Override
        public String caseModeIndicator(ModeIndicator object) {
            return String.valueOf(object.getMode());
        }

        @Override
        public String caseNullCountIndicator(NullCountIndicator object) {
            return String.valueOf(object.getNullCount());
        }

        @Override
        public String casePatternMatchingIndicator(PatternMatchingIndicator object) {
            return String.valueOf(object.getMatchingValueCount());
        }

        @Override
        public String caseRowCountIndicator(RowCountIndicator object) {
            return String.valueOf(object.getCount());
        }

        @Override
        public String caseUniqueCountIndicator(UniqueCountIndicator object) {
            return String.valueOf(object.getUniqueValueCount());
        }

        @Override
        public String caseValueIndicator(ValueIndicator object) {
            return object.getValue();
        }

        @Override
        public String caseValidPhoneCountIndicator(ValidPhoneCountIndicator object) {
            return String.valueOf(object.getValidPhoneNumCount());
        }

        @Override
        public String casePossiblePhoneCountIndicator(PossiblePhoneCountIndicator object) {
            return String.valueOf(object.getPossiblePhoneCount());
        }

        @Override
        public String caseValidRegCodeCountIndicator(ValidRegCodeCountIndicator object) {
            return String.valueOf(object.getValidRegCount());
        }

        @Override
        public String caseInvalidRegCodeCountIndicator(InvalidRegCodeCountIndicator object) {
            return String.valueOf(object.getInvalidRegCount());
        }

        @Override
        public String caseWellFormE164PhoneCountIndicator(WellFormE164PhoneCountIndicator object) {
            return String.valueOf(object.getWellFormE164PhoneCount());
        }

        @Override
        public String caseWellFormIntePhoneCountIndicator(WellFormIntePhoneCountIndicator object) {
            return String.valueOf(object.getWellFormIntePhoneCount());
        }

        @Override
        public String caseWellFormNationalPhoneCountIndicator(WellFormNationalPhoneCountIndicator object) {
            return String.valueOf(object.getWellFormNatiPhoneCount());
        }
    };
    // TDQ-11114: consider the UDI type
    IndicatorSqlSwitch<String> sqlSwitch = new IndicatorSqlSwitch<String>() {

        @Override
        public String caseWhereRuleIndicator(WhereRuleIndicator object) {
            return String.valueOf(object.getUserCount());
        }

        @Override
        public String caseUserDefIndicator(UserDefIndicator object) {
            // TDQ-11114: get the correct value for user define realvalue indicator
            if (object instanceof UserDefIndicator) {
                UserDefIndicator userDefineIndicator = object;
                IndicatorCategory category = IndicatorCategoryHelper.getCategory(userDefineIndicator.getIndicatorDefinition());
                if (IndicatorCategoryHelper.isUserDefRealValue(category)) {
                    return String.valueOf(userDefineIndicator.getRealValue());
                }
            }
            // TDQ-11485: fix the match udi get result value error
            return String.valueOf(object.getIntegerValue());
        }

        @Override
        public String caseJavaUserDefIndicator(JavaUserDefIndicator object) {
            return String.valueOf(object.getUserCount());
        }
    };
    String result = mySwitch.doSwitch(indicator);
    return result == null ? sqlSwitch.doSwitch(indicator) : result;
}
Also used : BlankCountIndicator(org.talend.dataquality.indicators.BlankCountIndicator) MedianIndicator(org.talend.dataquality.indicators.MedianIndicator) UniqueCountIndicator(org.talend.dataquality.indicators.UniqueCountIndicator) ModeIndicator(org.talend.dataquality.indicators.ModeIndicator) NullCountIndicator(org.talend.dataquality.indicators.NullCountIndicator) DistinctCountIndicator(org.talend.dataquality.indicators.DistinctCountIndicator) WellFormIntePhoneCountIndicator(org.talend.dataquality.indicators.WellFormIntePhoneCountIndicator) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) WhereRuleIndicator(org.talend.dataquality.indicators.sql.WhereRuleIndicator) IndicatorCategory(org.talend.dataquality.indicators.definition.IndicatorCategory) IndicatorsSwitch(org.talend.dataquality.indicators.util.IndicatorsSwitch) RowCountIndicator(org.talend.dataquality.indicators.RowCountIndicator) MeanIndicator(org.talend.dataquality.indicators.MeanIndicator) JavaUserDefIndicator(org.talend.dataquality.indicators.sql.JavaUserDefIndicator) UserDefIndicator(org.talend.dataquality.indicators.sql.UserDefIndicator) IndicatorSqlSwitch(org.talend.dataquality.indicators.sql.util.IndicatorSqlSwitch) PossiblePhoneCountIndicator(org.talend.dataquality.indicators.PossiblePhoneCountIndicator) WellFormE164PhoneCountIndicator(org.talend.dataquality.indicators.WellFormE164PhoneCountIndicator) ValidPhoneCountIndicator(org.talend.dataquality.indicators.ValidPhoneCountIndicator) DuplicateCountIndicator(org.talend.dataquality.indicators.DuplicateCountIndicator) MaxLengthIndicator(org.talend.dataquality.indicators.MaxLengthIndicator) MaxValueIndicator(org.talend.dataquality.indicators.MaxValueIndicator) MinValueIndicator(org.talend.dataquality.indicators.MinValueIndicator) ValueIndicator(org.talend.dataquality.indicators.ValueIndicator) ValidRegCodeCountIndicator(org.talend.dataquality.indicators.ValidRegCodeCountIndicator) MinLengthIndicator(org.talend.dataquality.indicators.MinLengthIndicator) InvalidRegCodeCountIndicator(org.talend.dataquality.indicators.InvalidRegCodeCountIndicator) JavaUserDefIndicator(org.talend.dataquality.indicators.sql.JavaUserDefIndicator) DefValueCountIndicator(org.talend.dataquality.indicators.DefValueCountIndicator) AverageLengthIndicator(org.talend.dataquality.indicators.AverageLengthIndicator) WellFormNationalPhoneCountIndicator(org.talend.dataquality.indicators.WellFormNationalPhoneCountIndicator)

Example 3 with WhereRuleIndicator

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

the class DQRuleUtilities method createCompositeWhereRuleIndicator.

/**
 * @return 0 based index is WhereRuleIndicator
 */
public static WhereRuleIndicator[] createCompositeWhereRuleIndicator(ModelElement anaElement, IndicatorDefinition whereRuleDef) {
    WhereRuleIndicator wrIndicator = IndicatorSqlFactory.eINSTANCE.createWhereRuleIndicator();
    wrIndicator.setAnalyzedElement(anaElement);
    wrIndicator.setIndicatorDefinition(whereRuleDef);
    return new WhereRuleIndicator[] { wrIndicator };
}
Also used : WhereRuleIndicator(org.talend.dataquality.indicators.sql.WhereRuleIndicator)

Example 4 with WhereRuleIndicator

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

the class AElementPersistanceRealTest method testSaveWithDependenciesAnalysis.

/**
 * Test method for
 * {@link org.talend.dq.writer.AElementPersistance#saveWithDependencies(org.talend.core.model.properties.Item, orgomg.cwm.objectmodel.core.ModelElement)}
 * .
 *
 * @throws PersistenceException
 */
@Test
public void testSaveWithDependenciesAnalysis() throws PersistenceException {
    AnalysisWriter createAnalysisWriter = ElementWriterFactory.getInstance().createAnalysisWrite();
    String anaName = "AElementPersistanceRealTestanalysis5";
    // create analysis
    Analysis createAnalysis = AnalysisFactory.eINSTANCE.createAnalysis();
    AnalysisResult createAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
    AnalysisContext createAnalysisContext = AnalysisFactory.eINSTANCE.createAnalysisContext();
    createAnalysis.setResults(createAnalysisResult);
    createAnalysis.setContext(createAnalysisContext);
    createAnalysis.setName(anaName);
    // create analysis item
    TDQAnalysisItem createTDQAnalysisItem = PropertiesFactory.eINSTANCE.createTDQAnalysisItem();
    createTDQAnalysisItem.setAnalysis(createAnalysis);
    Property createAnalysisProperty = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
    // $NON-NLS-1$
    createAnalysisProperty.setLabel("AElementPersistanceRealTestanalysis5");
    createTDQAnalysisItem.setProperty(createAnalysisProperty);
    createAnalysisProperty.setId(EcoreUtil.generateUUID());
    ProxyRepositoryFactory.getInstance().create(createTDQAnalysisItem, Path.EMPTY, false);
    // create pattern match indicator
    WhereRuleIndicator whereRuleIndicator = IndicatorSqlFactory.eINSTANCE.createWhereRuleIndicator();
    // create definition
    createAnalysisResult.getIndicators().add(whereRuleIndicator);
    DQRule dqRule = RulesFactory.eINSTANCE.createWhereRule();
    whereRuleIndicator.setIndicatorDefinition(dqRule);
    TDQBusinessRuleItem createTDQBusinessRuleItem = PropertiesFactory.eINSTANCE.createTDQBusinessRuleItem();
    createTDQBusinessRuleItem.setDqrule(dqRule);
    Property createPatternProperty = org.talend.core.model.properties.PropertiesFactory.eINSTANCE.createProperty();
    // $NON-NLS-1$
    createPatternProperty.setLabel("AElementPersistanceRealTestDQRule5");
    createTDQBusinessRuleItem.setProperty(createPatternProperty);
    createPatternProperty.setId(EcoreUtil.generateUUID());
    ProxyRepositoryFactory.getInstance().create(createTDQBusinessRuleItem, Path.EMPTY, false);
    // $NON-NLS-1$
    String exceptedFileName = anaName + "_0.1.ana";
    ReturnCode create = createAnalysisWriter.saveWithDependencies(createTDQAnalysisItem, createAnalysis);
    assertTrue(create.isOk());
    Assert.assertEquals(exceptedFileName, createTDQAnalysisItem.getFilename());
    // $NON-NLS-1$
    String anaName2 = "ana52";
    // $NON-NLS-1$
    String exceptedFileName2 = anaName2 + "_0.1.ana";
    createAnalysis.setName(anaName2);
    create = createAnalysisWriter.saveWithDependencies(createTDQAnalysisItem, createAnalysis);
    assertTrue(create.isOk());
    Assert.assertEquals(exceptedFileName2, createTDQAnalysisItem.getFilename());
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) WhereRuleIndicator(org.talend.dataquality.indicators.sql.WhereRuleIndicator) Analysis(org.talend.dataquality.analysis.Analysis) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) TDQBusinessRuleItem(org.talend.dataquality.properties.TDQBusinessRuleItem) Property(org.talend.core.model.properties.Property) AnalysisWriter(org.talend.dq.writer.impl.AnalysisWriter) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) TDQAnalysisItem(org.talend.dataquality.properties.TDQAnalysisItem) DQRule(org.talend.dataquality.rules.DQRule) Test(org.junit.Test)

Example 5 with WhereRuleIndicator

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

the class TableAnalysisSqlExecutor method runAnalysis.

@Override
protected boolean runAnalysis(Analysis analysis, String sqlStatement) {
    boolean isSuccess = true;
    TypedReturnCode<java.sql.Connection> trc = this.getConnectionBeforeRun(analysis);
    if (!trc.isOk()) {
        log.error(trc.getMessage());
        traceError(Messages.getString("FunctionalDependencyExecutor.CANNOTEXECUTEANALYSIS", analysis.getName(), // $NON-NLS-1$
        trc.getMessage()));
        return Boolean.FALSE;
    }
    Connection connection = trc.getObject();
    try {
        Long rowCount = 0L;
        List<Indicator> indicatorList = IndicatorHelper.getIndicatorLeavesBySingleNode(analysis.getResults());
        // execute the row count
        Indicator rowIndicator = indicatorList.get(0);
        isSuccess = executeIndicator(rowIndicator, connection);
        publishDynamicEvent(rowIndicator);
        // remember the row count
        rowCount = rowIndicator.getCount();
        // execute the sql statement for each group of aide and rule
        for (int i = 1; i < indicatorList.size(); i++) {
            final Indicator rule = indicatorList.get(i);
            isSuccess = executeRule((WhereRuleIndicator) rule, connection);
            // if there's no joins, should use the row count as the count.
            if (isJoinConditionEmpty(rule)) {
                rule.setCount(rowCount);
            }
            publishDynamicEvent(rule);
        }
    } finally {
        ReturnCode rc = closeConnection(analysis, connection);
        if (!rc.isOk()) {
            appendError(rc.getMessage());
            isSuccess = Boolean.FALSE;
        }
    }
    return isSuccess;
}
Also used : TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ReturnCode(org.talend.utils.sugars.ReturnCode) WhereRuleIndicator(org.talend.dataquality.indicators.sql.WhereRuleIndicator) Connection(java.sql.Connection) Indicator(org.talend.dataquality.indicators.Indicator) WhereRuleIndicator(org.talend.dataquality.indicators.sql.WhereRuleIndicator)

Aggregations

WhereRuleIndicator (org.talend.dataquality.indicators.sql.WhereRuleIndicator)9 Indicator (org.talend.dataquality.indicators.Indicator)6 Connection (org.talend.core.model.metadata.builder.connection.Connection)3 DistinctCountIndicator (org.talend.dataquality.indicators.DistinctCountIndicator)3 DuplicateCountIndicator (org.talend.dataquality.indicators.DuplicateCountIndicator)3 PatternMatchingIndicator (org.talend.dataquality.indicators.PatternMatchingIndicator)3 PossiblePhoneCountIndicator (org.talend.dataquality.indicators.PossiblePhoneCountIndicator)3 RowCountIndicator (org.talend.dataquality.indicators.RowCountIndicator)3 UniqueCountIndicator (org.talend.dataquality.indicators.UniqueCountIndicator)3 ValidPhoneCountIndicator (org.talend.dataquality.indicators.ValidPhoneCountIndicator)3 WellFormE164PhoneCountIndicator (org.talend.dataquality.indicators.WellFormE164PhoneCountIndicator)3 WellFormIntePhoneCountIndicator (org.talend.dataquality.indicators.WellFormIntePhoneCountIndicator)3 WellFormNationalPhoneCountIndicator (org.talend.dataquality.indicators.WellFormNationalPhoneCountIndicator)3 ArrayList (java.util.ArrayList)2 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)2 TdTable (org.talend.cwm.relational.TdTable)2 Analysis (org.talend.dataquality.analysis.Analysis)2 DatePatternFreqIndicator (org.talend.dataquality.indicators.DatePatternFreqIndicator)2 EastAsiaPatternFreqIndicator (org.talend.dataquality.indicators.EastAsiaPatternFreqIndicator)2 EastAsiaPatternLowFreqIndicator (org.talend.dataquality.indicators.EastAsiaPatternLowFreqIndicator)2