Search in sources :

Example 46 with ColumnSet

use of orgomg.cwm.resource.relational.ColumnSet in project tdq-studio-se by Talend.

the class RowMatchExplorer method getAllRowsStatement.

/**
 * get All Rows Statement.
 *
 * @return
 */
public String getAllRowsStatement() {
    ColumnSet tablea = (ColumnSet) indicator.getAnalyzedElement();
    String tableA = tablea.getName();
    ColumnSet tableb = ColumnHelper.getColumnOwnerAsColumnSet(((RowMatchingIndicator) indicator).getColumnSetB().get(0));
    String tableB = tableb.getName();
    return getComment(MENU_VIEW_ROWS) + "SELECT * " + dbmsLanguage.from() + getFullyQualifiedTableName(tablea) + // $NON-NLS-1$
    whereDataFilter(tableA.equals(tableB) ? null : tableA, null);
}
Also used : RowMatchingIndicator(org.talend.dataquality.indicators.columnset.RowMatchingIndicator) ColumnSet(orgomg.cwm.resource.relational.ColumnSet)

Example 47 with ColumnSet

use of orgomg.cwm.resource.relational.ColumnSet in project tdq-studio-se by Talend.

the class RowMatchExplorer method getRowsMatchStatement.

/**
 * get Rows for Matched Statement.
 *
 * @return
 */
public String getRowsMatchStatement() {
    ColumnSet tablea = (ColumnSet) indicator.getAnalyzedElement();
    String tableA = tablea.getName();
    String query = PluginConstant.EMPTY_STRING;
    if (ColumnsetPackage.eINSTANCE.getRowMatchingIndicator() == indicator.eClass()) {
        ColumnSet tableb = ColumnHelper.getColumnOwnerAsColumnSet(((RowMatchingIndicator) indicator).getColumnSetB().get(0));
        String tableB = tableb.getName();
        EList<TdColumn> columnSetA = ((RowMatchingIndicator) indicator).getColumnSetA();
        EList<TdColumn> columnSetB = ((RowMatchingIndicator) indicator).getColumnSetB();
        // $NON-NLS-1$
        String clauseA = " (SELECT *" + dbmsLanguage.from() + getFullyQualifiedTableName(tablea);
        // $NON-NLS-1$
        String clauseB = " (SELECT *" + dbmsLanguage.from() + getFullyQualifiedTableName(tableb);
        String where = null;
        // $NON-NLS-1$
        String onClause = " ON ";
        for (int i = 0; i < columnSetA.size(); i++) {
            where = dbmsLanguage.and();
            if (i == 0) {
                where = dbmsLanguage.where();
            } else {
                onClause += where;
            }
            onClause += // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
            " (A" + dbmsLanguage.getDelimiter() + dbmsLanguage.quote(columnSetA.get(i).getName()) + "=" + " B" + dbmsLanguage.getDelimiter() + dbmsLanguage.quote(columnSetB.get(i).getName()) + // $NON-NLS-1$
            ") ";
        }
        clauseA += (tableA.equals(tableB) ? whereDataFilter(tableA, (getdataFilterIndex(null) == AnalysisHelper.DATA_FILTER_A ? AnalysisHelper.DATA_FILTER_A : AnalysisHelper.DATA_FILTER_B)) : whereDataFilter(tableA, null)) + // $NON-NLS-1$
        ") A";
        clauseB += (tableB.equals(tableA) ? whereDataFilter(tableB, (getdataFilterIndex(null) == AnalysisHelper.DATA_FILTER_A ? AnalysisHelper.DATA_FILTER_B : AnalysisHelper.DATA_FILTER_A)) : whereDataFilter(tableB, null)) + // $NON-NLS-1$
        ") B";
        // $NON-NLS-1$
        query = "SELECT * FROM " + getFullyQualifiedTableName(tablea);
        String clause = PluginConstant.EMPTY_STRING;
        String columnNameByAlias = PluginConstant.EMPTY_STRING;
        for (int i = 0; i < columnSetA.size(); i++) {
            // $NON-NLS-1$
            columnNameByAlias += " A" + dbmsLanguage.getDelimiter() + dbmsLanguage.quote(columnSetA.get(i).getName());
            if (i != columnSetA.size() - 1) {
                // $NON-NLS-1$
                columnNameByAlias += ",";
            }
        }
        // $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
        clause = "(SELECT " + columnNameByAlias + dbmsLanguage.from() + clauseA + " JOIN " + clauseB + onClause + ")";
        // $NON-NLS-1$
        String fullColumnAName = "(";
        for (int j = 0; j < columnSetA.size(); j++) {
            fullColumnAName += getFullyQualifiedTableName(tablea) + PluginConstant.DOT_STRING + dbmsLanguage.quote(columnSetA.get(j).getName());
            if (j != columnSetA.size() - 1) {
                // $NON-NLS-1$
                fullColumnAName += ",";
            } else {
                // $NON-NLS-1$
                fullColumnAName += ")";
            }
        }
        // $NON-NLS-1$
        clause = dbmsLanguage.where() + "(" + fullColumnAName + dbmsLanguage.in() + clause;
        query += clause;
        query += // $NON-NLS-1$
        ") " + (tableA.equals(tableB) ? andDataFilter(tableA, (getdataFilterIndex(null) == AnalysisHelper.DATA_FILTER_A ? AnalysisHelper.DATA_FILTER_A : AnalysisHelper.DATA_FILTER_B)) : andDataFilter(tableA, null));
    }
    return getComment(MENU_VIEW_MATCH_ROWS) + query;
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) RowMatchingIndicator(org.talend.dataquality.indicators.columnset.RowMatchingIndicator) ColumnSet(orgomg.cwm.resource.relational.ColumnSet)

