alibaba / alibaba/DataX

建议优化MongoDBReader代码逻辑MongoDBReader 165-177行

Open
#444 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
17.4k
Forks
5.7k
PR merge metrics
No merged PRs in 30d

Description

目前代码段:
``` if(KeyConstant.isArrayType(column.getString(KeyConstant.COLUMN_TYPE))) {
String splitter = column.getString(KeyConstant.COLUMN_SPLITTER);
if(Strings.isNullOrEmpty(splitter)) {
throw DataXException.asDataXException(MongoDBReaderErrorCode.ILLEGAL_VALUE,
MongoDBReaderErrorCode.ILLEGAL_VALUE.getDescription());
} else {
ArrayList array = (ArrayList)tempCol;
String tempArrayStr = Joiner.on(splitter).join(array);
record.addColumn(new StringColumn(tempArrayStr));
}
} else {
record.addColumn(new StringColumn(tempCol.toString()));
} ```
其中new StringColumn(tempArrayStr) ,new StringColumn(tempCol.toString()) 入mysql库后,打乱了原有json形式,直接Document的 toString
``` @Override
public String toString() {
return "Document{"
+ documentAsMap
+ '}';
}```
json格式打乱了。不如换成:
`if(KeyConstant.isArrayType(column.getString(KeyConstant.COLUMN_TYPE))) {
String splitter = column.getString(KeyConstant.COLUMN_SPLITTER);

if(Strings.isNullOrEmpty(splitter)) {
throw DataXException.asDataXException(MongoDBReaderErrorCode.ILLEGAL_VALUE,
MongoDBReaderErrorCode.ILLEGAL_VALUE.getDescription());
} else {
ArrayList array = (ArrayList)tempCol;
record.addColumn(new StringColumn(JSON.toJSONString(array)));
}
} else {
if(tempCol instanceof Document){
record.addColumn(new StringColumn(JSON.toJSONString(tempCol)));
}else{
record.addColumn(new StringColumn(tempCol.toString()));
}

}`

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at MongoDBReader lines 165-177 and inspect how array values and Document instances are converted into StringColumn values. Compare the resulting values with the original JSON structure and verify that MongoDB data written to MySQL preserves that structure; no test file is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, mongodb, mysql
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.