Search in sources :

Example 1 with GenericSQLHandler

use of org.talend.dq.dbms.GenericSQLHandler in project tdq-studio-se by Talend.

the class ExpressionEditDialog method getAutoGeneratedQuery.

/**
 * get the auto generated query.
 */
public String getAutoGeneratedQuery() {
    autoGenQuery = UDIHelper.getQueryFromTemplates(selectTabNumber, language, category);
    // replace some variables in the auto generate sql
    if (isUDIndicatorDefinition) {
        GenericSQLHandler genericSQLHandler = new GenericSQLHandler(autoGenQuery);
        if (IndicatorCategoryHelper.isUserDefCount(category)) {
            // replace <WHERE_TEXT_FIELD>
            genericSQLHandler.replaceUDIWhere(tab0_count_where_var.getText().trim());
        } else if (IndicatorCategoryHelper.isUserDefRealValue(category)) {
            // replace <COLUMN_EXPRESSION_TEXT_FIELD>
            genericSQLHandler.replaceUDIColumn(tab0_realvalue_column_var.getText().trim());
            // replace <WHERE_TEXT_FIELD>
            genericSQLHandler.replaceUDIWhere(tab0_realvalue_where_var.getText().trim());
        } else if (IndicatorCategoryHelper.isUserDefFrequency(category)) {
            // replace <FIRST_COLUMN_EXPRESSION_TEXT_FIELD>
            genericSQLHandler.replaceUDIFirstColumn(tab0_fre_first_var.getText().trim());
            // replace <SECOND_COLUMN_EXPRESSION_TEXT_FIELD>
            genericSQLHandler.replaceUDISecondColumn(tab0_fre_second_var.getText().trim());
            // replace <WHERE_TEXT_FIELD>
            genericSQLHandler.replaceUDIWhere(tab0_fre_where_var.getText().trim());
            // replace <GROUP_BY_TEXT_FIELD>
            genericSQLHandler.replaceUDIGroupBy(tab0_fre_groupby_var.getText().trim());
            // replace <ORDER_BY_TEXT_FIELD>
            genericSQLHandler.replaceUDIOrderBy(tab0_fre_orderby_var.getText().trim());
        } else if (IndicatorCategoryHelper.isUserDefMatching(category)) {
            // replace <MATCHING_EXPRESSION_TEXT_FIELD>
            genericSQLHandler.replaceUDIMatching(tab0_match_match_var.getText().trim());
            // replace <WHERE_TEXT_FIELD>
            genericSQLHandler.replaceUDIWhere(tab0_match_where_var.getText().trim());
        }
        autoGenQuery = genericSQLHandler.replaceUDIQueryToMatch().getSqlString();
    }
    return autoGenQuery;
}
Also used : GenericSQLHandler(org.talend.dq.dbms.GenericSQLHandler)

Example 2 with GenericSQLHandler

use of org.talend.dq.dbms.GenericSQLHandler 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)

Example 3 with GenericSQLHandler

use of org.talend.dq.dbms.GenericSQLHandler in project tdq-studio-se by Talend.

the class ColumnDependencyExplorer method getStatement.

/**
 * DOC xqliu Comment method "getStatement".
 *
 * @param genericSQL
 * @return
 */
private String getStatement(String genericSQL) {
    ColumnDependencyIndicator cdIndicator = ((ColumnDependencyIndicator) this.indicator);
    TdColumn columnA = cdIndicator.getColumnA();
    TdColumn columnB = cdIndicator.getColumnB();
    GenericSQLHandler sqlHandler = new GenericSQLHandler(genericSQL);
    sqlHandler.replaceColumnA(dbmsLanguage.quote(columnA.getName())).replaceColumnB(dbmsLanguage.quote(columnB.getName())).replaceTable(dbmsLanguage.quote(getFullyQualifiedTableName(columnA)));
    String instantiatedSQL = sqlHandler.getSqlString();
    List<String> whereClauses = new ArrayList<String>();
    String dataFilter = ContextHelper.getDataFilterWithoutContext(this.analysis);
    if (!StringUtils.isEmpty(dataFilter)) {
        whereClauses.add(dataFilter);
    }
    instantiatedSQL = dbmsLanguage.addWhereToSqlStringStatement(instantiatedSQL, whereClauses);
    return instantiatedSQL;
}
Also used : ColumnDependencyIndicator(org.talend.dataquality.indicators.columnset.ColumnDependencyIndicator) TdColumn(org.talend.cwm.relational.TdColumn) ArrayList(java.util.ArrayList) GenericSQLHandler(org.talend.dq.dbms.GenericSQLHandler)

Example 4 with GenericSQLHandler

use of org.talend.dq.dbms.GenericSQLHandler in project tdq-studio-se by Talend.

the class UDIUtils method replaceQueryForMatchUDI.

/**
 * replace Query For Match UDI.
 *
 * @param genericSQLHandler
 * @return
 */
private static String replaceQueryForMatchUDI(String body) {
    GenericSQLHandler genericSQLHandler = new GenericSQLHandler(body);
    // replace <MATCHING_EXPRESSION_TEXT_FIELD>
    genericSQLHandler.replaceUDIMatching(PluginConstant.EMPTY_STRING);
    // replace <WHERE_TEXT_FIELD>
    genericSQLHandler.replaceUDIWhere(PluginConstant.EMPTY_STRING);
    return genericSQLHandler.replaceUDIQueryToMatch().getSqlString();
}
Also used : GenericSQLHandler(org.talend.dq.dbms.GenericSQLHandler)

Aggregations

GenericSQLHandler (org.talend.dq.dbms.GenericSQLHandler)4 ArrayList (java.util.ArrayList)1 TdColumn (org.talend.cwm.relational.TdColumn)1 TdExpression (org.talend.cwm.relational.TdExpression)1 ColumnDependencyIndicator (org.talend.dataquality.indicators.columnset.ColumnDependencyIndicator)1 IndicatorCategory (org.talend.dataquality.indicators.definition.IndicatorCategory)1