Search in sources :

Example 11 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class UpdateAllIndicators4DefaultTask method doExecute.

@Override
protected boolean doExecute() throws Exception {
    boolean result = true;
    List<IndicatorDefinition> indiDefinitions = DefinitionHandler.getInstance().getIndicatorsDefinitions();
    for (IndicatorDefinition indiDefinition : indiDefinitions) {
        if (indiDefinition != null) {
            EList<TdExpression> sqlGenericExpression = indiDefinition.getSqlGenericExpression();
            for (TdExpression exp : sqlGenericExpression) {
                // both "Default" and "Default "
                if (Language.equals(exp.getLanguage().trim())) {
                    exp.setLanguage(newLanguage);
                    break;
                }
            }
            result = result && IndicatorDefinitionFileHelper.save(indiDefinition);
        }
    }
    DefinitionHandler.getInstance().reloadIndicatorsDefinitions();
    return result;
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition)

Example 12 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class UpdateTextStatisticsIndicatorsTask method clearSqlGenericExpression.

/**
 * clear the specified language from the IndicatorDefinition.
 *
 * @param definition
 * @param languages the languages which need to be clear
 */
private void clearSqlGenericExpression(IndicatorDefinition definition, Set<String> languages) {
    List<TdExpression> expressions = new ArrayList<TdExpression>();
    for (TdExpression expression : definition.getSqlGenericExpression()) {
        if (expression != null && !languages.contains(expression.getLanguage())) {
            expressions.add(expression);
        }
    }
    definition.getSqlGenericExpression().clear();
    definition.getSqlGenericExpression().addAll(expressions);
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) ArrayList(java.util.ArrayList)

Example 13 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class UpdateTextStatisticsIndicatorsForSomeDatabasesTask method clearSqlGenericExpression.

/**
 * clear the specified language from the IndicatorDefinition.
 *
 * @param definition
 * @param languages the languages which need to be clear
 */
private void clearSqlGenericExpression(IndicatorDefinition definition, Set<String> languages) {
    List<TdExpression> expressions = new ArrayList<TdExpression>();
    for (TdExpression expression : definition.getSqlGenericExpression()) {
        if (expression != null && !languages.contains(expression.getLanguage())) {
            expressions.add(expression);
        }
    }
    definition.getSqlGenericExpression().clear();
    definition.getSqlGenericExpression().addAll(expressions);
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) ArrayList(java.util.ArrayList)

Example 14 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class MultiColumnAnalysisExecutorTest method setUp.

