use of org.talend.dataquality.matchmerge.Attribute in project tdq-studio-se by Talend.
the class BlockAndMatchManager method getBlockKey.
/**
* get the block key of one record
*
* @param record
* @return
*/
private String getBlockKey(RichRecord record) {
Map<String, String> columnValueMap = new HashMap<String, String>();
for (String columnName : colName2IndexMap.keySet()) {
int index = Integer.parseInt(colName2IndexMap.get(columnName));
columnValueMap.put(columnName, record.getAttributes().get(index).getValue());
}
String blockkey = blockKeyGenerator.getGenKey(blockKeyDefinition, columnValueMap);
// add the block key into the record
Attribute attribute = new Attribute(MatchAnalysisConstant.BLOCK_KEY, record.getAttributes().size());
attribute.setValue(blockkey);
record.getAttributes().add(attribute);
return blockkey;
}
use of org.talend.dataquality.matchmerge.Attribute in project tdq-studio-se by Talend.
the class FileDelimitedReader method createRichRecord.
/**
* DOC yyin Comment method "createRichRecord".
*
* @param analysedValues
* @return
*/
private Record createRichRecord(String[] analysedValues) {
ArrayList<Attribute> attributes = new ArrayList<Attribute>();
for (int i = 0; i < analysedValues.length; i++) {
Attribute attribute = new Attribute(analysedColumnName[i], i);
String value = String.valueOf(analysedValues[i]);
attribute.setValue(value);
attributes.add(attribute);
}
return new RichRecord(attributes, String.valueOf(index++), 0, StringUtils.EMPTY);
}
use of org.talend.dataquality.matchmerge.Attribute in project tdq-studio-se by Talend.
the class FileCSVReader method createRichRecord.
/**
* DOC yyin Comment method "createRichRecord".
*
* @param analysedValues
* @return
*/
private Record createRichRecord(String[] analysedValues) {
ArrayList<Attribute> attributes = new ArrayList<Attribute>();
for (int i = 0; i < analysedValues.length; i++) {
Attribute attribute = new Attribute(analysedColumnName[i], i);
String value = String.valueOf(analysedValues[i]);
attribute.setValue(value);
attributes.add(attribute);
}
return new RichRecord(attributes, String.valueOf(index++), 0, StringUtils.EMPTY);
}
use of org.talend.dataquality.matchmerge.Attribute in project tdq-studio-se by Talend.
the class FileCSVReaderTest method testNext.
/**
* Test method for {@link org.talend.cwm.db.connection.file.FileCSVReader#next()}.
*/
@Test
public void testNext() {
try {
File file = new File("./file.txt");
if (file.exists()) {
file.delete();
}
if (file.createNewFile()) {
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(file)));
out.println("id,name,email");
out.println("1,tom,a@b.cn");
out.println("2,jerry,x@b.cn");
out.println("3,bob,top@b.cn");
out.close();
DelimitedFileConnection delimitedFileconnection = ConnectionFactory.eINSTANCE.createDelimitedFileConnection();
delimitedFileconnection.setFilePath(file.getAbsolutePath());
delimitedFileconnection.setLimitValue("0");
delimitedFileconnection.setHeaderValue("1");
delimitedFileconnection.setFieldSeparatorValue(",");
List<ModelElement> analysisElementList = new ArrayList<ModelElement>();
MetadataTable table = ConnectionFactory.eINSTANCE.createMetadataTable();
table.setName("table");
MetadataColumn id = ConnectionFactory.eINSTANCE.createMetadataColumn();
id.setName("id");
id.setLabel("id");
id.setTable(table);
MetadataColumn name = ConnectionFactory.eINSTANCE.createMetadataColumn();
name.setName("name");
name.setLabel("name");
name.setTable(table);
MetadataColumn email = ConnectionFactory.eINSTANCE.createMetadataColumn();
email.setName("email");
email.setLabel("email");
email.setTable(table);
analysisElementList.add(id);
analysisElementList.add(name);
analysisElementList.add(email);
FileCSVReader fileCSVReader = new FileCSVReader(file, delimitedFileconnection, analysisElementList);
String fileContent = "";
int i = 0;
while (fileCSVReader.hasNext()) {
i++;
Record record = fileCSVReader.next();
List<Attribute> attributes = record.getAttributes();
fileContent += i + ":";
for (Attribute attribute : attributes) {
fileContent += "[" + attribute.getLabel() + "," + attribute.getValue() + "]";
}
}
fileCSVReader.close();
Assert.assertEquals("1:[id,1][name,tom][email,a@b.cn]2:[id,2][name,jerry][email,x@b.cn]3:[id,3][name,bob][email,top@b.cn]", fileContent);
}
// delete the temp file
if (file.exists()) {
file.delete();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations