Search in sources :

Example 1 with DbmsLanguage

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

the class ColumnAnalysisDetailsPage method checkUDIInvalid.

/**
 * Judge whether there are exist invalid udi
 *
 * @param modelElementIndicator
 * @return
 */
private boolean checkUDIInvalid(ModelElementIndicator modelElementIndicator, boolean isExist) {
    for (IndicatorUnit indicatorUnit : modelElementIndicator.getIndicatorUnits()) {
        boolean isExistSqlExpr = false;
        boolean sqlCaseNormal = false;
        if (IndicatorEnum.UserDefinedIndicatorEnum == indicatorUnit.getType()) {
            // mean that is there exist sql expression
            if (!indicatorUnit.getIndicator().getIndicatorDefinition().getSqlGenericExpression().isEmpty()) {
                isExistSqlExpr = true;
                DbmsLanguage dbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(this.getCurrentModelElement(), ExecutionLanguage.SQL);
                if (dbmsLanguage.getSqlExpression(indicatorUnit.getIndicator().getIndicatorDefinition()) != null) {
                    sqlCaseNormal = true;
                }
            }
            if (isExist && !(isExistSqlExpr && sqlCaseNormal)) {
                // case1:find JUDI exist and isExist=true then return true
                return true;
            } else if (!isExist && !UDIHelper.isJavaUDI(indicatorUnit.getIndicator())) {
                // case2:find JUDI is not exist and isExist=false then return true
                return true;
            }
        }
    }
    // other case(both valid)
    return false;
}
Also used : DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) IndicatorUnit(org.talend.dataprofiler.core.ui.editor.preview.IndicatorUnit)

Example 2 with DbmsLanguage

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

the class AbstractSchemaEvaluatorTest method testgetCatalogNameWithQuote_sqlServer.

@Test
public void testgetCatalogNameWithQuote_sqlServer() {
    SchemaEvaluator schemaEvaluator = new SchemaEvaluator();
    catalog.getOwnedElement().add(schema);
    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.MSSQLDEFAULTURL.getLanguage(), dbVersion);
    // $NON-NLS-1$
    stub(method(DbmsLanguageFactory.class, "createDbmsLanguage", DataManager.class, ExecutionLanguage.class)).toReturn(mysqlDbmsLanguage);
    String catalogNameWithQuote = schemaEvaluator.getCatalogNameWithQuote(schemarIndicator);
    assertNotNull(catalogNameWithQuote);
    assertEquals(catalogNameWithQuote, catalogName);
}
Also used : DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with DbmsLanguage

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

the class AbstractSchemaEvaluatorTest method testgetCatalogNameWithQuote_mySql.

@Test
public void testgetCatalogNameWithQuote_mySql() {
    CatalogEvaluator catalogEvaluator = new CatalogEvaluator();
    analysisElements.clear();
    analysisElements.add(catalog);
    // $NON-NLS-1$
    stub(method(Evaluator.class, "getAnalyzedElements")).toReturn(analysisElements);
    when(schemarIndicator.getAnalyzedElement()).thenReturn(catalog);
    DbmsLanguage mysqlDbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(SupportDBUrlType.MYSQLDEFAULTURL.getLanguage(), dbVersion);
    // $NON-NLS-1$
    stub(method(DbmsLanguageFactory.class, "createDbmsLanguage", DataManager.class, ExecutionLanguage.class)).toReturn(mysqlDbmsLanguage);
    String catalogNameWithQuote = catalogEvaluator.getCatalogNameWithQuote(schemarIndicator);
    assertNotNull(catalogNameWithQuote);
    // $NON-NLS-1$ //$NON-NLS-2$
    assertEquals(catalogNameWithQuote, "`" + catalogName + "`");
}
Also used : DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with DbmsLanguage

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

the class AnalysisExecutorHelperTest method testGetTableName_2.

/**
 * try the oracle db type. Test method for
 * {@link org.talend.dq.helper.AnalysisExecutorHelper#getTableName(orgomg.cwm.objectmodel.core.ModelElement, org.talend.dq.dbms.DbmsLanguage)}
 * .
 */
