use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class PatternExplorerRealTest method testGetInvalidValuesStatement_3.
/**
* Test method for {@link org.talend.dq.analysis.explore.PatternExplorer#getInvalidValuesStatement()}. when the test
* for indicator is user define indicator
*/
@Test
public void testGetInvalidValuesStatement_3() {
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(ViewInvalidValues);
indicatorDef.getViewInvalidValuesExpression().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.getInvalidValuesStatement();
// $NON-NLS-1$
assertEquals("SELECT `lname` FROM `catalog1`.`table1` WHERE NOT (id>=1) ", clause);
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class PatternExplorerRealTest method testGetValidRowsStatement_5.
/**
* Test method for {@link org.talend.dq.analysis.explore.PatternExplorer#getValidRowsStatement()}. when the test for
* indicator is user define indicator
*/
@Test
public void testGetValidRowsStatement_5() {
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(ViewValidRows);
indicatorDef.getViewValidRowsExpression().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.getValidRowsStatement();
// $NON-NLS-1$
assertEquals("SELECT * FROM `catalog1`.`table1` ", clause);
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class SQLPatternExplorerTest method setUp.
/**
* DOC msjian Comment method "setUp".
*
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
UnitTestBuildHelper.initProjectStructure();
if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQItemService.class)) {
ITDQItemService tdqService = (ITDQItemService) GlobalServiceRegister.getDefault().getService(ITDQItemService.class);
tdqService.createDQStructor();
}
sqlPatternExplorer = new SQLPatternExplorer();
// mock setEntity
SqlPatternMatchingIndicator indicator = creatSqlPatternMatchingIndicator();
Analysis ana = UnitTestBuildHelper.createAndInitAnalysis();
AnalysisResult createAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
ExecutionInformations createExecutionInformations = AnalysisFactory.eINSTANCE.createExecutionInformations();
createAnalysisResult.setResultMetadata(createExecutionInformations);
createAnalysisResult.getIndicators().add(indicator);
ana.setResults(createAnalysisResult);
sqlPatternExplorer.setAnalysis(ana);
// $NON-NLS-1$ //$NON-NLS-2$
ChartDataEntity chartDataEntity = new ChartDataEntity(indicator, "name1", "1");
chartDataEntity.setLabelNull(false);
// $NON-NLS-1$
chartDataEntity.setKey("name1");
sqlPatternExplorer.setEnitty(chartDataEntity);
IndicatorDefinition definition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
TdExpression expression = RelationalFactory.eINSTANCE.createTdExpression();
expression.setBody("SELECT * FROM tbi.customer ");
// $NON-NLS-1$
expression.setLanguage("SQL");
definition.getSqlGenericExpression().add(expression);
indicator.setIndicatorDefinition(definition);
indicator.getInstantiatedExpressions().add(expression);
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class DbmsLanguageTest method testGetSqlExpressionDB2Case6.
/**
* Test method for
* {@link org.talend.dq.dbms.DbmsLanguage#getSqlExpression(IndicatorDefinition, String, EList, ProductVersion)} .
*/
@Test
public void testGetSqlExpressionDB2Case6() {
// $NON-NLS-1$
String db2Lang = "DB2";
// $NON-NLS-1$
String db2Body = "DB2 body";
// $NON-NLS-1$
String db2NTLang = "DB2/NT";
// $NON-NLS-1$
String db2NTBody = "DB2/NT body";
IndicatorDefinition indicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
// $NON-NLS-1$
String language = "unknown";
EList<TdExpression> sqlGenericExpression = new BasicEList<TdExpression>();
TdExpression tdExpression2 = RelationalFactory.eINSTANCE.createTdExpression();
tdExpression2.setLanguage(db2Lang);
tdExpression2.setBody(db2Body);
sqlGenericExpression.add(tdExpression2);
TdExpression tdExpression3 = RelationalFactory.eINSTANCE.createTdExpression();
tdExpression3.setLanguage(db2NTLang);
tdExpression3.setBody(db2NTBody);
sqlGenericExpression.add(tdExpression3);
ProductVersion dbVersion = new ProductVersion(1, 0);
TdExpression sqlExpression = DbmsLanguage.getSqlExpression(indicatorDefinition, language, sqlGenericExpression, dbVersion);
Assert.assertEquals(null, sqlExpression);
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class DbmsLanguageTest method testGetSqlExpressionDB2Case4.
/**
* Test method for
* {@link org.talend.dq.dbms.DbmsLanguage#getSqlExpression(IndicatorDefinition, String, EList, ProductVersion)} .
*/
@Test
public void testGetSqlExpressionDB2Case4() {
// $NON-NLS-1$
String sqlLang = "SQL";
// $NON-NLS-1$
String sqlBody = "SQL body";
// $NON-NLS-1$
String db2Lang = "DB2";
// $NON-NLS-1$
String db2NTLang = "DB2/NT";
// $NON-NLS-1$
String db2NTBody = "DB2/NT body";
IndicatorDefinition indicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
String language = db2Lang;
EList<TdExpression> sqlGenericExpression = new BasicEList<TdExpression>();
TdExpression tdExpression1 = RelationalFactory.eINSTANCE.createTdExpression();
tdExpression1.setLanguage(sqlLang);
tdExpression1.setBody(sqlBody);
sqlGenericExpression.add(tdExpression1);
TdExpression tdExpression3 = RelationalFactory.eINSTANCE.createTdExpression();
tdExpression3.setLanguage(db2NTLang);
tdExpression3.setBody(db2NTBody);
sqlGenericExpression.add(tdExpression3);
ProductVersion dbVersion = new ProductVersion(1, 0);
TdExpression sqlExpression = DbmsLanguage.getSqlExpression(indicatorDefinition, language, sqlGenericExpression, dbVersion);
Assert.assertEquals(tdExpression3, sqlExpression);
}
Aggregations