Search in sources :

Example 51 with IndicatorParameters

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

the class BinFrequencyIndicatorImplTest method testHandleObject_1.

/**
 * Test method for {@link org.talend.dataquality.indicators.impl.BinFrequencyIndicatorImpl#handle(java.lang.Object)}
 * domain parameter is set in this case. .
 */
@Test
public void testHandleObject_1() {
    init();
    IndicatorParameters parameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
    // $NON-NLS-1$
    Domain domain = DomainHelper.createContiguousClosedBinsIntoDomain("test", 2, 1, 9);
    parameters.setBins(domain);
    binFreqIndicator.setParameters(parameters);
    binFreqIndicator.reset();
    int i = 1;
    binFreqIndicator.handle(i);
    HashMap<Object, Long> valueToFreq = binFreqIndicator.getValueToFreq();
    Long value = valueToFreq.get("id >= 1.0 AND id < 5.0");
    assertEquals(1l, value.longValue());
    i = 3;
    binFreqIndicator.handle(i);
    value = valueToFreq.get("id >= 1.0 AND id < 5.0");
    assertEquals(2l, value.longValue());
    i = 6;
    binFreqIndicator.handle(i);
    value = valueToFreq.get("id >= 5.0 AND id < 9.0");
    assertEquals(1l, value.longValue());
    Object obj = null;
    binFreqIndicator.handle(obj);
    value = valueToFreq.get(null);
    assertNull(value);
}
Also used : IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) Domain(org.talend.dataquality.domain.Domain) Test(org.junit.Test)

Example 52 with IndicatorParameters

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

the class ColumnAnalysisSqlExecutor method createSqlQuery.

/**
 * Method "createSqlQuery".
 *
 * @param dataFilterExpression
 * @param analysis
 * @param indicator
 *
 * @throws ParseException
 * @throws AnalysisExecutionException
 */
private boolean createSqlQuery(String dataFilterAsString, Indicator indicator) throws AnalysisExecutionException {
    TypedReturnCode<TdColumn> checkResult = getTdColumn(indicator);
    if (!checkResult.isOk()) {
        return false;
    }
    TdColumn tdColumn = checkResult.getObject();
    if (tdColumn.eIsProxy()) {
        tdColumn = (TdColumn) EObjectHelper.resolveObject(tdColumn);
    }
    TypedReturnCode<String> columnName = getColumnName(indicator, tdColumn);
    if (!columnName.isOk()) {
        return false;
    }
    String colName = columnName.getObject();
    TypedReturnCode<IndicatorDefinition> id = getIndicatorDefinition(indicator);
    if (!id.isOk()) {
        return false;
    }
    IndicatorDefinition indicatorDefinition = id.getObject();
    // get correct language for current database
    String language = dbms().getDbmsName();
    // --- create select statement
    // get indicator's sql columnS (generate the real SQL statement from its definition)
    Expression sqlGenericExpression = dbms().getSqlExpression(indicatorDefinition);
    final EClass indicatorEclass = indicator.eClass();
    if (sqlGenericExpression == null || sqlGenericExpression.getBody() == null) {
        // analysis, will not check the sql expression and create again(from the definition).
        if (UDIHelper.isUDI(indicator) && indicator.getInstantiatedExpressions().size() > 0) {
            return Boolean.TRUE;
        }
        // expressions.
        if (IndicatorsPackage.eINSTANCE.getRegexpMatchingIndicator().equals(indicatorEclass)) {
            // $NON-NLS-1$
            traceError(Messages.getString("ColumnAnalysisSqlExecutor.PLEASEREMOVEALLPATTEN"));
            return Boolean.FALSE;
        }
        traceError(Messages.getString(// $NON-NLS-1$
        "ColumnAnalysisSqlExecutor.UNSUPPORTEDINDICATOR", (indicator.getName() != null ? AnalysisExecutorHelper.getIndicatorName(indicator) : indicatorEclass.getName())));
        return Boolean.FALSE;
    }
    // --- get indicator parameters and convert them into sql expression
    List<String> whereExpression = new ArrayList<String>();
    if (StringUtils.isNotBlank(dataFilterAsString)) {
        whereExpression.add(dataFilterAsString);
    }
    List<String> rangeStrings = null;
    DateGrain dateAggregationType = null;
    IndicatorParameters parameters = indicator.getParameters();
    if (parameters != null) {
        // handle bins
        Domain bins = parameters.getBins();
        if (bins != null) {
            rangeStrings = getBinsAsGenericString(bins.getRanges(), colName);
        }
        DateParameters dateParameters = parameters.getDateParameters();
        if (dateParameters != null) {
            dateAggregationType = dateParameters.getDateAggregationType();
        }
        TextParameters textParameter = parameters.getTextParameter();
        if (textParameter != null) {
            if (textParameter.isIgnoreCase()) {
                colName = dbms().toUpperCase(colName);
            }
            if (!textParameter.isUseBlank() && IndicatorsPackage.eINSTANCE.getLengthIndicator().isSuperTypeOf(indicatorEclass)) {
                String tdColName = getQuotedColumnName(tdColumn);
                // $NON-NLS-1$
                tdColName = dbms().replaceNullsWithString(tdColName, "'NULL TALEND'");
            } else if (textParameter.isUseBlank() && IndicatorsPackage.eINSTANCE.getFrequencyIndicator().isSuperTypeOf(indicatorEclass)) {
                colName = dbms().trim(colName);
            }
        }
    }
    TypedReturnCode<String> completedQuery = getCompletedQuery(indicator, tdColumn, colName, indicatorDefinition, language, sqlGenericExpression, indicatorEclass, whereExpression, rangeStrings, dateAggregationType);
    if (!completedQuery.isOk()) {
        return false;
    }
    String finalQuery = completedQuery.getObject();
    if (finalQuery != null) {
        TdExpression instantiateSqlExpression = BooleanExpressionHelper.createTdExpression(language, finalQuery);
        indicator.setInstantiatedExpression(instantiateSqlExpression);
        return true;
    }
    return false;
}
Also used : DateGrain(org.talend.dataquality.indicators.DateGrain) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) ArrayList(java.util.ArrayList) DateParameters(org.talend.dataquality.indicators.DateParameters) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) TextParameters(org.talend.dataquality.indicators.TextParameters) EClass(org.eclipse.emf.ecore.EClass) TdColumn(org.talend.cwm.relational.TdColumn) TdExpression(org.talend.cwm.relational.TdExpression) Expression(orgomg.cwm.objectmodel.core.Expression) Domain(org.talend.dataquality.domain.Domain)

