use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.
the class ColumnAnalysisSqlExecutor method runAnalysisIndicators.
/**
* DOC xqliu Comment method "runAnalysisIndicators".
*
* @param connection
* @param elementToIndicator
* @param indicators
* @return
* @throws SQLException
*/
private boolean runAnalysisIndicators(Connection connection, Map<ModelElement, List<Indicator>> elementToIndicator, Collection<Indicator> indicators) throws SQLException {
boolean runStatus = Boolean.TRUE;
for (Indicator indicator : indicators) {
// skip composite indicators that do not require a sql execution
if (indicator instanceof CompositeIndicator) {
// options of composite indicators are handled elsewhere
continue;
}
// set the connection's catalog
if (needChangeCatalog(connection)) {
String catalogName = getCatalogOrSchemaName(indicator.getAnalyzedElement());
if (catalogName != null) {
// check whether null argument can be given
changeCatalog(catalogName, connection);
}
}
Expression query = dbms().getInstantiatedExpression(indicator);
if (query == null || !executeQuery(indicator, connection, query.getBody())) {
traceError(// $NON-NLS-1$//$NON-NLS-2$
"Query not executed for indicator: \"" + AnalysisExecutorHelper.getIndicatorName(indicator) + "\" " + // $NON-NLS-1$//$NON-NLS-2$
((query == null) ? "query is null" : "SQL query: " + query.getBody()));
runStatus = Boolean.FALSE;
} else {
// set computation done
indicator.setComputed(true);
}
// add mapping of analyzed elements to their indicators
addElements2IndicatorsMapping(elementToIndicator, indicator);
}
return runStatus;
}
use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.
the class ColumnAnalysisSqlExecutor method getPatterns.
/**
* DOC scorreia Comment method "getPatterns".
*
* @param indicator
* @return the patterns or null if none has been found
*/
protected List<String> getPatterns(Indicator indicator) {
List<String> patternStrings = new ArrayList<String>();
Domain dataValidDomain = indicator.getParameters().getDataValidDomain();
if (dataValidDomain == null) {
return patternStrings;
}
EList<Pattern> patterns = dataValidDomain.getPatterns();
for (Pattern pattern : patterns) {
Expression expression = this.dbms().getRegexp(pattern);
String regexp = expression == null ? null : expression.getBody();
if (regexp != null) {
patternStrings.add(regexp);
}
}
return patternStrings;
}
use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.
the class MultiColumnAnalysisExecutor method runAnalysis.
/**
* DOC scorreia Comment method "getTableName".
*
* @param analyzedColumns
* @return the quoted table name
*/
/*
* tableName = columnSetOwner.getName(); Package pack = PackageHelper.getCatalogOrSchema(columnSetOwner); if (pack
* == null) { log.error("No Catalog or Schema found for column set owner: " + tableName); continue; // do not break
* until we find the owner } this.catalogOrSchema = pack.getName(); break; // all columns should belong to the same
* table
*/
/*
* (non-Javadoc)
*
* @see org.talend.dq.analysis.AnalysisExecutor#runAnalysis(org.talend.dataquality.analysis.Analysis,
* java.lang.String)
*/
@Override
protected boolean runAnalysis(Analysis analysis, String sqlStatement) {
boolean isSuccess = true;
TypedReturnCode<java.sql.Connection> trc = this.getConnectionBeforeRun(analysis);
if (!trc.isOk()) {
log.error(trc.getMessage());
setError(trc.getMessage());
traceError(Messages.getString("FunctionalDependencyExecutor.CANNOTEXECUTEANALYSIS", analysis.getName(), // $NON-NLS-1$
trc.getMessage()));
return Boolean.FALSE;
}
Connection connection = trc.getObject();
try {
// execute the sql statement for each indicator
EList<Indicator> indicators = analysis.getResults().getIndicators();
for (Indicator indicator : indicators) {
indicator.prepare();
// set the connection's catalog
if (this.catalogOrSchema != null && needChangeCatalog(connection)) {
// check whether null argument can be given
changeCatalog(this.catalogOrSchema, connection);
}
Expression query = dbms().getInstantiatedExpression(indicator);
if (query == null) {
traceError(// $NON-NLS-1$//$NON-NLS-2$
"Query not executed for indicator: \"" + AnalysisExecutorHelper.getIndicatorName(indicator) + "\" " + // $NON-NLS-1$
"query is null");
isSuccess = Boolean.FALSE;
continue;
}
try {
Boolean isExeSuccess = executeQuery(indicator, connection, query);
if (!isExeSuccess) {
traceError(// $NON-NLS-1$//$NON-NLS-2$
"Query not executed for indicator: \"" + AnalysisExecutorHelper.getIndicatorName(indicator) + "\" " + // $NON-NLS-1$//$NON-NLS-2$
((query == null) ? "query is null" : "SQL query: " + query.getBody()));
isSuccess = Boolean.FALSE;
continue;
}
} catch (Exception e) {
traceError(e.getMessage());
isSuccess = Boolean.FALSE;
continue;
}
indicator.setComputed(true);
}
} finally {
ReturnCode rc = closeConnection(analysis, connection);
if (!rc.isOk()) {
isSuccess = Boolean.FALSE;
}
}
return isSuccess;
}
use of orgomg.cwm.objectmodel.core.Expression 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 orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.
the class FunctionalDependencyExecutor method instantiateQuery.
private boolean instantiateQuery(Indicator indicator, DbmsLanguage dbmsLanguage) {
if (ColumnsetPackage.eINSTANCE.getColumnDependencyIndicator().equals(indicator.eClass())) {
ColumnDependencyIndicator rowMatchingIndicator = (ColumnDependencyIndicator) indicator;
TdColumn columnA = rowMatchingIndicator.getColumnA();
TdColumn columnB = rowMatchingIndicator.getColumnB();
IndicatorDefinition indicatorDefinition = indicator.getIndicatorDefinition();
// SystemIndicator),the IndicatorDefinition maybe a proxy,should reset it.
if (indicatorDefinition == null || indicatorDefinition.eIsProxy()) {
// $NON-NLS-1$
indicatorDefinition = DefinitionHandler.getInstance().getIndicatorDefinition("Functional Dependency");
indicator.setIndicatorDefinition(indicatorDefinition);
}
Expression sqlGenericExpression = dbms().getSqlExpression(indicatorDefinition);
Expression instantiatedSqlExpression = createInstantiatedSqlExpression(sqlGenericExpression, columnA, columnB, dbmsLanguage);
indicator.setInstantiatedExpression(instantiatedSqlExpression);
return true;
}
traceError(Messages.getString("FunctionalDependencyExecutor.UNHANDLEDGIVENINDICATOR", // $NON-NLS-1$
AnalysisExecutorHelper.getIndicatorName(indicator)));
return Boolean.FALSE;
}
Aggregations