Example 48 with ColumnSet

use of orgomg.cwm.resource.relational.ColumnSet in project tdq-studio-se by Talend.

the class AnalysisColumnCompareTreeViewer method computeRefreshDataPreviewPart.

/**
 * DOC msjian Comment method "computeRefreshDataPreviewPart".
 *
 * @param isLeftPart
 * @param columnSet
 * @return
 */
protected ColumnSet computeRefreshDataPreviewPart(boolean isLeftPart, List<RepositoryNode> columnSet, TableViewer columnsElementViewer) {
    ColumnSet columnOwner = null;
    if (columnSet != null && columnSet.size() > 0) {
        RepositoryNode node = columnSet.get(0);
        columnOwner = RepositoryNodeHelper.getColumnOwner(node);
    }
    if (isLeftPart) {
        if ((previewDataColumnOwner == null && columnOwner != null) || (previewDataColumnOwner != null && columnOwner == null) || (!previewDataColumnOwner.equals(columnOwner))) {
            previewDataColumnOwner = columnOwner;
            notifyObservers();
        }
    }
    // set the columnsElementViewer's table name show
    String tableName = columnOwner == null ? "" : columnOwner.getName();
    columnsElementViewer.getTable().getColumn(0).setText(// $NON-NLS-1$
    DefaultMessagesImpl.getString("ColumnsComparisonMasterDetailsPage.elements", tableName));
    return columnOwner;
}
Also used : ColumnSet(orgomg.cwm.resource.relational.ColumnSet) RepositoryNode(org.talend.repository.model.RepositoryNode)

Example 49 with ColumnSet

use of orgomg.cwm.resource.relational.ColumnSet in project tdq-studio-se by Talend.

the class DrillDownEditorInput method getColumnsByTdColumn.

/**
 * DOC talend Comment method "getColumnsByIndicator".
 *
 * @param analysisElement
 * @return
 */
protected List<TdColumn> getColumnsByTdColumn(TdColumn analysisElement) {
    EObject eContainer = analysisElement.eContainer();
    if (eContainer == null) {
        return new ArrayList<TdColumn>();
    }
    ColumnSet columSet = SwitchHelpers.COLUMN_SET_SWITCH.doSwitch(eContainer);
    if (columSet == null) {
        return new ArrayList<TdColumn>();
    }
    List<TdColumn> columns = ColumnSetHelper.getColumns(columSet);
    return columns;
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) ColumnSet(orgomg.cwm.resource.relational.ColumnSet)

