Search in sources :

Example 21 with DbmsLanguage

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

the class AbstractSchemaEvaluatorTest method testgetCatalogNameWithQuote_oracle.

@Test
public void testgetCatalogNameWithQuote_oracle() {
    SchemaEvaluator schemaEvaluate = new SchemaEvaluator();
    analysisElements.clear();
    analysisElements.add(schema);
    // $NON-NLS-1$
    stub(method(Evaluator.class, "getAnalyzedElements")).toReturn(analysisElements);
    when(schemarIndicator.getAnalyzedElement()).thenReturn(schema);
    DbmsLanguage mysqlDbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(SupportDBUrlType.ORACLEWITHSIDDEFAULTURL.getLanguage(), dbVersion);
    // $NON-NLS-1$
    stub(method(DbmsLanguageFactory.class, "createDbmsLanguage", DataManager.class, ExecutionLanguage.class)).toReturn(mysqlDbmsLanguage);
    String catalogNameWithQuote = schemaEvaluate.getCatalogNameWithQuote(schemarIndicator);
    assertNull(catalogNameWithQuote);
}
Also used : DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 22 with DbmsLanguage

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

the class ModelElementIndicatorRuleTest method testPatternRule_3.

/**
 * test for Hive connection and some indicators should be disabled.
 */
@Test
public void testPatternRule_3() {
    when(tdsql.getJavaDataType()).thenReturn(Types.VARCHAR);
    DatabaseConnection connection = mock(DatabaseConnection.class);
    PowerMockito.mockStatic(ConnectionHelper.class);
    when(ConnectionHelper.getTdDataProvider(me)).thenReturn(connection);
    when(ConnectionHelper.isHive(connection)).thenReturn(true);
    DbmsLanguage dbmsLanguage = mock(DbmsLanguage.class);
    // $NON-NLS-1$
    when(dbmsLanguage.getDbmsName()).thenReturn("MySQL");
    when(dbmsLanguage.getDbVersion()).thenReturn(null);
    PowerMockito.mockStatic(DbmsLanguageFactory.class);
    when(DbmsLanguageFactory.createDbmsLanguage(connection)).thenReturn(dbmsLanguage);
    Assert.assertFalse(ModelElementIndicatorRule.patternRule(IndicatorEnum.SoundexIndicatorEnum, me, ExecutionLanguage.SQL));
    Assert.assertFalse(ModelElementIndicatorRule.patternRule(IndicatorEnum.SoundexLowIndicatorEnum, me, ExecutionLanguage.SQL));
    Assert.assertTrue(ModelElementIndicatorRule.patternRule(IndicatorEnum.PatternFreqIndicatorEnum, me, ExecutionLanguage.SQL));
    Assert.assertTrue(ModelElementIndicatorRule.patternRule(IndicatorEnum.PatternLowFreqIndicatorEnum, me, ExecutionLanguage.SQL));
    when(tdsql.getJavaDataType()).thenReturn(Types.INTEGER);
    Assert.assertFalse(ModelElementIndicatorRule.patternRule(IndicatorEnum.MedianIndicatorEnum, me, ExecutionLanguage.SQL));
    Assert.assertFalse(ModelElementIndicatorRule.patternRule(IndicatorEnum.UpperQuartileIndicatorEnum, me, ExecutionLanguage.SQL));
    Assert.assertFalse(ModelElementIndicatorRule.patternRule(IndicatorEnum.LowerQuartileIndicatorEnum, me, ExecutionLanguage.SQL));
}
Also used : DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 23 with DbmsLanguage

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

the class FunctionalDependencyExecutor method createSqlStatement.

@Override
public String createSqlStatement(Analysis analysis) {
    this.cachedAnalysis = analysis;
    DbmsLanguage dbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(analysis);
    EList<Indicator> indicators = analysis.getResults().getIndicators();
    for (Indicator indicator : indicators) {
        instantiateQuery(indicator, dbmsLanguage);
    }
    // no query to return, here we only instantiate several SQL queries
    return PluginConstant.EMPTY_STRING;
}
Also used : DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) Indicator(org.talend.dataquality.indicators.Indicator) ColumnDependencyIndicator(org.talend.dataquality.indicators.columnset.ColumnDependencyIndicator)

Example 24 with DbmsLanguage

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

