Search in sources :

Example 31 with TdColumn

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

the class SummaryStastictisExplorerTest method setUp.

/**
 * DOC yyin 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();
    }
    sumExp = new SummaryStastictisExplorer();
    indicator = IndicatorsFactory.eINSTANCE.createSumIndicator();
    TdColumn column = UnitTestBuildHelper.createRealTdColumn("INTERVAL_MONTH", "INTERVAL_MONTH", Types.VARCHAR);
    indicator.setAnalyzedElement(column);
    IndicatorParameters indicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
    indicatorParameters.setDateParameters(null);
    indicator.setParameters(indicatorParameters);
    analysis = UnitTestBuildHelper.createAndInitAnalysis();
    TaggedValueHelper.setTaggedValue(analysis.getContext().getConnection(), TaggedValueHelper.DB_PRODUCT_NAME, "Teradata");
    TaggedValueHelper.setTaggedValue(analysis.getContext().getConnection(), TaggedValueHelper.DB_PRODUCT_VERSION, "1");
    sumExp.setAnalysis(analysis);
    // $NON-NLS-1$  //$NON-NLS-2$
    ChartDataEntity chartDataEntity = new ChartDataEntity(indicator, "1", "1");
    chartDataEntity.setLabelNull(false);
    // $NON-NLS-1$
    chartDataEntity.setKey("1");
    assertFalse(chartDataEntity.isLabelNull());
    sumExp.setEnitty(chartDataEntity);
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) ChartDataEntity(org.talend.dq.indicators.preview.table.ChartDataEntity) ITDQItemService(org.talend.core.ITDQItemService) Before(org.junit.Before)

Example 32 with TdColumn

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

the class SummaryStastictisExplorerRealTest method testGetQueryMap.

/**
 * Test method for {@link org.talend.dq.analysis.explore.SummaryStastictisExplorer#getQueryMap()}.
 */
