Search in sources :

Example 26 with IndicatorDefinition

use of org.talend.dataquality.indicators.definition.IndicatorDefinition in project tdq-studio-se by Talend.

the class DbmsLanguageTest method testGetSqlExpressionRedshiftCase1.

/**
 * Test method for
 * {@link org.talend.dq.dbms.DbmsLanguage#getSqlExpression(IndicatorDefinition, String, EList, ProductVersion)} .
 */
@Test
public void testGetSqlExpressionRedshiftCase1() {
    // TDQ-11558 msjian: test for get sql expresstion for redshift database
    // $NON-NLS-1$
    String sqlLang = "SQL";
    // $NON-NLS-1$
    String sqlBody = "SQL body";
    String redshiftLang = SupportDBUrlType.REDSHIFT.getLanguage();
    // $NON-NLS-1$
    String redshiftBody = "Amazon redshift body";
    String postgresqlLang = SupportDBUrlType.POSTGRESQLEFAULTURL.getLanguage();
    // $NON-NLS-1$
    String postgresqlBody = "PostgreSQL body";
    IndicatorDefinition indicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    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(postgresqlLang);
    tdExpression3.setBody(postgresqlBody);
    sqlGenericExpression.add(tdExpression3);
    TdExpression tdExpression4 = RelationalFactory.eINSTANCE.createTdExpression();
    tdExpression4.setLanguage(redshiftLang);
    tdExpression4.setBody(redshiftBody);
    sqlGenericExpression.add(tdExpression4);
    ProductVersion dbVersion = new ProductVersion(1, 0);
    TdExpression sqlExpression = DbmsLanguage.getSqlExpression(indicatorDefinition, redshiftLang, sqlGenericExpression, dbVersion);
    Assert.assertEquals(tdExpression4, sqlExpression);
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) BasicEList(org.eclipse.emf.common.util.BasicEList) ProductVersion(org.talend.utils.ProductVersion) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) Test(org.junit.Test)

Example 27 with IndicatorDefinition

use of org.talend.dataquality.indicators.definition.IndicatorDefinition in project tdq-studio-se by Talend.

the class DbmsLanguageTest method testGetSqlExpressionRedshiftCase3.

/**
 * Test method for
 * {@link org.talend.dq.dbms.DbmsLanguage#getSqlExpression(IndicatorDefinition, String, EList, ProductVersion)} .
 */
@Test
public void testGetSqlExpressionRedshiftCase3() {
    // TDQ-11558 msjian: test for get sql expresstion for redshift database when there is no redshift and ParAccel
    // and PostgreSQL defined
    // $NON-NLS-1$
    String sqlLang = "SQL";
    // $NON-NLS-1$
    String sqlBody = "SQL body";
    String redshiftLang = SupportDBUrlType.REDSHIFT.getLanguage();
    IndicatorDefinition indicatorDefinition = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    EList<TdExpression> sqlGenericExpression = new BasicEList<TdExpression>();
    TdExpression tdExpression1 = RelationalFactory.eINSTANCE.createTdExpression();
    tdExpression1.setLanguage(sqlLang);
    tdExpression1.setBody(sqlBody);
    sqlGenericExpression.add(tdExpression1);
    ProductVersion dbVersion = new ProductVersion(1, 0);
    TdExpression sqlExpression = DbmsLanguage.getSqlExpression(indicatorDefinition, redshiftLang, sqlGenericExpression, dbVersion);
    Assert.assertEquals(tdExpression1, sqlExpression);
}
Also used : TdExpression(org.talend.cwm.relational.TdExpression) BasicEList(org.eclipse.emf.common.util.BasicEList) ProductVersion(org.talend.utils.ProductVersion) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) UDIndicatorDefinition(org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition) Test(org.junit.Test)

Example 28 with IndicatorDefinition

use of org.talend.dataquality.indicators.definition.IndicatorDefinition in project tdq-studio-se by Talend.

the class ExportFactoryTest method testExportFolderIFolderIndicatorDefinitionArrayNonNormalFolderNotExist.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.pattern.ExportFactory#export(java.io.File, org.eclipse.core.resources.IFolder, org.talend.dataquality.indicators.definition.IndicatorDefinition[])}
 * non-normal condition: exportFile is a folder and this folder does not exist.
 */
@Test
public void testExportFolderIFolderIndicatorDefinitionArrayNonNormalFolderNotExist() throws Exception {
    String udiName = getRandomUdiName();
    File exportFolder = new File(File.separator + StringUtilities.getRandomString(8));
    IFolder udiFolder = ResourceManager.getUDIFolder();
    IndicatorDefinition indDef = createExportIndicaorDefinition(udiFolder, udiName);
    ExportFactory.export(exportFolder, udiFolder, indDef);
    // $NON-NLS-1$
    File exportFile = new File(exportFolder.getAbsolutePath() + File.separator + udiName + ".csv");
    assertFalse(exportFile.exists());
}
Also used : File(java.io.File) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 29 with IndicatorDefinition