Example 53 with IndicatorParameters

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

the class FrequencyStatisticsExplorer method getFreqRowsStatement.

protected String getFreqRowsStatement() {
    IndicatorDefinition indicatorDefinition = this.indicator.getIndicatorDefinition();
    if (indicatorDefinition instanceof UDIndicatorDefinition) {
        return getQueryForUDIndicator(indicatorDefinition);
    }
    String clause = PluginConstant.EMPTY_STRING;
    TdColumn column = (TdColumn) indicator.getAnalyzedElement();
    int javaType = column.getSqlDataType().getJavaDataType();
    if (Java2SqlType.isTextInSQL(javaType)) {
        clause = getInstantiatedClause();
    } else if (Java2SqlType.isDateInSQL(javaType)) {
        // MOD scorreia 2009-09-22 first check whether the value is null
        if (entity.isLabelNull()) {
            clause = getInstantiatedClause();
        } else {
            IndicatorParameters parameters = indicator.getParameters();
            if (parameters != null) {
                DateParameters dateParameters = parameters.getDateParameters();
                if (dateParameters != null) {
                    DateGrain dateGrain = dateParameters.getDateAggregationType();
                    clause = entity.isLabelNull() ? getInstantiatedClause() : getClauseWithDate(dateGrain, clause);
                } else {
                    clause = getInstantiatedClause();
                }
            } else {
                clause = getInstantiatedClause();
            }
        }
    } else if (Java2SqlType.isNumbericInSQL(javaType)) {
        IndicatorParameters parameters = indicator.getParameters();
        if (parameters != null) {
            // handle bins
            Domain bins = parameters.getBins();
            if (bins != null) {
                // rangeStrings = getBinsAsGenericString(bins.getRanges());
                final EList<RangeRestriction> ranges = bins.getRanges();
                for (RangeRestriction rangeRestriction : ranges) {
                    // find the rangeLabel
                    if (entity.getLabel() != null && entity.getLabel().equals(rangeRestriction.getName())) {
                        clause = createWhereClause(rangeRestriction);
                        break;
                    }
                }
            } else {
                // MOD hcheng 2009-05-18.Bug 7377,Frequency indicator,when bins is null,handle as textual data
                clause = getInstantiatedClause();
            }
        } else {
            // MOD scorreia 2009-05-13. Bug 7235
            // no parameter set: handle as textual data
            clause = getInstantiatedClause();
        }
    } else {
        // no quote here
        clause = getDefaultQuotedStatement(PluginConstant.EMPTY_STRING);
    }
    return // $NON-NLS-1$
    "SELECT * FROM " + getFullyQualifiedTableName(column) + dbmsLanguage.where() + inBrackets(clause) + andDataFilterClause();
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) DateGrain(org.talend.dataquality.indicators.DateGrain) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) DateParameters(org.talend.dataquality.indicators.DateParameters) RangeRestriction(org.talend.dataquality.domain.RangeRestriction) Domain(org.talend.dataquality.domain.Domain) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition)