@Test
public void testGetTableName_2() {
    TdColumn tdColumn = RelationalFactory.eINSTANCE.createTdColumn();
    TdTable tdTable = RelationalFactory.eINSTANCE.createTdTable();
    // $NON-NLS-1$
    tdTable.setName("tableName");
    tdColumn.setOwner(tdTable);
    // $NON-NLS-1$
    tdColumn.setName("columnName");
    DbmsLanguage dbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(SupportDBUrlType.ORACLEWITHSIDDEFAULTURL.getLanguage(), null);
    // mock(Schema.class);
    Package schema = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createSchema();
    // $NON-NLS-1$
    schema.setName("schemaName");
    tdTable.setNamespace(schema);
    // $NON-NLS-1$
    assertEquals("\"SCHEMANAME\".\"TABLENAME\"", AnalysisExecutorHelper.getTableName(tdColumn, dbmsLanguage));
}
Also used : DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) TdColumn(org.talend.cwm.relational.TdColumn) TdTable(org.talend.cwm.relational.TdTable) Package(orgomg.cwm.objectmodel.core.Package) Test(org.junit.Test)

Example 5 with DbmsLanguage

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

the class ModelElementIndicatorRuleTest method testPatternRule_7.

/**
 * test for teradata connection and Pattern Frequency Statistics indicators should be disabled.
 */
@Test
public void testPatternRule_7() {
    when(tdsql.getJavaDataType()).thenReturn(Types.VARCHAR);
    DatabaseConnection connection = mock(DatabaseConnection.class);
    PowerMockito.mockStatic(ConnectionHelper.class);
    when(ConnectionHelper.getTdDataProvider(me)).thenReturn(connection);
    when(ConnectionHelper.isTeradata(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.PatternFreqIndicatorEnum, me, ExecutionLanguage.SQL));
    Assert.assertFalse(ModelElementIndicatorRule.patternRule(IndicatorEnum.PatternLowFreqIndicatorEnum, me, ExecutionLanguage.SQL));
    Assert.assertFalse(ModelElementIndicatorRule.patternRule(IndicatorEnum.DatePatternFreqIndicatorEnum, me, ExecutionLanguage.SQL));
    Assert.assertTrue(ModelElementIndicatorRule.patternRule(IndicatorEnum.PatternFreqIndicatorEnum, me, ExecutionLanguage.JAVA));
    Assert.assertTrue(ModelElementIndicatorRule.patternRule(IndicatorEnum.PatternLowFreqIndicatorEnum, me, ExecutionLanguage.JAVA));
    Assert.assertTrue(ModelElementIndicatorRule.patternRule(IndicatorEnum.DatePatternFreqIndicatorEnum, me, ExecutionLanguage.JAVA));
    when(tdsql.getJavaDataType()).thenReturn(Types.DATE);
    Assert.assertFalse(ModelElementIndicatorRule.patternRule(IndicatorEnum.PatternFreqIndicatorEnum, me, ExecutionLanguage.SQL));
    Assert.assertFalse(ModelElementIndicatorRule.patternRule(IndicatorEnum.PatternLowFreqIndicatorEnum, me, ExecutionLanguage.SQL));
    Assert.assertFalse(ModelElementIndicatorRule.patternRule(IndicatorEnum.DatePatternFreqIndicatorEnum, me, ExecutionLanguage.SQL));
    Assert.assertTrue(ModelElementIndicatorRule.patternRule(IndicatorEnum.PatternFreqIndicatorEnum, me, ExecutionLanguage.JAVA));
    Assert.assertTrue(ModelElementIndicatorRule.patternRule(IndicatorEnum.PatternLowFreqIndicatorEnum, me, ExecutionLanguage.JAVA));
    Assert.assertTrue(ModelElementIndicatorRule.patternRule(IndicatorEnum.DatePatternFreqIndicatorEnum, me, ExecutionLanguage.JAVA));
}
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)

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