You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wayang.apache.org by be...@apache.org on 2021/10/27 12:55:23 UTC
[incubator-wayang] 02/04: [RELEASE][PREPARATION] Update names form
JSONArray to WayangJsonArray, and from JSONObject to WayangJsonObj
This is an automated email from the ASF dual-hosted git repository.
bertty pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-wayang.git
commit a55f56b0c02548a82e0db182807c9bc55ae8c851
Author: Bertty Contreras-Rojas <be...@scalytics.io>
AuthorDate: Wed Oct 27 14:17:11 2021 +0200
[RELEASE][PREPARATION] Update names form JSONArray to WayangJsonArray, and from JSONObject to WayangJsonObj
Signed-off-by: bertty <be...@gmail.com>
---
.../apache/wayang/core/monitor/FileMonitor.java | 6 +-
.../optimizer/cardinality/CardinalityEstimate.java | 14 +-
.../core/optimizer/costs/EstimationContext.java | 12 +-
.../wayang/core/optimizer/costs/LoadEstimate.java | 14 +-
.../wayang/core/optimizer/costs/LoadProfile.java | 24 ++--
.../optimizer/costs/LoadProfileEstimators.java | 12 +-
.../optimizer/costs/SimpleEstimationContext.java | 10 +-
.../wayang/core/platform/AtomicExecution.java | 39 ++---
.../wayang/core/platform/AtomicExecutionGroup.java | 8 +-
.../wayang/core/platform/PartialExecution.java | 16 +--
.../org/apache/wayang/core/platform/Platform.java | 8 +-
.../core/profiling/CardinalityRepository.java | 16 +--
.../apache/wayang/core/profiling/ExecutionLog.java | 6 +-
.../apache/wayang/core/util/JsonSerializable.java | 18 +--
.../apache/wayang/core/util/JsonSerializables.java | 159 +++++++++++----------
.../apache/wayang/core/util/JsonSerializer.java | 8 +-
.../json/{JSONArray.java => WayangJsonArray.java} | 31 ++--
.../json/{JSONObject.java => WayangJsonObj.java} | 61 ++++----
.../wayang/core/platform/PartialExecutionTest.java | 6 +-
.../test/SerializableDummyExecutionOperator.java | 10 +-
.../wayang/jdbc/operators/SqlToStreamOperator.java | 10 +-
21 files changed, 242 insertions(+), 246 deletions(-)
diff --git a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/monitor/FileMonitor.java b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/monitor/FileMonitor.java
index aee3af3..c4c04f9 100644
--- a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/monitor/FileMonitor.java
+++ b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/monitor/FileMonitor.java
@@ -29,7 +29,7 @@ import java.io.UncheckedIOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.wayang.core.util.json.JSONObject;
+import org.apache.wayang.core.util.json.WayangJsonObj;
public class FileMonitor extends Monitor {
@@ -47,7 +47,7 @@ public class FileMonitor extends Monitor {
HashMap<String, Object> jsonPlanMap = new HashMap<>();
jsonPlanMap.put("stages", initialExecutionPlan);
jsonPlanMap.put("run_id", runId);
- JSONObject jsonPlan = new JSONObject(jsonPlanMap);
+ WayangJsonObj jsonPlan = new WayangJsonObj(jsonPlanMap);
writer.write(jsonPlan.toString());
} catch (UncheckedIOException e) {
@@ -84,7 +84,7 @@ public class FileMonitor extends Monitor {
progressBar.put("overall", overall);
progressBar.put("details", progress);
- JSONObject jsonProgress = new JSONObject(progressBar);
+ WayangJsonObj jsonProgress = new WayangJsonObj(progressBar);
writer.write(jsonProgress.toString());
} catch (UncheckedIOException e) {
throw e.getCause();
diff --git a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/cardinality/CardinalityEstimate.java b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/cardinality/CardinalityEstimate.java
index e757dc8..c4410e1 100644
--- a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/cardinality/CardinalityEstimate.java
+++ b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/cardinality/CardinalityEstimate.java
@@ -22,7 +22,7 @@ import org.apache.wayang.core.optimizer.ProbabilisticIntervalEstimate;
import org.apache.wayang.core.plan.wayangplan.WayangPlan;
import org.apache.wayang.core.util.Formats;
import org.apache.wayang.core.util.JsonSerializable;
-import org.apache.wayang.core.util.json.JSONObject;
+import org.apache.wayang.core.util.json.WayangJsonObj;
/**
* An estimate of cardinality within a {@link WayangPlan} expressed as a {@link ProbabilisticIntervalEstimate}.
@@ -72,27 +72,27 @@ public class CardinalityEstimate extends ProbabilisticIntervalEstimate implement
}
/**
- * Parses the given {@link JSONObject} to create a new instance.
+ * Parses the given {@link WayangJsonObj} to create a new instance.
*
* @param json that should be parsed
* @return the new instance
*/
- public static CardinalityEstimate fromJson(JSONObject json) {
+ public static CardinalityEstimate fromJson(WayangJsonObj json) {
return new CardinalityEstimate(json.getLong("lowerBound"), json.getLong("upperBound"), json.getDouble("confidence"));
}
@Override
- public JSONObject toJson() {
- return this.toJson(new JSONObject());
+ public WayangJsonObj toJson() {
+ return this.toJson(new WayangJsonObj());
}
/**
- * Serializes this instance to the given {@link JSONObject}.
+ * Serializes this instance to the given {@link WayangJsonObj}.
*
* @param json to which this instance should be serialized
* @return {@code json}
*/
- public JSONObject toJson(JSONObject json) {
+ public WayangJsonObj toJson(WayangJsonObj json) {
json.put("lowerBound", this.getLowerEstimate());
json.put("upperBound", this.getUpperEstimate());
json.put("confidence", this.getCorrectnessProbability());
diff --git a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/costs/EstimationContext.java b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/costs/EstimationContext.java
index d1896fd..bd2830c 100644
--- a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/costs/EstimationContext.java
+++ b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/costs/EstimationContext.java
@@ -25,7 +25,7 @@ import org.apache.wayang.core.util.JsonSerializer;
import java.util.Arrays;
import java.util.Collection;
-import org.apache.wayang.core.util.json.JSONObject;
+import org.apache.wayang.core.util.json.WayangJsonObj;
/**
* Provides parameters required by {@link LoadProfileEstimator}s.
@@ -143,22 +143,22 @@ public interface EstimationContext {
JsonSerializer<EstimationContext> defaultSerializer = new JsonSerializer<EstimationContext>() {
@Override
- public JSONObject serialize(EstimationContext ctx) {
- JSONObject doubleProperties = new JSONObject();
+ public WayangJsonObj serialize(EstimationContext ctx) {
+ WayangJsonObj doubleProperties = new WayangJsonObj();
for (String key : ctx.getPropertyKeys()) {
double value = ctx.getDoubleProperty(key, 0);
doubleProperties.put(key, value);
}
if (doubleProperties.length() == 0) doubleProperties = null;
- return new JSONObject()
+ return new WayangJsonObj()
.put("inCards", JsonSerializables.serializeAll(Arrays.asList(ctx.getInputCardinalities()), false))
.put("outCards", JsonSerializables.serializeAll(Arrays.asList(ctx.getOutputCardinalities()), false))
.put("executions", ctx.getNumExecutions())
- .putOpt("properties", doubleProperties);
+ .putOptional("properties", doubleProperties);
}
@Override
- public EstimationContext deserialize(JSONObject json, Class<? extends EstimationContext> cls) {
+ public EstimationContext deserialize(WayangJsonObj json, Class<? extends EstimationContext> cls) {
throw new UnsupportedOperationException("Deserialization not supported.");
}
};
diff --git a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/costs/LoadEstimate.java b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/costs/LoadEstimate.java
index 87d4360..8fcc9f9 100644
--- a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/costs/LoadEstimate.java
+++ b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/costs/LoadEstimate.java
@@ -21,7 +21,7 @@ package org.apache.wayang.core.optimizer.costs;
import org.apache.wayang.core.optimizer.ProbabilisticIntervalEstimate;
import org.apache.wayang.core.util.JsonSerializable;
import org.apache.wayang.core.util.JsonSerializables;
-import org.apache.wayang.core.util.json.JSONObject;
+import org.apache.wayang.core.util.json.WayangJsonObj;
/**
* An estimate of costs of some executable code expressed as a {@link ProbabilisticIntervalEstimate}.
@@ -74,8 +74,8 @@ public class LoadEstimate extends ProbabilisticIntervalEstimate implements JsonS
}
@Override
- public JSONObject toJson() {
- JSONObject json = new JSONObject();
+ public WayangJsonObj toJson() {
+ WayangJsonObj json = new WayangJsonObj();
json.put("lower", JsonSerializables.serialize(this.getLowerEstimate(), false));
json.put("upper", JsonSerializables.serialize(this.getUpperEstimate(), false));
json.put("prob", JsonSerializables.serialize(this.getCorrectnessProbability(), false));
@@ -83,11 +83,11 @@ public class LoadEstimate extends ProbabilisticIntervalEstimate implements JsonS
}
@SuppressWarnings("unused")
- public static LoadEstimate fromJson(JSONObject jsonObject) {
+ public static LoadEstimate fromJson(WayangJsonObj wayangJsonObj) {
return new LoadEstimate(
- jsonObject.getLong("lower"),
- jsonObject.getLong("upper"),
- jsonObject.getDouble("prob")
+ wayangJsonObj.getLong("lower"),
+ wayangJsonObj.getLong("upper"),
+ wayangJsonObj.getDouble("prob")
);
}
}
diff --git a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/costs/LoadProfile.java b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/costs/LoadProfile.java
index 94f5856..a9cd145 100644
--- a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/costs/LoadProfile.java
+++ b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/costs/LoadProfile.java
@@ -25,7 +25,7 @@ import org.apache.wayang.core.util.JsonSerializables;
import java.util.Collection;
import java.util.LinkedList;
-import org.apache.wayang.core.util.json.JSONObject;
+import org.apache.wayang.core.util.json.WayangJsonObj;
/**
* Reflects the (estimated) required resources of an {@link Operator} or {@link FunctionDescriptor}.
@@ -188,26 +188,26 @@ public class LoadProfile implements JsonSerializable {
}
@Override
- public JSONObject toJson() {
- JSONObject json = new JSONObject();
+ public WayangJsonObj toJson() {
+ WayangJsonObj json = new WayangJsonObj();
json.put("cpu", JsonSerializables.serialize(this.cpuUsage, false));
json.put("ram", JsonSerializables.serialize(this.ramUsage, false));
- json.putOpt("network", JsonSerializables.serialize(this.networkUsage, false));
- json.putOpt("disk", JsonSerializables.serialize(this.diskUsage, false));
+ json.putOptional("network", JsonSerializables.serialize(this.networkUsage, false));
+ json.putOptional("disk", JsonSerializables.serialize(this.diskUsage, false));
json.put("utilization", this.resourceUtilization);
json.put("overhead", this.overheadMillis);
return json;
}
@SuppressWarnings("unused")
- public static LoadProfile fromJson(JSONObject jsonObject) {
+ public static LoadProfile fromJson(WayangJsonObj wayangJsonObj) {
return new LoadProfile(
- JsonSerializables.deserialize(jsonObject.getJSONObject("cpu"), LoadEstimate.class),
- JsonSerializables.deserialize(jsonObject.getJSONObject("ram"), LoadEstimate.class),
- JsonSerializables.deserialize(jsonObject.optJSONObject("network"), LoadEstimate.class),
- JsonSerializables.deserialize(jsonObject.optJSONObject("disk"), LoadEstimate.class),
- jsonObject.getDouble("utilization"),
- jsonObject.getLong("overhead")
+ JsonSerializables.deserialize(wayangJsonObj.getJSONObject("cpu"), LoadEstimate.class),
+ JsonSerializables.deserialize(wayangJsonObj.getJSONObject("ram"), LoadEstimate.class),
+ JsonSerializables.deserialize(wayangJsonObj.optionalWayangJsonObj("network"), LoadEstimate.class),
+ JsonSerializables.deserialize(wayangJsonObj.optionalWayangJsonObj("disk"), LoadEstimate.class),
+ wayangJsonObj.getDouble("utilization"),
+ wayangJsonObj.getLong("overhead")
);
}
}
diff --git a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/costs/LoadProfileEstimators.java b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/costs/LoadProfileEstimators.java
index fcfe1fe..d4093b9 100644
--- a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/costs/LoadProfileEstimators.java
+++ b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/costs/LoadProfileEstimators.java
@@ -27,7 +27,7 @@ import org.apache.wayang.core.optimizer.cardinality.CardinalityEstimate;
import org.apache.wayang.core.optimizer.costs.LoadEstimator.SinglePointEstimationFunction;
import org.apache.wayang.core.plan.wayangplan.ExecutionOperator;
import org.apache.wayang.core.util.JuelUtils;
-import org.apache.wayang.core.util.json.JSONObject;
+import org.apache.wayang.core.util.json.WayangJsonObj;
import org.apache.wayang.core.util.mathex.Context;
import org.apache.wayang.core.util.mathex.DefaultContext;
import org.apache.wayang.core.util.mathex.Expression;
@@ -124,7 +124,7 @@ public class LoadProfileEstimators {
*/
public static NestableLoadProfileEstimator createFromSpecification(String configKey, String specification) {
try {
- final JSONObject spec = new JSONObject(specification);
+ final WayangJsonObj spec = new WayangJsonObj(specification);
if (!spec.has("type") || "juel".equalsIgnoreCase(spec.getString("type"))) {
return createFromJuelSpecification(configKey, spec);
} else if ("mathex".equalsIgnoreCase(spec.getString("type"))) {
@@ -159,12 +159,12 @@ public class LoadProfileEstimators {
* @param spec a specification that adheres to above format
* @return the new instance
*/
- public static NestableLoadProfileEstimator createFromJuelSpecification(String configKey, JSONObject spec) {
+ public static NestableLoadProfileEstimator createFromJuelSpecification(String configKey, WayangJsonObj spec) {
int numInputs = spec.getInt("in");
int numOutputs = spec.getInt("out");
double correctnessProb = spec.getDouble("p");
List<String> operatorProperties = spec.has("import") ?
- StreamSupport.stream(spec.optJSONArray("import").spliterator(), false).map(Objects::toString).collect(Collectors.toList()) :
+ StreamSupport.stream(spec.optionalWayangJsonArray("import").spliterator(), false).map(Objects::toString).collect(Collectors.toList()) :
Collections.emptyList();
@@ -234,12 +234,12 @@ public class LoadProfileEstimators {
* @param spec a specification that adheres to above format
* @return the new instance
*/
- public static NestableLoadProfileEstimator createFromMathExSpecification(String configKey, JSONObject spec) {
+ public static NestableLoadProfileEstimator createFromMathExSpecification(String configKey, WayangJsonObj spec) {
int numInputs = spec.getInt("in");
int numOutputs = spec.getInt("out");
double correctnessProb = spec.getDouble("p");
List<String> operatorProperties = spec.has("import") ?
- StreamSupport.stream(spec.optJSONArray("import").spliterator(), false).map(Objects::toString).collect(Collectors.toList()) :
+ StreamSupport.stream(spec.optionalWayangJsonArray("import").spliterator(), false).map(Objects::toString).collect(Collectors.toList()) :
Collections.emptyList();
diff --git a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/costs/SimpleEstimationContext.java b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/costs/SimpleEstimationContext.java
index 5e3cac2..406c2ac 100644
--- a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/costs/SimpleEstimationContext.java
+++ b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/optimizer/costs/SimpleEstimationContext.java
@@ -25,7 +25,7 @@ import org.apache.wayang.core.util.JsonSerializer;
import java.util.Collection;
import java.util.List;
-import org.apache.wayang.core.util.json.JSONObject;
+import org.apache.wayang.core.util.json.WayangJsonObj;
/**
* This {@link EstimationContext} implementation just stores all required variables without any further logic.
@@ -85,17 +85,17 @@ public class SimpleEstimationContext implements EstimationContext {
new JsonSerializer<SimpleEstimationContext>() {
@Override
- public JSONObject serialize(SimpleEstimationContext ctx) {
+ public WayangJsonObj serialize(SimpleEstimationContext ctx) {
return EstimationContext.defaultSerializer.serialize(ctx);
}
@Override
- public SimpleEstimationContext deserialize(JSONObject json) {
+ public SimpleEstimationContext deserialize(WayangJsonObj json) {
return this.deserialize(json, SimpleEstimationContext.class);
}
@Override
- public SimpleEstimationContext deserialize(JSONObject json, Class<? extends SimpleEstimationContext> cls) {
+ public SimpleEstimationContext deserialize(WayangJsonObj json, Class<? extends SimpleEstimationContext> cls) {
final List<CardinalityEstimate> inCards = JsonSerializables.deserializeAllAsList(
json.getJSONArray("inCards"),
CardinalityEstimate.class
@@ -106,7 +106,7 @@ public class SimpleEstimationContext implements EstimationContext {
);
final HashMap<String, Double> doubleProperties = new HashMap<String, Double>();
- final JSONObject doublePropertiesJson = json.optJSONObject("properties");
+ final WayangJsonObj doublePropertiesJson = json.optionalWayangJsonObj("properties");
if (doublePropertiesJson != null) {
for (String key : doublePropertiesJson.keySet()) {
doubleProperties.put(key, doublePropertiesJson.getDouble(key));
diff --git a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/platform/AtomicExecution.java b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/platform/AtomicExecution.java
index d697d42..09f02a9 100644
--- a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/platform/AtomicExecution.java
+++ b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/platform/AtomicExecution.java
@@ -27,8 +27,8 @@ import org.apache.wayang.core.optimizer.costs.LoadProfileEstimator;
import org.apache.wayang.core.optimizer.costs.LoadProfileEstimators;
import org.apache.wayang.core.util.JsonSerializables;
import org.apache.wayang.core.util.JsonSerializer;
-import org.apache.wayang.core.util.json.JSONArray;
-import org.apache.wayang.core.util.json.JSONObject;
+import org.apache.wayang.core.util.json.WayangJsonArray;
+import org.apache.wayang.core.util.json.WayangJsonObj;
/**
* An atomic execution describes the smallest work unit considered by Wayang's cost model.
@@ -82,14 +82,14 @@ public class AtomicExecution {
}
@Override
- public JSONObject serialize(AtomicExecution atomicExecution) {
- JSONArray estimators = new JSONArray();
+ public WayangJsonObj serialize(AtomicExecution atomicExecution) {
+ WayangJsonArray estimators = new WayangJsonArray();
this.serialize(atomicExecution.loadProfileEstimator, estimators);
- return new JSONObject().put("estimators", JsonSerializables.serialize(estimators, false));
+ return new WayangJsonObj().put("estimators", JsonSerializables.serialize(estimators, false));
}
- private void serialize(LoadProfileEstimator estimator, JSONArray collector) {
- JSONObject json = new JSONObject();
+ private void serialize(LoadProfileEstimator estimator, WayangJsonArray collector) {
+ WayangJsonObj json = new WayangJsonObj();
if (estimator.getConfigurationKey() != null) {
json.put("key", estimator.getConfigurationKey());
} else {
@@ -103,18 +103,18 @@ public class AtomicExecution {
}
@Override
- public AtomicExecution deserialize(JSONObject json) {
+ public AtomicExecution deserialize(WayangJsonObj json) {
return this.deserialize(json, AtomicExecution.class);
}
@Override
- public AtomicExecution deserialize(JSONObject json, Class<? extends AtomicExecution> cls) {
- final JSONArray estimators = json.getJSONArray("estimators");
+ public AtomicExecution deserialize(WayangJsonObj json, Class<? extends AtomicExecution> cls) {
+ final WayangJsonArray estimators = json.getJSONArray("estimators");
if (estimators.length() < 1) {
throw new IllegalStateException("Expected at least one serialized estimator.");
}
// De-serialize the main estimator.
- final JSONObject mainEstimatorJson = estimators.getJSONObject(0);
+ final WayangJsonObj mainEstimatorJson = estimators.getJSONObject(0);
LoadProfileEstimator mainEstimator = this.deserializeEstimator(mainEstimatorJson);
// De-serialize nested estimators.
@@ -126,24 +126,25 @@ public class AtomicExecution {
}
/**
- * Deserialize a {@link LoadProfileEstimator} according to {@link #serialize(LoadProfileEstimator, JSONArray)}.
+ * Deserialize a {@link LoadProfileEstimator} according to {@link #serialize(LoadProfileEstimator, WayangJsonArray)}.
*
- * @param jsonObject that should be deserialized
+ * @param wayangJsonObj that should be deserialized
* @return the {@link LoadProfileEstimator}
*/
- private LoadProfileEstimator deserializeEstimator(JSONObject jsonObject) {
- if (jsonObject.has("key")) {
- final String key = jsonObject.getString("key");
+ private LoadProfileEstimator deserializeEstimator(WayangJsonObj wayangJsonObj) {
+ if (wayangJsonObj.has("key")) {
+ final String key = wayangJsonObj.getString("key");
final LoadProfileEstimator estimator = LoadProfileEstimators.createFromSpecification(key, this.configuration);
if (estimator == null) {
throw new SerializationException("Could not create estimator for key " + key);
}
return estimator;
- } else if (jsonObject.has("load")) {
- final LoadProfile load = JsonSerializables.deserialize(jsonObject.getJSONObject("load"), LoadProfile.class);
+ } else if (wayangJsonObj.has("load")) {
+ final LoadProfile load = JsonSerializables.deserialize(wayangJsonObj.getJSONObject("load"), LoadProfile.class);
return new ConstantLoadProfileEstimator(load);
}
- throw new SerializationException(String.format("Cannot deserialize load estimator from %s.", jsonObject));
+ throw new SerializationException(String.format("Cannot deserialize load estimator from %s.",
+ wayangJsonObj));
}
}
diff --git a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/platform/AtomicExecutionGroup.java b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/platform/AtomicExecutionGroup.java
index 1f8ba8a..58693cd 100644
--- a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/platform/AtomicExecutionGroup.java
+++ b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/platform/AtomicExecutionGroup.java
@@ -28,7 +28,7 @@ import org.apache.wayang.core.util.JsonSerializables;
import org.apache.wayang.core.util.JsonSerializer;
import java.util.Collection;
-import org.apache.wayang.core.util.json.JSONObject;
+import org.apache.wayang.core.util.json.WayangJsonObj;
/**
* This class groups {@link AtomicExecution}s with a common {@link EstimationContext} and {@link Platform}.
@@ -152,17 +152,17 @@ public class AtomicExecutionGroup {
@Override
- public JSONObject serialize(AtomicExecutionGroup aeg) {
+ public WayangJsonObj serialize(AtomicExecutionGroup aeg) {
AtomicExecution.KeyOrLoadSerializer atomicExecutionSerializer =
new AtomicExecution.KeyOrLoadSerializer(null, aeg.estimationContext);
- return new JSONObject()
+ return new WayangJsonObj()
.put("ctx", JsonSerializables.serialize(aeg.estimationContext, false, EstimationContext.defaultSerializer))
.put("platform", JsonSerializables.serialize(aeg.platform, true, Platform.jsonSerializer))
.put("executions", JsonSerializables.serializeAll(aeg.atomicExecutions, false, atomicExecutionSerializer));
}
@Override
- public AtomicExecutionGroup deserialize(JSONObject json, Class<? extends AtomicExecutionGroup> cls) {
+ public AtomicExecutionGroup deserialize(WayangJsonObj json, Class<? extends AtomicExecutionGroup> cls) {
return new AtomicExecutionGroup(
JsonSerializables.deserialize(
json.getJSONObject("ctx"),
diff --git a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/platform/PartialExecution.java b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/platform/PartialExecution.java
index ef3a8f1..75b5d03 100644
--- a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/platform/PartialExecution.java
+++ b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/platform/PartialExecution.java
@@ -33,7 +33,7 @@ import java.util.Collection;
import java.util.LinkedList;
import java.util.Set;
import java.util.stream.Collectors;
-import org.apache.wayang.core.util.json.JSONObject;
+import org.apache.wayang.core.util.json.WayangJsonObj;
/**
* Captures data of a execution of a set of {@link ExecutionOperator}s.
@@ -210,8 +210,8 @@ public class PartialExecution {
@Override
- public JSONObject serialize(PartialExecution pe) {
- return new JSONObject()
+ public WayangJsonObj serialize(PartialExecution pe) {
+ return new WayangJsonObj()
.put("millis", pe.measuredExecutionTime)
.put("lowerCost", pe.lowerCost)
.put("upperCost", pe.upperCost)
@@ -220,17 +220,17 @@ public class PartialExecution {
false,
new AtomicExecutionGroup.Serializer(this.configuration))
)
- .putOpt(
+ .putOptional(
"initPlatforms",
JsonSerializables.serializeAll(pe.initializedPlatforms, true, Platform.jsonSerializer)
);
}
@Override
- public PartialExecution deserialize(JSONObject json, Class<? extends PartialExecution> cls) {
+ public PartialExecution deserialize(WayangJsonObj json, Class<? extends PartialExecution> cls) {
final long measuredExecutionTime = json.getLong("millis");
- final double lowerCost = json.optDouble("lowerCost", -1);
- final double uppserCost = json.optDouble("upperCost", -1);
+ final double lowerCost = json.optionalDouble("lowerCost", -1);
+ final double uppserCost = json.optionalDouble("upperCost", -1);
final Collection<AtomicExecutionGroup> atomicExecutionGroups =
JsonSerializables.deserializeAllAsList(
json.getJSONArray("execGroups"),
@@ -238,7 +238,7 @@ public class PartialExecution {
AtomicExecutionGroup.class
);
final Collection<Platform> initializedPlatforms =
- JsonSerializables.deserializeAllAsList(json.optJSONArray("initPlatforms"), Platform.jsonSerializer);
+ JsonSerializables.deserializeAllAsList(json.optionalWayangJsonArray("initPlatforms"), Platform.jsonSerializer);
final PartialExecution partialExecution = new PartialExecution(
atomicExecutionGroups, measuredExecutionTime, lowerCost, uppserCost
);
diff --git a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/platform/Platform.java b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/platform/Platform.java
index a8c2a30..7a4e113 100644
--- a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/platform/Platform.java
+++ b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/platform/Platform.java
@@ -30,7 +30,7 @@ import org.apache.wayang.core.plan.wayangplan.ExecutionOperator;
import org.apache.wayang.core.util.JsonSerializables;
import org.apache.wayang.core.util.JsonSerializer;
import org.apache.wayang.core.util.ReflectionUtils;
-import org.apache.wayang.core.util.json.JSONObject;
+import org.apache.wayang.core.util.json.WayangJsonObj;
/**
* A platform describes an execution engine that executes {@link ExecutionOperator}s.
@@ -155,13 +155,13 @@ public abstract class Platform {
public static final JsonSerializer<Platform> jsonSerializer = new JsonSerializer<Platform>() {
@Override
- public JSONObject serialize(Platform platform) {
+ public WayangJsonObj serialize(Platform platform) {
// Enforce polymorph serialization.
- return JsonSerializables.addClassTag(platform, new JSONObject());
+ return JsonSerializables.addClassTag(platform, new WayangJsonObj());
}
@Override
- public Platform deserialize(JSONObject json, Class<? extends Platform> cls) {
+ public Platform deserialize(WayangJsonObj json, Class<? extends Platform> cls) {
return ReflectionUtils.evaluate(cls.getCanonicalName() + ".getInstance()");
}
};
diff --git a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/profiling/CardinalityRepository.java b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/profiling/CardinalityRepository.java
index 3418ba0..e650c5c 100644
--- a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/profiling/CardinalityRepository.java
+++ b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/profiling/CardinalityRepository.java
@@ -39,8 +39,8 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
-import org.apache.wayang.core.util.json.JSONArray;
-import org.apache.wayang.core.util.json.JSONObject;
+import org.apache.wayang.core.util.json.WayangJsonArray;
+import org.apache.wayang.core.util.json.WayangJsonObj;
/**
* Stores cardinalities that have been collected by the {@link CrossPlatformExecutor}. Current version uses
@@ -122,13 +122,13 @@ public class CardinalityRepository {
OutputSlot<?> output,
long outputCardinality) {
- JSONArray jsonInputCardinalities = new JSONArray();
+ WayangJsonArray jsonInputCardinalities = new WayangJsonArray();
final Operator operator = operatorContext.getOperator();
for (int inputIndex = 0; inputIndex < operator.getNumInputs(); inputIndex++) {
final InputSlot<?> input = operator.getInput(inputIndex);
final CardinalityEstimate inputEstimate = operatorContext.getInputCardinality(inputIndex);
- JSONObject jsonInputCardinality = new JSONObject();
+ WayangJsonObj jsonInputCardinality = new WayangJsonObj();
jsonInputCardinality.put("name", input.getName());
jsonInputCardinality.put("index", input.getIndex());
jsonInputCardinality.put("isBroadcast", input.isBroadcast());
@@ -138,16 +138,16 @@ public class CardinalityRepository {
jsonInputCardinalities.put(jsonInputCardinality);
}
- JSONObject jsonOperator = new JSONObject();
+ WayangJsonObj jsonOperator = new WayangJsonObj();
jsonOperator.put("class", operator.getClass().getCanonicalName());
// TODO: UDFs? How can we reference them?
- JSONObject jsonOutput = new JSONObject();
+ WayangJsonObj jsonOutput = new WayangJsonObj();
jsonOutput.put("name", output.getName());
jsonOutput.put("index", output.getIndex());
jsonOutput.put("cardinality", outputCardinality);
- JSONObject jsonMeasurement = new JSONObject();
+ WayangJsonObj jsonMeasurement = new WayangJsonObj();
jsonMeasurement.put("inputs", jsonInputCardinalities);
jsonMeasurement.put("operator", jsonOperator);
jsonMeasurement.put("output", jsonOutput);
@@ -158,7 +158,7 @@ public class CardinalityRepository {
/**
* Writes the measuremnt to the {@link #repositoryPath}.
*/
- private void write(JSONObject jsonMeasurement) {
+ private void write(WayangJsonObj jsonMeasurement) {
try {
jsonMeasurement.write(this.getWriter());
writer.write('\n');
diff --git a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/profiling/ExecutionLog.java b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/profiling/ExecutionLog.java
index ce1a3d8..3ca139b 100644
--- a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/profiling/ExecutionLog.java
+++ b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/profiling/ExecutionLog.java
@@ -39,7 +39,7 @@ import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Stream;
-import org.apache.wayang.core.util.json.JSONObject;
+import org.apache.wayang.core.util.json.WayangJsonObj;
/**
* Stores execution data have been collected by the {@link CrossPlatformExecutor}.
@@ -127,7 +127,7 @@ public class ExecutionLog implements AutoCloseable {
/**
* Writes the measuremnt to the {@link #repositoryPath}.
*/
- private void write(JSONObject jsonMeasurement) throws IOException {
+ private void write(WayangJsonObj jsonMeasurement) throws IOException {
jsonMeasurement.write(this.getWriter());
writer.write('\n');
}
@@ -145,7 +145,7 @@ public class ExecutionLog implements AutoCloseable {
return Files.lines(Paths.get(this.repositoryPath), Charset.forName("UTF-8"))
.map(line -> {
try {
- return JsonSerializables.deserialize(new JSONObject(line), serializer, PartialExecution.class);
+ return JsonSerializables.deserialize(new WayangJsonObj(line), serializer, PartialExecution.class);
} catch (Exception e) {
throw new WayangException(String.format("Could not parse \"%s\".", line), e);
}
diff --git a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/JsonSerializable.java b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/JsonSerializable.java
index dba692e..d1bd5da 100644
--- a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/JsonSerializable.java
+++ b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/JsonSerializable.java
@@ -22,10 +22,10 @@ import org.apache.wayang.core.api.exception.WayangException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import org.apache.wayang.core.util.json.JSONObject;
+import org.apache.wayang.core.util.json.WayangJsonObj;
/**
- * This interface prescribes implementing instances to be able to provide itself as a {@link JSONObject}. To allow
+ * This interface prescribes implementing instances to be able to provide itself as a {@link WayangJsonObj}. To allow
* for deserialization, implementing class should furthermore provide a static {@code fromJson(JSONObject)} method.
* <i>Note that it is recommended to use the {@link JsonSerializables} utility to class to handle serialization.</i>
*
@@ -34,11 +34,11 @@ import org.apache.wayang.core.util.json.JSONObject;
public interface JsonSerializable {
/**
- * Convert this instance to a {@link JSONObject}.
+ * Convert this instance to a {@link WayangJsonObj}.
*
- * @return the {@link JSONObject}
+ * @return the {@link WayangJsonObj}
*/
- JSONObject toJson();
+ WayangJsonObj toJson();
/**
* A {@link JsonSerializer} implementation to serialize {@link JsonSerializable}s.
@@ -59,17 +59,17 @@ public interface JsonSerializable {
class Serializer<T extends JsonSerializable> implements JsonSerializer<T> {
@Override
- public JSONObject serialize(T serializable) {
+ public WayangJsonObj serialize(T serializable) {
if (serializable == null) return null;
return serializable.toJson();
}
@Override
@SuppressWarnings("unchecked")
- public T deserialize(JSONObject json, Class<? extends T> cls) {
- if (json == null || json.equals(JSONObject.NULL)) return null;
+ public T deserialize(WayangJsonObj json, Class<? extends T> cls) {
+ if (json == null || json.equals(WayangJsonObj.NULL)) return null;
try {
- final Method fromJsonMethod = cls.getMethod("fromJson", JSONObject.class);
+ final Method fromJsonMethod = cls.getMethod("fromJson", WayangJsonObj.class);
return (T) fromJsonMethod.invoke(null, json);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new WayangException(String.format("Could not execute %s.fromJson(...).", cls.getCanonicalName()), e);
diff --git a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/JsonSerializables.java b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/JsonSerializables.java
index b164eac..eeb5238 100644
--- a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/JsonSerializables.java
+++ b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/JsonSerializables.java
@@ -24,8 +24,8 @@ import org.apache.commons.lang3.SerializationException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import org.apache.wayang.core.util.json.JSONArray;
-import org.apache.wayang.core.util.json.JSONObject;
+import org.apache.wayang.core.util.json.WayangJsonArray;
+import org.apache.wayang.core.util.json.WayangJsonObj;
/**
* Utility to deal with {@link JsonSerializable}s.
@@ -36,7 +36,7 @@ public class JsonSerializables {
* Try to serialize the given {@link Object}. It must be JSON-compatible or a {@link JsonSerializable}.
*
* @param obj the {@link Object} to serialize
- * @param isPolymorph in case a {@link JSONObject} is created, whether it should be tagged with the {@link Class}
+ * @param isPolymorph in case a {@link WayangJsonObj} is created, whether it should be tagged with the {@link Class}
* of {@code obj}
* @return the serialization result
* @see #isJsonCompatible(Object)
@@ -54,11 +54,11 @@ public class JsonSerializables {
* Serialize the given {@link JsonSerializable}.
*
* @param serializable the {@link JsonSerializable} to serialize
- * @param isPolymorph in case a {@link JSONObject} is created, whether it should be tagged with the {@link Class}
+ * @param isPolymorph in case a {@link WayangJsonObj} is created, whether it should be tagged with the {@link Class}
* of {@code serializable}
* @return the serialization result
*/
- public static JSONObject serialize(JsonSerializable serializable, boolean isPolymorph) {
+ public static WayangJsonObj serialize(JsonSerializable serializable, boolean isPolymorph) {
return serialize(serializable, isPolymorph, JsonSerializable.uncheckedSerializer);
}
@@ -66,12 +66,12 @@ public class JsonSerializables {
* Serialize the given {@link Object} using a specific {@link JsonSerializer}.
*
* @param obj the {@link Object} to serialize
- * @param isPolymorph in case a {@link JSONObject} is created, whether it should be tagged with the {@link Class}
+ * @param isPolymorph in case a {@link WayangJsonObj} is created, whether it should be tagged with the {@link Class}
* of {@code serializable}
* @param serializer the {@link JsonSerializer}
* @return the serialization result
*/
- public static <T> JSONObject serialize(T obj, boolean isPolymorph, JsonSerializer<T> serializer) {
+ public static <T> WayangJsonObj serialize(T obj, boolean isPolymorph, JsonSerializer<T> serializer) {
return addClassTag(obj, serializer.serialize(obj), isPolymorph);
}
@@ -79,36 +79,36 @@ public class JsonSerializables {
* Try to serialize the given {@link Object}s. They must be JSON-compatible or a {@link JsonSerializable}s.
*
* @param collection the {@link Object}s to serialize
- * @param isPolymorph in case a {@link JSONObject} is created, whether it should be tagged with the {@link Class}
+ * @param isPolymorph in case a {@link WayangJsonObj} is created, whether it should be tagged with the {@link Class}
* of the according {@link Object}
* @return the serialization result
* @see #isJsonCompatible(Object)
*/
- public static JSONArray serializeAll(Collection<?> collection, boolean isPolymorph) {
+ public static WayangJsonArray serializeAll(Collection<?> collection, boolean isPolymorph) {
if (isJsonNull(collection)) return null;
- JSONArray jsonArray = new JSONArray();
+ WayangJsonArray wayangJsonArray = new WayangJsonArray();
for (Object obj : collection) {
- jsonArray.put(serialize(obj, isPolymorph));
+ wayangJsonArray.put(serialize(obj, isPolymorph));
}
- return jsonArray;
+ return wayangJsonArray;
}
/**
* Serialize the given {@link Object}s using a specific {@link JsonSerializer}.
*
* @param collection the {@link Object}s to serialize
- * @param isPolymorph in case a {@link JSONObject} is created, whether it should be tagged with the {@link Class}
+ * @param isPolymorph in case a {@link WayangJsonObj} is created, whether it should be tagged with the {@link Class}
* of {@code serializable}
* @param serializer the {@link JsonSerializer}
* @return the serialization result
*/
- public static <T> JSONArray serializeAll(Collection<T> collection, boolean isPolymorph, JsonSerializer<T> serializer) {
+ public static <T> WayangJsonArray serializeAll(Collection<T> collection, boolean isPolymorph, JsonSerializer<T> serializer) {
if (collection == null) return null;
- JSONArray jsonArray = new JSONArray();
+ WayangJsonArray wayangJsonArray = new WayangJsonArray();
for (T serializable : collection) {
- jsonArray.put(serialize(serializable, isPolymorph, serializer));
+ wayangJsonArray.put(serialize(serializable, isPolymorph, serializer));
}
- return jsonArray;
+ return wayangJsonArray;
}
/**
@@ -116,8 +116,8 @@ public class JsonSerializables {
* <ul>
* <li>{@code json} is a (JSON) {@code null} value;</li>
* <li>{@code json} is a basic (JSON) datatype;</li>
- * <li>{@code json} is a {@link Class}-tagged {@link JSONObject} that corresponds to a {@link JsonSerializable};</li>
- * <li>{@code json} is a {@link JSONArray} with {@link Class}-tagged {@link JSONObject}s that correspond to a
+ * <li>{@code json} is a {@link Class}-tagged {@link WayangJsonObj} that corresponds to a {@link JsonSerializable};</li>
+ * <li>{@code json} is a {@link WayangJsonArray} with {@link Class}-tagged {@link WayangJsonObj}s that correspond to a
* {@link JsonSerializable}s - in this case, the result type is a {@link List}.</li>
* </ul>
*
@@ -127,158 +127,158 @@ public class JsonSerializables {
public static Object deserialize(Object json) {
if (isJsonNull(json)) return null;
else if (isUnconvertedInstance(json)) return json;
- else if (json instanceof JSONObject) return deserialize((JSONObject) json);
- else if (json instanceof JSONArray) return deserializeAllAsList((JSONArray) json);
+ else if (json instanceof WayangJsonObj) return deserialize((WayangJsonObj) json);
+ else if (json instanceof WayangJsonArray) return deserializeAllAsList((WayangJsonArray) json);
throw new SerializationException(String.format("Don't know how to deserialize %s.", json));
}
/**
- * Deserialize a {@link Class}-tagged {@link JSONObject} that should correspond to a {@link JsonSerializable}.
+ * Deserialize a {@link Class}-tagged {@link WayangJsonObj} that should correspond to a {@link JsonSerializable}.
*
- * @param jsonObject the {@link JSONObject}
+ * @param wayangJsonObj the {@link WayangJsonObj}
* @return the deserialization product
*/
@SuppressWarnings("unchecked")
- public static <T> T deserialize(JSONObject jsonObject) {
- if (isJsonNull(jsonObject)) return null;
- return deserialize(jsonObject, JsonSerializable.uncheckedSerializer());
+ public static <T> T deserialize(WayangJsonObj wayangJsonObj) {
+ if (isJsonNull(wayangJsonObj)) return null;
+ return deserialize(wayangJsonObj, JsonSerializable.uncheckedSerializer());
}
/**
- * Deserialize a {@link JSONObject} that should correspond to a {@link JsonSerializable}.
+ * Deserialize a {@link WayangJsonObj} that should correspond to a {@link JsonSerializable}.
*
- * @param jsonObject the {@link JSONObject}
+ * @param wayangJsonObj the {@link WayangJsonObj}
* @param cls the {@link Class} of the deserialization product
* @return the deserialization product
*/
@SuppressWarnings("unchecked")
- public static <T> T deserialize(JSONObject jsonObject, Class<? extends T> cls) {
- if (isJsonNull(jsonObject)) return null;
- return deserialize(jsonObject, (JsonSerializer<T>) JsonSerializable.uncheckedSerializer(), cls);
+ public static <T> T deserialize(WayangJsonObj wayangJsonObj, Class<? extends T> cls) {
+ if (isJsonNull(wayangJsonObj)) return null;
+ return deserialize(wayangJsonObj, (JsonSerializer<T>) JsonSerializable.uncheckedSerializer(), cls);
}
/**
- * Deserialize a ({@link Class}-tagged) {@link JSONObject} with a {@link JsonSerializer}.
+ * Deserialize a ({@link Class}-tagged) {@link WayangJsonObj} with a {@link JsonSerializer}.
*
- * @param jsonObject the {@link JSONObject}
+ * @param wayangJsonObj the {@link WayangJsonObj}
* @param serializer the {@link JsonSerializer}
* @return the deserialization product
*/
- public static <T> T deserialize(JSONObject jsonObject, JsonSerializer<T> serializer) {
- if (isJsonNull(jsonObject)) return null;
- return serializer.deserialize(jsonObject);
+ public static <T> T deserialize(WayangJsonObj wayangJsonObj, JsonSerializer<T> serializer) {
+ if (isJsonNull(wayangJsonObj)) return null;
+ return serializer.deserialize(wayangJsonObj);
}
/**
- * Deserialize a {@link JSONObject} with a {@link JsonSerializer}.
+ * Deserialize a {@link WayangJsonObj} with a {@link JsonSerializer}.
*
- * @param jsonObject the {@link JSONObject}
+ * @param wayangJsonObj the {@link WayangJsonObj}
* @param serializer the {@link JsonSerializer}
* @param cls the {@link Class} of the deserialization product
* @return the deserialization product
*/
- public static <T> T deserialize(JSONObject jsonObject, JsonSerializer<T> serializer, Class<? extends T> cls) {
- if (jsonObject == null || jsonObject.equals(JSONObject.NULL)) return null;
- return serializer.deserialize(jsonObject, cls);
+ public static <T> T deserialize(WayangJsonObj wayangJsonObj, JsonSerializer<T> serializer, Class<? extends T> cls) {
+ if (wayangJsonObj == null || wayangJsonObj.equals(WayangJsonObj.NULL)) return null;
+ return serializer.deserialize(wayangJsonObj, cls);
}
/**
- * Deserialize a {@link JSONArray} according to the rules of {@link #deserialize(Object)}.
+ * Deserialize a {@link WayangJsonArray} according to the rules of {@link #deserialize(Object)}.
*
- * @param jsonArray the {@link JSONArray}
+ * @param wayangJsonArray the {@link WayangJsonArray}
* @return the deserialization product
*/
@SuppressWarnings("unchecked")
- public static <T> List<T> deserializeAllAsList(JSONArray jsonArray) {
- if (isJsonNull(jsonArray)) return null;
- List<T> result = new ArrayList<>(jsonArray.length());
- for (Object jsonElement : jsonArray) {
+ public static <T> List<T> deserializeAllAsList(WayangJsonArray wayangJsonArray) {
+ if (isJsonNull(wayangJsonArray)) return null;
+ List<T> result = new ArrayList<>(wayangJsonArray.length());
+ for (Object jsonElement : wayangJsonArray) {
result.add((T) deserialize(jsonElement));
}
return result;
}
/**
- * Deserialize a {@link JSONArray} according to the rules of {@link #deserialize(JSONObject, Class)}.
+ * Deserialize a {@link WayangJsonArray} according to the rules of {@link #deserialize(WayangJsonObj, Class)}.
*
- * @param jsonArray the {@link JSONArray}
+ * @param wayangJsonArray the {@link WayangJsonArray}
* @param cls the {@link Class} of the elements in the {@code jsonArray}
* @return the deserialization product
*/
@SuppressWarnings("unchecked")
- public static <T> List<T> deserializeAllAsList(JSONArray jsonArray, Class<T> cls) {
- return deserializeAllAsList(jsonArray, (JsonSerializer<T>) JsonSerializable.uncheckedSerializer(), cls);
+ public static <T> List<T> deserializeAllAsList(WayangJsonArray wayangJsonArray, Class<T> cls) {
+ return deserializeAllAsList(wayangJsonArray, (JsonSerializer<T>) JsonSerializable.uncheckedSerializer(), cls);
}
/**
- * Deserialize a {@link JSONArray} according to the rules of {@link #deserialize(JSONObject, JsonSerializer)}.
+ * Deserialize a {@link WayangJsonArray} according to the rules of {@link #deserialize(WayangJsonObj, JsonSerializer)}.
*
- * @param jsonArray the {@link JSONArray}
+ * @param wayangJsonArray the {@link WayangJsonArray}
* @param serializer the {@link JsonSerializer}
* @return the deserialization product
*/
@SuppressWarnings("unchecked")
- public static <T> List<T> deserializeAllAsList(JSONArray jsonArray, JsonSerializer<T> serializer) {
- List<T> result = new ArrayList<>(jsonArray.length());
- for (Object jsonElement : jsonArray) {
- result.add(isJsonNull(jsonElement) ? null : deserialize((JSONObject) jsonElement, serializer));
+ public static <T> List<T> deserializeAllAsList(WayangJsonArray wayangJsonArray, JsonSerializer<T> serializer) {
+ List<T> result = new ArrayList<>(wayangJsonArray.length());
+ for (Object jsonElement : wayangJsonArray) {
+ result.add(isJsonNull(jsonElement) ? null : deserialize((WayangJsonObj) jsonElement, serializer));
}
return result;
}
/**
- * Deserialize a {@link JSONArray} according to the rules of {@link #deserialize(JSONObject, JsonSerializer, Class)}.
+ * Deserialize a {@link WayangJsonArray} according to the rules of {@link #deserialize(WayangJsonObj, JsonSerializer, Class)}.
*
- * @param jsonArray the {@link JSONArray}
+ * @param wayangJsonArray the {@link WayangJsonArray}
* @param serializer the {@link JsonSerializer}
* @param cls the {@link Class} of the elements in the {@code jsonArray}
* @return the deserialization product
*/
@SuppressWarnings("unchecked")
- public static <T> List<T> deserializeAllAsList(JSONArray jsonArray, JsonSerializer<T> serializer, Class<T> cls) {
- List<T> result = new ArrayList<>(jsonArray.length());
- for (Object jsonElement : jsonArray) {
- result.add(isJsonNull(jsonElement) ? null : deserialize((JSONObject) jsonElement, serializer, cls));
+ public static <T> List<T> deserializeAllAsList(WayangJsonArray wayangJsonArray, JsonSerializer<T> serializer, Class<T> cls) {
+ List<T> result = new ArrayList<>(wayangJsonArray.length());
+ for (Object jsonElement : wayangJsonArray) {
+ result.add(isJsonNull(jsonElement) ? null : deserialize((WayangJsonObj) jsonElement, serializer, cls));
}
return result;
}
/**
- * Tag the {@link JSONObject} with the {@link Class} of the other {@link Object}.
+ * Tag the {@link WayangJsonObj} with the {@link Class} of the other {@link Object}.
*
* @param obj whose {@link Class} should be tagged
- * @param jsonObject that should be tagged
+ * @param wayangJsonObj that should be tagged
* @return the {@code jsonObject}
*/
- public static JSONObject addClassTag(Object obj, JSONObject jsonObject) {
- if (isJsonNull(jsonObject)) return jsonObject;
- return jsonObject.put("_class", obj.getClass().getCanonicalName());
+ public static WayangJsonObj addClassTag(Object obj, WayangJsonObj wayangJsonObj) {
+ if (isJsonNull(wayangJsonObj)) return wayangJsonObj;
+ return wayangJsonObj.put("_class", obj.getClass().getCanonicalName());
}
/**
- * Optionally tag the {@link JSONObject} with the {@link Class} of the other {@link Object}.
+ * Optionally tag the {@link WayangJsonObj} with the {@link Class} of the other {@link Object}.
*
* @param obj whose {@link Class} should be tagged
- * @param jsonObject that should be tagged
+ * @param wayangJsonObj that should be tagged
* @param isAddClassTag if this is {@code false}, no action will be performed
* @return the {@code jsonObject}
*/
- public static JSONObject addClassTag(Object obj, JSONObject jsonObject, boolean isAddClassTag) {
- return isAddClassTag ? addClassTag(obj, jsonObject) : jsonObject;
+ public static WayangJsonObj addClassTag(Object obj, WayangJsonObj wayangJsonObj, boolean isAddClassTag) {
+ return isAddClassTag ? addClassTag(obj, wayangJsonObj) : wayangJsonObj;
}
/**
- * Read and load the specified {@link Class} in a {@link JSONObject}.
+ * Read and load the specified {@link Class} in a {@link WayangJsonObj}.
*
- * @param jsonObject that contains the {@link Class} tag
+ * @param wayangJsonObj that contains the {@link Class} tag
* @return the loaded {@link Class} or {@code null} if none exists
* @throws ClassNotFoundException if the {@link Class} could not be loaded
*/
- public static Class<?> getClassTag(JSONObject jsonObject) throws ClassNotFoundException {
- if (isJsonNull(jsonObject) || !jsonObject.has("_class")) return null;
- final String className = jsonObject.getString("_class");
+ public static Class<?> getClassTag(WayangJsonObj wayangJsonObj) throws ClassNotFoundException {
+ if (isJsonNull(wayangJsonObj) || !wayangJsonObj.has("_class")) return null;
+ final String className = wayangJsonObj.getString("_class");
return Class.forName(className);
}
@@ -289,7 +289,7 @@ public class JsonSerializables {
* @return whether {@code obj} is a (JSON) {@code null} value
*/
public static boolean isJsonNull(Object obj) {
- return obj == null || JSONObject.NULL.equals(obj);
+ return obj == null || WayangJsonObj.NULL.equals(obj);
}
/**
@@ -299,7 +299,8 @@ public class JsonSerializables {
* @return whether {@code obj} is a JSON datatype
*/
public static boolean isJsonCompatible(Object obj) {
- return isUnconvertedInstance(obj) || obj == JSONObject.NULL || obj instanceof JSONObject || obj instanceof JSONArray;
+ return isUnconvertedInstance(obj) || obj == WayangJsonObj.NULL || obj instanceof WayangJsonObj
+ || obj instanceof WayangJsonArray;
}
/**
diff --git a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/JsonSerializer.java b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/JsonSerializer.java
index f2ae7fa..c02288a 100644
--- a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/JsonSerializer.java
+++ b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/JsonSerializer.java
@@ -19,7 +19,7 @@
package org.apache.wayang.core.util;
import org.apache.commons.lang3.SerializationException;
-import org.apache.wayang.core.util.json.JSONObject;
+import org.apache.wayang.core.util.json.WayangJsonObj;
/**
@@ -33,7 +33,7 @@ public interface JsonSerializer<T> {
* @param object that should be serialized
* @return the serialized object
*/
- JSONObject serialize(T object);
+ WayangJsonObj serialize(T object);
/**
* Deserializes an object.
@@ -42,7 +42,7 @@ public interface JsonSerializer<T> {
* @return the deserialized object
*/
@SuppressWarnings("unchecked")
- default T deserialize(JSONObject json) {
+ default T deserialize(WayangJsonObj json) {
if (JsonSerializables.isJsonNull(json)) return null;
try {
final Class<?> classTag = JsonSerializables.getClassTag(json);
@@ -63,6 +63,6 @@ public interface JsonSerializer<T> {
* @return the deserialized object
*/
- T deserialize(JSONObject json, Class<? extends T> cls);
+ T deserialize(WayangJsonObj json, Class<? extends T> cls);
}
diff --git a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/json/JSONArray.java b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/json/WayangJsonArray.java
similarity index 81%
rename from wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/json/JSONArray.java
rename to wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/json/WayangJsonArray.java
index 35155a4..556df68 100644
--- a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/json/JSONArray.java
+++ b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/json/WayangJsonArray.java
@@ -36,25 +36,22 @@ import org.apache.wayang.core.api.exception.WayangException;
/**
* JSONArray is the wrapper for the {@link ArrayNode} to enable the
- * similar functionality as the http://javadox.com/org.json/json/20151123/org/json/JSONArray.html
- *
- * TODO: require implement the rest of the functionalities follow the link below
- * https://github.com/stleary/JSON-java/blob/master/src/main/java/org/json/JSONArray.java
+ * easy access to Json data
*
* TODO: the java doc is not done because is missing implementation and it performed some
* modification on the code
*/
-public class JSONArray implements Iterable<Object>{
+public class WayangJsonArray implements Iterable<Object>{
private ArrayNode node;
- public JSONArray(){
+ public WayangJsonArray(){
ObjectMapper mapper = new ObjectMapper();
// create a JSON object
this.node = mapper.createArrayNode();
}
- JSONArray(ArrayNode node){
+ WayangJsonArray(ArrayNode node){
this.node = node;
}
@@ -66,11 +63,11 @@ public class JSONArray implements Iterable<Object>{
return this.node.size();
}
- public JSONObject getJSONObject(int index){
- return new JSONObject((ObjectNode) this.node.get(index));
+ public WayangJsonObj getJSONObject(int index){
+ return new WayangJsonObj((ObjectNode) this.node.get(index));
}
- public void put(JSONObject value){
+ public void put(WayangJsonObj value){
this.node.add(value.getNode());
}
@@ -81,7 +78,7 @@ public class JSONArray implements Iterable<Object>{
Consumer<Object> insertType(Object value){
ArrayNode node = this.getNode();
if(value == null){
- return (v) -> node.add(JSONObject.NULL);
+ return (v) -> node.add(WayangJsonObj.NULL);
}else if(value instanceof Integer){
return (v) -> node.add((Integer) v);
}else if(value instanceof Long){
@@ -94,10 +91,10 @@ public class JSONArray implements Iterable<Object>{
return (v) -> node.add((Double) v);
}else if(value instanceof JsonNode){
return (v) -> node.add((JsonNode) v);
- }else if(value instanceof JSONArray){
- return (v) -> node.add(((JSONArray)v).getNode());
- }else if(value instanceof JSONObject){
- return (v) -> node.add(((JSONObject)v).getNode());
+ }else if(value instanceof WayangJsonArray){
+ return (v) -> node.add(((WayangJsonArray)v).getNode());
+ }else if(value instanceof WayangJsonObj){
+ return (v) -> node.add(((WayangJsonObj)v).getNode());
}
throw new WayangException("The type is not recognizable "+ value.getClass());
}
@@ -114,9 +111,9 @@ public class JSONArray implements Iterable<Object>{
false)
.map(v -> {
if(v instanceof ArrayNode){
- return new JSONArray((ArrayNode) v);
+ return new WayangJsonArray((ArrayNode) v);
}else if(v instanceof ObjectNode) {
- return new JSONObject((ObjectNode) v);
+ return new WayangJsonObj((ObjectNode) v);
}else if(v instanceof NullNode) {
return null;
} else if(v instanceof TextNode){
diff --git a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/json/JSONObject.java b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/json/WayangJsonObj.java
similarity index 80%
rename from wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/json/JSONObject.java
rename to wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/json/WayangJsonObj.java
index ebb4c2f..5fe26a2 100644
--- a/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/json/JSONObject.java
+++ b/wayang-commons/wayang-core/src/main/java/org/apache/wayang/core/util/json/WayangJsonObj.java
@@ -35,26 +35,23 @@ import org.apache.wayang.core.api.exception.WayangException;
/**
* JSONObject is the wrapper for the {@link ObjectNode} to enable the
- * similar functionality as the http://javadox.com/org.json/json/20151123/org/json/JSONObject.html
- *
- * TODO: require implement the rest of the functionalities follow the link below
- * https://github.com/stleary/JSON-java/blob/master/src/main/java/org/json/JSONObject.java
+ * easy access to the json data
*
* TODO: the java doc is not done because is missing implementation and it performed some
* modification on the code
*/
-public class JSONObject {
+public class WayangJsonObj {
public static final NullNode NULL = NullNode.getInstance();
private ObjectNode node;
- public JSONObject(){
+ public WayangJsonObj(){
ObjectMapper mapper = new ObjectMapper();
// create a JSON object
this.node = mapper.createObjectNode();
}
- public JSONObject(String content){
+ public WayangJsonObj(String content){
ObjectMapper mapper = new ObjectMapper();
// create a JSON object
try {
@@ -64,7 +61,7 @@ public class JSONObject {
}
}
- public JSONObject(Map<String, Object> map){
+ public WayangJsonObj(Map<String, Object> map){
ObjectMapper mapper = new ObjectMapper();
this.node = mapper.createObjectNode();
// create a JSON object
@@ -78,7 +75,7 @@ public class JSONObject {
}
- JSONObject(ObjectNode node){
+ WayangJsonObj(ObjectNode node){
this.node = node;
}
@@ -110,7 +107,7 @@ public class JSONObject {
return this.node.get(key).asInt();
}
- public JSONObject getJSONObject(String key){
+ public WayangJsonObj getJSONObject(String key){
JsonNode value = this.getNode().get(key);
if(value == null){
return null;
@@ -118,10 +115,10 @@ public class JSONObject {
if(!value.isObject()) {
throw new WayangException("the key does not exist on the component");
}
- return new JSONObject((ObjectNode) value);
+ return new WayangJsonObj((ObjectNode) value);
}
- public JSONArray getJSONArray(String key){
+ public WayangJsonArray getJSONArray(String key){
JsonNode value = this.getNode().get(key);
if(value == null){
return null;
@@ -129,29 +126,29 @@ public class JSONObject {
if(!value.isArray()) {
throw new WayangException("the key does not exist on the component");
}
- return new JSONArray((ArrayNode) value);
+ return new WayangJsonArray((ArrayNode) value);
}
- public JSONObject put(String key, String value){
+ public WayangJsonObj put(String key, String value){
this.getNode().put(key, value);
return this;
}
- public JSONObject put(String key, int value){
+ public WayangJsonObj put(String key, int value){
this.getNode().put(key, value);
return this;
}
- public JSONObject put(String key, double value){
+ public WayangJsonObj put(String key, double value){
this.getNode().put(key, value);
return this;
}
- public JSONObject put(String key, long value){
+ public WayangJsonObj put(String key, long value){
this.getNode().put(key, value);
return this;
}
- public JSONObject put(String key, Object value){
+ public WayangJsonObj put(String key, Object value){
this.insertType(value).accept(key, value);
return this;
}
@@ -160,7 +157,7 @@ public class JSONObject {
writter.write(this.getNode().toString());
}
- public JSONObject put(String key, JSONObject value){
+ public WayangJsonObj put(String key, WayangJsonObj value){
if(this.getNode().has(key)){
this.getNode().replace(key, (value == null)? NULL:value.getNode());
}else {
@@ -169,7 +166,7 @@ public class JSONObject {
return this;
}
- public JSONObject put(String key, JSONArray value){
+ public WayangJsonObj put(String key, WayangJsonArray value){
if(this.getNode().has(key)){
this.getNode().replace(key, value.getNode());
}else {
@@ -178,7 +175,7 @@ public class JSONObject {
return this;
}
- public JSONObject putOpt(String key, Object value){
+ public WayangJsonObj putOptional(String key, Object value){
if(value == null){
return this;
}
@@ -186,7 +183,7 @@ public class JSONObject {
return this;
}
- public JSONObject optJSONObject(String key){
+ public WayangJsonObj optionalWayangJsonObj(String key){
try {
return this.getJSONObject(key);
}catch (WayangException ex){
@@ -194,7 +191,7 @@ public class JSONObject {
}
}
- public JSONArray optJSONArray(String key){
+ public WayangJsonArray optionalWayangJsonArray(String key){
try {
return this.getJSONArray(key);
}catch (WayangException ex){
@@ -202,11 +199,11 @@ public class JSONObject {
}
}
- public double optDouble(String key){
- return this.optDouble(key, Double.NaN);
+ public double optionalDouble(String key){
+ return this.optionalDouble(key, Double.NaN);
}
- public double optDouble(String key, double value){
+ public double optionalDouble(String key, double value){
try {
return this.getDouble(key);
}catch (WayangException ex){
@@ -258,20 +255,20 @@ public class JSONObject {
node.set(k, (ArrayNode)v);
}
};
- }else if(value instanceof JSONArray){
+ }else if(value instanceof WayangJsonArray){
return (k, v) -> {
if(node.has(k)){
- node.replace(k, ((JSONArray)v).getNode());
+ node.replace(k, ((WayangJsonArray)v).getNode());
}else{
- node.set(k, ((JSONArray)v).getNode());
+ node.set(k, ((WayangJsonArray)v).getNode());
}
};
- }else if(value instanceof JSONObject){
+ }else if(value instanceof WayangJsonObj){
return (k, v) -> {
if(node.has(k)){
- node.replace(k, ((JSONObject)v).getNode());
+ node.replace(k, ((WayangJsonObj)v).getNode());
}else{
- node.set(k, ((JSONObject)v).getNode());
+ node.set(k, ((WayangJsonObj)v).getNode());
}
};
}
diff --git a/wayang-commons/wayang-core/src/test/java/org/apache/wayang/core/platform/PartialExecutionTest.java b/wayang-commons/wayang-core/src/test/java/org/apache/wayang/core/platform/PartialExecutionTest.java
index f39d331..bf28c94 100644
--- a/wayang-commons/wayang-core/src/test/java/org/apache/wayang/core/platform/PartialExecutionTest.java
+++ b/wayang-commons/wayang-core/src/test/java/org/apache/wayang/core/platform/PartialExecutionTest.java
@@ -18,7 +18,7 @@
package org.apache.wayang.core.platform;
-import org.apache.wayang.core.util.json.JSONObject;
+import org.apache.wayang.core.util.json.WayangJsonObj;
import org.junit.Assert;
import org.junit.Test;
import org.apache.wayang.core.api.Configuration;
@@ -73,8 +73,8 @@ public class PartialExecutionTest {
original.addInitializedPlatform(DummyPlatform.getInstance());
final PartialExecution.Serializer serializer = new PartialExecution.Serializer(configuration);
- final JSONObject jsonObject = JsonSerializables.serialize(original, false, serializer);
- final PartialExecution loaded = JsonSerializables.deserialize(jsonObject, serializer, PartialExecution.class);
+ final WayangJsonObj wayangJsonObj = JsonSerializables.serialize(original, false, serializer);
+ final PartialExecution loaded = JsonSerializables.deserialize(wayangJsonObj, serializer, PartialExecution.class);
Assert.assertEquals(original.getMeasuredExecutionTime(), loaded.getMeasuredExecutionTime());
Assert.assertEquals(2, loaded.getAtomicExecutionGroups().size());
diff --git a/wayang-commons/wayang-core/src/test/java/org/apache/wayang/core/test/SerializableDummyExecutionOperator.java b/wayang-commons/wayang-core/src/test/java/org/apache/wayang/core/test/SerializableDummyExecutionOperator.java
index 81a1ef7..5c72412 100644
--- a/wayang-commons/wayang-core/src/test/java/org/apache/wayang/core/test/SerializableDummyExecutionOperator.java
+++ b/wayang-commons/wayang-core/src/test/java/org/apache/wayang/core/test/SerializableDummyExecutionOperator.java
@@ -20,7 +20,7 @@ package org.apache.wayang.core.test;
import org.apache.wayang.core.plan.wayangplan.ExecutionOperator;
import org.apache.wayang.core.util.JsonSerializable;
-import org.apache.wayang.core.util.json.JSONObject;
+import org.apache.wayang.core.util.json.WayangJsonObj;
/**
* Dummy {@link ExecutionOperator} for test purposes.
@@ -33,12 +33,12 @@ public class SerializableDummyExecutionOperator extends DummyExecutionOperator i
}
@Override
- public JSONObject toJson() {
- return new JSONObject().put("someProperty", this.getSomeProperty());
+ public WayangJsonObj toJson() {
+ return new WayangJsonObj().put("someProperty", this.getSomeProperty());
}
@SuppressWarnings("unused")
- public static SerializableDummyExecutionOperator fromJson(JSONObject jsonObject) {
- return new SerializableDummyExecutionOperator(jsonObject.getInt("someProperty"));
+ public static SerializableDummyExecutionOperator fromJson(WayangJsonObj wayangJsonObj) {
+ return new SerializableDummyExecutionOperator(wayangJsonObj.getInt("someProperty"));
}
}
diff --git a/wayang-platforms/wayang-jdbc-template/src/main/java/org/apache/wayang/jdbc/operators/SqlToStreamOperator.java b/wayang-platforms/wayang-jdbc-template/src/main/java/org/apache/wayang/jdbc/operators/SqlToStreamOperator.java
index 12d77f0..ef882cb 100644
--- a/wayang-platforms/wayang-jdbc-template/src/main/java/org/apache/wayang/jdbc/operators/SqlToStreamOperator.java
+++ b/wayang-platforms/wayang-jdbc-template/src/main/java/org/apache/wayang/jdbc/operators/SqlToStreamOperator.java
@@ -32,7 +32,7 @@ import org.apache.wayang.core.types.DataSetType;
import org.apache.wayang.core.util.JsonSerializable;
import org.apache.wayang.core.util.ReflectionUtils;
import org.apache.wayang.core.util.Tuple;
-import org.apache.wayang.core.util.json.JSONObject;
+import org.apache.wayang.core.util.json.WayangJsonObj;
import org.apache.wayang.java.channels.StreamChannel;
import org.apache.wayang.java.execution.JavaExecutor;
import org.apache.wayang.java.operators.JavaExecutionOperator;
@@ -225,13 +225,13 @@ public class SqlToStreamOperator extends UnaryToUnaryOperator<Record, Record> im
}
@Override
- public JSONObject toJson() {
- return new JSONObject().put("platform", this.jdbcPlatform.getClass().getCanonicalName());
+ public WayangJsonObj toJson() {
+ return new WayangJsonObj().put("platform", this.jdbcPlatform.getClass().getCanonicalName());
}
@SuppressWarnings("unused")
- public static SqlToStreamOperator fromJson(JSONObject jsonObject) {
- final String platformClassName = jsonObject.getString("platform");
+ public static SqlToStreamOperator fromJson(WayangJsonObj wayangJsonObj) {
+ final String platformClassName = wayangJsonObj.getString("platform");
JdbcPlatformTemplate jdbcPlatform = ReflectionUtils.evaluate(platformClassName + ".getInstance()");
return new SqlToStreamOperator(jdbcPlatform);
}