@Test
public void testGetQueryMap() {
    // testing code for SQL Engine here
    SummaryStastictisExplorer summaryExplorerSql = new SummaryStastictisExplorer();
    Analysis analysisReal = AnalysisFactory.eINSTANCE.createAnalysis();
    AnalysisParameters analysisParametersReal = AnalysisFactory.eINSTANCE.createAnalysisParameters();
    analysisParametersReal.setExecutionLanguage(ExecutionLanguage.SQL);
    analysisReal.setParameters(analysisParametersReal);
    AnalysisContext analysisContextReal = AnalysisFactory.eINSTANCE.createAnalysisContext();
    DataManager dataManagerReal = SoftwaredeploymentFactory.eINSTANCE.createDataManager();
    analysisContextReal.setConnection(dataManagerReal);
    analysisReal.setContext(analysisContextReal);
    summaryExplorerSql.setAnalysis(analysisReal);
    TdColumn tdColumnReal = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdColumn();
    TdTable tdTableReal = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdTable();
    // $NON-NLS-1$
    tdTableReal.setName("tableName");
    tdColumnReal.setOwner(tdTableReal);
    // $NON-NLS-1$
    tdColumnReal.setName("id");
    TdSqlDataType tdsqlReal = org.talend.cwm.relational.RelationalFactory.eINSTANCE.createTdSqlDataType();
    // $NON-NLS-1$
    tdsqlReal.setName("Integer");
    tdColumnReal.setSqlDataType(tdsqlReal);
    // test for MeanIndicator
    MeanIndicator meanIndicator = IndicatorsFactory.eINSTANCE.createMeanIndicator();
    meanIndicator.setAnalyzedElement(tdColumnReal);
    IndicatorDefinition meanIndicatorDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    meanIndicatorDef.setName("Mean");
    meanIndicator.setIndicatorDefinition(meanIndicatorDef);
    ChartDataEntity entityReal = new ChartDataEntity();
    // $NON-NLS-1$
    entityReal.setValue("0");
    entityReal.setIndicator(meanIndicator);
    summaryExplorerSql.setEnitty(entityReal);
    Map<String, String> queryMap = summaryExplorerSql.getQueryMap();
    Assert.assertTrue(queryMap.isEmpty());
    // test for MedianIndicator
    MedianIndicator medianIndicator = IndicatorsFactory.eINSTANCE.createMedianIndicator();
    medianIndicator.setAnalyzedElement(tdColumnReal);
    IndicatorDefinition medianIndicatorDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    medianIndicatorDef.setName("Median");
    medianIndicator.setIndicatorDefinition(medianIndicatorDef);
    entityReal.setIndicator(medianIndicator);
    summaryExplorerSql.setEnitty(entityReal);
    queryMap = summaryExplorerSql.getQueryMap();
    Assert.assertTrue(queryMap.size() == 1);
    // test for IQRIndicator
    MaxValueIndicator maxValueIndicator = IndicatorsFactory.eINSTANCE.createMaxValueIndicator();
    // $NON-NLS-1$
    maxValueIndicator.setValue("80");
    IndicatorDefinition maxValueIndicatorDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    maxValueIndicatorDef.setName("Maximum");
    maxValueIndicator.setIndicatorDefinition(maxValueIndicatorDef);
    MinValueIndicator minValueIndicator = IndicatorsFactory.eINSTANCE.createMinValueIndicator();
    // $NON-NLS-1$
    minValueIndicator.setValue("20");
    IndicatorDefinition minValueIndicatorDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    minValueIndicatorDef.setName("Minimum");
    minValueIndicator.setIndicatorDefinition(minValueIndicatorDef);
    IQRIndicator iqrIndicator = IndicatorsFactory.eINSTANCE.createIQRIndicator();
    iqrIndicator.setUpperValue(maxValueIndicator);
    iqrIndicator.setLowerValue(minValueIndicator);
    iqrIndicator.setAnalyzedElement(tdColumnReal);
    IndicatorDefinition iqrIndicatorDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    iqrIndicatorDef.setName("Inter Quartile Range");
    iqrIndicator.setIndicatorDefinition(iqrIndicatorDef);
    entityReal.setIndicator(iqrIndicator);
    summaryExplorerSql.setEnitty(entityReal);
    queryMap = summaryExplorerSql.getQueryMap();
    Assert.assertTrue(queryMap.size() == 2);
    // test for LowerQuartileIndicator
    LowerQuartileIndicator lowerQuartileIndicator = IndicatorsFactory.eINSTANCE.createLowerQuartileIndicator();
    lowerQuartileIndicator.setAnalyzedElement(tdColumnReal);
    IndicatorDefinition lowerQuartileIndicatorDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    lowerQuartileIndicatorDef.setName("Lower Quartile");
    lowerQuartileIndicator.setIndicatorDefinition(lowerQuartileIndicatorDef);
    entityReal.setIndicator(lowerQuartileIndicator);
    summaryExplorerSql.setEnitty(entityReal);
    queryMap = summaryExplorerSql.getQueryMap();
    Assert.assertTrue(queryMap.size() == 1);
    // test for UpperQuartileIndicator
    UpperQuartileIndicator upperQuartileIndicator = IndicatorsFactory.eINSTANCE.createUpperQuartileIndicator();
    upperQuartileIndicator.setAnalyzedElement(tdColumnReal);
    IndicatorDefinition upperQuartileIndicatorDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    upperQuartileIndicatorDef.setName("Upper Quartile");
    upperQuartileIndicator.setIndicatorDefinition(upperQuartileIndicatorDef);
    entityReal.setIndicator(upperQuartileIndicator);
    summaryExplorerSql.setEnitty(entityReal);
    queryMap = summaryExplorerSql.getQueryMap();
    Assert.assertTrue(queryMap.size() == 1);
    // test for RangeIndicator
    RangeIndicator rangeIndicator = IndicatorsFactory.eINSTANCE.createRangeIndicator();
    rangeIndicator.setUpperValue(maxValueIndicator);
    rangeIndicator.setLowerValue(minValueIndicator);
    rangeIndicator.setAnalyzedElement(tdColumnReal);
    IndicatorDefinition rangeIndicatorDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    rangeIndicatorDef.setName("Range");
    rangeIndicator.setIndicatorDefinition(rangeIndicatorDef);
    entityReal.setIndicator(rangeIndicator);
    summaryExplorerSql.setEnitty(entityReal);
    queryMap = summaryExplorerSql.getQueryMap();
    Assert.assertTrue(queryMap.size() == 2);
    // test for MinValueIndicator
    minValueIndicator.setAnalyzedElement(tdColumnReal);
    entityReal.setIndicator(minValueIndicator);
    summaryExplorerSql.setEnitty(entityReal);
    queryMap = summaryExplorerSql.getQueryMap();
    Assert.assertTrue(queryMap.size() == 1);
    // test for MaxValueIndicator
    maxValueIndicator.setAnalyzedElement(tdColumnReal);
    entityReal.setIndicator(maxValueIndicator);
    summaryExplorerSql.setEnitty(entityReal);
    queryMap = summaryExplorerSql.getQueryMap();
    Assert.assertTrue(queryMap.size() == 1);
    // testing code for Java Engine here
    analysisParametersReal.setExecutionLanguage(ExecutionLanguage.JAVA);
    analysisReal.setParameters(analysisParametersReal);
    summaryExplorerSql.setAnalysis(analysisReal);
    // test for MeanIndicator
    meanIndicator.setAnalyzedElement(tdColumnReal);
    entityReal.setIndicator(meanIndicator);
    summaryExplorerSql.setEnitty(entityReal);
    queryMap = summaryExplorerSql.getQueryMap();
    Assert.assertTrue(queryMap.isEmpty());
    // test for MedianIndicator
    medianIndicator.setAnalyzedElement(tdColumnReal);
    entityReal.setIndicator(medianIndicator);
    summaryExplorerSql.setEnitty(entityReal);
    queryMap = summaryExplorerSql.getQueryMap();
    Assert.assertTrue(queryMap.isEmpty());
    // test for IQRIndicator
    iqrIndicator.setAnalyzedElement(tdColumnReal);
    entityReal.setIndicator(iqrIndicator);
    summaryExplorerSql.setEnitty(entityReal);
    queryMap = summaryExplorerSql.getQueryMap();
    Assert.assertTrue(queryMap.isEmpty());
    // test for LowerQuartileIndicator
    lowerQuartileIndicator.setAnalyzedElement(tdColumnReal);
    entityReal.setIndicator(lowerQuartileIndicator);
    summaryExplorerSql.setEnitty(entityReal);
    queryMap = summaryExplorerSql.getQueryMap();
    Assert.assertTrue(queryMap.isEmpty());
    // test for UpperQuartileIndicator
    upperQuartileIndicator.setAnalyzedElement(tdColumnReal);
    entityReal.setIndicator(upperQuartileIndicator);
    summaryExplorerSql.setEnitty(entityReal);
    queryMap = summaryExplorerSql.getQueryMap();
    Assert.assertTrue(queryMap.isEmpty());
    // test for RangeIndicator
    rangeIndicator.setAnalyzedElement(tdColumnReal);
    entityReal.setIndicator(rangeIndicator);
    summaryExplorerSql.setEnitty(entityReal);
    queryMap = summaryExplorerSql.getQueryMap();
    Assert.assertTrue(queryMap.isEmpty());
    // test for MinValueIndicator
    minValueIndicator.setAnalyzedElement(tdColumnReal);
    entityReal.setIndicator(minValueIndicator);
    summaryExplorerSql.setEnitty(entityReal);
    queryMap = summaryExplorerSql.getQueryMap();
    Assert.assertTrue(queryMap.isEmpty());
    // test for MaxValueIndicator
    maxValueIndicator.setAnalyzedElement(tdColumnReal);
    entityReal.setIndicator(maxValueIndicator);
    summaryExplorerSql.setEnitty(entityReal);
    queryMap = summaryExplorerSql.getQueryMap();
    Assert.assertTrue(queryMap.isEmpty());
}
Also used : TdTable(org.talend.cwm.relational.TdTable) MedianIndicator(org.talend.dataquality.indicators.MedianIndicator) IQRIndicator(org.talend.dataquality.indicators.IQRIndicator) DataManager(orgomg.cwm.foundation.softwaredeployment.DataManager) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) ChartDataEntity(org.talend.dq.indicators.preview.table.ChartDataEntity) TdSqlDataType(org.talend.cwm.relational.TdSqlDataType) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) MaxValueIndicator(org.talend.dataquality.indicators.MaxValueIndicator) TdColumn(org.talend.cwm.relational.TdColumn) Analysis(org.talend.dataquality.analysis.Analysis) AnalysisParameters(org.talend.dataquality.analysis.AnalysisParameters) RangeIndicator(org.talend.dataquality.indicators.RangeIndicator) LowerQuartileIndicator(org.talend.dataquality.indicators.LowerQuartileIndicator) UpperQuartileIndicator(org.talend.dataquality.indicators.UpperQuartileIndicator) MeanIndicator(org.talend.dataquality.indicators.MeanIndicator) MinValueIndicator(org.talend.dataquality.indicators.MinValueIndicator) Test(org.junit.Test)

