[NO ISSUE][RT] Improve debuggability of runtime functions
- user model changes: no
- storage format changes: no
- interface changes: no
Details:
- This change introduce util methods to facilitate debugging
functions runtime. Runtime functions read and write
values from and into byte arrays.
- To allow easier inspection of such values, we provide
a method that takes a pointable and produces an adm
node representing the value pointed to by the pointable.
Change-Id: I33257507e9bdd3be80355218e4bafecd1c71c650
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2926
Reviewed-by: Till Westmann <tillw@apache.org>
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/jackson/ObjectPool.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/jackson/ObjectPool.java
index 5ccd9e9..8945e71 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/jackson/ObjectPool.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/jackson/ObjectPool.java
@@ -59,4 +59,9 @@
recycledObjects.add(object);
}
}
+
+ @Override
+ public String toString() {
+ return recycledObjects.toString();
+ }
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/SerializerDeserializerProvider.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/SerializerDeserializerProvider.java
index 0cba8b6..356b84c 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/SerializerDeserializerProvider.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/formats/nontagged/SerializerDeserializerProvider.java
@@ -171,7 +171,7 @@
}
@SuppressWarnings("rawtypes")
- private ISerializerDeserializer addTag(final ISerializerDeserializer nonTaggedSerde) {
+ public static ISerializerDeserializer addTag(final ISerializerDeserializer nonTaggedSerde) {
return new ISerializerDeserializer<IAObject>() {
private static final long serialVersionUID = 1L;
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/AbstractVisitablePointable.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/AbstractVisitablePointable.java
index 2ff9357..e9aa99c 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/AbstractVisitablePointable.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/AbstractVisitablePointable.java
@@ -59,4 +59,10 @@
set(ivf.getByteArray(), ivf.getStartOffset(), ivf.getLength());
}
+ @Override
+ public String toString() {
+ return "{ \"class\" : \"" + getClass().getSimpleName() + "\", \"data\" : "
+ + (data == null ? "null" : ("\"" + System.identityHashCode(data) + ":" + data.length + "\""))
+ + ", \"offset\" : " + start + ", \"length\" : " + len + " }";
+ }
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/PointableAllocator.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/PointableAllocator.java
index 91c47fd..411f067 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/PointableAllocator.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/pointables/PointableAllocator.java
@@ -58,7 +58,7 @@
}
});
- public IVisitablePointable allocateEmpty() {
+ public AFlatValuePointable allocateEmpty() {
return flatValueAllocator.allocate(null);
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/utils/AdmNodeUtils.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/utils/AdmNodeUtils.java
index 6f4ee17..f8ce905 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/utils/AdmNodeUtils.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/utils/AdmNodeUtils.java
@@ -36,6 +36,7 @@
import org.apache.asterix.om.types.AOrderedListType;
import org.apache.asterix.om.types.ARecordType;
import org.apache.asterix.om.types.ATypeTag;
+import org.apache.hyracks.data.std.api.IPointable;
import org.apache.hyracks.data.std.primitive.BooleanPointable;
import org.apache.hyracks.data.std.primitive.DoublePointable;
import org.apache.hyracks.data.std.primitive.LongPointable;
@@ -56,6 +57,45 @@
return map;
}
+ public static IAdmNode getAsAdmNode(IPointable pointable) throws IOException {
+ byte[] bytes = pointable.getByteArray();
+ int offset = pointable.getStartOffset();
+ int len = pointable.getLength();
+ if (len == 0) {
+ throw new IllegalArgumentException();
+ }
+ byte tagByte = bytes[offset];
+ ATypeTag tag = ATypeTag.VALUE_TYPE_MAPPING[tagByte];
+ switch (tag) {
+ case ARRAY:
+ AListPointable listPointable = AListPointable.FACTORY.createPointable();
+ listPointable.set(bytes, offset, len);
+ return getAsAdmNode(listPointable);
+ case BIGINT:
+ return new AdmBigIntNode(LongPointable.getLong(bytes, offset + 1));
+ case BOOLEAN:
+ return AdmBooleanNode.get(BooleanPointable.getBoolean(bytes, offset + 1));
+ case DOUBLE:
+ return new AdmDoubleNode(DoublePointable.getDouble(bytes, offset + 1));
+ case NULL:
+ return AdmNullNode.INSTANCE;
+ case OBJECT:
+ ARecordPointable recPointable = ARecordPointable.FACTORY.createPointable();
+ recPointable.set(bytes, offset, len);
+ try {
+ return new AdmObjectNode(getOpenFields(recPointable, RecordUtil.FULLY_OPEN_RECORD_TYPE));
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e);
+ }
+ case STRING:
+ UTF8StringPointable str = UTF8StringPointable.FACTORY.createPointable();
+ str.set(bytes, offset + 1, len - 1);
+ return new AdmStringNode(str.toString());
+ default:
+ throw new UnsupportedOperationException("Unsupported item type: " + tag);
+ }
+ }
+
private static IAdmNode getOpenField(ARecordPointable recPointable, ARecordType type, int i) throws IOException {
byte tagByte = recPointable.getOpenFieldTag(type, i);
ATypeTag tag = ATypeTag.VALUE_TYPE_MAPPING[tagByte];