[NO-ISSUE][GRAPHIX] Fixing serialization error for requirements.
Marking the following as serializable (so as to properly send messages
to the metadata node):
- IEntityRequirements
- DependencyIdentifier
- EdgeDescriptor
- ElementLabel
Change-Id: Ia9718d56ef5e1d7dbc80a16e6df0cc67ef689f11
Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb-graph/+/16603
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Glenn Galvizo <ggalvizo@uci.edu>
diff --git a/asterix-graphix/src/main/java/org/apache/asterix/graphix/lang/struct/EdgeDescriptor.java b/asterix-graphix/src/main/java/org/apache/asterix/graphix/lang/struct/EdgeDescriptor.java
index 2898a16..d5f88e4 100644
--- a/asterix-graphix/src/main/java/org/apache/asterix/graphix/lang/struct/EdgeDescriptor.java
+++ b/asterix-graphix/src/main/java/org/apache/asterix/graphix/lang/struct/EdgeDescriptor.java
@@ -18,6 +18,7 @@
*/
package org.apache.asterix.graphix.lang.struct;
+import java.io.Serializable;
import java.util.List;
import java.util.Objects;
import java.util.Set;
@@ -36,7 +37,9 @@
* 5. A maximum number of hops (not allowed to be NULL).
* 6. An edge direction (left to right, right to left, or undirected).
*/
-public class EdgeDescriptor {
+public class EdgeDescriptor implements Serializable {
+ private static final long serialVersionUID = 1L;
+
private final Set<ElementLabel> edgeLabels;
private final Integer minimumHops;
private final Integer maximumHops;
diff --git a/asterix-graphix/src/main/java/org/apache/asterix/graphix/lang/struct/ElementLabel.java b/asterix-graphix/src/main/java/org/apache/asterix/graphix/lang/struct/ElementLabel.java
index 9add17a..a65afc6 100644
--- a/asterix-graphix/src/main/java/org/apache/asterix/graphix/lang/struct/ElementLabel.java
+++ b/asterix-graphix/src/main/java/org/apache/asterix/graphix/lang/struct/ElementLabel.java
@@ -18,9 +18,12 @@
*/
package org.apache.asterix.graphix.lang.struct;
+import java.io.Serializable;
import java.util.Objects;
-public class ElementLabel {
+public class ElementLabel implements Serializable {
+ private static final long serialVersionUID = 1L;
+
private final String labelName;
private boolean isInferred;
diff --git a/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entity/dependency/DependencyIdentifier.java b/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entity/dependency/DependencyIdentifier.java
index 7c63de8..8a2ffe5 100644
--- a/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entity/dependency/DependencyIdentifier.java
+++ b/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entity/dependency/DependencyIdentifier.java
@@ -18,6 +18,7 @@
*/
package org.apache.asterix.graphix.metadata.entity.dependency;
+import java.io.Serializable;
import java.util.Objects;
import org.apache.asterix.common.functions.FunctionSignature;
@@ -30,7 +31,9 @@
* A graph may depend on datasets, synonyms, functions, and other graphs. Similarly, functions and views may depend
* on graphs themselves.
*/
-public class DependencyIdentifier {
+public class DependencyIdentifier implements Serializable {
+ private static final long serialVersionUID = 1L;
+
private final DataverseName dataverseName;
private final String entityName;
private final String entityDetail;
diff --git a/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entity/dependency/FunctionRequirements.java b/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entity/dependency/FunctionRequirements.java
index 5e73325..0b88f27 100644
--- a/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entity/dependency/FunctionRequirements.java
+++ b/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entity/dependency/FunctionRequirements.java
@@ -18,6 +18,7 @@
*/
package org.apache.asterix.graphix.metadata.entity.dependency;
+import java.io.IOException;
import java.util.Iterator;
import java.util.Objects;
import java.util.Set;
@@ -25,7 +26,6 @@
import org.apache.asterix.common.functions.FunctionSignature;
import org.apache.asterix.common.metadata.DataverseName;
import org.apache.asterix.om.base.AGeneratedUUID;
-import org.apache.asterix.om.base.AUUID;
/**
* A collection of {@link org.apache.asterix.graphix.metadata.entity.schema.Graph} dependencies associated with a
@@ -33,20 +33,27 @@
* for functions.
*/
public class FunctionRequirements implements IEntityRequirements {
+ private static final long serialVersionUID = 1L;
+
private final Set<DependencyIdentifier> functionRequirements;
private final FunctionSignature functionSignature;
- // Physically, our requirements are indexed by a UUID. Logically, we ignore this.
- private final AUUID primaryKeyValue;
+ // Physically, our requirements are indexed by the string below. Logically, we ignore this.
+ private final String primaryKeyValue;
- public FunctionRequirements(FunctionSignature functionSignature, Set<DependencyIdentifier> functionRequirements) {
+ public FunctionRequirements(FunctionSignature functionSignature, Set<DependencyIdentifier> functionRequirements)
+ throws IOException {
this.functionRequirements = Objects.requireNonNull(functionRequirements);
this.functionSignature = Objects.requireNonNull(functionSignature);
- this.primaryKeyValue = new AGeneratedUUID();
+
+ // Generate a unique primary key from a AUUID.
+ StringBuilder sb = new StringBuilder();
+ new AGeneratedUUID().appendLiteralOnly(sb);
+ this.primaryKeyValue = sb.toString();
}
public FunctionRequirements(FunctionSignature functionSignature, Set<DependencyIdentifier> functionRequirements,
- AUUID primaryKeyValue) {
+ String primaryKeyValue) {
this.functionRequirements = Objects.requireNonNull(functionRequirements);
this.functionSignature = Objects.requireNonNull(functionSignature);
this.primaryKeyValue = Objects.requireNonNull(primaryKeyValue);
@@ -57,7 +64,7 @@
}
@Override
- public AUUID getPrimaryKeyValue() {
+ public String getPrimaryKeyValue() {
return primaryKeyValue;
}
diff --git a/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entity/dependency/GraphRequirements.java b/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entity/dependency/GraphRequirements.java
index 98c669a..ef4dab2 100644
--- a/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entity/dependency/GraphRequirements.java
+++ b/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entity/dependency/GraphRequirements.java
@@ -18,6 +18,7 @@
*/
package org.apache.asterix.graphix.metadata.entity.dependency;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@@ -33,7 +34,6 @@
import org.apache.asterix.lang.common.util.ExpressionUtils;
import org.apache.asterix.metadata.utils.MetadataUtil;
import org.apache.asterix.om.base.AGeneratedUUID;
-import org.apache.asterix.om.base.AUUID;
import org.apache.hyracks.algebricks.common.utils.Triple;
/**
@@ -41,29 +41,35 @@
* {@link org.apache.asterix.graphix.metadata.entity.schema.Graph} instance.
*/
public class GraphRequirements implements IEntityRequirements {
+ private static final long serialVersionUID = 1L;
+
// A graph potentially depends on datasets, synonyms, functions, and graphs.
private final Set<DependencyIdentifier> graphRequirements;
private final DataverseName dataverseName;
private final String graphName;
- // Physically, our requirements are indexed by a UUID. Logically, we ignore this.
- private AUUID primaryKeyValue;
+ // Physically, our requirements are indexed by the string below. Logically, we ignore this.
+ private String primaryKeyValue;
+
+ public GraphRequirements(DataverseName dataverseName, String graphName) throws IOException {
+ this.graphRequirements = new HashSet<>();
+ this.dataverseName = Objects.requireNonNull(dataverseName);
+ this.graphName = Objects.requireNonNull(graphName);
+
+ // Generate a unique primary key from a AUUID.
+ StringBuilder sb = new StringBuilder();
+ new AGeneratedUUID().appendLiteralOnly(sb);
+ this.primaryKeyValue = sb.toString();
+ }
public GraphRequirements(DataverseName dataverseName, String graphName, Set<DependencyIdentifier> graphRequirements,
- AUUID primaryKeyValue) {
+ String primaryKeyValue) {
this.graphRequirements = Objects.requireNonNull(graphRequirements);
this.dataverseName = Objects.requireNonNull(dataverseName);
this.graphName = Objects.requireNonNull(graphName);
this.primaryKeyValue = Objects.requireNonNull(primaryKeyValue);
}
- public GraphRequirements(DataverseName dataverseName, String graphName) {
- this.graphRequirements = new HashSet<>();
- this.dataverseName = Objects.requireNonNull(dataverseName);
- this.graphName = Objects.requireNonNull(graphName);
- this.primaryKeyValue = new AGeneratedUUID();
- }
-
public void loadNonGraphDependencies(Expression body, IQueryRewriter queryRewriter) throws CompilationException {
// Collect our dependencies as triples.
List<Triple<DataverseName, String, String>> datasetDependencies = new ArrayList<>();
@@ -88,12 +94,12 @@
graphRequirements.addAll(graphDependencies);
}
- public void setPrimaryKeyValue(AUUID primaryKeyValue) {
+ public void setPrimaryKeyValue(String primaryKeyValue) {
this.primaryKeyValue = primaryKeyValue;
}
@Override
- public AUUID getPrimaryKeyValue() {
+ public String getPrimaryKeyValue() {
return primaryKeyValue;
}
diff --git a/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entity/dependency/IEntityRequirements.java b/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entity/dependency/IEntityRequirements.java
index 371d4e3..c0e111c 100644
--- a/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entity/dependency/IEntityRequirements.java
+++ b/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entity/dependency/IEntityRequirements.java
@@ -18,11 +18,12 @@
*/
package org.apache.asterix.graphix.metadata.entity.dependency;
+import java.io.Serializable;
+
import org.apache.asterix.common.metadata.DataverseName;
import org.apache.asterix.graphix.metadata.bootstrap.GraphixIndexDetailProvider;
import org.apache.asterix.metadata.api.ExtensionMetadataDatasetId;
import org.apache.asterix.metadata.api.IExtensionMetadataEntity;
-import org.apache.asterix.om.base.AUUID;
/**
* Metadata for describing the pair [entity, list of dependencies for said entity]. This includes the following:
@@ -32,8 +33,8 @@
* 4. The kind associated with the entity (FUNCTION, GRAPH, or VIEW).
* 5. An iterator of the dependencies associated with the entity.
*/
-public interface IEntityRequirements extends Iterable<DependencyIdentifier>, IExtensionMetadataEntity {
- AUUID getPrimaryKeyValue();
+public interface IEntityRequirements extends Iterable<DependencyIdentifier>, IExtensionMetadataEntity, Serializable {
+ String getPrimaryKeyValue();
DataverseName getDataverseName();
diff --git a/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entity/dependency/ViewRequirements.java b/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entity/dependency/ViewRequirements.java
index 2e529a6..6c84eab 100644
--- a/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entity/dependency/ViewRequirements.java
+++ b/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entity/dependency/ViewRequirements.java
@@ -18,6 +18,7 @@
*/
package org.apache.asterix.graphix.metadata.entity.dependency;
+import java.io.IOException;
import java.util.Iterator;
import java.util.Objects;
import java.util.Set;
@@ -25,29 +26,35 @@
import org.apache.asterix.common.metadata.DataverseName;
import org.apache.asterix.metadata.utils.DatasetUtil;
import org.apache.asterix.om.base.AGeneratedUUID;
-import org.apache.asterix.om.base.AUUID;
/**
* A collection of {@link org.apache.asterix.graphix.metadata.entity.schema.Graph} dependencies associated with a view
* instance. This does **not** include non-graph dependencies for views.
*/
public class ViewRequirements implements IEntityRequirements {
+ private static final long serialVersionUID = 1L;
+
private final Set<DependencyIdentifier> viewRequirements;
private final DataverseName dataverseName;
private final String viewName;
- // Physically, our requirements are indexed by a UUID. Logically, we ignore this.
- private final AUUID primaryKeyValue;
+ // Physically, our requirements are indexed by the string below. Logically, we ignore this.
+ private final String primaryKeyValue;
- public ViewRequirements(DataverseName dataverseName, String viewName, Set<DependencyIdentifier> viewRequirements) {
+ public ViewRequirements(DataverseName dataverseName, String viewName, Set<DependencyIdentifier> viewRequirements)
+ throws IOException {
this.viewRequirements = Objects.requireNonNull(viewRequirements);
this.dataverseName = Objects.requireNonNull(dataverseName);
this.viewName = Objects.requireNonNull(viewName);
- this.primaryKeyValue = new AGeneratedUUID();
+
+ // Generate a unique primary key from a AUUID.
+ StringBuilder sb = new StringBuilder();
+ new AGeneratedUUID().appendLiteralOnly(sb);
+ this.primaryKeyValue = sb.toString();
}
public ViewRequirements(DataverseName dataverseName, String viewName, Set<DependencyIdentifier> viewRequirements,
- AUUID primaryKeyValue) {
+ String primaryKeyValue) {
this.viewRequirements = Objects.requireNonNull(viewRequirements);
this.dataverseName = Objects.requireNonNull(dataverseName);
this.viewName = Objects.requireNonNull(viewName);
@@ -55,7 +62,7 @@
}
@Override
- public AUUID getPrimaryKeyValue() {
+ public String getPrimaryKeyValue() {
return primaryKeyValue;
}
diff --git a/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entitytupletranslators/DependencyTupleTranslator.java b/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entitytupletranslators/DependencyTupleTranslator.java
index 77c1637..b59f661 100644
--- a/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entitytupletranslators/DependencyTupleTranslator.java
+++ b/asterix-graphix/src/main/java/org/apache/asterix/graphix/metadata/entitytupletranslators/DependencyTupleTranslator.java
@@ -25,7 +25,6 @@
import static org.apache.asterix.metadata.bootstrap.MetadataRecordTypes.FIELD_NAME_DEPENDENCIES;
import static org.apache.asterix.metadata.bootstrap.MetadataRecordTypes.FIELD_NAME_KIND;
-import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
@@ -43,17 +42,14 @@
import org.apache.asterix.graphix.metadata.entity.dependency.IEntityRequirements;
import org.apache.asterix.graphix.metadata.entity.dependency.ViewRequirements;
import org.apache.asterix.metadata.entitytupletranslators.AbstractTupleTranslator;
-import org.apache.asterix.om.base.AMutableUUID;
import org.apache.asterix.om.base.AOrderedList;
import org.apache.asterix.om.base.ARecord;
import org.apache.asterix.om.base.AString;
-import org.apache.asterix.om.base.AUUID;
import org.apache.asterix.om.base.IACursor;
import org.apache.asterix.om.base.IAObject;
import org.apache.asterix.om.types.AOrderedListType;
import org.apache.asterix.om.types.BuiltinType;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
-import org.apache.hyracks.api.exceptions.ErrorCode;
import org.apache.hyracks.api.exceptions.HyracksDataException;
import org.apache.hyracks.dataflow.common.data.accessors.ITupleReference;
@@ -88,14 +84,7 @@
protected IEntityRequirements createMetadataEntityFromARecord(ARecord requirements) throws AlgebricksException {
// Read in our primary key value.
IAObject primaryKeyValueObj = GRA_RECORD_DETAIL.getObjectForField(requirements, FIELD_NAME_DEPENDENCY_ID);
- String primaryKeyValueString = ((AString) primaryKeyValueObj).getStringValue();
- AMutableUUID primaryKeyValue = new AMutableUUID();
- try {
- primaryKeyValue.parseUUIDString(primaryKeyValueString.toCharArray(), 0, AUUID.UUID_CHARS);
-
- } catch (HyracksDataException e) {
- throw new AlgebricksException(ErrorCode.ILLEGAL_STATE, "Could not extract UUID bytes from ARecord.");
- }
+ String primaryKeyValue = ((AString) primaryKeyValueObj).getStringValue();
// Read in the dataverse name.
IAObject dataverseNameObj = GRA_RECORD_DETAIL.getObjectForField(requirements, FIELD_NAME_DATAVERSE_NAME);
@@ -191,20 +180,9 @@
@Override
public ITupleReference getTupleFromMetadataEntity(IEntityRequirements requirements) throws HyracksDataException {
- // TODO (GLENN): There is currently a bug where a metadata dataset index cannot have a UUID primary key field.
- String primaryKeyValue;
- try {
- StringBuilder sb = new StringBuilder();
- requirements.getPrimaryKeyValue().appendLiteralOnly(sb);
- primaryKeyValue = sb.toString();
-
- } catch (IOException e) {
- throw new HyracksDataException(ErrorCode.ILLEGAL_STATE, "Could not extract UUID bytes from AUUID.");
- }
-
- // Write our primary key, which is an autogenerated UUID (we serialize this as a string for our tuple).
+ // Write our primary key.
tupleBuilder.reset();
- aString.setValue(primaryKeyValue);
+ aString.setValue(requirements.getPrimaryKeyValue());
stringSerde.serialize(aString, tupleBuilder.getDataOutput());
tupleBuilder.addFieldEndOffset();
@@ -213,7 +191,7 @@
// Write our primary key.
fieldValue.reset();
- aString.setValue(primaryKeyValue);
+ aString.setValue(requirements.getPrimaryKeyValue());
stringSerde.serialize(aString, fieldValue.getDataOutput());
recordBuilder.addField(GRA_RECORD_DETAIL.getIndexForField(FIELD_NAME_DEPENDENCY_ID), fieldValue);