You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by am...@apache.org on 2020/05/01 18:05:42 UTC
[atlas] branch master updated: ATLAS-3773: Shadow Attributes Update
Post-Migration from 0.8.
This is an automated email from the ASF dual-hosted git repository.
amestry pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/atlas.git
The following commit(s) were added to refs/heads/master by this push:
new a43b548 ATLAS-3773: Shadow Attributes Update Post-Migration from 0.8.
a43b548 is described below
commit a43b5488fbd10c874d181bf27e076fd502693a93
Author: Ashutosh Mestry <am...@cloudera.com>
AuthorDate: Fri May 1 10:54:41 2020 -0700
ATLAS-3773: Shadow Attributes Update Post-Migration from 0.8.
---
.../repository/patches/UniqueAttributePatch.java | 43 +++++++++++++++++++---
1 file changed, 37 insertions(+), 6 deletions(-)
diff --git a/repository/src/main/java/org/apache/atlas/repository/patches/UniqueAttributePatch.java b/repository/src/main/java/org/apache/atlas/repository/patches/UniqueAttributePatch.java
index 2b58119..d3111f1 100644
--- a/repository/src/main/java/org/apache/atlas/repository/patches/UniqueAttributePatch.java
+++ b/repository/src/main/java/org/apache/atlas/repository/patches/UniqueAttributePatch.java
@@ -23,7 +23,11 @@ import org.apache.atlas.pc.WorkItemManager;
import org.apache.atlas.repository.Constants;
import org.apache.atlas.repository.IndexException;
import org.apache.atlas.repository.graph.GraphBackedSearchIndexer.UniqueKind;
-import org.apache.atlas.repository.graphdb.*;
+import org.apache.atlas.repository.graphdb.AtlasCardinality;
+import org.apache.atlas.repository.graphdb.AtlasGraph;
+import org.apache.atlas.repository.graphdb.AtlasGraphManagement;
+import org.apache.atlas.repository.graphdb.AtlasSchemaViolationException;
+import org.apache.atlas.repository.graphdb.AtlasVertex;
import org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2;
import org.apache.atlas.repository.store.graph.v2.EntityGraphRetriever;
import org.apache.atlas.type.AtlasEntityType;
@@ -159,10 +163,37 @@ public class UniqueAttributePatch extends AtlasPatchHandler {
protected void processItem(Long vertexId, AtlasVertex vertex, String typeName, AtlasEntityType entityType) {
LOG.debug("processItem(typeName={}, vertexId={})", typeName, vertexId);
+ processIndexStringAttribute(vertexId, vertex, typeName, entityType);
+ processUniqueAttribute(vertexId, vertex, typeName, entityType);
+
+ LOG.debug("processItem(typeName={}, vertexId={}): Done!", typeName, vertexId);
+ }
+
+ private void processIndexStringAttribute(Long vertexId, AtlasVertex vertex, String typeName, AtlasEntityType entityType) {
+ for (AtlasAttribute attribute : entityType.getAllAttributes().values()) {
+ if (attribute.getAttributeDef().getIndexType() != null &&
+ attribute.getAttributeDef().getIndexType() == AtlasAttributeDef.IndexType.STRING) {
+
+ String vertexPropertyName = attribute.getVertexPropertyName();
+ if (vertex.getProperty(vertexPropertyName, String.class) != null) {
+ continue;
+ }
+
+ Object attrVal = AtlasGraphUtilsV2.getEncodedProperty(vertex, attribute.getQualifiedName(), String.class);
+ if (attrVal != null) {
+ AtlasGraphUtilsV2.setEncodedProperty(vertex, vertexPropertyName, attrVal);
+ }
+ }
+ }
+
+ LOG.debug("processIndexStringAttribute(typeName={}, vertexId={}): Done!", typeName, vertexId);
+ }
+
+ private void processUniqueAttribute(Long vertexId, AtlasVertex vertex, String typeName, AtlasEntityType entityType) {
for (AtlasAttribute attribute : entityType.getUniqAttributes().values()) {
- String uniquePropertyKey = attribute.getVertexUniquePropertyName();
- Collection<? extends String> propertyKeys = vertex.getPropertyKeys();
- Object uniqAttrValue = null;
+ String uniquePropertyKey = attribute.getVertexUniquePropertyName();
+ Collection<? extends String> propertyKeys = vertex.getPropertyKeys();
+ Object uniqAttrValue = null;
if (propertyKeys == null || !propertyKeys.contains(uniquePropertyKey)) {
try {
@@ -171,14 +202,14 @@ public class UniqueAttributePatch extends AtlasPatchHandler {
uniqAttrValue = EntityGraphRetriever.mapVertexToPrimitive(vertex, propertyKey, attribute.getAttributeDef());
AtlasGraphUtilsV2.setEncodedProperty(vertex, uniquePropertyKey, uniqAttrValue);
- } catch(AtlasSchemaViolationException ex) {
+ } catch (AtlasSchemaViolationException ex) {
LOG.error("Duplicates detected: {}:{}:{}", typeName, uniqAttrValue, getIdFromVertex(vertex));
vertex.removeProperty(uniquePropertyKey);
}
}
}
- LOG.debug("processItem(typeName={}, vertexId={}): Done!", typeName, vertexId);
+ LOG.debug("processUniqueAttribute(typeName={}, vertexId={}): Done!", typeName, vertexId);
}
}
}