use of org.talend.dataquality.indicators.definition.IndicatorDefinition in project tdq-studio-se by Talend.

the class ExportFactoryTest method createExportIndicaorDefinition.

/**
 * create the IndicaorDefinition for test.
 *
 * @return
 */
private IndicatorDefinition createExportIndicaorDefinition(IFolder folder, String udiName) {
    IndicatorDefinition indDef = DefinitionFactory.eINSTANCE.createIndicatorDefinition();
    indDef.setName(udiName);
    Map<String, String> indDefParaMap = getIndDefParaMap();
    for (String key : indDefParaMap.keySet()) {
        IndicatorDefinitionParameter indDefPara = DefinitionFactory.eINSTANCE.createIndicatorDefinitionParameter();
        indDefPara.setKey(key);
        indDefPara.setValue(indDefParaMap.get(key));
        indDef.getIndicatorDefinitionParameter().add(indDefPara);
    }
    UDIHelper.setUDICategory(indDef, DefinitionHandler.getInstance().getUserDefinedCountIndicatorCategory());
    ElementWriterFactory.getInstance().createIndicatorDefinitionWriter().create(indDef, folder);
    DefinitionHandler.getInstance().reloadIndicatorsDefinitions();
    return indDef;
}
Also used : IndicatorDefinitionParameter(org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition)

Example 30 with IndicatorDefinition

use of org.talend.dataquality.indicators.definition.IndicatorDefinition in project tdq-studio-se by Talend.

the class ExportFactoryTest method testExportFolderIFolderIndicatorDefinitionArray.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.pattern.ExportFactory#export(java.io.File, org.eclipse.core.resources.IFolder, org.talend.dataquality.indicators.definition.IndicatorDefinition[])}
 * normal condition: exportFile is a folder(not a file).
 */
@Test
public void testExportFolderIFolderIndicatorDefinitionArray() throws Exception {
    String udiName = getRandomUdiName();
    // $NON-NLS-1$
    File exportFolder = new File(System.getProperty("java.io.tmpdir") + File.separator + StringUtilities.getRandomString(8));
    if (!exportFolder.exists()) {
        exportFolder.mkdirs();
    }
    IFolder udiFolder = ResourceManager.getUDIFolder();
    IndicatorDefinition indDef = createExportIndicaorDefinition(udiFolder, udiName);
    ExportFactory.export(exportFolder, udiFolder, indDef);
    // $NON-NLS-1$
    File exportFile = new File(exportFolder.getAbsolutePath() + File.separator + udiName + ".csv");
    assertTrue(exportFile.exists());
    assertTrue(exportFile.isFile());
    assertTrue(exportFile.length() > 0);
    CSVReader reader = FileUtils.createCSVReader(exportFile, FileUtils.TEXT_QUAL, FileUtils.TEXT_QUAL);
    reader.setSkipEmptyRecords(true);
    reader.readHeaders();
    boolean haveRecord = false;
    while (reader.readNext()) {
        haveRecord = true;
        String name = reader.get(PatternToExcelEnum.Label.getLiteral());
        assertEquals(name, indDef.getName());
        String paraString = reader.get(PatternToExcelEnum.IndicatorDefinitionParameter.getLiteral());
        EList<IndicatorDefinitionParameter> indDefParas = indDef.getIndicatorDefinitionParameter();
        for (IndicatorDefinitionParameter indDefPara : indDefParas) {
            String temp = indDefPara.getKey() + UDIHelper.PARA_SEPARATE_1 + indDefPara.getValue() + UDIHelper.PARA_SEPARATE_2;
            assertTrue(paraString.indexOf(temp) > -1);
        }
    }
    reader.close();
    assertTrue(haveRecord);
}
Also used : CSVReader(com.talend.csv.CSVReader) IndicatorDefinitionParameter(org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter) File(java.io.File) IndicatorDefinition(org.talend.dataquality.indicators.definition.IndicatorDefinition) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Aggregations

IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)141 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)37 Test (org.junit.Test)35 ArrayList (java.util.ArrayList)34 TdExpression (org.talend.cwm.relational.TdExpression)31 File (java.io.File)22 Analysis (org.talend.dataquality.analysis.Analysis)16 IFile (org.eclipse.core.resources.IFile)15 Property (org.talend.core.model.properties.Property)14 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14 TDQIndicatorDefinitionItem (org.talend.dataquality.properties.TDQIndicatorDefinitionItem)14 PersistenceException (org.talend.commons.exception.PersistenceException)13 Indicator (org.talend.dataquality.indicators.Indicator)12 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)12 Path (org.eclipse.core.runtime.Path)10 IFolder (org.eclipse.core.resources.IFolder)9 BasicEList (org.eclipse.emf.common.util.BasicEList)9 TdColumn (org.talend.cwm.relational.TdColumn)9 UserDefIndicator (org.talend.dataquality.indicators.sql.UserDefIndicator)7 TDQAnalysisItem (org.talend.dataquality.properties.TDQAnalysisItem)7