Search in sources :

Example 51 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class UDIMasterPage method initExpresstionEditDialog.

@Override
protected ExpressionEditDialog initExpresstionEditDialog(final CCombo combo, final String version, String patternText) {
    TdExpression tdExpression = getTdExpression(combo, version);
    String language = tdExpression.getLanguage();
    ExpressionEditDialog editDialog = new ExpressionEditDialog(null, patternText, true, cloneExpression(tdExpression));
    editDialog.setVersion(version);
    editDialog.setLanguage(language);
    editDialog.setCategory(category);
    if (IndicatorCategoryHelper.isUserDefMatching(category)) {
        EList<TdExpression> viewValidRowsExpression = ((UDIndicatorDefinition) getCurrentModelElement()).getViewValidRowsExpression();
        TdExpression viewValidRows = getCurrentLanguageExp(viewValidRowsExpression, language, version);
        if (isDirty()) {
            viewValidRows = tempViewValidRowsExpressionMap.get(combo);
        }
        editDialog.setTempViewValidRowsExp(cloneExpression(viewValidRows));
        EList<TdExpression> viewInvalidRowsExpression = ((UDIndicatorDefinition) getCurrentModelElement()).getViewInvalidRowsExpression();
        TdExpression viewInvalidRows = getCurrentLanguageExp(viewInvalidRowsExpression, language, version);
        if (isDirty()) {
            viewInvalidRows = tempViewInvalidRowsExpressionMap.get(combo);
        }
        editDialog.setTempViewInvalidRowsExp(cloneExpression(viewInvalidRows));
        EList<TdExpression> viewValidValuesExpression = ((UDIndicatorDefinition) getCurrentModelElement()).getViewValidValuesExpression();
        TdExpression viewValidValues = getCurrentLanguageExp(viewValidValuesExpression, language, version);
        if (isDirty()) {
            viewValidValues = tempViewValidValuesExpressionMap.get(combo);
        }
        editDialog.setTempViewValidValuesExp(cloneExpression(viewValidValues));
        EList<TdExpression> viewInvalidValuesExpression = ((UDIndicatorDefinition) getCurrentModelElement()).getViewInvalidValuesExpression();
        TdExpression viewInvalidValues = getCurrentLanguageExp(viewInvalidValuesExpression, language, version);
        if (isDirty()) {
            viewInvalidValues = tempViewInvalidValuesExpressionMap.get(combo);
        }
        editDialog.setTempViewInvalidValuesExp(cloneExpression(viewInvalidValues));
    } else {
        EList<TdExpression> viewRowsExpression = ((UDIndicatorDefinition) getCurrentModelElement()).getViewRowsExpression();
        TdExpression viewRows = getCurrentLanguageExp(viewRowsExpression, language, version);
        if (isDirty()) {
            viewRows = tempViewRowsExpressionMap.get(combo);
        }
        editDialog.setTempViewRowsExp(cloneExpression(viewRows));
    }
    return editDialog;
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) ExpressionEditDialog(org.talend.dataprofiler.core.ui.dialog.ExpressionEditDialog)

Example 52 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class PatternExplorer method getInvalidRowsStatement.

/**
 * get the Invalid Rows Statement.
 *
 * @return
 */
public String getInvalidRowsStatement() {
    // when the indicator is the use define match
    IndicatorDefinition indicatorDefinition = this.indicator.getIndicatorDefinition();
    if (indicatorDefinition instanceof UDIndicatorDefinition) {
        EList<TdExpression> list = ((UDIndicatorDefinition) indicatorDefinition).getViewInvalidRowsExpression();
        return getQueryAfterReplaced(indicatorDefinition, list);
    }
    String regexPatternString = dbmsLanguage.getRegexPatternString(this.indicator);
    String regexCmp = getRegexNotLike(regexPatternString);
    // add null as invalid rows
    String nullClause = dbmsLanguage.or() + columnName + dbmsLanguage.isNull();
    // mzhao TDQ-4967 add "(" and ")" for regex and null clause.
    // $NON-NLS-1$//$NON-NLS-2$
    String pattCondStr = "(" + regexCmp + nullClause + ")";
    return getRowsStatement(pattCondStr);
}
Also used : UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)

Example 53 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class PatternExplorer method getValidRowsStatement.

/**
 * get the Valid Rows Statement.
 *
 * @return
 */
