Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atlas
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dataplatform
atlas
Commits
0e0f217a
Commit
0e0f217a
authored
Jan 18, 2019
by
Madhan Neethiraj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-3043: added unique-attributes constraints at store-level
Change-Id: Ica44b1739b504bebc2ab39dc856ccb079b8f4003
parent
7527ca06
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
66 additions
and
0 deletions
+66
-0
AtlasStructType.java
.../src/main/java/org/apache/atlas/type/AtlasStructType.java
+6
-0
GraphBackedSearchIndexer.java
...ache/atlas/repository/graph/GraphBackedSearchIndexer.java
+0
-0
DeleteHandlerV1.java
...ache/atlas/repository/store/graph/v1/DeleteHandlerV1.java
+6
-0
AtlasGraphUtilsV2.java
...he/atlas/repository/store/graph/v2/AtlasGraphUtilsV2.java
+44
-0
EntityGraphMapper.java
...he/atlas/repository/store/graph/v2/EntityGraphMapper.java
+10
-0
No files found.
intg/src/main/java/org/apache/atlas/type/AtlasStructType.java
View file @
0e0f217a
...
@@ -43,6 +43,8 @@ import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.C
...
@@ -43,6 +43,8 @@ import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef.C
public
class
AtlasStructType
extends
AtlasType
{
public
class
AtlasStructType
extends
AtlasType
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
AtlasStructType
.
class
);
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
AtlasStructType
.
class
);
public
static
final
String
UNIQUE_ATTRIBUTE_SHADE_PROPERTY_PREFIX
=
"__u_"
;
private
final
AtlasStructDef
structDef
;
private
final
AtlasStructDef
structDef
;
protected
Map
<
String
,
AtlasAttribute
>
allAttributes
=
Collections
.
emptyMap
();
protected
Map
<
String
,
AtlasAttribute
>
allAttributes
=
Collections
.
emptyMap
();
...
@@ -697,6 +699,7 @@ public class AtlasStructType extends AtlasType {
...
@@ -697,6 +699,7 @@ public class AtlasStructType extends AtlasType {
private
final
AtlasAttributeDef
attributeDef
;
private
final
AtlasAttributeDef
attributeDef
;
private
final
String
qualifiedName
;
private
final
String
qualifiedName
;
private
final
String
vertexPropertyName
;
private
final
String
vertexPropertyName
;
private
final
String
vertexUniquePropertyName
;
private
final
boolean
isOwnedRef
;
private
final
boolean
isOwnedRef
;
private
final
String
inverseRefAttributeName
;
private
final
String
inverseRefAttributeName
;
private
AtlasAttribute
inverseRefAttribute
;
private
AtlasAttribute
inverseRefAttribute
;
...
@@ -709,6 +712,7 @@ public class AtlasStructType extends AtlasType {
...
@@ -709,6 +712,7 @@ public class AtlasStructType extends AtlasType {
this
.
attributeType
=
attributeType
.
getTypeForAttribute
();
this
.
attributeType
=
attributeType
.
getTypeForAttribute
();
this
.
qualifiedName
=
getQualifiedAttributeName
(
definedInType
.
getStructDef
(),
attributeDef
.
getName
());
this
.
qualifiedName
=
getQualifiedAttributeName
(
definedInType
.
getStructDef
(),
attributeDef
.
getName
());
this
.
vertexPropertyName
=
encodePropertyKey
(
this
.
qualifiedName
);
this
.
vertexPropertyName
=
encodePropertyKey
(
this
.
qualifiedName
);
this
.
vertexUniquePropertyName
=
attrDef
.
getIsUnique
()
?
encodePropertyKey
(
getQualifiedAttributeName
(
definedInType
.
getStructDef
(),
UNIQUE_ATTRIBUTE_SHADE_PROPERTY_PREFIX
+
attributeDef
.
getName
()))
:
null
;
this
.
relationshipEdgeLabel
=
getRelationshipEdgeLabel
(
relationshipLabel
);
this
.
relationshipEdgeLabel
=
getRelationshipEdgeLabel
(
relationshipLabel
);
boolean
isOwnedRef
=
false
;
boolean
isOwnedRef
=
false
;
String
inverseRefAttribute
=
null
;
String
inverseRefAttribute
=
null
;
...
@@ -758,6 +762,8 @@ public class AtlasStructType extends AtlasType {
...
@@ -758,6 +762,8 @@ public class AtlasStructType extends AtlasType {
public
String
getVertexPropertyName
()
{
return
vertexPropertyName
;
}
public
String
getVertexPropertyName
()
{
return
vertexPropertyName
;
}
public
String
getVertexUniquePropertyName
()
{
return
vertexUniquePropertyName
;
}
public
boolean
isOwnedRef
()
{
return
isOwnedRef
;
}
public
boolean
isOwnedRef
()
{
return
isOwnedRef
;
}
public
String
getInverseRefAttributeName
()
{
return
inverseRefAttributeName
;
}
public
String
getInverseRefAttributeName
()
{
return
inverseRefAttributeName
;
}
...
...
repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java
View file @
0e0f217a
This diff is collapsed.
Click to expand it.
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/DeleteHandlerV1.java
View file @
0e0f217a
...
@@ -794,6 +794,12 @@ public abstract class DeleteHandlerV1 {
...
@@ -794,6 +794,12 @@ public abstract class DeleteHandlerV1 {
}
}
}
}
break
;
break
;
case
PRIMITIVE:
if
(
attributeInfo
.
getVertexUniquePropertyName
()
!=
null
)
{
instanceVertex
.
removeProperty
(
attributeInfo
.
getVertexUniquePropertyName
());
}
break
;
}
}
}
}
}
}
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasGraphUtilsV2.java
View file @
0e0f217a
...
@@ -72,6 +72,7 @@ public class AtlasGraphUtilsV2 {
...
@@ -72,6 +72,7 @@ public class AtlasGraphUtilsV2 {
public
static
final
String
VERTEX_TYPE
=
"typeSystem"
;
public
static
final
String
VERTEX_TYPE
=
"typeSystem"
;
private
static
boolean
USE_INDEX_QUERY_TO_FIND_ENTITY_BY_UNIQUE_ATTRIBUTES
=
false
;
private
static
boolean
USE_INDEX_QUERY_TO_FIND_ENTITY_BY_UNIQUE_ATTRIBUTES
=
false
;
private
static
boolean
USE_UNIQUE_INDEX_PROPERTY_TO_FIND_ENTITY
=
false
;
private
static
String
INDEX_SEARCH_PREFIX
;
private
static
String
INDEX_SEARCH_PREFIX
;
static
{
static
{
...
@@ -79,6 +80,7 @@ public class AtlasGraphUtilsV2 {
...
@@ -79,6 +80,7 @@ public class AtlasGraphUtilsV2 {
Configuration
conf
=
ApplicationProperties
.
get
();
Configuration
conf
=
ApplicationProperties
.
get
();
USE_INDEX_QUERY_TO_FIND_ENTITY_BY_UNIQUE_ATTRIBUTES
=
conf
.
getBoolean
(
"atlas.use.index.query.to.find.entity.by.unique.attributes"
,
USE_INDEX_QUERY_TO_FIND_ENTITY_BY_UNIQUE_ATTRIBUTES
);
USE_INDEX_QUERY_TO_FIND_ENTITY_BY_UNIQUE_ATTRIBUTES
=
conf
.
getBoolean
(
"atlas.use.index.query.to.find.entity.by.unique.attributes"
,
USE_INDEX_QUERY_TO_FIND_ENTITY_BY_UNIQUE_ATTRIBUTES
);
USE_UNIQUE_INDEX_PROPERTY_TO_FIND_ENTITY
=
conf
.
getBoolean
(
"atlas.unique.index.property.to.find.entity"
,
USE_UNIQUE_INDEX_PROPERTY_TO_FIND_ENTITY
);
INDEX_SEARCH_PREFIX
=
conf
.
getString
(
INDEX_SEARCH_VERTEX_PREFIX_PROPERTY
,
INDEX_SEARCH_VERTEX_PREFIX_DEFAULT
);
INDEX_SEARCH_PREFIX
=
conf
.
getString
(
INDEX_SEARCH_VERTEX_PREFIX_PROPERTY
,
INDEX_SEARCH_VERTEX_PREFIX_DEFAULT
);
}
catch
(
Exception
excp
)
{
}
catch
(
Exception
excp
)
{
LOG
.
error
(
"Error reading configuration"
,
excp
);
LOG
.
error
(
"Error reading configuration"
,
excp
);
...
@@ -287,6 +289,14 @@ public class AtlasGraphUtilsV2 {
...
@@ -287,6 +289,14 @@ public class AtlasGraphUtilsV2 {
if
(
canUseIndexQuery
(
entityType
,
attribute
.
getName
()))
{
if
(
canUseIndexQuery
(
entityType
,
attribute
.
getName
()))
{
vertex
=
AtlasGraphUtilsV2
.
getAtlasVertexFromIndexQuery
(
entityType
,
attribute
,
attrValue
);
vertex
=
AtlasGraphUtilsV2
.
getAtlasVertexFromIndexQuery
(
entityType
,
attribute
,
attrValue
);
}
else
{
}
else
{
if
(
USE_UNIQUE_INDEX_PROPERTY_TO_FIND_ENTITY
&&
attribute
.
getVertexUniquePropertyName
()
!=
null
)
{
vertex
=
AtlasGraphUtilsV2
.
findByTypeAndUniquePropertyName
(
entityType
.
getTypeName
(),
attribute
.
getVertexUniquePropertyName
(),
attrValue
);
// if no instance of given typeName is found, try to find an instance of type's sub-type
if
(
vertex
==
null
&&
!
entityType
.
getAllSubTypes
().
isEmpty
())
{
vertex
=
AtlasGraphUtilsV2
.
findBySuperTypeAndUniquePropertyName
(
entityType
.
getTypeName
(),
attribute
.
getVertexUniquePropertyName
(),
attrValue
);
}
}
else
{
vertex
=
AtlasGraphUtilsV2
.
findByTypeAndPropertyName
(
entityType
.
getTypeName
(),
attribute
.
getVertexPropertyName
(),
attrValue
);
vertex
=
AtlasGraphUtilsV2
.
findByTypeAndPropertyName
(
entityType
.
getTypeName
(),
attribute
.
getVertexPropertyName
(),
attrValue
);
// if no instance of given typeName is found, try to find an instance of type's sub-type
// if no instance of given typeName is found, try to find an instance of type's sub-type
...
@@ -295,6 +305,8 @@ public class AtlasGraphUtilsV2 {
...
@@ -295,6 +305,8 @@ public class AtlasGraphUtilsV2 {
}
}
}
}
}
if
(
vertex
!=
null
)
{
if
(
vertex
!=
null
)
{
if
(
LOG
.
isDebugEnabled
())
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"findByUniqueAttributes(type={}, attrName={}, attrValue={}: found vertex {}"
,
LOG
.
debug
(
"findByUniqueAttributes(type={}, attrName={}, attrValue={}: found vertex {}"
,
...
@@ -350,6 +362,38 @@ public class AtlasGraphUtilsV2 {
...
@@ -350,6 +362,38 @@ public class AtlasGraphUtilsV2 {
return
hasInstanceVertex
;
return
hasInstanceVertex
;
}
}
public
static
AtlasVertex
findByTypeAndUniquePropertyName
(
String
typeName
,
String
propertyName
,
Object
attrVal
)
{
MetricRecorder
metric
=
RequestContext
.
get
().
startMetricRecord
(
"findByTypeAndUniquePropertyName"
);
AtlasGraphQuery
query
=
AtlasGraphProvider
.
getGraphInstance
().
query
()
.
has
(
Constants
.
ENTITY_TYPE_PROPERTY_KEY
,
typeName
)
.
has
(
propertyName
,
attrVal
);
Iterator
<
AtlasVertex
>
results
=
query
.
vertices
().
iterator
();
AtlasVertex
vertex
=
results
.
hasNext
()
?
results
.
next
()
:
null
;
RequestContext
.
get
().
endMetricRecord
(
metric
);
return
vertex
;
}
public
static
AtlasVertex
findBySuperTypeAndUniquePropertyName
(
String
typeName
,
String
propertyName
,
Object
attrVal
)
{
MetricRecorder
metric
=
RequestContext
.
get
().
startMetricRecord
(
"findBySuperTypeAndUniquePropertyName"
);
AtlasGraphQuery
query
=
AtlasGraphProvider
.
getGraphInstance
().
query
()
.
has
(
Constants
.
SUPER_TYPES_PROPERTY_KEY
,
typeName
)
.
has
(
propertyName
,
attrVal
);
Iterator
<
AtlasVertex
>
results
=
query
.
vertices
().
iterator
();
AtlasVertex
vertex
=
results
.
hasNext
()
?
results
.
next
()
:
null
;
RequestContext
.
get
().
endMetricRecord
(
metric
);
return
vertex
;
}
public
static
AtlasVertex
findByTypeAndPropertyName
(
String
typeName
,
String
propertyName
,
Object
attrVal
)
{
public
static
AtlasVertex
findByTypeAndPropertyName
(
String
typeName
,
String
propertyName
,
Object
attrVal
)
{
MetricRecorder
metric
=
RequestContext
.
get
().
startMetricRecord
(
"findByTypeAndPropertyName"
);
MetricRecorder
metric
=
RequestContext
.
get
().
startMetricRecord
(
"findByTypeAndPropertyName"
);
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java
View file @
0e0f217a
...
@@ -705,6 +705,16 @@ public class EntityGraphMapper {
...
@@ -705,6 +705,16 @@ public class EntityGraphMapper {
AtlasGraphUtilsV2
.
setEncodedProperty
(
ctx
.
getReferringVertex
(),
ctx
.
getVertexProperty
(),
ret
);
AtlasGraphUtilsV2
.
setEncodedProperty
(
ctx
.
getReferringVertex
(),
ctx
.
getVertexProperty
(),
ret
);
String
uniqPropName
=
ctx
.
getAttribute
()
!=
null
?
ctx
.
getAttribute
().
getVertexUniquePropertyName
()
:
null
;
if
(
uniqPropName
!=
null
)
{
if
(
AtlasGraphUtilsV2
.
getState
(
ctx
.
getReferringVertex
())
==
DELETED
)
{
ctx
.
getReferringVertex
().
removeProperty
(
uniqPropName
);
}
else
{
AtlasGraphUtilsV2
.
setEncodedProperty
(
ctx
.
getReferringVertex
(),
uniqPropName
,
ret
);
}
}
return
ret
;
return
ret
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment