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;
}
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;
}
}
}
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;
}
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;
}
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;
}
Aggregations