Search in sources :

Example 1 with Classifier

use of orgomg.cwm.objectmodel.core.Classifier in project tdq-studio-se by Talend.

the class ColumnAnalysisExecutor method createSqlStatement.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.dq.analysis.AnalysisExecutor#createSqlStatement(org.talend.dataquality.analysis.Analysis)
     */
@Override
public String createSqlStatement(Analysis analysis) {
    this.cachedAnalysis = analysis;
    // CwmZQuery query = new CwmZQuery();
    // $NON-NLS-1$
    StringBuilder sql = new StringBuilder("SELECT ");
    EList<ModelElement> analysedElements = analysis.getContext().getAnalysedElements();
    // so if you modify the code here, please also modify the same part.
    if (analysedElements.isEmpty()) {
        setError(// $NON-NLS-1$
        Messages.getString(// $NON-NLS-1$
        "ColumnAnalysisExecutor.CannotCreateSQLStatement", analysis.getName()));
        return null;
    }
    Set<ColumnSet> fromPart = new HashSet<ColumnSet>();
    final Iterator<ModelElement> iterator = analysedElements.iterator();
    while (iterator.hasNext()) {
        // for (ModelElement modelElement : analysedElements) {
        ModelElement modelElement = iterator.next();
        // --- preconditions
        TdColumn col = SwitchHelpers.COLUMN_SWITCH.doSwitch(modelElement);
        if (col == null) {
            // $NON-NLS-1$
            setError(Messages.getString("ColumnAnalysisExecutor.GivenElementIsNotColumn", modelElement));
            return null;
        }
        Classifier owner = col.getOwner();
        if (owner == null) {
            // $NON-NLS-1$
            setError(Messages.getString("ColumnAnalysisExecutor.NoOwnerFound", col.getName()));
        }
        ColumnSet colSet = SwitchHelpers.COLUMN_SET_SWITCH.doSwitch(owner);
        if (colSet == null) {
            // $NON-NLS-1$
            setError(Messages.getString("ColumnAnalysisExecutor.NoContainerFound", col.getName()));
            return null;
        }
        // MOD zshen feature 12919 select all the column to be prepare for drill down when user need.
        if (!analysis.getParameters().isStoreData()) {
            sql.append(this.quote(col.getName()));
            // append comma if more columns exist
            if (iterator.hasNext()) {
                sql.append(',');
            }
        }
        // add from
        fromPart.add(colSet);
    }
    if (fromPart.size() != 1) {
        // $NON-NLS-1$
        log.error(Messages.getString("ColumnAnalysisExecutor.ANALYSISMUSTRUNONONETABLE") + fromPart.size() + PluginConstant.DOT_STRING);
        // $NON-NLS-1$
        setError(Messages.getString("ColumnAnalysisExecutor.ANALYSISMUSTRUNONONETABLEERRORMESSAGE"));
        return null;
    }
    TdColumn firstColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(analysedElements.get(0));
    // MOD zshen feature 12919 select all the column to be prepare for drill down.
    if (analysis.getParameters().isStoreData()) {
        // MOD klliu 2011-06-30 bug 22523 whichever is Table or View,that finds columns should ues columnset
        EObject eContainer = firstColumn.eContainer();
        List<TdColumn> columnList = ColumnSetHelper.getColumns(SwitchHelpers.COLUMN_SET_SWITCH.doSwitch(eContainer));
        // ~
        Iterator<TdColumn> iter = columnList.iterator();
        while (iter.hasNext()) {
            TdColumn column = iter.next();
            sql.append(this.quote(column.getName()));
            // append comma if more columns exist
            if (iter.hasNext()) {
                sql.append(',');
            }
        }
    }
    // add from clause
    sql.append(dbms().from());
    sql.append(dbms().getQueryColumnSetWithPrefix(firstColumn));
    // add where clause
    // --- get data filter
    ModelElementAnalysisHandler handler = new ModelElementAnalysisHandler();
    handler.setAnalysis(analysis);
    String stringDataFilter = handler.getStringDataFilter();
    if (!(stringDataFilter == null || "".equals(stringDataFilter))) {
        // $NON-NLS-1$
        sql.append(GenericSQLHandler.WHERE_CLAUSE);
    }
    String sqlStatement = sql.toString();
    sqlStatement = dbms().addWhereToStatement(sqlStatement, stringDataFilter);
    return sqlStatement;
}
Also used : ColumnSet(orgomg.cwm.resource.relational.ColumnSet) Classifier(orgomg.cwm.objectmodel.core.Classifier) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TdColumn(org.talend.cwm.relational.TdColumn) EObject(org.eclipse.emf.ecore.EObject) HashSet(java.util.HashSet)

Example 2 with Classifier

use of orgomg.cwm.objectmodel.core.Classifier in project tdq-studio-se by Talend.

the class ColumnSetAnalysisExecutor method createSqlStatement.

/*
     * (non-Jsdoc)
     * 
     * @see org.talend.dq.analysis.AnalysisExecutor#createSqlStatement(org.talend.dataquality.analysis.Analysis)
     */
