Search in sources :

Example 36 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class DelimitedFileIndicatorEvaluator method useCsvReader.

private ReturnCode useCsvReader(File file, List<ModelElement> analysisElementList, List<MetadataColumn> columnElementList, EMap<Indicator, AnalyzedDataSet> indicToRowMap) {
    ReturnCode returnCode = new ReturnCode(true);
    int limitValue = getCsvReaderLimit();
    int headValue = JavaSqlFactory.getHeadValue(delimitedFileconnection);
    CSVReader csvReader = null;
    try {
        csvReader = FileUtils.createCsvReader(file, delimitedFileconnection);
        FileUtils.initializeCsvReader(delimitedFileconnection, csvReader);
        for (int i = 0; i < headValue && csvReader.readNext(); i++) {
        // do nothing, just ignore the header part
        }
        String[] rowValues = null;
        long currentRecord = 0;
        while (csvReader.readNext()) {
            currentRecord++;
            if (!continueRun() || limitValue != -1 && currentRecord > limitValue) {
                break;
            }
            rowValues = csvReader.getValues();
            returnCode.setOk(returnCode.isOk() && handleByARow(rowValues, currentRecord, analysisElementList, columnElementList, indicToRowMap).isOk());
        }
    } catch (IOException e) {
        log.error(e, e);
    } finally {
        if (csvReader != null) {
            try {
                csvReader.close();
            } catch (IOException e) {
                log.error(e, e);
            }
        }
    }
    return returnCode;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) CSVReader(com.talend.csv.CSVReader) IOException(java.io.IOException)

Example 37 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class Evaluator method evaluateIndicators.

/**
 * Method "evaluateIndicators". A connection must be open. This method does not close the connection. It is to the
 * caller responsibility to close the connection.
 *
 * @param sqlStatement
 * @return a return code with an error message if any problem has been encountered.
 */
public ReturnCode evaluateIndicators(String sqlStatement, boolean closeConnection) {
    ReturnCode rc = evaluateIndicators(sqlStatement);
    if (this.isPooledConnection()) {
        return rc;
    } else {
        if (!closeConnection) {
            return rc;
        } else {
            if (rc.isOk()) {
                return closeConnection();
            } else {
                // problem with evaluation
                ReturnCode connRc = closeConnection();
                if (!connRc.isOk()) {
                    // add the message to returned code
                    String message = rc.getMessage();
                    // $NON-NLS-1$
                    message = Messages.getString("Evaluator.ConnectionProblem", message, connRc.getMessage());
                    rc.setMessage(message);
                }
            }
            return rc;
        }
    }
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode)

Example 38 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class ColumnSetIndicatorEvaluator method executeSqlQuery.

@Override
protected ReturnCode executeSqlQuery(String sqlStatement) throws SQLException {
    ReturnCode ok = new ReturnCode(true);
    AnalysisResult anaResult = analysis.getResults();
    EMap<Indicator, AnalyzedDataSet> indicToRowMap = anaResult.getIndicToRowMap();
    indicToRowMap.clear();
    if (isDelimitedFile) {
        ok = evaluateByDelimitedFile(sqlStatement, ok);
    } else {
        ok = evaluateBySql(sqlStatement, ok);
    }
    return ok;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) AnalyzedDataSet(org.talend.dataquality.analysis.AnalyzedDataSet) AnalysisResult(org.talend.dataquality.analysis.AnalysisResult) UniqueCountIndicator(org.talend.dataquality.indicators.UniqueCountIndicator) Indicator(org.talend.dataquality.indicators.Indicator) DistinctCountIndicator(org.talend.dataquality.indicators.DistinctCountIndicator) AllMatchIndicator(org.talend.dataquality.indicators.columnset.AllMatchIndicator) SimpleStatIndicator(org.talend.dataquality.indicators.columnset.SimpleStatIndicator) DuplicateCountIndicator(org.talend.dataquality.indicators.DuplicateCountIndicator) RowCountIndicator(org.talend.dataquality.indicators.RowCountIndicator)

Example 39 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class ExecuteMatchRuleHandler method computeMatchGroupWithBlockKey.

/**
 * DOC zhao Comment method "computeMatchGroupWithBlockKey".
 *
 * @param recordMatchingIndicator
 * @param blockKeyIndicator
 * @param columnMap
 * @param matchResultConsumer
 * @param matchRows
 */
