use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.
the class DbmsLanguage method getTableCountQueryExpression.
/**
* Get the query Expression for one table of column
*
* @param column
* @param where
* @return
*/
public Expression getTableCountQueryExpression(MetadataTable metadataTable, String where) {
Schema parentSchema = SchemaHelper.getParentSchema(metadataTable);
Catalog parentCatalog = CatalogHelper.getParentCatalog(metadataTable);
if (parentSchema != null) {
parentCatalog = CatalogHelper.getParentCatalog(parentSchema);
}
String schemaName = parentSchema == null ? null : parentSchema.getName();
String catalogName = parentCatalog == null ? null : parentCatalog.getName();
String qualifiedName = this.toQualifiedName(catalogName, schemaName, metadataTable.getName());
Expression queryExpression = CoreFactory.eINSTANCE.createExpression();
String expressionBody = getQuerySql(COUNT_ASTERISK, qualifiedName, where);
queryExpression.setBody(expressionBody);
queryExpression.setLanguage(this.getDbmsName());
return queryExpression;
}
use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.
the class DbmsLanguage method getColumnQueryExpression.
/**
* Get the query Expression for one column
*
* @param column
* @param where
* @return
*/
public Expression getColumnQueryExpression(TdColumn column, String where) {
ModelElement columnSet = ColumnHelper.getColumnOwnerAsColumnSet(column);
Schema parentSchema = SchemaHelper.getParentSchema(columnSet);
Catalog parentCatalog = CatalogHelper.getParentCatalog(columnSet);
if (parentSchema != null) {
parentCatalog = CatalogHelper.getParentCatalog(parentSchema);
}
String schemaName = parentSchema == null ? null : parentSchema.getName();
String catalogName = parentCatalog == null ? null : parentCatalog.getName();
String qualifiedName = this.toQualifiedName(catalogName, schemaName, columnSet.getName());
Expression queryExpression = CoreFactory.eINSTANCE.createExpression();
String expressionBody = getQuerySql(column.getName(), qualifiedName, where);
queryExpression.setBody(expressionBody);
queryExpression.setLanguage(this.getDbmsName());
return queryExpression;
}
use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.
the class DbmsLanguage method getExpression.
/**
* Method "getExpression".
*
* @param patternComponent
* @return the expression for the correct language or null
*/
public Expression getExpression(PatternComponent patternComponent) {
if (patternComponent != null && patternComponent.eClass().equals(PatternPackage.eINSTANCE.getRegularExpression())) {
RegularExpression regExp = (RegularExpression) patternComponent;
Expression expression = regExp.getExpression();
if (expression != null) {
return getApplicable(expression);
}
}
// not a regular expression
return null;
}
use of orgomg.cwm.objectmodel.core.Expression 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 orgomg.cwm.objectmodel.core.Expression 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