Browse Source

[Improvement] Fix inefficient map iterator (#6004)

* Fix inefficient map iterator

* Use forEach and remove call to valueOf

* Modify AbstractParameters
2.0.7-release
Anton Lyxell 3 years ago committed by GitHub
parent
commit
ca93b8a40c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/task/AbstractParameters.java
  2. 6
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/task/sql/SqlParameters.java

3
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/task/AbstractParameters.java

@ -30,6 +30,7 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ArrayNode;
@ -152,7 +153,7 @@ public abstract class AbstractParameters implements IParameters {
ArrayNode paramsByJson = JSONUtils.parseArray(json); ArrayNode paramsByJson = JSONUtils.parseArray(json);
Iterator<JsonNode> listIterator = paramsByJson.iterator(); Iterator<JsonNode> listIterator = paramsByJson.iterator();
while (listIterator.hasNext()) { while (listIterator.hasNext()) {
Map<String, String> param = JSONUtils.toMap(listIterator.next().toString(), String.class, String.class); Map<String, String> param = JSONUtils.parseObject(listIterator.next().toString(), new TypeReference<Map<String, String>>() {});
allParams.add(param); allParams.add(param);
} }
return allParams; return allParams;

6
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/task/sql/SqlParameters.java

@ -251,9 +251,9 @@ public class SqlParameters extends AbstractParameters {
sqlResultFormat.put(key, new ArrayList<>()); sqlResultFormat.put(key, new ArrayList<>());
} }
for (Map<String, String> info : sqlResult) { for (Map<String, String> info : sqlResult) {
for (String key : info.keySet()) { info.forEach((key, value) -> {
sqlResultFormat.get(key).add(String.valueOf(info.get(key))); sqlResultFormat.get(key).add(value);
} });
} }
for (Property info : outProperty) { for (Property info : outProperty) {
if (info.getType() == DataType.LIST) { if (info.getType() == DataType.LIST) {

Loading…
Cancel
Save