private ReturnCode computeMatchGroupWithBlockKey(RecordMatchingIndicator recordMatchingIndicator, BlockKeyIndicator blockKeyIndicator, Map<MetadataColumn, String> columnMap, MatchGroupResultConsumer matchResultConsumer, List<Object[]> matchRows) {
    ReturnCode rc = new ReturnCode(Boolean.TRUE);
    Map<String, List<String[]>> resultWithBlockKey = computeBlockingKey(columnMap, matchRows, recordMatchingIndicator);
    Iterator<String> keyIterator = resultWithBlockKey.keySet().iterator();
    TreeMap<Object, Long> blockSize2Freq = new TreeMap<Object, Long>();
    while (keyIterator.hasNext()) {
        // Match group with in each block
        List<String[]> matchRowsInBlock = resultWithBlockKey.get(keyIterator.next());
        List<Object[]> objList = new ArrayList<Object[]>();
        objList.addAll(matchRowsInBlock);
        // Add check match key
        try {
            computeMatchGroupResult(columnMap, matchResultConsumer, objList, recordMatchingIndicator);
        } catch (BusinessException e) {
            rc.setOk(Boolean.FALSE);
            rc.setMessage(e.getAdditonalMessage());
            return rc;
        }
        // Store indicator
        Integer blockSize = matchRowsInBlock.size();
        if (blockSize == null) {
            // should not happen
            blockSize = 0;
        }
        Long freq = blockSize2Freq.get(Long.valueOf(blockSize));
        if (freq == null) {
            freq = 0l;
        }
        blockSize2Freq.put(Long.valueOf(blockSize), freq + 1);
    }
    blockKeyIndicator.setBlockSize2frequency(blockSize2Freq);
    return rc;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) BusinessException(org.talend.commons.exception.BusinessException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 40 with ReturnCode

use of org.talend.utils.sugars.ReturnCode in project tdq-studio-se by Talend.

the class ExecuteMatchRuleHandler method execute.

public TypedReturnCode<MatchGroupResultConsumer> execute(Map<MetadataColumn, String> columnMap, RecordMatchingIndicator recordMatchingIndicator, List<Object[]> matchRows, BlockKeyIndicator blockKeyIndicator, MatchGroupResultConsumer matchResultConsumer) {
    TypedReturnCode<MatchGroupResultConsumer> returnCode = new TypedReturnCode<MatchGroupResultConsumer>(false);
    returnCode.setObject(matchResultConsumer);
    // By default for analysis, the applied blocking key will be the key
    // from key generation definition. This
    // will be refined when there is a need to define the applied blocking
    // key manually by user later.
    AnalysisRecordGroupingUtils.createAppliedBlockKeyByGenKey(recordMatchingIndicator);
    ReturnCode computeMatchGroupReturnCode = null;
    // Blocking key specified.
    computeMatchGroupReturnCode = computeMatchGroupWithBlockKey(recordMatchingIndicator, blockKeyIndicator, columnMap, matchResultConsumer, matchRows);
    returnCode.setOk(computeMatchGroupReturnCode.isOk());
    returnCode.setMessage(computeMatchGroupReturnCode.getMessage());
    return returnCode;
}
Also used : ReturnCode(org.talend.utils.sugars.ReturnCode) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) MatchGroupResultConsumer(org.talend.dataquality.record.linkage.grouping.MatchGroupResultConsumer) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode)

Aggregations

ReturnCode (org.talend.utils.sugars.ReturnCode)175 ArrayList (java.util.ArrayList)42 TypedReturnCode (org.talend.utils.sugars.TypedReturnCode)42 Test (org.junit.Test)29 File (java.io.File)26 Connection (org.talend.core.model.metadata.builder.connection.Connection)26 Indicator (org.talend.dataquality.indicators.Indicator)25 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)20 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)18 Analysis (org.talend.dataquality.analysis.Analysis)18 Property (org.talend.core.model.properties.Property)17 IFile (org.eclipse.core.resources.IFile)16 IRepositoryNode (org.talend.repository.model.IRepositoryNode)16 IFolder (org.eclipse.core.resources.IFolder)15 SQLException (java.sql.SQLException)14 PersistenceException (org.talend.commons.exception.PersistenceException)11 TdColumn (org.talend.cwm.relational.TdColumn)11 IOException (java.io.IOException)10 EObject (org.eclipse.emf.ecore.EObject)10 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)10