use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class TextIndicatorForNetezzaTest method testPatternLow.
@Test
public void testPatternLow() {
TdExpression expression = findExpressionForNetezza(PATTERN_LOW_FREQUENCY);
Assert.assertNotNull(expression);
Assert.assertEquals(PATTERN_LOW_FREQUENCY_SQL, expression.getBody());
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class UDIUtilsTest method testIsCurrentLanguageAndVersion.
/**
* Test method for
* {@link org.talend.dataprofiler.core.ui.utils.UDIUtils#isCurrentLanguageAndVersion(org.talend.cwm.relational.TdExpression, java.lang.String, java.lang.String)}
* .
*/
@Test
public void testIsCurrentLanguageAndVersion() {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
TdExpression tdExpression = UDIUtils.createNewTdExpression("MySQL", "5.0.2", "select * from test");
// $NON-NLS-1$ //$NON-NLS-2$
assertTrue(UDIUtils.isCurrentLanguageAndVersion(tdExpression, "MySQL", "5.0.2"));
// $NON-NLS-1$ //$NON-NLS-2$
assertFalse(UDIUtils.isCurrentLanguageAndVersion(tdExpression, "MySQL", "5.1.2"));
// $NON-NLS-1$ //$NON-NLS-2$
assertFalse(UDIUtils.isCurrentLanguageAndVersion(tdExpression, "Oracle", "5.0.2"));
// $NON-NLS-1$
assertFalse(UDIUtils.isCurrentLanguageAndVersion(tdExpression, "Oracle", null));
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class ColumnAnalysisSqlExecutor method createSqlQuery.
/**
* Method "createSqlQuery".
*
* @param dataFilterExpression
* @param analysis
* @param indicator
*
* @throws ParseException
* @throws AnalysisExecutionException
*/
private boolean createSqlQuery(String dataFilterAsString, Indicator indicator) throws AnalysisExecutionException {
TypedReturnCode<TdColumn> checkResult = getTdColumn(indicator);
if (!checkResult.isOk()) {
return false;
}
TdColumn tdColumn = checkResult.getObject();
if (tdColumn.eIsProxy()) {
tdColumn = (TdColumn) EObjectHelper.resolveObject(tdColumn);
}
TypedReturnCode<String> columnName = getColumnName(indicator, tdColumn);
if (!columnName.isOk()) {
return false;
}
String colName = columnName.getObject();
TypedReturnCode<IndicatorDefinition> id = getIndicatorDefinition(indicator);
if (!id.isOk()) {
return false;
}
IndicatorDefinition indicatorDefinition = id.getObject();
// get correct language for current database
String language = dbms().getDbmsName();
// --- create select statement
// get indicator's sql columnS (generate the real SQL statement from its definition)
Expression sqlGenericExpression = dbms().getSqlExpression(indicatorDefinition);
final EClass indicatorEclass = indicator.eClass();
if (sqlGenericExpression == null || sqlGenericExpression.getBody() == null) {
// analysis, will not check the sql expression and create again(from the definition).
if (UDIHelper.isUDI(indicator) && indicator.getInstantiatedExpressions().size() > 0) {
return Boolean.TRUE;
}
// expressions.
if (IndicatorsPackage.eINSTANCE.getRegexpMatchingIndicator().equals(indicatorEclass)) {
// $NON-NLS-1$
traceError(Messages.getString("ColumnAnalysisSqlExecutor.PLEASEREMOVEALLPATTEN"));
return Boolean.FALSE;
}
traceError(Messages.getString(// $NON-NLS-1$
"ColumnAnalysisSqlExecutor.UNSUPPORTEDINDICATOR", (indicator.getName() != null ? AnalysisExecutorHelper.getIndicatorName(indicator) : indicatorEclass.getName())));
return Boolean.FALSE;
}
// --- get indicator parameters and convert them into sql expression
List<String> whereExpression = new ArrayList<String>();
if (StringUtils.isNotBlank(dataFilterAsString)) {
whereExpression.add(dataFilterAsString);
}
List<String> rangeStrings = null;
DateGrain dateAggregationType = null;
IndicatorParameters parameters = indicator.getParameters();
if (parameters != null) {
// handle bins
Domain bins = parameters.getBins();
if (bins != null) {
rangeStrings = getBinsAsGenericString(bins.getRanges(), colName);
}
DateParameters dateParameters = parameters.getDateParameters();
if (dateParameters != null) {
dateAggregationType = dateParameters.getDateAggregationType();
}
TextParameters textParameter = parameters.getTextParameter();
if (textParameter != null) {
if (textParameter.isIgnoreCase()) {
colName = dbms().toUpperCase(colName);
}
if (!textParameter.isUseBlank() && IndicatorsPackage.eINSTANCE.getLengthIndicator().isSuperTypeOf(indicatorEclass)) {
String tdColName = getQuotedColumnName(tdColumn);
// $NON-NLS-1$
tdColName = dbms().replaceNullsWithString(tdColName, "'NULL TALEND'");
} else if (textParameter.isUseBlank() && IndicatorsPackage.eINSTANCE.getFrequencyIndicator().isSuperTypeOf(indicatorEclass)) {
colName = dbms().trim(colName);
}
}
}
TypedReturnCode<String> completedQuery = getCompletedQuery(indicator, tdColumn, colName, indicatorDefinition, language, sqlGenericExpression, indicatorEclass, whereExpression, rangeStrings, dateAggregationType);
if (!completedQuery.isOk()) {
return false;
}
String finalQuery = completedQuery.getObject();
if (finalQuery != null) {
TdExpression instantiateSqlExpression = BooleanExpressionHelper.createTdExpression(language, finalQuery);
indicator.setInstantiatedExpression(instantiateSqlExpression);
return true;
}
return false;
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class TableAnalysisSqlExecutor method createSqlQuery.
private boolean createSqlQuery(String dataFilterAsString, Indicator indicator, boolean withWhereOfRule) throws AnalysisExecutionException {
if (!isAnalyzedElementValid(indicator)) {
return Boolean.FALSE;
}
IndicatorDefinition indicatorDefinition = indicator.getIndicatorDefinition();
if (!isIndicatorDefinitionValid(indicatorDefinition, AnalysisExecutorHelper.getIndicatorName(indicator))) {
return Boolean.FALSE;
}
Expression sqlGenericExpression = dbms().getSqlExpression(indicatorDefinition);
if (!isExpressionValid(sqlGenericExpression, indicator)) {
return Boolean.FALSE;
}
// --- get indicator parameters and convert them into sql expression
List<String> whereExpressionDQRule = new ArrayList<String>();
final EList<JoinElement> joinConditions = indicator.getJoinConditions();
if (RulesPackage.eINSTANCE.getWhereRule().equals(indicatorDefinition.eClass())) {
WhereRule wr = (WhereRule) indicatorDefinition;
if (withWhereOfRule) {
whereExpressionDQRule.add(wr.getWhereExpression());
}
// MOD scorreia 2009-03-13 copy joins conditions into the indicator
joinConditions.clear();
if (!isJoinConditionEmpty(indicator)) {
for (JoinElement joinelt : wr.getJoins()) {
JoinElement joinCopy = EcoreUtil.copy(joinelt);
joinConditions.add(joinCopy);
}
}
}
NamedColumnSet set = SwitchHelpers.NAMED_COLUMN_SET_SWITCH.doSwitch(indicator.getAnalyzedElement());
String schemaName = getQuotedSchemaName(set);
// --- normalize table name
String catalogName = getQuotedCatalogName(set);
if (catalogName == null && schemaName != null) {
// try to get catalog above schema
final Schema parentSchema = SchemaHelper.getParentSchema(set);
final Catalog parentCatalog = CatalogHelper.getParentCatalog(parentSchema);
catalogName = parentCatalog != null ? parentCatalog.getName() : null;
}
// --- default case
// allow join
String joinclause = (!joinConditions.isEmpty()) ? dbms().createJoinConditionAsString(set, joinConditions, catalogName, schemaName) : PluginConstant.EMPTY_STRING;
String setName = dbms().toQualifiedName(catalogName, schemaName, quote(set.getName()));
String completedSqlString = dbms().fillGenericQueryWithJoin(sqlGenericExpression.getBody(), setName, joinclause);
// ~
List<String> whereExpressionAnalysis = new ArrayList<String>();
if (StringUtils.isNotBlank(dataFilterAsString)) {
whereExpressionAnalysis.add(dataFilterAsString);
}
completedSqlString = addWhereToSqlStringStatement(whereExpressionAnalysis, whereExpressionDQRule, completedSqlString, true);
// completedSqlString is the final query
String finalQuery = completedSqlString;
TdExpression instantiateSqlExpression = BooleanExpressionHelper.createTdExpression(dbms().getDbmsName(), finalQuery);
indicator.setInstantiatedExpression(instantiateSqlExpression);
return true;
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class FrequencyStatisticsExplorer method getQueryForUDIndicator.
/**
* get Query For User define indicator.
*
* @param indicatorDefinition
* @return
*/
private String getQueryForUDIndicator(IndicatorDefinition indicatorDefinition) {
String sql = PluginConstant.EMPTY_STRING;
EList<TdExpression> list = ((UDIndicatorDefinition) indicatorDefinition).getViewRowsExpression();
TdExpression tdExp = DbmsLanguage.getSqlExpression(indicatorDefinition, dbmsLanguage.getDbmsName(), list, dbmsLanguage.getDbVersion());
sql = tdExp.getBody();
String dataFilterClause = getDataFilterClause();
if (!dataFilterClause.equals(PluginConstant.EMPTY_STRING)) {
// $NON-NLS-1$ //$NON-NLS-2$
sql = sql.replace(GenericSQLHandler.WHERE_CLAUSE, dbmsLanguage.where() + "(" + dataFilterClause + ")");
// $NON-NLS-1$ //$NON-NLS-2$
sql = sql.replace(GenericSQLHandler.AND_WHERE_CLAUSE, dbmsLanguage.and() + "(" + dataFilterClause + ")");
} else {
sql = sql.replace(GenericSQLHandler.WHERE_CLAUSE, PluginConstant.EMPTY_STRING);
sql = sql.replace(GenericSQLHandler.AND_WHERE_CLAUSE, PluginConstant.EMPTY_STRING);
}
ModelElement analyzedElement = this.indicator.getAnalyzedElement();
String tableName = getFullyQualifiedTableName(analyzedElement);
sql = sql.replace(GenericSQLHandler.TABLE_NAME, tableName);
sql = sql.replace(GenericSQLHandler.COLUMN_NAMES, dbmsLanguage.quote(analyzedElement.getName()));
if (sql.indexOf(GenericSQLHandler.UDI_INDICATOR_VALUE) != -1) {
Object key = entity.getKey();
if (key == null) {
// $NON-NLS-1$ //$NON-NLS-2$
sql = sql.replace("= " + GenericSQLHandler.UDI_INDICATOR_VALUE, "IS NULL");
} else {
// $NON-NLS-1$ //$NON-NLS-2$
sql = sql.replace(GenericSQLHandler.UDI_INDICATOR_VALUE, "'" + key + "'");
}
}
if (sql.indexOf(GenericSQLHandler.GROUP_BY_ALIAS) != -1) {
sql = sql.replace(GenericSQLHandler.GROUP_BY_ALIAS, dbmsLanguage.quote(analyzedElement.getName()));
}
return sql;
}
Aggregations