use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class RegexpMatchingIndicatorImplTest method testGetRegexsuccess.
/**
* Test method for {@link org.talend.dataquality.indicators.impl.RegexpMatchingIndicatorImpl#getJavaRegex()}.
*/
@Test
public void testGetRegexsuccess() {
// RegexpMatchingIndicator
RegexpMatchingIndicator createRegexpMatchingIndicator = IndicatorsFactory.eINSTANCE.createRegexpMatchingIndicator();
// ~RegexpMatchingIndicator
// IndicatorParameters
IndicatorParameters createIndicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
// ~IndicatorParameters
// Domain
Domain createDomain = DomainFactory.eINSTANCE.createDomain();
EList<Pattern> patterns = createDomain.getPatterns();
// ~Domain
// Pattern
Pattern createJavaPattern = PatternFactory.eINSTANCE.createPattern();
Pattern createSQLPattern = PatternFactory.eINSTANCE.createPattern();
Pattern createMSSQLPattern = PatternFactory.eINSTANCE.createPattern();
patterns.add(createJavaPattern);
patterns.add(createSQLPattern);
patterns.add(createMSSQLPattern);
// ~Pattern
// init java Pattern data
RegularExpression createJavaRegularExpression = PatternFactory.eINSTANCE.createRegularExpression();
TdExpression createJavaTdExpression = RelationalFactory.eINSTANCE.createTdExpression();
createJavaTdExpression.setBody(JavaRegex);
createJavaTdExpression.setLanguage("Java");
createJavaRegularExpression.setExpression(createJavaTdExpression);
createJavaRegularExpression.setExpressionType(ExpressionType.REGEXP.getLiteral());
EList<PatternComponent> components = createJavaPattern.getComponents();
components.add(createJavaRegularExpression);
// ~init java Pattern data
createIndicatorParameters.setDataValidDomain(createDomain);
createRegexpMatchingIndicator.setParameters(createIndicatorParameters);
// call getRegex()
String regexResult = createRegexpMatchingIndicator.getRegex();
String JavaRegex2 = JavaRegex.substring(1, JavaRegex.length() - 1);
// ~call getRegex()
Assert.assertTrue(JavaRegex2.equalsIgnoreCase(regexResult));
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class MultiColumnAnalysisExecutorTest method testCreateSqlStatement_3.
/**
* test for leaf indicator's drill down sql , with interval type. MOD TDQ-7287 lost some columns(type!=norminal)
* when view values in column set ana. yyin 20130514
*/
@Test
public void testCreateSqlStatement_3() {
DistinctCountIndicator distinctCountIndicator = IndicatorsFactory.eINSTANCE.createDistinctCountIndicator();
IndicatorDefinition definition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
String body = "SELECT COUNT(*) FROM (SELECT DISTINCT <%=__COLUMN_NAMES__%> FROM <%=__TABLE_NAME__%> <%=__WHERE_CLAUSE__%>) A";
TdExpression expression = RelationalFactory.eINSTANCE.createTdExpression();
expression.setBody(body);
// $NON-NLS-1$
expression.setLanguage("SQL");
definition.getSqlGenericExpression().add(expression);
distinctCountIndicator.setIndicatorDefinition(definition);
simpleStatIndicator.setDistinctCountIndicator(distinctCountIndicator);
simpleStatIndicator.setDataminingType(DataminingType.NOMINAL);
MultiColumnAnalysisExecutor multiColumnAnalysisExecutor = new MultiColumnAnalysisExecutor();
// $NON-NLS-1$
assertEquals("", multiColumnAnalysisExecutor.createSqlStatement(analysis));
String viewValues = "SELECT COUNT(*) FROM (SELECT DISTINCT date_accnt_opened,product_id FROM tbi.customer ) A";
assertEquals(viewValues, simpleStatIndicator.getLeafIndicators().get(0).getInstantiatedExpressions("SQL").getBody());
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class TableAnalysisSqlExecutorTest method testCreateSqlStatementCase2.
/**
* Test method for
* {@link org.talend.dq.analysis.TableAnalysisSqlExecutor#createSqlStatement(org.talend.dataquality.analysis.Analysis)}
* . case 1:the where rule have join conditions
*/
@Test
public void testCreateSqlStatementCase2() {
// $NON-NLS-1$
String sql = "select count(*) from table where 1=1";
TdExpression expression = RelationalFactory.eINSTANCE.createTdExpression();
expression.setBody(sql);
// $NON-NLS-1$
expression.setLanguage("SQL");
testWhereRuleIndicatorDefinition.getSqlGenericExpression().add(expression);
JoinElement createJoinElement = RulesFactory.eINSTANCE.createJoinElement();
// $NON-NLS-1$
createJoinElement.setColumnAliasA("colA");
// $NON-NLS-1$
createJoinElement.setColumnAliasB("colB");
// $NON-NLS-1$
createJoinElement.setTableAliasA("tabA");
// $NON-NLS-1$
createJoinElement.setTableAliasB("tabB");
TdColumn createTdColumnA = RelationalFactory.eINSTANCE.createTdColumn();
// $NON-NLS-1$
createTdColumnA.setName("colA");
TdTable createTdTableA = RelationalFactory.eINSTANCE.createTdTable();
// $NON-NLS-1$
createTdTableA.setName("tableA");
createTdColumnA.setOwner(createTdTableA);
TdColumn createTdColumnB = RelationalFactory.eINSTANCE.createTdColumn();
// $NON-NLS-1$
createTdColumnB.setName("colB");
TdTable createTdTableB = RelationalFactory.eINSTANCE.createTdTable();
// $NON-NLS-1$
createTdTableB.setName("tableB");
createTdColumnB.setOwner(createTdTableB);
createJoinElement.setColA(createTdColumnA);
createJoinElement.setColB(createTdColumnB);
testWhereRuleIndicatorDefinition.getJoins().add(createJoinElement);
TableAnalysisSqlExecutor tableAnalysisSqlExecutor = new TableAnalysisSqlExecutor();
String actualSqlStatement = tableAnalysisSqlExecutor.createSqlStatement(testAnalysis);
Assert.assertEquals(StringUtils.EMPTY, actualSqlStatement);
EList<Expression> instantiatedExpressions = testWhereRuleIndicator.getInstantiatedExpressions();
Assert.assertNotNull(instantiatedExpressions);
Assert.assertEquals(1, instantiatedExpressions.size());
Assert.assertEquals(sql, instantiatedExpressions.get(0).getBody());
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class FrequencyStatisticsExplorerTest method testGetFreqRowsStatement_4.
/**
* Test method for {@link org.talend.dq.analysis.explore.FrequencyStatisticsExplorer#getFreqRowsStatement()} case_3:
* for UDIndicatorDefinition
*/
@Test
public void testGetFreqRowsStatement_4() {
// create database construction
TdTable table = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdTable();
// $NON-NLS-1$
table.setName("TDQ_CALENDAR");
TdColumn column = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdColumn();
// $NON-NLS-1$
column.setName("CAL_DATE");
TdSqlDataType tdsql = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdSqlDataType();
// $NON-NLS-1$
tdsql.setName("DATE");
tdsql.setJavaDataType(Types.DATE);
column.setSqlDataType(tdsql);
table.getOwnedElement().add(column);
column.setOwner(table);
// create indicator
UserDefIndicator userDefIndicator = IndicatorSqlFactory.eINSTANCE.createUserDefIndicator();
UDIndicatorDefinition indicatorDefinition = UserdefineFactory.eINSTANCE.createUDIndicatorDefinition();
// $NON-NLS-1$
indicatorDefinition.setName("user define count");
userDefIndicator.setName(indicatorDefinition.getName());
userDefIndicator.setIndicatorDefinition(indicatorDefinition);
TdExpression newTdExp = // $NON-NLS-1$
BooleanExpressionHelper.createTdExpression(// $NON-NLS-1$
"SQL", "SELECT * FROM <%=__TABLE_NAME__%> <%=__WHERE_CLAUSE__%>", // $NON-NLS-1$
null);
newTdExp.setModificationDate(DateUtils.getCurrentDate(DateUtils.PATTERN_5));
indicatorDefinition.getViewRowsExpression().add(newTdExp);
// $NON-NLS-1$ //$NON-NLS-2$
ChartDataEntity chartDataEntity = new ChartDataEntity(userDefIndicator, "2012-06-05", "1");
chartDataEntity.setLabelNull(false);
// $NON-NLS-1$
chartDataEntity.setKey("2012-06-05");
assertFalse(chartDataEntity.isLabelNull());
userDefIndicator.setAnalyzedElement(column);
IndicatorParameters indicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
indicatorParameters.setDateParameters(null);
userDefIndicator.setParameters(indicatorParameters);
assertNull(indicatorParameters.getDateParameters());
AnalysisResult createAnalysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
ExecutionInformations createExecutionInformations = AnalysisFactory.eINSTANCE.createExecutionInformations();
createAnalysisResult.setResultMetadata(createExecutionInformations);
createAnalysisResult.getIndicators().add(userDefIndicator);
userDefIndicator.setAnalyzedElement(column);
ana.setResults(createAnalysisResult);
freqExp = new FrequencyStatisticsExplorer();
freqExp.setAnalysis(ana);
freqExp.setEnitty(chartDataEntity);
String clause = freqExp.getFreqRowsStatement();
// $NON-NLS-1$
assertEquals("SELECT * FROM TDQ_CALENDAR ", clause);
}
use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.
the class PatternExplorerRealTest method setUp.
/**
* DOC zshen Comment method "setUp".
*
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
patternExplorer = new RegexPatternExplorer();
// mock setEntity
PatternMatchingIndicator indicator = IndicatorsFactoryImpl.eINSTANCE.createRegexpMatchingIndicator();
// 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.*`");
ModelElement element = RelationalFactoryImpl.eINSTANCE.createTdColumn();
// $NON-NLS-1$
element.setName("lname");
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);
}
Aggregations