use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.
the class PatternExplorerRealTest method testGetValidValuesStatement_2.
/**
* Test method for {@link org.talend.dq.analysis.explore.PatternExplorer#getValidValuesStatement()}. when the test
* for indicator is user define indicator
*/
@Test
public void testGetValidValuesStatement_2() {
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(ViewValidValues);
indicatorDef.getViewValidValuesExpression().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);
patternExplorer.setAnalysis(analysis);
ChartDataEntity cdEntity = new ChartDataEntity();
cdEntity.setIndicator(indicator);
patternExplorer.setEnitty(cdEntity);
Assert.assertTrue(patternExplorer.setAnalysis(analysis));
String clause = patternExplorer.getValidValuesStatement();
// $NON-NLS-1$
assertEquals("SELECT `lname` FROM `catalog1`.`table1` ", clause);
}
use of orgomg.cwm.objectmodel.core.Expression 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 orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.
the class DbmsLanguageTest method testGetSqlExpressionUserDefineCase1.
/**
* Test method for
* {@link org.talend.dq.dbms.DbmsLanguage#getSqlExpression(org.talend.dataquality.indicators.definition.IndicatorDefinition)}
* .
*/
@Test
public void testGetSqlExpressionUserDefineCase1() {
// create indicator
UserDefIndicator userDefIndicator = IndicatorSqlFactory.eINSTANCE.createUserDefIndicator();
UDIndicatorDefinition indicatorDefinition = UserdefineFactory.eINSTANCE.createUDIndicatorDefinition();
// $NON-NLS-1$
indicatorDefinition.setName("user define");
userDefIndicator.setName(indicatorDefinition.getName());
userDefIndicator.setIndicatorDefinition(indicatorDefinition);
TdExpression newTdExp = // $NON-NLS-1$
BooleanExpressionHelper.createTdExpression(// $NON-NLS-1$
"MySQL", sql_1, null);
newTdExp.setModificationDate(DateUtils.getCurrentDate(DateUtils.PATTERN_5));
indicatorDefinition.getSqlGenericExpression().add(newTdExp);
TdExpression newTdExp_2 = // $NON-NLS-1$
BooleanExpressionHelper.createTdExpression(// $NON-NLS-1$
"SQL", sql_2, null);
newTdExp_2.setModificationDate(DateUtils.getCurrentDate(DateUtils.PATTERN_5));
indicatorDefinition.getSqlGenericExpression().add(newTdExp_2);
DbmsLanguage dbms = getMysqlDbmsLanguage();
Expression sqlExpression = dbms.getSqlExpression(indicatorDefinition);
Assert.assertNotNull(sqlExpression);
Assert.assertEquals(sql_1, sqlExpression.getBody());
}
use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.
the class DbmsLanguageTest method testSetFunctionReturnValueCase3.
/**
* {@link org.talend.dq.dbms.DbmsLanguage#setFunctionReturnValue(Expression)}.
*
* case 3:Can not find the keyword for ")" in the body of expression.
*/
@Test
public void testSetFunctionReturnValueCase3() {
// $NON-NLS-1$
DbmsLanguage dbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(DbmsLanguage.MSSQL, "1.0");
Expression createExpression = CoreFactory.eINSTANCE.createExpression();
// default Database
// $NON-NLS-1$
createExpression.setBody("**** WHEN RegularFunctionName(***returnValue THEN ******");
// $NON-NLS-1$
dbmsLanguage.setFunctionReturnValue(dbmsLanguage.extractRegularExpressionFunctionReturnValue(createExpression, "***"));
String regularfunctionReturnValue = dbmsLanguage.getFunctionReturnValue();
Assert.assertEquals(StringUtils.EMPTY, regularfunctionReturnValue);
}
use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.
the class DbmsLanguageTest method testGetSqlExpressionUserDefineCase2.
/**
* Test method for
* {@link org.talend.dq.dbms.DbmsLanguage#getSqlExpression(org.talend.dataquality.indicators.definition.IndicatorDefinition)}
* .
*/
@Test
public void testGetSqlExpressionUserDefineCase2() {
// test for can not get sql expression(means: both database type and default type don't exist)
// create indicator
UserDefIndicator userDefIndicator = IndicatorSqlFactory.eINSTANCE.createUserDefIndicator();
UDIndicatorDefinition indicatorDefinition = UserdefineFactory.eINSTANCE.createUDIndicatorDefinition();
// $NON-NLS-1$
indicatorDefinition.setName("user define");
userDefIndicator.setName(indicatorDefinition.getName());
userDefIndicator.setIndicatorDefinition(indicatorDefinition);
TdExpression newTdExp = // $NON-NLS-1$
BooleanExpressionHelper.createTdExpression(// $NON-NLS-1$
"Ingres", sql_1, null);
newTdExp.setModificationDate(DateUtils.getCurrentDate(DateUtils.PATTERN_5));
indicatorDefinition.getSqlGenericExpression().add(newTdExp);
DbmsLanguage dbms = getMysqlDbmsLanguage();
Expression sqlExpression = dbms.getSqlExpression(indicatorDefinition);
Assert.assertNull(sqlExpression);
}
Aggregations