Search in sources :

Example 61 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class BooleanExpressionHelper method createTdExpression.

public static TdExpression createTdExpression(String language, String body) {
    TdExpression expression = RelationalFactory.eINSTANCE.createTdExpression();
    expression.setBody(body);
    expression.setLanguage(language);
    return expression;
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression)

Example 62 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class BooleanExpressionHelper method createBooleanExpressionNode.

/**
 * Method "createBooleanExpressionNode".
 *
 * @param body the body of the Expression
 * @return a BooleanExpressionNode with the given Expression.
 */
public static BooleanExpressionNode createBooleanExpressionNode(String body) {
    BooleanExpressionNode expr = ExpressionsFactory.eINSTANCE.createBooleanExpressionNode();
    TdExpression expression = createTdExpression(DEFAULT_LANGUAGE, body);
    expr.setExpression(expression);
    return expr;
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) BooleanExpressionNode(org.talend.dataquality.expressions.BooleanExpressionNode)

Example 63 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class DbmsLanguage method getSqlExpression.

/**
 * 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 TdExpression getSqlExpression(IndicatorDefinition indicatorDefinition, String language, EList<TdExpression> sqlGenericExpression, ProductVersion dbVersion) {
    TdExpression defaultExpression = null;
    if (sqlGenericExpression == null || sqlGenericExpression.size() == 0) {
        return defaultExpression;
    }
    List<TdExpression> tempExpressions = new ArrayList<TdExpression>();
    // exact match the language first, if don't match then use fuzzy matching
    boolean matchingFlag = false;
    for (TdExpression sqlGenExpr : sqlGenericExpression) {
        if (DbmsLanguageFactory.equalsDbmsLanguage(language, sqlGenExpr.getLanguage())) {
            tempExpressions.add(sqlGenExpr);
            matchingFlag = true;
        }
    }
    if (!matchingFlag) {
        // if the language contain the key word, it is considered to be equals
        for (TdExpression sqlGenExpr : sqlGenericExpression) {
            if (DbmsLanguageFactory.compareDbmsLanguage(language, sqlGenExpr.getLanguage())) {
                tempExpressions.add(sqlGenExpr);
            }
        }
    }
    List<TdExpression> tempExpressions2 = new ArrayList<TdExpression>();
    for (TdExpression exp : tempExpressions) {
        if (exp.getVersion() == null || PluginConstant.EMPTY_STRING.equals(exp.getVersion())) {
            defaultExpression = exp;
        } else {
            if (dbVersion.toString().equals(exp.getVersion())) {
                // find the identical version
                return exp;
            } else {
                tempExpressions2.add(exp);
            }
        }
    }
    for (TdExpression exp : tempExpressions2) {
        if (dbVersion.toString().startsWith(exp.getVersion()) || exp.getVersion().startsWith(dbVersion.toString())) {
            // opposite
            return exp;
        }
    }
    if (defaultExpression != null) {
        // return the found default version expression
        return defaultExpression;
    }
    // TDQ-11558: added by msjian when there is no REDSHIFT definition, we use postgresql first
    if (language.equals(SupportDBUrlType.REDSHIFT.getLanguage())) {
        return getSqlExpression(indicatorDefinition, SupportDBUrlType.POSTGRESQLEFAULTURL.getLanguage(), sqlGenericExpression, dbVersion);
    }
    // TDQ-11558~
    // 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 getSqlExpression(indicatorDefinition, defaultLanguage, sqlGenericExpression, dbVersion);
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) ArrayList(java.util.ArrayList)

Example 64 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class DbmsLanguage method getFunctions.

private List<String> getFunctions(IndicatorDefinition indicatorDefinition, final EList<TdExpression> functions) {
    // MOD xqliu 2010-02-25 feature 11201
    TdExpression sqlGenExpr = getSqlExpression(indicatorDefinition, this.dbmsName, functions, this.getDbVersion());
    // ~11201
    if (sqlGenExpr != null) {
        final String body = sqlGenExpr.getBody();
        // $NON-NLS-1$
        final String[] fonc = body.split(";");
        // language found
        return Arrays.asList(fonc);
    }
    return Collections.emptyList();
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression)

Example 65 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class ParserRuleImpl method addExpression.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
public boolean addExpression(String name, String type, String value) {
    if (name == null) {
        return false;
    }
    TdExpression tdExpression = getExpression(name);
    if (tdExpression == null) {
        tdExpression = RelationalFactory.eINSTANCE.createTdExpression();
    }
    tdExpression.setBody(value == null ? "" : value);
    tdExpression.setLanguage(type);
    tdExpression.setName(name);
    return this.getExpression().add(tdExpression);
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression)

Aggregations

TdExpression (org.talend.cwm.relational.TdExpression)121 Test (org.junit.Test)51 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)30 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)29 ArrayList (java.util.ArrayList)19 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)19 Pattern (org.talend.dataquality.domain.pattern.Pattern)16 TdColumn (org.talend.cwm.relational.TdColumn)12 Expression (orgomg.cwm.objectmodel.core.Expression)12 BasicEList (org.eclipse.emf.common.util.BasicEList)11 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)11 Domain (org.talend.dataquality.domain.Domain)10 TdTable (org.talend.cwm.relational.TdTable)9 ProductVersion (org.talend.utils.ProductVersion)9 Analysis (org.talend.dataquality.analysis.Analysis)8 PatternComponent (org.talend.dataquality.domain.pattern.PatternComponent)8 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)8 File (java.io.File)7 IFile (org.eclipse.core.resources.IFile)6 IFolder (org.eclipse.core.resources.IFolder)6