public String getValidRowsStatement() {
    // when the indicator is the use define match
    IndicatorDefinition indicatorDefinition = this.indicator.getIndicatorDefinition();
    if (indicatorDefinition instanceof UDIndicatorDefinition) {
        EList<TdExpression> list = ((UDIndicatorDefinition) indicatorDefinition).getViewValidRowsExpression();
        return getQueryAfterReplaced(indicatorDefinition, list);
    }
    String regexPatternString = dbmsLanguage.getRegexPatternString(this.indicator);
    String regexCmp = getRegexLike(regexPatternString);
    return getRowsStatement(regexCmp);
}
Also used : UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) TdExpression(org.talend.cwm.relational.TdExpression) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)

Example 54 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class SimpleStatisticsExplorer method getQueryForViewRows.

/**
 * get Query For View Rows.
 *
 * @param indicatorDefinition
 * @return
 */
private String getQueryForViewRows(IndicatorDefinition indicatorDefinition) {
    String sql = PluginConstant.EMPTY_STRING;
    IndicatorCategory category = IndicatorCategoryHelper.getCategory(indicatorDefinition);
    EList<TdExpression> list = ((UDIndicatorDefinition) indicatorDefinition).getViewRowsExpression();
    TdExpression tdExp = DbmsLanguage.getSqlExpression(indicatorDefinition, dbmsLanguage.getDbmsName(), list, dbmsLanguage.getDbVersion());
    sql = tdExp.getBody();
    String dataFilterClause = getDataFilterClause();
    if (!dataFilterClause.equals(PluginConstant.EMPTY_STRING)) {
        // $NON-NLS-1$ //$NON-NLS-2$
        sql = sql.replace(GenericSQLHandler.WHERE_CLAUSE, dbmsLanguage.where() + "(" + dataFilterClause + ")");
        // $NON-NLS-1$ //$NON-NLS-2$
        sql = sql.replace(GenericSQLHandler.AND_WHERE_CLAUSE, dbmsLanguage.and() + "(" + dataFilterClause + ")");
    } else {
        sql = sql.replace(GenericSQLHandler.WHERE_CLAUSE, PluginConstant.EMPTY_STRING);
        sql = sql.replace(GenericSQLHandler.AND_WHERE_CLAUSE, PluginConstant.EMPTY_STRING);
    }
    String tableName = getFullyQualifiedTableName(this.indicator.getAnalyzedElement());
    sql = sql.replace(GenericSQLHandler.TABLE_NAME, tableName);
    // TDQ-12398 msjian: add quote for the column
    sql = sql.replace(GenericSQLHandler.COLUMN_NAMES, dbmsLanguage.quote(this.indicator.getAnalyzedElement().getName()));
    if (sql.indexOf(GenericSQLHandler.UDI_INDICATOR_VALUE) != -1) {
        if (IndicatorCategoryHelper.isUserDefRealValue(category)) {
            // replace <%=__INDICATOR_VALUE__%>
            Double realValue = this.indicator.getRealValue();
            // $NON-NLS-1$
            sql = sql.replace(GenericSQLHandler.UDI_INDICATOR_VALUE, realValue == null ? "0" : realValue.toString());
        } else {
            sql = sql.replace(GenericSQLHandler.UDI_INDICATOR_VALUE, (String.valueOf(this.indicator.getIntegerValue().intValue())));
        }
    }
    return sql;
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) IndicatorCategory(org.talend.dataquality.indicators.definition.IndicatorCategory)

Example 55 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class UDIUtils method createDefaultDrillDownList.

/**
 * create Default Drill Down List for UDI.
 *
 * @param indiDefinition
 * @return
 */