the class AnalysisTableTreeViewer method isExpressionNull.

private String isExpressionNull(TreeItem item) {
    String expressContent = null;
    TableIndicatorUnit indicatorUnit = (TableIndicatorUnit) item.getData(INDICATOR_UNIT_KEY);
    TableIndicator tableIndicator = (TableIndicator) item.getData(TABLE_INDICATOR_KEY);
    NamedColumnSet set = tableIndicator.getColumnSet();
    Connection dataprovider = ConnectionHelper.getTdDataProvider(ColumnSetHelper.getParentCatalogOrSchema(set));
    DbmsLanguage dbmsLang = DbmsLanguageFactory.createDbmsLanguage(dataprovider);
    Expression expression = dbmsLang.getInstantiatedExpression(indicatorUnit.getIndicator());
    if (expression != null) {
        expressContent = expression.getBody();
    }
    return expressContent;
}
Also used : DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) TableIndicator(org.talend.dataprofiler.core.model.TableIndicator) Expression(orgomg.cwm.objectmodel.core.Expression) Connection(org.talend.core.model.metadata.builder.connection.Connection) TableIndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.TableIndicatorUnit) NamedColumnSet(orgomg.cwm.resource.relational.NamedColumnSet)

Example 25 with DbmsLanguage

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

the class ModelElementTreeMenuProvider method viewQueryForSelectedElement.

/**
 * DOC mzhao Comment method "viewQueryForSelectedElement".
 *
 * @param newTree
 */
private void viewQueryForSelectedElement(Tree newTree) {
    TreeItem[] selection = newTree.getSelection();
    for (TreeItem item : selection) {
        ModelElementIndicator meIndicator = (ModelElementIndicator) item.getData(AbstractColumnDropTree.MODELELEMENT_INDICATOR_KEY);
        ConnectionItem connItem = (ConnectionItem) meIndicator.getModelElementRepositoryNode().getObject().getProperty().getItem();
        Connection dataprovider = connItem.getConnection();
        IndicatorUnit indicatorUnit = (IndicatorUnit) item.getData(AbstractColumnDropTree.INDICATOR_UNIT_KEY);
        DbmsLanguage dbmsLang = DbmsLanguageFactory.createDbmsLanguage(dataprovider);
        Expression expression = dbmsLang.getInstantiatedExpression(indicatorUnit.getIndicator());
        if (expression == null) {
            MessageDialogWithToggle.openWarning(null, DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.Warn"), // $NON-NLS-1$ //$NON-NLS-2$
            DefaultMessagesImpl.getString("AnalysisColumnTreeViewer.NoQueryDefined"));
            return;
        }
        SqlExplorerUtils.getDefault().runInDQViewer(dataprovider, expression.getBody(), meIndicator.getModelElementRepositoryNode().getObject().getProperty().getLabel());
    }
}
Also used : DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) TreeItem(org.eclipse.swt.widgets.TreeItem) Expression(orgomg.cwm.objectmodel.core.Expression) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Connection(org.talend.core.model.metadata.builder.connection.Connection) IndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit) ColumnIndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.ColumnIndicatorUnit) ModelElementIndicator(org.talend.dataprofiler.core.model.ModelElementIndicator)

Aggregations

DbmsLanguage (org.talend.dq.dbms.DbmsLanguage)29 Test (org.junit.Test)10 Connection (org.talend.core.model.metadata.builder.connection.Connection)9 TdColumn (org.talend.cwm.relational.TdColumn)9 Expression (orgomg.cwm.objectmodel.core.Expression)7 TdTable (org.talend.cwm.relational.TdTable)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 ModelElementIndicator (org.talend.dataprofiler.core.model.ModelElementIndicator)5 IndicatorUnit (org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit)5 Indicator (org.talend.dataquality.indicators.Indicator)5 Package (orgomg.cwm.objectmodel.core.Package)4 ArrayList (java.util.ArrayList)3 IFolder (org.eclipse.core.resources.IFolder)3 Shell (org.eclipse.swt.widgets.Shell)3 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)3 CreatePatternAction (org.talend.dataprofiler.core.pattern.actions.CreatePatternAction)3 IRepositoryNode (org.talend.repository.model.IRepositoryNode)3 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)3 Statement (java.sql.Statement)2 HashMap (java.util.HashMap)2