@Before
public void setUp() throws Exception {
    analysis = AnalysisFactory.eINSTANCE.createAnalysis();
    AnalysisContext context = AnalysisFactory.eINSTANCE.createAnalysisContext();
    analysis.setContext(context);
    // mock(Catalog.class);
    Package catalog = orgomg.cwm.resource.relational.RelationalFactory.eINSTANCE.createCatalog();
    // $NON-NLS-1$
    catalog.setName("tbi");
    TdTable tdTable = RelationalFactory.eINSTANCE.createTdTable();
    // $NON-NLS-1$
    tdTable.setName("customer");
    tdTable.setNamespace(catalog);
    TdColumn tdColumn = RelationalFactory.eINSTANCE.createTdColumn();
    tdColumn.setOwner(tdTable);
    // $NON-NLS-1$
    tdColumn.setName("date_accnt_opened");
    tdColumn.setContentType(DataminingType.INTERVAL.getName());
    TdColumn tdColumn2 = RelationalFactory.eINSTANCE.createTdColumn();
    tdColumn2.setOwner(tdTable);
    // $NON-NLS-1$
    tdColumn2.setName("product_id");
    tdColumn2.setContentType(DataminingType.INTERVAL.getName());
    AnalysisParameters analysisPara = AnalysisFactory.eINSTANCE.createAnalysisParameters();
    analysisPara.setStoreData(false);
    // set analysis type is columnset
    analysisPara.setAnalysisType(AnalysisType.COLUMN_SET);
    analysis.setParameters(analysisPara);
    context.getAnalysedElements().add(tdColumn);
    context.getAnalysedElements().add(tdColumn2);
    AnalysisResult analysisResult = AnalysisFactory.eINSTANCE.createAnalysisResult();
    ExecutionInformations info = AnalysisFactory.eINSTANCE.createExecutionInformations();
    analysisResult.setResultMetadata(info);
    simpleStatIndicator = ColumnsetFactory.eINSTANCE.createSimpleStatIndicator();
    TdExpression expression = RelationalFactory.eINSTANCE.createTdExpression();
    expression.setBody(// $NON-NLS-1$
    "SELECT <%=__COLUMN_NAMES__%> FROM <%=__TABLE_NAME__%> <%=__WHERE_CLAUSE__%> GROUP BY <%=__GROUP_BY_ALIAS__%>");
    // $NON-NLS-1$
    expression.setLanguage("SQL");
    IndicatorDefinition indicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    indicatorDefinition.getSqlGenericExpression().add(expression);
    simpleStatIndicator.setIndicatorDefinition(indicatorDefinition);
    // $NON-NLS-1$
    simpleStatIndicator.getDateFunctions().add("");
    // $NON-NLS-1$
    simpleStatIndicator.getNumericFunctions().add("");
    simpleStatIndicator.setDataminingType(DataminingType.NOMINAL);
    simpleStatIndicator.getAnalyzedColumns().add(tdColumn);
    simpleStatIndicator.getAnalyzedColumns().add(tdColumn2);
    analysisResult.getIndicators().add(simpleStatIndicator);
    analysis.setResults(analysisResult);
}
Also used : ExecutionInformations(org.talend.dataquality.analysis.ExecutionInformations) TdTable(org.talend.cwm.relational.TdTable) TdColumn(org.talend.cwm.relational.TdColumn) TdExpression(org.talend.cwm.relational.TdExpression) AnalysisParameters(org.talend.dataquality.analysis.AnalysisParameters) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) Package(orgomg.cwm.objectmodel.core.Package) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) Before(org.junit.Before)

Example 15 with TdExpression

use of org.talend.cwm.relational.TdExpression in project tdq-studio-se by Talend.

the class TableAnalysisSqlExecutorTest method testCreateSqlStatementCase1.

/**
 * Test method for
 * {@link org.talend.dq.analysis.TableAnalysisSqlExecutor#createSqlStatement(org.talend.dataquality.analysis.Analysis)}
 * . case 1:the where rule have not join conditions
 */
@Test
public void testCreateSqlStatementCase1() {
    TdExpression expression = RelationalFactory.eINSTANCE.createTdExpression();
    // $NON-NLS-1$
    expression.setBody("SELECT COUNT(*) FROM &lt;%=__TABLE_NAME__%> &lt;%=__JOIN_CLAUSE__%> &lt;%=__WHERE_CLAUSE__%>");
    // $NON-NLS-1$
    expression.setLanguage("SQL");
    testWhereRuleIndicatorDefinition.getSqlGenericExpression().add(expression);
    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());
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) TdExpression(org.talend.cwm.relational.TdExpression) Expression(orgomg.cwm.objectmodel.core.Expression) Test(org.junit.Test)

Aggregations

TdExpression (org.talend.cwm.relational.TdExpression)121 Test (org.junit.Test)51 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)30 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)29 ArrayList (java.util.ArrayList)19 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)19 Pattern (org.talend.dataquality.domain.pattern.Pattern)16 TdColumn (org.talend.cwm.relational.TdColumn)12 Expression (orgomg.cwm.objectmodel.core.Expression)12 BasicEList (org.eclipse.emf.common.util.BasicEList)11 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)11 Domain (org.talend.dataquality.domain.Domain)10 TdTable (org.talend.cwm.relational.TdTable)9 ProductVersion (org.talend.utils.ProductVersion)9 Analysis (org.talend.dataquality.analysis.Analysis)8 PatternComponent (org.talend.dataquality.domain.pattern.PatternComponent)8 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)8 File (java.io.File)7 IFile (org.eclipse.core.resources.IFile)6 IFolder (org.eclipse.core.resources.IFolder)6