Example 33 with TdColumn

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

the class TextStatisticsExplorerTest method testGetQueryMap.

/**
 * Test method for Text indicators with Hive connection,should don't have any menu items.
 */
@Test
public void testGetQueryMap() {
    AverageLengthIndicator averageLengthIndicator = IndicatorsFactory.eINSTANCE.createAverageLengthIndicator();
    TdColumn column = UnitTestBuildHelper.createRealTdColumn("NAME", "NAME", Types.VARCHAR);
    averageLengthIndicator.setAnalyzedElement(column);
    IndicatorParameters indicatorParameters = IndicatorsFactory.eINSTANCE.createIndicatorParameters();
    indicatorParameters.setDateParameters(null);
    averageLengthIndicator.setParameters(indicatorParameters);
    IndicatorDefinition averageLengthIndicatorDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    averageLengthIndicatorDef.setName("Average Length");
    averageLengthIndicator.setIndicatorDefinition(averageLengthIndicatorDef);
    Analysis analysis = UnitTestBuildHelper.createAndInitAnalysis();
    TaggedValueHelper.setTaggedValue(analysis.getContext().getConnection(), TaggedValueHelper.DB_PRODUCT_NAME, "Teradata");
    TaggedValueHelper.setTaggedValue(analysis.getContext().getConnection(), TaggedValueHelper.DB_PRODUCT_VERSION, "1");
    // $NON-NLS-1$  //$NON-NLS-2$
    ChartDataEntity chartDataEntity = new ChartDataEntity(averageLengthIndicator, "1", "1");
    chartDataEntity.setLabelNull(false);
    // $NON-NLS-1$
    chartDataEntity.setKey("1");
    TextStatisticsExplorer textStatisticsExplorer = new TextStatisticsExplorer();
    textStatisticsExplorer.setAnalysis(analysis);
    textStatisticsExplorer.setEnitty(chartDataEntity);
    Map<String, String> queryMap = textStatisticsExplorer.getQueryMap();
    assertFalse(queryMap.isEmpty());
    assertEquals("-- Analysis: anaA ;\n" + "-- Type of Analysis: Column Analysis ;\n" + "-- Purpose:  ;\n" + "-- Description:  ;\n" + "-- AnalyzedElement: NAME ;\n" + "-- Indicator: Average Length ;\n" + "-- Showing: View rows ;\n" + "SELECT t.* FROM(SELECT CAST(SUM( CHAR_LENGTH( CASE WHEN   CHAR_LENGTH( TRIM(NAME) ) =0  THEN '' ELSE  NAME END) ) / (COUNT(NAME )*1.00)+0.99 as int) c,CAST(SUM( CHAR_LENGTH( CASE WHEN   CHAR_LENGTH( TRIM(NAME) ) =0  THEN '' ELSE  NAME END) ) / (COUNT(NAME)*1.00) as int) f FROM TDQ_CALENDAR WHERE(NAME IS NOT NULL)) e, TDQ_CALENDAR t WHERE  CHAR_LENGTH( CASE WHEN   CHAR_LENGTH( TRIM(NAME) ) =0  THEN '' ELSE  NAME END)  BETWEEN f AND c", queryMap.get("View rows"));
}
Also used : AverageLengthIndicator(org.talend.dataquality.indicators.AverageLengthIndicator) TdColumn(org.talend.cwm.relational.TdColumn) Analysis(org.talend.dataquality.analysis.Analysis) IndicatorParameters(org.talend.dataquality.indicators.IndicatorParameters) ChartDataEntity(org.talend.dq.indicators.preview.table.ChartDataEntity) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) Test(org.junit.Test)