Example 54 with IndicatorParameters

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

the class AnalysisTableTreeViewer method hasIndicatorParameters.

/**
 * DOC msjian Comment method "hasIndicatorParameters".
 *
 * @param indicatorUnit
 * @return
 */
private boolean hasIndicatorParameters(TableIndicatorUnit indicatorUnit) {
    IndicatorParameters parameters = indicatorUnit.getIndicator().getParameters();
    if (parameters == null) {
        return false;
    }
    if (indicatorUnit.getIndicator() instanceof FrequencyIndicator) {
        return true;
    }
    TextParameters tParameter = parameters.getTextParameter();
    if (tParameter != null) {
        return true;
    }
    DateParameters dParameters = parameters.getDateParameters();
    if (dParameters != null) {
        return true;
    }
    Domain dataValidDomain = parameters.getDataValidDomain();
    if (dataValidDomain != null) {
        return true;
    }
    Domain indicatorValidDomain = parameters.getIndicatorValidDomain();
    if (indicatorValidDomain != null) {
        return true;
    }
    Domain bins = parameters.getBins();
    if (bins != null) {
        return true;
    }
    return false;
}
Also used : TextParameters(org.talend.dataquality.indicators.TextParameters) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) DateParameters(org.talend.dataquality.indicators.DateParameters) Domain(org.talend.dataquality.domain.Domain) FrequencyIndicator(org.talend.dataquality.indicators.FrequencyIndicator)

Example 55 with IndicatorParameters

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

the class DynamicIndicatorOptionsPage method createForm.

public AbstractIndicatorForm[] createForm(Composite parent, ICheckListener listener, FormEnum[] formTypes) {
    IndicatorParameters parameters = indicatorUnit.getIndicator().getParameters();
    if (parameters == null) {
        parameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
        indicatorUnit.getIndicator().setParameters(parameters);
    }
    AbstractIndicatorForm[] froms = new AbstractIndicatorForm[formTypes.length];
    for (int i = 0; i < formTypes.length; i++) {
        AbstractIndicatorForm form = IndicatorFormFactory.createForm(parent, formTypes[i], parameters);
        form.setListener(listener);
        froms[i] = form;
    }
    return froms;
}
Also used : IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) AbstractIndicatorForm(org.talend.dataprofiler.core.ui.wizard.indicator.forms.AbstractIndicatorForm)

Aggregations

IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)65 Domain (org.talend.dataquality.domain.Domain)27 DateParameters (org.talend.dataquality.indicators.DateParameters)15 Test (org.junit.Test)14 TdColumn (org.talend.cwm.relational.TdColumn)14 Pattern (org.talend.dataquality.domain.pattern.Pattern)14 TdExpression (org.talend.cwm.relational.TdExpression)13 TextParameters (org.talend.dataquality.indicators.TextParameters)12 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)10 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)10 Indicator (org.talend.dataquality.indicators.Indicator)9 ArrayList (java.util.ArrayList)8 PatternMatchingIndicator (org.talend.dataquality.indicators.PatternMatchingIndicator)8 Expression (orgomg.cwm.objectmodel.core.Expression)8 RegexpMatchingIndicator (org.talend.dataquality.indicators.RegexpMatchingIndicator)7 UserDefIndicator (org.talend.dataquality.indicators.sql.UserDefIndicator)7 PhoneNumberUtil (com.google.i18n.phonenumbers.PhoneNumberUtil)6 PhoneNumber (com.google.i18n.phonenumbers.Phonenumber.PhoneNumber)6 Analysis (org.talend.dataquality.analysis.Analysis)6 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)6