Search in sources :

Example 6 with CharactersMapping

use of org.talend.dataquality.indicators.definition.CharactersMapping in project tdq-studio-se by Talend.

the class FunctionFrequencyStatExplorer method columnNameConvert.

@SuppressWarnings("deprecation")
private String columnNameConvert() {
    String colName = columnName;
    TdColumn column = (TdColumn) indicator.getAnalyzedElement();
    IndicatorDefinition indicatorDefinition;
    String label = indicator.getIndicatorDefinition().getLabel();
    if (label == null || PluginConstant.EMPTY_STRING.equals(label)) {
        indicatorDefinition = indicator.getIndicatorDefinition();
    } else {
        indicatorDefinition = DefinitionHandler.getInstance().getIndicatorDefinition(label);
    }
    if (indicator.eClass().equals(IndicatorsPackage.eINSTANCE.getPatternFreqIndicator()) || indicator.eClass().equals(IndicatorsPackage.eINSTANCE.getPatternLowFreqIndicator())) {
        // MOD zshen for bug 12675 2010-05-12
        if (Java2SqlType.isNumbericInSQL(column.getSqlDataType().getJavaDataType())) {
            colName = addFunctionTypeConvert(colName);
        }
        // ~12675
        final EList<CharactersMapping> charactersMapping = indicatorDefinition.getCharactersMapping();
        colName = dbmsLanguage.getPatternFinderFunction(colName, charactersMapping);
        if (columnName == null) {
            // no replacement found, try the default one
            colName = dbmsLanguage.getPatternFinderDefaultFunction(colName);
        }
    }
    return colName;
}
Also used : CharactersMapping(org.talend.dataquality.indicators.definition.CharactersMapping) TdColumn(org.talend.cwm.relational.TdColumn) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition)

Example 7 with CharactersMapping

use of org.talend.dataquality.indicators.definition.CharactersMapping in project tdq-studio-se by Talend.

the class DbmsLanguage method getCharacterMappingExpression.

/**
 * get language Sql Expression from TdExpression list with dbVersion, if not found, use the default "SQL" language.
 *
 * @param language
 * @param sqlGenericExpression
 * @param dbVersion
 * @return
 */
public static CharactersMapping getCharacterMappingExpression(IndicatorDefinition indicatorDefinition, String language, EList<CharactersMapping> characterMappingExpression, ProductVersion dbVersion) {
    CharactersMapping defaultExpression = null;
    if (characterMappingExpression == null || characterMappingExpression.size() == 0) {
        return defaultExpression;
    }
    List<CharactersMapping> tempExpressions = new ArrayList<CharactersMapping>();
    // exact match the language first, if don't match then use fuzzy matching
    boolean matchingFlag = false;
    for (CharactersMapping cmExpr : characterMappingExpression) {
        if (DbmsLanguageFactory.equalsDbmsLanguage(language, cmExpr.getLanguage())) {
            tempExpressions.add(cmExpr);
            matchingFlag = true;
        }
    }
    if (!matchingFlag) {
        // if the language contain the key word, it is considered to be equals
        for (CharactersMapping sqlGenExpr : characterMappingExpression) {
            if (DbmsLanguageFactory.compareDbmsLanguage(language, sqlGenExpr.getLanguage())) {
                tempExpressions.add(sqlGenExpr);
            }
        }
    }
    for (CharactersMapping exp : tempExpressions) {
        defaultExpression = exp;
    }
    if (defaultExpression != null) {
        // return the found default version expression
        return defaultExpression;
    }
    // else try with default language (ANSI SQL)
    String defaultLanguage = getDefaultLanguage();
    // if can not find the expression of default language, return null
    if (language.equals(defaultLanguage)) {
        return null;
    }
    if (log.isDebugEnabled()) {
        log.warn(// $NON-NLS-1$
        "The indicator SQL expression has not been found for the database type " + language + " for the indicator" + // $NON-NLS-1$
        indicatorDefinition.getName() + // $NON-NLS-1$
        ". This is not necessarily a problem since the default SQL expression will be used. " + // $NON-NLS-1$
        "Nevertheless, if an SQL error during the analysis, this could be the cause.");
        // $NON-NLS-1$
        log.info("Trying to compute the indicator with the default language " + defaultLanguage);
    }
    return getCharacterMappingExpression(indicatorDefinition, defaultLanguage, characterMappingExpression, dbVersion);
}
Also used : CharactersMapping(org.talend.dataquality.indicators.definition.CharactersMapping) ArrayList(java.util.ArrayList)

Example 8 with CharactersMapping

use of org.talend.dataquality.indicators.definition.CharactersMapping in project tdq-studio-se by Talend.

the class DbmsLanguageTest method testGetPatternFinderFunctionStringEListOfCharactersMappingCase2.

/**
 * Test method for
 * {@link org.talend.dq.dbms.DbmsLanguage#getPatternFinderFunction(java.lang.String, org.eclipse.emf.common.util.EList)}
 * .
 *
 * case 2 : default case
 */