public static UDIndicatorDefinition createDefaultDrillDownList(UDIndicatorDefinition indiDefinition) {
    IndicatorCategory category = IndicatorCategoryHelper.getCategory(indiDefinition);
    if (IndicatorCategoryHelper.isUserDefMatching(category)) {
        // set default value from templates
        EList<TdExpression> viewValidRowsList = indiDefinition.getViewValidRowsExpression();
        EList<TdExpression> viewInvalidRowsList = indiDefinition.getViewInvalidRowsExpression();
        EList<TdExpression> viewValidValuesList = indiDefinition.getViewValidValuesExpression();
        EList<TdExpression> viewInvalidValuesList = indiDefinition.getViewInvalidValuesExpression();
        EList<TdExpression> sqlGenericExpression = indiDefinition.getSqlGenericExpression();
        if (sqlGenericExpression != null) {
            for (TdExpression tdExp : sqlGenericExpression) {
                String language = tdExp.getLanguage();
                String version = tdExp.getVersion();
                // if not exist, add one.(when do migration more than one time, will add one)
                if (!UDIUtils.checkExistInList(viewValidRowsList, language, version)) {
                    // for match is View Valid Rows template
                    String body = UDIHelper.getQueryFromTemplates(2, language, category);
                    viewValidRowsList.add(UDIUtils.createNewTdExpression(language, version, replaceQueryForMatchUDI(body)));
                }
                if (!UDIUtils.checkExistInList(viewInvalidRowsList, language, version)) {
                    // for match is View Invalid Rows Template
                    String body = UDIHelper.getQueryFromTemplates(3, language, category);
                    viewInvalidRowsList.add(UDIUtils.createNewTdExpression(language, version, replaceQueryForMatchUDI(body)));
                }
                if (!UDIUtils.checkExistInList(viewValidValuesList, language, version)) {
                    // for match is View Valid Values Template
                    String body = UDIHelper.getQueryFromTemplates(4, language, category);
                    viewValidValuesList.add(UDIUtils.createNewTdExpression(language, version, replaceQueryForMatchUDI(body)));
                }
                if (!UDIUtils.checkExistInList(viewInvalidValuesList, language, version)) {
                    // for match is View Invalid Values Template
                    String body = UDIHelper.getQueryFromTemplates(5, language, category);
                    viewInvalidValuesList.add(UDIUtils.createNewTdExpression(language, version, replaceQueryForMatchUDI(body)));
                }
            }
        }
    } else {
        // for others is view rows template
        EList<TdExpression> viewRowsList = indiDefinition.getViewRowsExpression();
        EList<TdExpression> sqlGenericExpression = indiDefinition.getSqlGenericExpression();
        if (sqlGenericExpression != null) {
            for (TdExpression tdExp : sqlGenericExpression) {
                String language = tdExp.getLanguage();
                String version = tdExp.getVersion();
                // if not exist, add one.(when do migration more than one time, will add one)
                if (!UDIUtils.checkExistInList(viewRowsList, language, version)) {
                    String body = UDIHelper.getQueryFromTemplates(2, language, category);
                    GenericSQLHandler genericSQLHandler = new GenericSQLHandler(body);
                    if (IndicatorCategoryHelper.isUserDefRealValue(category)) {
                        // replace <COLUMN_EXPRESSION_TEXT_FIELD>
                        genericSQLHandler.replaceUDIColumn(PluginConstant.EMPTY_STRING);
                    } else if (IndicatorCategoryHelper.isUserDefFrequency(category)) {
                        // replace <FIRST_COLUMN_EXPRESSION_TEXT_FIELD>
                        // replace <SECOND_COLUMN_EXPRESSION_TEXT_FIELD>
                        genericSQLHandler.replaceUDIFirstColumn(PluginConstant.EMPTY_STRING).replaceUDISecondColumn(PluginConstant.EMPTY_STRING);
                    }
                    viewRowsList.add(UDIUtils.createNewTdExpression(language, version, genericSQLHandler.replaceUDIQueryToMatch().getSqlString()));
                }
            }
        }
    }
    return indiDefinition;
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) IndicatorCategory(org.talend.dataquality.indicators.definition.IndicatorCategory) GenericSQLHandler(org.talend.dq.dbms.GenericSQLHandler)

Aggregations

TdExpression (org.talend.cwm.relational.TdExpression)121 Test (org.junit.Test)51 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)30 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)29 ArrayList (java.util.ArrayList)19 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)19 Pattern (org.talend.dataquality.domain.pattern.Pattern)16 TdColumn (org.talend.cwm.relational.TdColumn)12 Expression (orgomg.cwm.objectmodel.core.Expression)12 BasicEList (org.eclipse.emf.common.util.BasicEList)11 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)11 Domain (org.talend.dataquality.domain.Domain)10 TdTable (org.talend.cwm.relational.TdTable)9 ProductVersion (org.talend.utils.ProductVersion)9 Analysis (org.talend.dataquality.analysis.Analysis)8 PatternComponent (org.talend.dataquality.domain.pattern.PatternComponent)8 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)8 File (java.io.File)7 IFile (org.eclipse.core.resources.IFile)6 IFolder (org.eclipse.core.resources.IFolder)6