Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] simplify some code in routine load #9532

Merged
merged 2 commits into from
May 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,8 @@ private void checkJobProperties() throws UserException {
format = ""; // if it's not json, then it's mean csv and set empty
} else if (format.equalsIgnoreCase("json")) {
format = "json";
jsonPaths = jobProperties.get(JSONPATHS);
jsonRoot = jobProperties.get(JSONROOT);
jsonPaths = jobProperties.getOrDefault(JSONPATHS, "");
jsonRoot = jobProperties.getOrDefault(JSONROOT, "");
stripOuterArray = Boolean.valueOf(jobProperties.getOrDefault(STRIP_OUTER_ARRAY, "false"));
numAsString = Boolean.valueOf(jobProperties.getOrDefault(NUM_AS_STRING, "false"));
fuzzyParse = Boolean.valueOf(jobProperties.getOrDefault(FUZZY_PARSE, "false"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,53 +299,46 @@ protected void setOptional(CreateRoutineLoadStmt stmt) throws UserException {

if (Strings.isNullOrEmpty(stmt.getFormat()) || stmt.getFormat().equals("csv")) {
jobProperties.put(PROPS_FORMAT, "csv");
jobProperties.put(PROPS_STRIP_OUTER_ARRAY, "false");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the loaded file format is csv, but the json related parameter is configured to true, does it have any effect on the load?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. If format is csv, the json related parameter will always configured to false in analyze state.

jobProperties.put(PROPS_NUM_AS_STRING, "false");
jobProperties.put(PROPS_JSONPATHS, "");
jobProperties.put(PROPS_JSONROOT, "");
jobProperties.put(PROPS_FUZZY_PARSE, "false");
} else if (stmt.getFormat().equals("json")) {
jobProperties.put(PROPS_FORMAT, "json");
if (!Strings.isNullOrEmpty(stmt.getJsonPaths())) {
jobProperties.put(PROPS_JSONPATHS, stmt.getJsonPaths());
} else {
jobProperties.put(PROPS_JSONPATHS, "");
}
if (!Strings.isNullOrEmpty(stmt.getJsonRoot())) {
jobProperties.put(PROPS_JSONROOT, stmt.getJsonRoot());
} else {
jobProperties.put(PROPS_JSONROOT, "");
}
if (stmt.isStripOuterArray()) {
jobProperties.put(PROPS_STRIP_OUTER_ARRAY, "true");
} else {
jobProperties.put(PROPS_STRIP_OUTER_ARRAY, "false");
}
if (stmt.isNumAsString()) {
jobProperties.put(PROPS_NUM_AS_STRING, "true");
} else {
jobProperties.put(PROPS_NUM_AS_STRING, "false");
}
if (stmt.isFuzzyParse()) {
jobProperties.put(PROPS_FUZZY_PARSE, "true");
} else {
jobProperties.put(PROPS_FUZZY_PARSE, "false");
}

} else {
throw new UserException("Invalid format type.");
}

if (!Strings.isNullOrEmpty(stmt.getJsonPaths())) {
jobProperties.put(PROPS_JSONPATHS, stmt.getJsonPaths());
} else {
jobProperties.put(PROPS_JSONPATHS, "");
}
if (!Strings.isNullOrEmpty(stmt.getJsonRoot())) {
jobProperties.put(PROPS_JSONROOT, stmt.getJsonRoot());
} else {
jobProperties.put(PROPS_JSONROOT, "");
}
if (stmt.isStripOuterArray()) {
jobProperties.put(PROPS_STRIP_OUTER_ARRAY, "true");
} else {
jobProperties.put(PROPS_STRIP_OUTER_ARRAY, "false");
}
if (stmt.isNumAsString()) {
jobProperties.put(PROPS_NUM_AS_STRING, "true");
} else {
jobProperties.put(PROPS_NUM_AS_STRING, "false");
}
if (stmt.isFuzzyParse()) {
jobProperties.put(PROPS_FUZZY_PARSE, "true");
} else {
jobProperties.put(PROPS_FUZZY_PARSE, "false");
}
}

private void setRoutineLoadDesc(RoutineLoadDesc routineLoadDesc) {
if (routineLoadDesc != null) {
columnDescs = new ImportColumnDescs();
if (routineLoadDesc.getColumnsInfo() != null) {
ImportColumnsStmt columnsStmt = routineLoadDesc.getColumnsInfo();
if (columnsStmt.getColumns() != null || columnsStmt.getColumns().size() != 0) {
for (ImportColumnDesc columnDesc : columnsStmt.getColumns()) {
columnDescs.descs.add(columnDesc);
}
if (columnsStmt.getColumns() != null) {
columnDescs.descs.addAll(columnsStmt.getColumns());
}
}
if (routineLoadDesc.getPrecedingFilter() != null) {
Expand Down Expand Up @@ -1316,7 +1309,7 @@ public List<String> getShowInfo() {

public List<List<String>> getTasksShowInfo() {
List<List<String>> rows = Lists.newArrayList();
routineLoadTaskInfoList.stream().forEach(entity -> {
routineLoadTaskInfoList.forEach(entity -> {
try {
entity.setTxnStatus(Catalog.getCurrentCatalog().getGlobalTransactionMgr().getDatabaseTransactionMgr(dbId).getTransactionState(entity.getTxnId()).getTransactionStatus());
rows.add(entity.getTaskShowInfo());
Expand Down Expand Up @@ -1481,10 +1474,7 @@ public boolean needRemove() {
return false;
}
Preconditions.checkState(endTimestamp != -1, endTimestamp);
if ((System.currentTimeMillis() - endTimestamp) > Config.label_keep_max_second * 1000) {
return true;
}
return false;
return (System.currentTimeMillis() - endTimestamp) > Config.label_keep_max_second * 1000;
}

public boolean isFinal() {
Expand Down