use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.
the class DbmsLanguageTest method testExtractRegularExpressionFunctionForPostgreSQL.
/**
* {@link org.talend.dq.dbms.DbmsLanguage#extractRegularExpressionFunction(Expression)}.
*
* case 3:PostgreSQL database expression
*/
@Test
public void testExtractRegularExpressionFunctionForPostgreSQL() {
DbmsLanguage netezzaDbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(SupportDBUrlType.POSTGRESQLEFAULTURL);
Expression createExpression = CoreFactory.eINSTANCE.createExpression();
// Postgresql Database
// $NON-NLS-1$
createExpression.setBody("**");
// $NON-NLS-1$
String regularFunctionName = netezzaDbmsLanguage.extractRegularExpressionFunction(createExpression, "***");
// $NON-NLS-1$
Assert.assertEquals("~", regularFunctionName);
}
use of orgomg.cwm.objectmodel.core.Expression 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;
}
use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.
the class RespositoryDetailView method createTdColumn.
private void createTdColumn(TdColumn column) {
createNameCommentDetail(column);
newLabelAndText(gContainer, DefaultMessagesImpl.getString("RespositoryDetailView.typex"), // $NON-NLS-1$ //$NON-NLS-2$
column.getSqlDataType() != null ? column.getSqlDataType().getName() : "");
// $NON-NLS-1$
String purpose = "" + column.isNullable();
// $NON-NLS-1$
newLabelAndText(gContainer, DefaultMessagesImpl.getString("RespositoryDetailView.nullable"), purpose);
final Expression initialValue = column.getInitialValue();
String defValueText = (initialValue != null) ? initialValue.getBody() : null;
// $NON-NLS-1$
newLabelAndText(gContainer, DefaultMessagesImpl.getString("RespositoryDetailView.DefaultValue"), defValueText);
newLabelAndText(gContainer, DefaultMessagesImpl.getString("RespositoryDetailView.Size"), // $NON-NLS-1$
String.valueOf(column.getLength()));
if (PluginChecker.isTDQLoaded()) {
String semanticName = TaggedValueHelper.getValueString(TaggedValueHelper.SEMANTIC_NAME, column);
// $NON-NLS-1$
newLabelAndText(gContainer, DefaultMessagesImpl.getString("RespositoryDetailView.semanticName"), semanticName);
}
}
use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.
the class AnalysisHandleTest method testUpdate.
/**
* Test method for
* {@link org.talend.dataprofiler.core.ui.action.actions.handle.AnalysisDuplicateHandle#update(orgomg.cwm.objectmodel.core.ModelElement, orgomg.cwm.objectmodel.core.ModelElement)}
* .
*/
@Test
public void testUpdate() {
// $NON-NLS-1$
Analysis newAnalysis = AnalysisHelper.createAnalysis("new ana");
AnalysisParameters parameters = AnalysisFactory.eINSTANCE.createAnalysisParameters();
newAnalysis.setParameters(parameters);
// make the new analysis use the old domain
EList<Domain> oldDataFilters = oldAnalysis.getParameters().getDataFilter();
assertEquals(2, oldDataFilters.size());
EList<Domain> newFilter = parameters.getDataFilter();
for (Domain domain : oldDataFilters) {
newFilter.add(domain);
}
ModelElement copiedAna = handle.update(oldAnalysis, newAnalysis);
EList<Domain> newDataFilters = ((Analysis) copiedAna).getParameters().getDataFilter();
assertEquals(2, newDataFilters.size());
// after update, the old domain should be replaced by a new one, but with same body& language
for (int i = 0; i < newDataFilters.size(); i++) {
Domain domain = newDataFilters.get(i);
Domain oldDomain = oldDataFilters.get(i);
Assert.assertNotSame(oldDomain, domain);
// $NON-NLS-1$
assertTrue(domain.getName().equals("Analysis Data Filter"));
// the expressions are different instances, with same boby&language.
if (domain.getRanges() != null && oldDomain.getRanges() != null) {
Expression ex = domain.getRanges().get(0).getExpressions().getExpression();
Expression oldex = oldDomain.getRanges().get(0).getExpressions().getExpression();
Assert.assertNotSame(oldex, ex);
assertTrue(ex.getBody().equals(oldex.getBody()));
assertTrue(ex.getLanguage().equals(oldex.getLanguage()));
}
}
// check the patterns
String tablePattern = DomainHelper.getTablePattern(newDataFilters);
assertEquals(TABLE_PATTERN_FILTER, tablePattern);
String viewPattern = DomainHelper.getViewPattern(newDataFilters);
assertEquals(VIEW_PATTERN_FILTER, viewPattern);
}
use of orgomg.cwm.objectmodel.core.Expression 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;
}
Aggregations