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;
}
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;
}
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);
}
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();
}
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);
}
Aggregations