@Test
public void testGetPatternFinderFunctionStringEListOfCharactersMappingCase2() {
    // $NON-NLS-1$
    String expectedResult = "TRANSLATE(name , \'abcdefghijklmnopqrstuvwxyzçâêîôûéèùïöüABCDEFGHIJKLMNOPQRSTUVWXYZÇÂÊÎÔÛÉÈÙÏÖÜ0123456789Default\' , \'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9999999999Default\')";
    NetezzaDbmsLanguage netezzaDbmsLanguage = (NetezzaDbmsLanguage) DbmsLanguageFactory.createDbmsLanguage(SupportDBUrlType.NETEZZADEFAULTURL);
    IndicatorDefinition createIndicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    EList<CharactersMapping> charactersMapping = createIndicatorDefinition.getCharactersMapping();
    CharactersMapping createCharactersMapping = DefinitionFactory.eINSTANCE.createCharactersMapping();
    // mysql
    createCharactersMapping.setLanguage(SupportDBUrlType.MYSQLDEFAULTURL.getLanguage());
    createCharactersMapping.setCharactersToReplace(// $NON-NLS-1$
    "abcdefghijklmnopqrstuvwxyzçâêîôûéèùïöüABCDEFGHIJKLMNOPQRSTUVWXYZÇÂÊÎÔÛÉÈÙÏÖÜ0123456789MySql");
    createCharactersMapping.setReplacementCharacters(// $NON-NLS-1$
    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9999999999MySql");
    charactersMapping.add(createCharactersMapping);
    // ~mysql
    // default
    createCharactersMapping.setLanguage(DbmsLanguage.SQL);
    createCharactersMapping.setCharactersToReplace(// $NON-NLS-1$
    "abcdefghijklmnopqrstuvwxyzçâêîôûéèùïöüABCDEFGHIJKLMNOPQRSTUVWXYZÇÂÊÎÔÛÉÈÙÏÖÜ0123456789Default");
    createCharactersMapping.setReplacementCharacters(// $NON-NLS-1$
    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9999999999Default");
    charactersMapping.add(createCharactersMapping);
    // ~default
    // $NON-NLS-1$
    String patternFinderFunction = netezzaDbmsLanguage.getPatternFinderFunction("name", charactersMapping);
    Assert.assertEquals(expectedResult, patternFinderFunction);
}
Also used : CharactersMapping(org.talend.dataquality.indicators.definition.CharactersMapping) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) Test(org.junit.Test)

Example 9 with CharactersMapping

use of org.talend.dataquality.indicators.definition.CharactersMapping in project tdq-studio-se by Talend.

the class IndicatorDefinitionFileHelper method addCharacterMapping.

/**
 * Added yyin TDQ-6099 20121227
 *
 * @param definition
 * @param newLanguage
 * @param newCharactersToReplace
 * @param newReplacementCharacters
 * @return
 */
public static boolean addCharacterMapping(IndicatorDefinition definition, String newLanguage, String name, String newCharactersToReplace, String newReplacementCharacters) {
    if (null == definition) {
        return false;
    }
    CharactersMapping newMapping = DefinitionFactory.eINSTANCE.createCharactersMapping();
    newMapping.setLanguage(newLanguage);
    newMapping.setCharactersToReplace(newCharactersToReplace);
    newMapping.setReplacementCharacters(newReplacementCharacters);
    newMapping.setName(name);
    return definition.getCharactersMapping().add(newMapping);
}
Also used : CharactersMapping(org.talend.dataquality.indicators.definition.CharactersMapping)

Example 10 with CharactersMapping

use of org.talend.dataquality.indicators.definition.CharactersMapping in project tdq-studio-se by Talend.

the class ModelElementIndicatorRule method isEmpryExpression.

/**
 * DOC talend Comment method "isEmpryExpression".
 *
 * @param indicator
 * @return
 */
private static boolean isEmpryExpression(Indicator indicator, DbmsLanguage dbmsLanguage) {
    Expression sqlExpression = dbmsLanguage.getSqlExpression(indicator.getIndicatorDefinition());
    CharactersMapping characterMappingExpression = dbmsLanguage.getChartacterMappingExpression(indicator.getIndicatorDefinition());
    return sqlExpression == null || characterMappingExpression == null;
}
Also used : CharactersMapping(org.talend.dataquality.indicators.definition.CharactersMapping) Expression(orgomg.cwm.objectmodel.core.Expression)

Aggregations

CharactersMapping (org.talend.dataquality.indicators.definition.CharactersMapping)12 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)4 Test (org.junit.Test)3 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)3 GridData (org.eclipse.swt.layout.GridData)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 TdColumn (org.talend.cwm.relational.TdColumn)1 ReturnCode (org.talend.utils.sugars.ReturnCode)1 Expression (orgomg.cwm.objectmodel.core.Expression)1