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;
}
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;
}
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 };
}
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());
}
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;
}
Aggregations