Search in sources :

Example 31 with Expression

use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.

the class PatternRepNode method getChildren.

@Override
public List<IRepositoryNode> getChildren() {
    List<IRepositoryNode> languageElement = new ArrayList<IRepositoryNode>();
    IRepositoryViewObject object = this.getObject();
    TDQPatternItem patternItem = (TDQPatternItem) object.getProperty().getItem();
    Pattern pattern = patternItem.getPattern();
    EList<PatternComponent> components = pattern.getComponents();
    for (PatternComponent component : components) {
        RegularExpression re = (RegularExpression) component;
        Expression expression = re.getExpression();
        String language = expression.getLanguage();
        PatternLanguageRepNode plrn = new PatternLanguageRepNode(this, ENodeType.TDQ_REPOSITORY_ELEMENT, getProject());
        plrn.setRegularExpression(re);
        plrn.setId(language);
        plrn.setLabel(language);
        languageElement.add(plrn);
    }
    // MOD gdbu 2011-7-11 bug : 22204
    return filterResultsIfAny(languageElement);
// ~22204
}
Also used : Pattern(org.talend.dataquality.domain.pattern.Pattern) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Expression(orgomg.cwm.objectmodel.core.Expression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) ArrayList(java.util.ArrayList) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PatternComponent(org.talend.dataquality.domain.pattern.PatternComponent) TDQPatternItem(org.talend.dataquality.properties.TDQPatternItem)

Example 32 with Expression

use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.

the class ResultSetHelper method getResultSet.

public static ResultSet getResultSet(MetadataTable metadataTable, java.sql.Connection sqlConn, String whereExpression, int maxRows) throws SQLException {
    Connection tdDataProvider = ConnectionHelper.getTdDataProvider(metadataTable);
    if (sqlConn == null) {
        IMetadataConnection metadataBean = ConvertionHelper.convert(tdDataProvider);
        TypedReturnCode<java.sql.Connection> createConnection = MetadataConnectionUtils.createConnection(metadataBean, false);
        if (!createConnection.isOk()) {
            return null;
        }
        sqlConn = createConnection.getObject();
    }
    DbmsLanguage dbmsLanguage = DbmsLanguageFactory.createDbmsLanguage(tdDataProvider);
    Statement createStatement = null;
    if (maxRows != 0) {
        // TOPN algorithm, it has row limited,no need the fetch size.
        createStatement = dbmsLanguage.createStatement(sqlConn);
    } else {
        // Resevoir Sample algorithm
        createStatement = dbmsLanguage.createStatement(sqlConn, 1000);
    }
    createStatement.setMaxRows(maxRows);
    Expression columnQueryExpression = dbmsLanguage.getTableQueryExpression(metadataTable, whereExpression);
    return createStatement.executeQuery(columnQueryExpression.getBody());
}
Also used : DbmsLanguage(org.talend.dq.dbms.DbmsLanguage) Expression(orgomg.cwm.objectmodel.core.Expression) Statement(java.sql.Statement) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection)

Example 33 with Expression

use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.

the class ExportFactory method getRelatedValueFromIndicatorDefinition.

private static Map<PatternToExcelEnum, String> getRelatedValueFromIndicatorDefinition(IndicatorDefinition indicatorDefinition, IFolder folder) {
    Map<PatternToExcelEnum, String> idMap = new HashMap<PatternToExcelEnum, String>();
    if (folder != null) {
        IFile file = ResourceFileMap.findCorrespondingFile(indicatorDefinition);
        URI relativeURI = folder.getLocationURI().relativize(file.getParent().getLocationURI());
        // get the basic information
        idMap.put(PatternToExcelEnum.Label, relpaceTempHasEscapeCharactor(indicatorDefinition.getName()));
        idMap.put(PatternToExcelEnum.Purpose, relpaceTempHasEscapeCharactor(MetadataHelper.getPurpose(indicatorDefinition)));
        idMap.put(PatternToExcelEnum.Description, relpaceTempHasEscapeCharactor(MetadataHelper.getDescription(indicatorDefinition)));
        idMap.put(PatternToExcelEnum.Author, relpaceTempHasEscapeCharactor(MetadataHelper.getAuthor(indicatorDefinition)));
        idMap.put(PatternToExcelEnum.RelativePath, relativeURI.toString());
        idMap.put(PatternToExcelEnum.Category, UDIHelper.getUDICategory(indicatorDefinition).getLabel());
        TaggedValue tagValue = TaggedValueHelper.getTaggedValue(TaggedValueHelper.CLASS_NAME_TEXT, indicatorDefinition.getTaggedValue());
        idMap.put(PatternToExcelEnum.JavaClassName, tagValue == null ? null : tagValue.getValue());
        tagValue = TaggedValueHelper.getTaggedValue(TaggedValueHelper.JAR_FILE_PATH, indicatorDefinition.getTaggedValue());
        idMap.put(PatternToExcelEnum.JavaJarPath, tagValue == null ? null : tagValue.getValue());
        for (PatternLanguageType languagetype : PatternLanguageType.values()) {
            for (Expression expression : indicatorDefinition.getSqlGenericExpression()) {
                if (expression != null && expression.getLanguage().equalsIgnoreCase(languagetype.getLiteral())) {
                    idMap.put(languagetype.getExcelEnum(), expression.getBody());
                }
            }
            if (!idMap.containsKey(languagetype.getExcelEnum())) {
                // $NON-NLS-1$
                idMap.put(languagetype.getExcelEnum(), "");
            }
        }
        // put the IndicatorDefinitionParameter into Map
        StringBuffer strBuf = new StringBuffer();
        EList<IndicatorDefinitionParameter> indDefParas = indicatorDefinition.getIndicatorDefinitionParameter();
        for (IndicatorDefinitionParameter indDefPara : indDefParas) {
            strBuf.append(indDefPara.getKey() + UDIHelper.PARA_SEPARATE_1 + indDefPara.getValue() + UDIHelper.PARA_SEPARATE_2);
        }
        idMap.put(PatternToExcelEnum.IndicatorDefinitionParameter, strBuf.toString());
    }
    return idMap;
}
Also used : IFile(org.eclipse.core.resources.IFile) HashMap(java.util.HashMap) TdExpression(org.talend.cwm.relational.TdExpression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Expression(orgomg.cwm.objectmodel.core.Expression) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) IndicatorDefinitionParameter(org.talend.dataquality.indicators.definition.IndicatorDefinitionParameter) URI(java.net.URI)

