use of org.talend.dataquality.domain.pattern.RegularExpression in project tdq-studio-se by Talend.
the class PatternExplorerRealTest method testGetInvalidRowsStatement_4.
/**
* Test method for {@link org.talend.dq.analysis.explore.PatternExplorer#getInvalidRowsStatement()}. when the test
* for indicator is user define indicator
*/
@Test
public void testGetInvalidRowsStatement_4() {
patternExplorer = new RegexPatternExplorer();
// mock setEntity
PatternMatchingIndicator indicator = IndicatorsFactoryImpl.eINSTANCE.createRegexpMatchingIndicator();
UDIndicatorDefinition indicatorDef = UserdefineFactoryImpl.eINSTANCE.createUDIndicatorDefinition();
indicator.setIndicatorDefinition(indicatorDef);
TdExpression udiTdExpression = RelationalFactoryImpl.eINSTANCE.createTdExpression();
udiTdExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
udiTdExpression.setBody(ViewInvalidRows);
indicatorDef.getViewInvalidRowsExpression().add(udiTdExpression);
// create pattern parameter
IndicatorParameters createIndicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
indicator.setParameters(createIndicatorParameters);
Domain createDomain = DomainFactoryImpl.eINSTANCE.createDomain();
createIndicatorParameters.setDataValidDomain(createDomain);
Pattern createPattern = PatternFactoryImpl.eINSTANCE.createPattern();
createDomain.getPatterns().add(createPattern);
RegularExpression createPatternComponent = PatternFactoryImpl.eINSTANCE.createRegularExpression();
createPattern.getComponents().add(createPatternComponent);
TdExpression createTdExpression = RelationalFactoryImpl.eINSTANCE.createTdExpression();
createPatternComponent.setExpression(createTdExpression);
createTdExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
// $NON-NLS-1$
createTdExpression.setBody("`su.*`");
TdColumn element = RelationalFactoryImpl.eINSTANCE.createTdColumn();
// $NON-NLS-1$
element.setName("lname");
TdTable createTdTable = RelationalFactoryImpl.eINSTANCE.createTdTable();
// $NON-NLS-1$
createTdTable.setName("table1");
TableHelper.addColumn(createTdTable, element);
Catalog createCatalog = orgomg.cwm.resource.relational.impl.RelationalFactoryImpl.eINSTANCE.createCatalog();
// $NON-NLS-1$
createCatalog.setName("catalog1");
List<TdTable> tableList = new ArrayList<TdTable>();
tableList.add(createTdTable);
CatalogHelper.addTables(tableList, createCatalog);
indicator.setAnalyzedElement(element);
Expression createIndiExpression = CoreFactoryImpl.eINSTANCE.createExpression();
createIndiExpression.setLanguage(SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
// $NON-NLS-1$
createIndiExpression.setBody("SELECT * FROM `tbi`.`customer` WHERE (customer.lname = \"sunny\")");
indicator.setInstantiatedExpression(createIndiExpression);
Analysis analysis = AnalysisFactoryImpl.eINSTANCE.createAnalysis();
AnalysisContext createAnalysisContext = AnalysisFactoryImpl.eINSTANCE.createAnalysisContext();
analysis.setContext(createAnalysisContext);
DatabaseConnection createDatabaseConnection = ConnectionFactoryImpl.eINSTANCE.createDatabaseConnection();
TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_PRODUCT_NAME, SupportDBUrlType.HIVEDEFAULTURL.getLanguage());
// $NON-NLS-1$
TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_PRODUCT_VERSION, "1.0");
// $NON-NLS-1$
TaggedValueHelper.setTaggedValue(createDatabaseConnection, TaggedValueHelper.DB_IDENTIFIER_QUOTE_STRING, "`");
createAnalysisContext.setConnection(createDatabaseConnection);
ChartDataEntity cdEntity = new ChartDataEntity();
cdEntity.setIndicator(indicator);
Assert.assertTrue(patternExplorer.setAnalysis(analysis));
patternExplorer.setEnitty(cdEntity);
String clause = patternExplorer.getInvalidRowsStatement();
// $NON-NLS-1$
assertEquals("SELECT * FROM `catalog1`.`table1` WHERE NOT (id>=1) ", clause);
}
use of org.talend.dataquality.domain.pattern.RegularExpression in project tdq-studio-se by Talend.
the class SQLPatternExplorerTest method creatSqlPatternMatchingIndicator.
private SqlPatternMatchingIndicator creatSqlPatternMatchingIndicator() {
// create database construction
TdColumn column = UnitTestBuildHelper.createRealTdColumn("lname", "lname", Types.VARCHAR);
// create indicator
SqlPatternMatchingIndicator indicator = IndicatorsFactory.eINSTANCE.createSqlPatternMatchingIndicator();
indicator.setAnalyzedElement(column);
IndicatorParameters indicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
indicatorParameters.setDateParameters(null);
indicator.setParameters(indicatorParameters);
Pattern pattern = PatternFactory.eINSTANCE.createPattern();
// $NON-NLS-1$
pattern.setName("My Pattern");
RegularExpression regularExpr = PatternFactory.eINSTANCE.createRegularExpression();
TdExpression expression = RelationalFactory.eINSTANCE.createTdExpression();
expression.setBody("'su%'");
// $NON-NLS-1$
expression.setLanguage("SQL");
regularExpr.setExpression(expression);
pattern.getComponents().add(regularExpr);
// create Domain
Domain createDomain = DomainFactory.eINSTANCE.createDomain();
indicatorParameters.setDataValidDomain(createDomain);
indicatorParameters.getDataValidDomain().getPatterns().add(pattern);
return indicator;
}
use of org.talend.dataquality.domain.pattern.RegularExpression in project tdq-studio-se by Talend.
the class DbmsLanguageTest method testGetRegexpGetMssqlFromContainDefaultAndWithoutMssql.
/**
* Test method for
* {@link org.talend.dq.dbms.DbmsLanguage#getRegexp(org.talend.dataquality.domain.pattern.Pattern, boolean)}.
*/
@Test
public void testGetRegexpGetMssqlFromContainDefaultAndWithoutMssql() {
// Pattern
Pattern createPattern = PatternFactory.eINSTANCE.createPattern();
// ~Pattern
// init sql Expression data
RegularExpression createSqlRegularExpression = PatternFactory.eINSTANCE.createRegularExpression();
TdExpression createSqlTdExpression = RelationalFactory.eINSTANCE.createTdExpression();
createSqlTdExpression.setBody(SqlRegex);
createSqlTdExpression.setLanguage(ExecutionLanguage.SQL.getName());
createSqlRegularExpression.setExpression(createSqlTdExpression);
createSqlRegularExpression.setExpressionType(ExpressionType.REGEXP.getLiteral());
EList<PatternComponent> components = createPattern.getComponents();
components.add(createSqlRegularExpression);
// ~init sql Expression data
// init java Expression data
RegularExpression createJavaRegularExpression = PatternFactory.eINSTANCE.createRegularExpression();
TdExpression createJavaTdExpression = RelationalFactory.eINSTANCE.createTdExpression();
createJavaTdExpression.setBody(JavaRegex);
createJavaTdExpression.setLanguage(SupportDBUrlType.JAVADEFAULTURL.getLanguage());
createJavaRegularExpression.setExpression(createJavaTdExpression);
createJavaRegularExpression.setExpressionType(ExpressionType.REGEXP.getLiteral());
components = createPattern.getComponents();
components.add(createJavaRegularExpression);
try {
DbmsLanguage dbms = DbmsLanguageFactory.createDbmsLanguage(SupportDBUrlType.MSSQLDEFAULTURL);
Assert.assertTrue(SqlRegex.equalsIgnoreCase(dbms.getRegexp(createPattern).getBody()));
} catch (Exception e) {
fail(e.getMessage());
}
}
use of org.talend.dataquality.domain.pattern.RegularExpression in project tdq-studio-se by Talend.
the class PatternTestView method savePattern.
/**
* If the pattern is not null, will save it and update the corresponding pattern editor content.
*/
private void savePattern() {
// If the pattern is not null, will update the pattern editor content.
if (pattern != null) {
String expressionLanguage = this.regularExpression.getExpression().getLanguage();
DbmsLanguage dbmsLanguage = this.getDbmsLanguage();
// MOD gdbu 2011-6-13 bug : 21695
if (null != dbmsLanguage) {
dbmsLanguage.setRegularExpressionFunction(getFunctionName());
}
// ~21695
// ~19119
// MOD qiongli 2011-1-7 featrue 16799.
boolean isLanguageMatched = false;
if (isJavaEngine && expressionLanguage.equals(ExecutionLanguage.JAVA.getLiteral()) || dbmsLanguage != null && (dbmsLanguage.getDbmsName().equalsIgnoreCase(expressionLanguage))) {
isLanguageMatched = true;
}
if (!isLanguageMatched) {
String messageInfo = DefaultMessagesImpl.getString("PatternTestView.modifiedTheRegularExpression", expressionLanguage, dbmsLanguage.getDbmsName(), expressionLanguage, expressionLanguage, // $NON-NLS-1$
dbmsLanguage.getDbmsName());
MessageDialog messageDialog = new MessageDialog(new Shell(), // $NON-NLS-1$
DefaultMessagesImpl.getString("PatternTestView.warning"), // $NON-NLS-1$
null, // $NON-NLS-1$
messageInfo, // $NON-NLS-1$
MessageDialog.WARNING, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
int result = messageDialog.open();
if (result == MessageDialog.OK) {
regularExpression.getExpression().setBody(regularText.getText());
} else {
EList<PatternComponent> components = this.pattern.getComponents();
boolean isContainLanguage = false;
for (int i = 0; i < components.size(); i++) {
RegularExpressionImpl regularExpress = (RegularExpressionImpl) components.get(i);
// expression
if (dbmsLanguage.getDbmsName().equalsIgnoreCase(regularExpress.getExpression().getLanguage())) {
regularExpress.getExpression().setBody(regularText.getText());
isContainLanguage = true;
break;
}
}
// expression.
if (!isContainLanguage) {
RegularExpression newRegularExpress = BooleanExpressionHelper.createRegularExpression(dbmsLanguage.getDbmsName(), regularText.getText());
this.pattern.getComponents().add(newRegularExpress);
}
}
} else {
regularExpression.getExpression().setBody(regularText.getText());
}
EMFUtil.saveSingleResource(pattern.eResource());
editorPage.updatePatternDefinitonSection();
// MessageDialog.openInformation(new Shell(), "Success",
// "Success to save the pattern '" +
// pattern.getName()
// + "'");
saveButton.setEnabled(false);
}
}
use of org.talend.dataquality.domain.pattern.RegularExpression in project tdq-studio-se by Talend.
the class RespositoryDetailView method createPatternDetail.
private void createPatternDetail(Pattern pattern) {
createName(pattern);
createPurpose(pattern);
createDescription(pattern);
EList<PatternComponent> components = pattern.getComponents();
StringBuilder description = new StringBuilder();
for (PatternComponent poc : components) {
if (poc instanceof RegularExpression) {
RegularExpression expression = (RegularExpression) poc;
// $NON-NLS-1$
description.append(" ").append(expression.getExpression().getLanguage());
}
}
// $NON-NLS-1$
newLabelAndText(gContainer, DefaultMessagesImpl.getString("RespositoryDetailView.type"), description.toString().trim());
}
Aggregations