Example 50 with ColumnSet

use of orgomg.cwm.resource.relational.ColumnSet in project tdq-studio-se by Talend.

the class ChartTableFactory method addMenuAndTip.

public static void addMenuAndTip(final TableViewer tbViewer, final IDataExplorer explorer, final Analysis analysis) {
    final Table table = tbViewer.getTable();
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent e) {
            // MOD xqliu 2009-05-11 bug 6561
            if (table.getMenu() != null) {
                table.getMenu().setVisible(false);
            }
            if (e.button == 3) {
                StructuredSelection selection = (StructuredSelection) tbViewer.getSelection();
                final ChartDataEntity dataEntity = (ChartDataEntity) selection.getFirstElement();
                final Indicator indicator = dataEntity != null ? dataEntity.getIndicator() : null;
                if (indicator != null && dataEntity != null) {
                    Menu menu = new Menu(table.getShell(), SWT.POP_UP);
                    table.setMenu(menu);
                    MenuItemEntity[] itemEntities = ChartTableMenuGenerator.generate(explorer, analysis, dataEntity);
                    if (ExecutionLanguage.SQL == analysis.getParameters().getExecutionLanguage()) {
                        boolean showExtraMenu = false;
                        for (final MenuItemEntity itemEntity : itemEntities) {
                            MenuItem item = new MenuItem(menu, SWT.PUSH);
                            item.setText(itemEntity.geti18nLabel());
                            item.setImage(itemEntity.getIcon());
                            item.addSelectionListener(new SelectionAdapter() {

                                @Override
                                public void widgetSelected(SelectionEvent e1) {
                                    // DBMSLanguage.
                                    if (isPatternMatchingIndicator(indicator) && !((PatternExplorer) explorer).isImplementRegexFunction(itemEntity.getLabel())) {
                                        MessageDialog.openInformation(null, itemEntity.getLabel(), // $NON-NLS-1$
                                        DefaultMessagesImpl.getString("ChartTableFactory.NoSupportPatternTeradata"));
                                        return;
                                    }
                                    String query = itemEntity.getQuery();
                                    String editorName = indicator.getName();
                                    Connection tdDataProvider = (Connection) analysis.getContext().getConnection();
                                    SqlExplorerUtils.getDefault().runInDQViewer(tdDataProvider, query, editorName);
                                }
                            });
                            // condition columns
                            if (IndicatorHelper.isWhereRuleIndicator(indicator)) {
                                // MOD yyin 20121126 TDQ-6477,show the menu only when Join condition exists
                                WhereRuleIndicator ind = (WhereRuleIndicator) indicator;
                                EList<JoinElement> joinConditions = ind.getJoinConditions();
                                if (joinConditions.size() > 0) {
                                    showExtraMenu = true;
                                }
                            }
                            if (isPatternFrequencyIndicator(indicator) && !isEastAsiaPatternFrequencyIndicator(indicator)) {
                                createMenuOfGenerateRegularPattern(analysis, menu, dataEntity);
                            }
                        }
                        // show extra menu to create simple analysis, help user to find the duplicated rows
                        if (showExtraMenu) {
                            MenuItem itemCreateWhereRule = new MenuItem(menu, SWT.PUSH);
                            itemCreateWhereRule.setText(DefaultMessagesImpl.getString(// $NON-NLS-1$
                            "ChartTableFactory.JoinConditionColumnsAnalysis"));
                            itemCreateWhereRule.addSelectionListener(new SelectionAdapter() {

                                @Override
                                public void widgetSelected(SelectionEvent e1) {
                                    final StructuredSelection selectionOne = (StructuredSelection) tbViewer.getSelection();
                                    // MOD xqliu 2012-05-11 TDQ-5314
                                    Object firstElement = selectionOne.getFirstElement();
                                    if (firstElement instanceof WhereRuleChartDataEntity) {
                                        // get the WhereRuleIndicator
                                        WhereRuleChartDataEntity wrChartDataEntity = (WhereRuleChartDataEntity) firstElement;
                                        WhereRuleIndicator wrInd = (WhereRuleIndicator) wrChartDataEntity.getIndicator();
                                        // run the CreateDuplicatesAnalysisAction
                                        CreateDuplicatesAnalysisAction action = new CreateDuplicatesAnalysisAction(buildColumnsMap(wrInd));
                                        action.run();
                                    }
                                // ~ TDQ-5314
                                }

                                /**
                                 * DOC xqliu Comment method "buildColumnsMap".
                                 *
                                 * @param wrInd
                                 * @return
                                 */
                                private Map<ColumnSet, List<TdColumn>> buildColumnsMap(WhereRuleIndicator wrInd) {
                                    Map<ColumnSet, List<TdColumn>> map = new HashMap<ColumnSet, List<TdColumn>>();
                                    // get all columns from the WhereRuleIndicator
                                    List<TdColumn> columns = new ArrayList<TdColumn>();
                                    EList<JoinElement> joinConditions = wrInd.getJoinConditions();
                                    for (JoinElement joinElement : joinConditions) {
                                        // add left column
                                        TdColumn tempColumn = (TdColumn) joinElement.getColA();
                                        if (!columns.contains(tempColumn)) {
                                            columns.add(tempColumn);
                                        }
                                        // add right column
                                        tempColumn = (TdColumn) joinElement.getColB();
                                        if (!columns.contains(tempColumn)) {
                                            columns.add(tempColumn);
                                        }
                                    }
                                    // build the map
                                    for (TdColumn column : columns) {
                                        ColumnSet columnSet = ColumnHelper.getColumnOwnerAsColumnSet(column);
                                        List<TdColumn> list = map.get(columnSet);
                                        if (list == null) {
                                            list = new ArrayList<TdColumn>();
                                            map.put(columnSet, list);
                                        }
                                        list.add(column);
                                    }
                                    // get the user selected map
                                    return getUserSelectedMap(map);
                                }

                                /**
                                 * DOC xqliu Comment method "getUserSelectedMap".
                                 *
                                 * @param map
                                 * @return
                                 */
                                private Map<ColumnSet, List<TdColumn>> getUserSelectedMap(Map<ColumnSet, List<TdColumn>> map) {
                                    Map<ColumnSet, List<TdColumn>> userMap = new HashMap<ColumnSet, List<TdColumn>>();
                                    // get the column nodes
                                    List<RepositoryNode> columnNodes = getColumnNodes(map);
                                    // get the connection node
                                    RepositoryNode rootNode = getConnectionNode(map);
                                    // show the dialog, let user select the columns
                                    if (!columnNodes.isEmpty() && rootNode != null) {
                                        ColumnsMapSelectionDialog dialog = new ColumnsMapSelectionDialog(null, PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), // $NON-NLS-1$
                                        DefaultMessagesImpl.getString("ColumnsMapSelectionDialog.columnSelection"), // $NON-NLS-1$
                                        columnNodes, // $NON-NLS-1$
                                        rootNode, // $NON-NLS-1$
                                        DefaultMessagesImpl.getString("ColumnsMapSelectionDialog.columnSelections"));
                                        dialog.setAllMap(map);
                                        if (dialog.open() == Window.OK) {
                                            userMap = dialog.getUserMap();
                                        }
                                    }
                                    return userMap;
                                }

                                /**
                                 * DOC xqliu Comment method "getConnectionNode".
                                 *
                                 * @param map
                                 * @return
                                 */
                                private RepositoryNode getConnectionNode(Map<ColumnSet, List<TdColumn>> map) {
                                    RepositoryNode node = null;
                                    if (map != null && !map.isEmpty()) {
                                        Connection connection = ConnectionHelper.getConnection(map.keySet().iterator().next());
                                        if (connection != null) {
                                            node = RepositoryNodeHelper.recursiveFind(connection);
                                        }
                                    }
                                    return node;
                                }

                                /**
                                 * DOC xqliu Comment method "getColumnNodes".
                                 *
                                 * @param map
                                 * @return
                                 */
                                private List<RepositoryNode> getColumnNodes(Map<ColumnSet, List<TdColumn>> map) {
                                    List<RepositoryNode> nodes = new ArrayList<RepositoryNode>();
                                    if (map != null && !map.isEmpty()) {
                                        List<TdColumn> columns = new ArrayList<TdColumn>();
                                        Set<ColumnSet> keySet = map.keySet();
                                        for (ColumnSet cs : keySet) {
                                            columns.addAll(map.get(cs));
                                        }
                                        if (!columns.isEmpty()) {
                                            for (TdColumn column : columns) {
                                                nodes.add(RepositoryNodeHelper.recursiveFind(column));
                                            }
                                        }
                                    }
                                    return nodes;
                                }
                            });
                        }
                    } else {
                        if (analysis.getParameters().isStoreData()) {
                            // if allow drill down
                            if (indicator.isUsedMapDBMode()) {
                                DrillDownUtils.createDrillDownMenuForMapDB(dataEntity, menu, itemEntities, analysis);
                            } else {
                                DrillDownUtils.createDrillDownMenuForJava(dataEntity, menu, itemEntities, analysis);
                            }
                            if (isPatternFrequencyIndicator(indicator) && !isEastAsiaPatternFrequencyIndicator(indicator)) {
                                for (final MenuItemEntity itemEntity : itemEntities) {
                                    createMenuOfGenerateRegularPattern(analysis, menu, dataEntity);
                                }
                            }
                        }
                        // MOD by zshen feature 11574:add menu "Generate regular pattern" to date pattern
                        if (isDatePatternFrequencyIndicator(indicator)) {
                            final DatePatternFreqIndicator dateIndicator = (DatePatternFreqIndicator) indicator;
                            MenuItem itemCreatePatt = new MenuItem(menu, SWT.PUSH);
                            // $NON-NLS-1$
                            itemCreatePatt.setText(DefaultMessagesImpl.getString("ChartTableFactory.GenerateRegularPattern"));
                            itemCreatePatt.setImage(ImageLib.getImage(ImageLib.PATTERN_REG));
                            itemCreatePatt.addSelectionListener(new SelectionAdapter() {

                                @Override
                                public void widgetSelected(SelectionEvent e1) {
                                    DbmsLanguage language = DbmsLanguageFactory.createDbmsLanguage(analysis);
                                    IFolder folder = ResourceManager.getPatternRegexFolder();
                                    String model = dataEntity.getLabel();
                                    String regex = dateIndicator.getRegex(model);
                                    new CreatePatternAction(folder, ExpressionType.REGEXP, "'" + regex + "'", model == null ? "" : "match \"" + model + "\"", language.getDbmsName()).run();
                                }
                            });
                        }
                    }
                    addJobGenerationMenu(menu, analysis, indicator);
                    // ~11574
                    menu.setVisible(true);
                }
            }
        }
    });
    // add tooltip
    TableUtils.addTooltipForTable(table);
    TableUtils.addActionTooltip(table);
}
Also used : HashMap(java.util.HashMap) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ArrayList(java.util.ArrayList) ColumnSet(orgomg.cwm.resource.relational.ColumnSet) DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) WhereRuleIndicator(org.talend.dataquality.indicators.sql.WhereRuleIndicator) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) Menu(org.eclipse.swt.widgets.Menu) CreatePatternAction(org.talend.dataprofiler.core.pattern.actions.CreatePatternAction) CreateDuplicatesAnalysisAction(org.talend.dataprofiler.core.ui.action.actions.CreateDuplicatesAnalysisAction) TdTable(org.talend.cwm.relational.TdTable) Table(org.eclipse.swt.widgets.Table) MouseEvent(org.eclipse.swt.events.MouseEvent) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MouseAdapter(org.eclipse.swt.events.MouseAdapter) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) MenuItem(org.eclipse.swt.widgets.MenuItem) WhereRuleChartDataEntity(org.talend.dq.indicators.preview.table.WhereRuleChartDataEntity) ChartDataEntity(org.talend.dq.indicators.preview.table.ChartDataEntity) RepositoryNode(org.talend.repository.model.RepositoryNode) ColumnsMapSelectionDialog(org.talend.dataprofiler.core.ui.dialog.ColumnsMapSelectionDialog) UniqueCountIndicator(org.talend.dataquality.indicators.UniqueCountIndicator) EastAsiaPatternLowFreqIndicator(org.talend.dataquality.indicators.EastAsiaPatternLowFreqIndicator) FrequencyIndicator(org.talend.dataquality.indicators.FrequencyIndicator) DatePatternFreqIndicator(org.talend.dataquality.indicators.DatePatternFreqIndicator) EastAsiaPatternFreqIndicator(org.talend.dataquality.indicators.EastAsiaPatternFreqIndicator) WellFormE164PhoneCountIndicator(org.talend.dataquality.indicators.WellFormE164PhoneCountIndicator) PatternLowFreqIndicator(org.talend.dataquality.indicators.PatternLowFreqIndicator) PatternFreqIndicator(org.talend.dataquality.indicators.PatternFreqIndicator) AllMatchIndicator(org.talend.dataquality.indicators.columnset.AllMatchIndicator) ValidPhoneCountIndicator(org.talend.dataquality.indicators.ValidPhoneCountIndicator) WellFormIntePhoneCountIndicator(org.talend.dataquality.indicators.WellFormIntePhoneCountIndicator) PossiblePhoneCountIndicator(org.talend.dataquality.indicators.PossiblePhoneCountIndicator) PatternMatchingIndicator(org.talend.dataquality.indicators.PatternMatchingIndicator) Indicator(org.talend.dataquality.indicators.Indicator) SqlPatternMatchingIndicator(org.talend.dataquality.indicators.SqlPatternMatchingIndicator) DistinctCountIndicator(org.talend.dataquality.indicators.DistinctCountIndicator) DuplicateCountIndicator(org.talend.dataquality.indicators.DuplicateCountIndicator) WellFormNationalPhoneCountIndicator(org.talend.dataquality.indicators.WellFormNationalPhoneCountIndicator) WhereRuleIndicator(org.talend.dataquality.indicators.sql.WhereRuleIndicator) JoinElement(org.talend.dataquality.rules.JoinElement) EList(org.eclipse.emf.common.util.EList) TdColumn(org.talend.cwm.relational.TdColumn) WhereRuleChartDataEntity(org.talend.dq.indicators.preview.table.WhereRuleChartDataEntity) DatePatternFreqIndicator(org.talend.dataquality.indicators.DatePatternFreqIndicator) Map(java.util.Map) HashMap(java.util.HashMap) PatternExplorer(org.talend.dq.analysis.explore.PatternExplorer) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

ColumnSet (orgomg.cwm.resource.relational.ColumnSet)55 TdColumn (org.talend.cwm.relational.TdColumn)35 Package (orgomg.cwm.objectmodel.core.Package)14 ArrayList (java.util.ArrayList)12 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)11 Connection (org.talend.core.model.metadata.builder.connection.Connection)9 RepositoryNode (org.talend.repository.model.RepositoryNode)9 ReloadCompareException (org.talend.cwm.compare.exception.ReloadCompareException)7 TdTable (org.talend.cwm.relational.TdTable)7 Catalog (orgomg.cwm.resource.relational.Catalog)7 Schema (orgomg.cwm.resource.relational.Schema)7 Resource (org.eclipse.emf.ecore.resource.Resource)6 EObject (org.eclipse.emf.ecore.EObject)5 ReturnCode (org.talend.utils.sugars.ReturnCode)5 Indicator (org.talend.dataquality.indicators.Indicator)4 IRepositoryNode (org.talend.repository.model.IRepositoryNode)4 List (java.util.List)3 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)3 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)3 DuplicateCountIndicator (org.talend.dataquality.indicators.DuplicateCountIndicator)3