Example 34 with Expression

use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.

the class DomainHelper method getExpression.

/**
 * Method "getExpression".
 *
 * @param patternComponent
 * @param language a language (see DbmsLanguage)
 * @return the expression for the given language or null
 */
public static Expression getExpression(PatternComponent patternComponent, String language) {
    if (patternComponent != null && patternComponent.eClass().equals(PatternPackage.eINSTANCE.getRegularExpression())) {
        RegularExpression regExp = (RegularExpression) patternComponent;
        Expression expr = regExp.getExpression();
        if (expr != null && language != null && language.equalsIgnoreCase(regExp.getExpression().getLanguage())) {
            return expr;
        }
    }
    // not a regular expression
    return null;
}
Also used : RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) RegularExpression(org.talend.dataquality.domain.pattern.RegularExpression) Expression(orgomg.cwm.objectmodel.core.Expression)

Example 35 with Expression

use of orgomg.cwm.objectmodel.core.Expression in project tdq-studio-se by Talend.

the class UDIHelper method validate.

public static ReturnCode validate(IndicatorDefinition indicatorDefinition) {
    ReturnCode rc = new ReturnCode(true);
    List<String> errorList = new ArrayList<String>();
    // MOD mzhao feature 11128, In case of Java UDI, No expression is allowed to be saved.
    if (!containsJavaUDI(indicatorDefinition)) {
        if (0 == indicatorDefinition.getSqlGenericExpression().size()) {
            // $NON-NLS-1$
            errorList.add(Messages.getString("UDIHelper.validateNoExpression"));
            rc.setOk(false);
        }
    }
    if (PluginConstant.EMPTY_STRING.equals(indicatorDefinition.getName())) {
        // $NON-NLS-1$
        errorList.add(Messages.getString("UDIHelper.validateNoName"));
        rc.setOk(false);
    }
    for (Expression exp : indicatorDefinition.getSqlGenericExpression()) {
        if (null == exp.getBody() || exp.getBody().length() + 1 < MIN_EXPRESSION_LENGTH) {
            // $NON-NLS-1$
            errorList.add(Messages.getString("UDIHelper.validateTooShort"));
            rc.setOk(false);
        }
    }
    // $NON-NLS-1$
    String message = Messages.getString("UDIHelper.validateCannotSave");
    // $NON-NLS-1$
    String wrap = System.getProperty("line.separator");
    for (int i = 0; i < errorList.size(); i++) {
        message += wrap + (i + 1) + org.talend.dataquality.PluginConstant.DOT_STRING + errorList.get(i);
    }
    rc.setMessage(message);
    return rc;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) Expression(orgomg.cwm.objectmodel.core.Expression) ArrayList(java.util.ArrayList)

Aggregations

Expression (orgomg.cwm.objectmodel.core.Expression)71 TdExpression (org.talend.cwm.relational.TdExpression)42 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)37 Test (org.junit.Test)25 Domain (org.talend.dataquality.domain.Domain)14 ArrayList (java.util.ArrayList)13 TdColumn (org.talend.cwm.relational.TdColumn)11 Pattern (org.talend.dataquality.domain.pattern.Pattern)10 Catalog (orgomg.cwm.resource.relational.Catalog)10 Indicator (org.talend.dataquality.indicators.Indicator)9 IndicatorParameters (org.talend.dataquality.indicators.IndicatorParameters)8 Analysis (org.talend.dataquality.analysis.Analysis)7 PatternMatchingIndicator (org.talend.dataquality.indicators.PatternMatchingIndicator)7 UDIndicatorDefinition (org.talend.dataquality.indicators.definition.userdefine.UDIndicatorDefinition)7 DbmsLanguage (org.talend.dq.dbms.DbmsLanguage)7 Connection (org.talend.core.model.metadata.builder.connection.Connection)6 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)6 AnalysisContext (org.talend.dataquality.analysis.AnalysisContext)6 IndicatorDefinition (org.talend.dataquality.indicators.definition.IndicatorDefinition)6 ChartDataEntity (org.talend.dq.indicators.preview.table.ChartDataEntity)6