Example 34 with TdColumn

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

the class DbmsLanguageTest method testGetTable.

/**
 * Test method for {@link org.talend.dq.dbms.DbmsLanguage#getTable(orgomg.cwm.objectmodel.core.ModelElement)}.
 */
@Test
public void testGetTable() {
    try {
        TdTable tdTable = RelationalFactory.eINSTANCE.createTdTable();
        tdTable.setName(TABLE_NAME);
        TdColumn tdColumn = RelationalFactory.eINSTANCE.createTdColumn();
        tdColumn.setName(COLUMN_NAME);
        tdTable.getOwnedElement().add(tdColumn);
        tdColumn.setOwner(tdTable);
        DbmsLanguage dbms = getMysqlDbmsLanguage();
        Assert.assertTrue(tdTable.equals(dbms.getTable(tdColumn)));
    } catch (Exception e) {
        fail(e.getMessage());
    }
}
Also used : TdTable(org.talend.cwm.relational.TdTable) TdColumn(org.talend.cwm.relational.TdColumn) Test(org.junit.Test)

Example 35 with TdColumn

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

the class DbmsLanguageTest method testGetQueryColumnsWithPrefix.

@Test
public void testGetQueryColumnsWithPrefix() {
    DbmsLanguage dbms = getMysqlDbmsLanguage();
    TdColumn col1 = RelationalPackage.eINSTANCE.getRelationalFactory().createTdColumn();
    // $NON-NLS-1$
    col1.setName("myCol1");
    TdColumn col2 = RelationalPackage.eINSTANCE.getRelationalFactory().createTdColumn();
    // $NON-NLS-1$
    col2.setName("myCol2");
    TdColumn[] columns = new TdColumn[] { col1, col2 };
    TdTable tdTable = createTdTable();
    ColumnSetHelper.addColumn(col1, tdTable);
    ColumnSetHelper.addColumn(col2, tdTable);
    String queryColWithPrefix = dbms.getQueryColumnsWithPrefix(columns);
    // $NON-NLS-1$
    Assert.assertEquals("`myCatalog`.`myTable`.`myCol1`,`myCatalog`.`myTable`.`myCol2`", queryColWithPrefix);
    // Assert hive
    dbms = getHiveDbmsLanguage();
    queryColWithPrefix = dbms.getQueryColumnsWithPrefix(columns);
    // $NON-NLS-1$
    Assert.assertEquals("`myCol1`,`myCol2`", queryColWithPrefix);
}
Also used : TdColumn(org.talend.cwm.relational.TdColumn) TdTable(org.talend.cwm.relational.TdTable) Test(org.junit.Test)

Aggregations

TdColumn (org.talend.cwm.relational.TdColumn)177 TdTable (org.talend.cwm.relational.TdTable)47 ArrayList (java.util.ArrayList)45 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)40 Test (org.junit.Test)37 ColumnSet (orgomg.cwm.resource.relational.ColumnSet)35 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)26 RepositoryNode (org.talend.repository.model.RepositoryNode)26 IRepositoryNode (org.talend.repository.model.IRepositoryNode)23 Indicator (org.talend.dataquality.indicators.Indicator)20 Connection (org.talend.core.model.metadata.builder.connection.Connection)17 Catalog (orgomg.cwm.resource.relational.Catalog)17 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)16 TdSqlDataType (org.talend.cwm.relational.TdSqlDataType)16 Analysis (org.talend.dataquality.analysis.Analysis)16 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)15 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)14 DBColumnRepNode (org.talend.dq.nodes.DBColumnRepNode)14 Package (orgomg.cwm.objectmodel.core.Package)14 MetadataColumnRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject)13