@Override
protected String createSqlStatement(Analysis analysis) {
    // MOD yyi 2011-02-22 17871:delimitefile
    if (isDelimitedFile) {
        return PluginConstant.EMPTY_STRING;
    }
    // ~
    this.cachedAnalysis = analysis;
    // $NON-NLS-1$
    StringBuilder sql = new StringBuilder("SELECT ");
    EList<Indicator> indicators = analysis.getResults().getIndicators();
    // MOD yyi 2011-02-22 17871:delimitefile
    EList<ModelElement> analysedElements = null;
    for (Indicator indicator : indicators) {
        if (ColumnsetPackage.eINSTANCE.getColumnSetMultiValueIndicator().isSuperTypeOf(indicator.eClass())) {
            ColumnSetMultiValueIndicator colSetMultValIndicator = (ColumnSetMultiValueIndicator) indicator;
            if (analysedElements == null) {
                analysedElements = colSetMultValIndicator.getAnalyzedColumns();
            } else {
                analysedElements.addAll(colSetMultValIndicator.getAnalyzedColumns());
            }
        }
    }
    if (analysedElements == null || analysedElements.isEmpty()) {
        setError(// $NON-NLS-1$
        Messages.getString(// $NON-NLS-1$
        "ColumnAnalysisExecutor.CannotCreateSQLStatement", analysis.getName()));
        return null;
    }
    // MOD yyi 2011-02-22 17871:delimitefile, indiactor changed
    final Iterator<ModelElement> iterator = analysedElements.iterator();
    while (iterator.hasNext()) {
        // for (ModelElement modelElement : analysedElements) {
        ModelElement modelElement = iterator.next();
        // --- preconditions
        TdColumn col = SwitchHelpers.COLUMN_SWITCH.doSwitch(modelElement);
        if (col == null) {
            // $NON-NLS-1$
            setError(Messages.getString("ColumnAnalysisExecutor.GivenElementIsNotColumn", modelElement));
            return null;
        }
        Classifier owner = col.getOwner();
        if (owner == null) {
            // $NON-NLS-1$
            setError(Messages.getString("ColumnAnalysisExecutor.NoOwnerFound", col.getName()));
        }
        ColumnSet colSet = SwitchHelpers.COLUMN_SET_SWITCH.doSwitch(owner);
        if (colSet == null) {
            // $NON-NLS-1$
            setError(Messages.getString("ColumnAnalysisExecutor.NoContainerFound", col.getName()));
            return null;
        }
        // select all the column to be prepare for drill down when user need.
        if (!analysis.getParameters().isStoreData()) {
            sql.append(this.quote(col.getName()));
            // append comma if more columns exist
            if (iterator.hasNext()) {
                sql.append(',');
            }
        }
    }
    TdColumn firstColumn = SwitchHelpers.COLUMN_SWITCH.doSwitch(analysedElements.get(0));
    // select all the column to be prepare for drill down.
    if (analysis.getParameters().isStoreData()) {
        // MOD klliu 2011-06-30 bug 22523 whichever is Table or View,that finds columns should ues columnset
        EObject eContainer = firstColumn.eContainer();
        List<TdColumn> columnList = ColumnSetHelper.getColumns(SwitchHelpers.COLUMN_SET_SWITCH.doSwitch(eContainer));
        // ~
        Iterator<TdColumn> iter = columnList.iterator();
        while (iter.hasNext()) {
            TdColumn column = iter.next();
            sql.append(this.quote(column.getName()));
            // append comma if more columns exist
            if (iter.hasNext()) {
                sql.append(',');
            }
        }
    }
    // add from clause
    sql.append(dbms().from());
    sql.append(dbms().getQueryColumnSetWithPrefix(firstColumn));
    // add where clause
    // --- get data filter
    ModelElementAnalysisHandler handler = new ModelElementAnalysisHandler();
    handler.setAnalysis(analysis);
    String stringDataFilter = handler.getStringDataFilter();
    sql.append(GenericSQLHandler.WHERE_CLAUSE);
    String sqlStatement = sql.toString();
    sqlStatement = dbms().addWhereToStatement(sqlStatement, stringDataFilter);
    return sqlStatement;
}
Also used : ColumnSet(orgomg.cwm.resource.relational.ColumnSet) Classifier(orgomg.cwm.objectmodel.core.Classifier) ColumnSetMultiValueIndicator(org.talend.dataquality.indicators.columnset.ColumnSetMultiValueIndicator) ColumnSetMultiValueIndicator(org.talend.dataquality.indicators.columnset.ColumnSetMultiValueIndicator) RegexpMatchingIndicator(org.talend.dataquality.indicators.RegexpMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) AllMatchIndicator(org.talend.dataquality.indicators.columnset.AllMatchIndicator) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) TdColumn(org.talend.cwm.relational.TdColumn) EObject(org.eclipse.emf.ecore.EObject)

Aggregations

EObject (org.eclipse.emf.ecore.EObject)2 TdColumn (org.talend.cwm.relational.TdColumn)2 Classifier (orgomg.cwm.objectmodel.core.Classifier)2 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)2 ColumnSet (orgomg.cwm.resource.relational.ColumnSet)2 HashSet (java.util.HashSet)1 Indicator (org.talend.dataquality.indicators.Indicator)1 RegexpMatchingIndicator (org.talend.dataquality.indicators.RegexpMatchingIndicator)1 AllMatchIndicator (org.talend.dataquality.indicators.columnset.AllMatchIndicator)1 ColumnSetMultiValueIndicator (org.talend.dataquality.indicators.columnset.ColumnSetMultiValueIndicator)1