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
f5cd728d
Commit
f5cd728d
authored
Mar 31, 2020
by
Madhan Neethiraj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-3700: added option to append value to array, map type attributes
parent
521118c8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
168 additions
and
22 deletions
+168
-22
EntityMutationResponse.java
...g/apache/atlas/model/instance/EntityMutationResponse.java
+5
-0
AtlasStructDef.java
...n/java/org/apache/atlas/model/typedef/AtlasStructDef.java
+12
-4
TestUtilsV2.java
intg/src/test/java/org/apache/atlas/TestUtilsV2.java
+14
-1
EntityGraphMapper.java
...he/atlas/repository/store/graph/v2/EntityGraphMapper.java
+37
-15
AtlasComplexAttributesTest.java
...repository/store/graph/v2/AtlasComplexAttributesTest.java
+100
-2
No files found.
intg/src/main/java/org/apache/atlas/model/instance/EntityMutationResponse.java
View file @
f5cd728d
...
...
@@ -209,6 +209,11 @@ public class EntityMutationResponse {
}
@JsonIgnore
public
AtlasEntityHeader
getFirstPartialUpdatedEntityByTypeName
(
String
typeName
)
{
return
getFirstEntityByType
(
getEntitiesByOperation
(
EntityOperation
.
PARTIAL_UPDATE
),
typeName
);
}
@JsonIgnore
public
void
addEntity
(
EntityOperation
op
,
AtlasEntityHeader
header
)
{
// if an entity is already included in CREATE, ignore subsequent UPDATE, PARTIAL_UPDATE
if
(
op
==
EntityOperation
.
UPDATE
||
op
==
EntityOperation
.
PARTIAL_UPDATE
)
{
...
...
intg/src/main/java/org/apache/atlas/model/typedef/AtlasStructDef.java
View file @
f5cd728d
...
...
@@ -263,10 +263,11 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
public
static
final
int
DEFAULT_SEARCHWEIGHT
=
-
1
;
public
static
final
String
SEARCH_WEIGHT_ATTR_NAME
=
"searchWeight"
;
public
static
final
String
INDEX_TYPE_ATTR_NAME
=
"indexType"
;
public
static
final
String
ATTRDEF_OPTION_SOFT_REFERENCE
=
"isSoftReference"
;
private
final
String
STRING_TRUE
=
"true"
;
public
static
final
String
SEARCH_WEIGHT_ATTR_NAME
=
"searchWeight"
;
public
static
final
String
INDEX_TYPE_ATTR_NAME
=
"indexType"
;
public
static
final
String
ATTRDEF_OPTION_SOFT_REFERENCE
=
"isSoftReference"
;
public
static
final
String
ATTRDEF_OPTION_APPEND_ON_PARTIAL_UPDATE
=
"isAppendOnPartialUpdate"
;
private
final
String
STRING_TRUE
=
"true"
;
/**
* single-valued attribute or multi-valued attribute.
...
...
@@ -520,6 +521,13 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
}
@JsonIgnore
public
boolean
isAppendOnPartialUpdate
()
{
String
val
=
getOption
(
AtlasAttributeDef
.
ATTRDEF_OPTION_APPEND_ON_PARTIAL_UPDATE
);
return
val
!=
null
&&
Boolean
.
valueOf
(
val
);
}
@JsonIgnore
public
void
setOption
(
String
name
,
String
value
)
{
if
(
this
.
options
==
null
)
{
this
.
options
=
new
HashMap
<>();
...
...
intg/src/test/java/org/apache/atlas/TestUtilsV2.java
View file @
f5cd728d
...
...
@@ -627,6 +627,13 @@ public final class TestUtilsV2 {
}
public
static
AtlasTypesDef
defineSimpleAttrType
()
{
AtlasAttributeDef
attrPuArray
=
new
AtlasAttributeDef
(
"puArray"
,
"array<string>"
,
true
,
SINGLE
,
1
,
1
,
false
,
false
,
false
,
null
);
AtlasAttributeDef
attrPuMap
=
new
AtlasAttributeDef
(
"puMap"
,
"map<string,string>"
,
true
,
SINGLE
,
1
,
1
,
false
,
false
,
false
,
null
);
attrPuArray
.
setOption
(
AtlasAttributeDef
.
ATTRDEF_OPTION_APPEND_ON_PARTIAL_UPDATE
,
"true"
);
attrPuMap
.
setOption
(
AtlasAttributeDef
.
ATTRDEF_OPTION_APPEND_ON_PARTIAL_UPDATE
,
"true"
);
AtlasEntityDef
simpleAttributesEntityType
=
createClassTypeDef
(
ENTITY_TYPE_WITH_SIMPLE_ATTR
,
ENTITY_TYPE_WITH_SIMPLE_ATTR
+
"_description"
,
null
,
createUniqueRequiredAttrDef
(
"name"
,
"string"
),
...
...
@@ -641,7 +648,11 @@ public final class TestUtilsV2 {
false
,
false
,
false
,
null
),
new
AtlasAttributeDef
(
"mapOfStrings"
,
"map<string,string>"
,
true
,
SINGLE
,
1
,
1
,
false
,
false
,
false
,
null
)
true
,
SINGLE
,
1
,
1
,
false
,
false
,
false
,
null
),
attrPuArray
,
attrPuMap
);
AtlasTypesDef
ret
=
AtlasTypeUtil
.
getTypesDef
(
Collections
.<
AtlasEnumDef
>
emptyList
(),
...
...
@@ -659,6 +670,8 @@ public final class TestUtilsV2 {
entity
.
setAttribute
(
"stringAtrr"
,
"DummyThree"
);
entity
.
setAttribute
(
"arrayOfStrings"
,
Arrays
.
asList
(
"DummyOne"
,
"DummyTwo"
));
entity
.
setAttribute
(
"mapOfStrings"
,
Collections
.
singletonMap
(
"one"
,
"DummyString"
));
entity
.
setAttribute
(
"puArray"
,
Arrays
.
asList
(
"DummyOne"
,
"DummyTwo"
));
entity
.
setAttribute
(
"puMap"
,
Collections
.
singletonMap
(
"one"
,
"DummyString"
));
return
new
AtlasEntityWithExtInfo
(
entity
);
}
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v2/EntityGraphMapper.java
View file @
f5cd728d
...
...
@@ -284,6 +284,8 @@ public class EntityGraphMapper {
}
}
EntityOperation
updateType
=
isPartialUpdate
?
PARTIAL_UPDATE
:
UPDATE
;
if
(
CollectionUtils
.
isNotEmpty
(
updatedEntities
))
{
for
(
AtlasEntity
updatedEntity
:
updatedEntities
)
{
String
guid
=
updatedEntity
.
getGuid
();
...
...
@@ -292,14 +294,10 @@ public class EntityGraphMapper {
mapRelationshipAttributes
(
updatedEntity
,
entityType
,
vertex
,
UPDATE
,
context
);
mapAttributes
(
updatedEntity
,
entityType
,
vertex
,
UPDATE
,
context
);
mapAttributes
(
updatedEntity
,
entityType
,
vertex
,
updateType
,
context
);
setCustomAttributes
(
vertex
,
updatedEntity
);
if
(
isPartialUpdate
)
{
resp
.
addEntity
(
PARTIAL_UPDATE
,
constructHeader
(
updatedEntity
,
entityType
,
vertex
));
}
else
{
resp
.
addEntity
(
UPDATE
,
constructHeader
(
updatedEntity
,
entityType
,
vertex
));
}
resp
.
addEntity
(
updateType
,
constructHeader
(
updatedEntity
,
entityType
,
vertex
));
if
(
replaceClassifications
)
{
deleteClassifications
(
guid
);
...
...
@@ -325,12 +323,7 @@ public class EntityGraphMapper {
}
for
(
AtlasEntityHeader
entity
:
req
.
getUpdatedEntities
())
{
if
(
isPartialUpdate
)
{
resp
.
addEntity
(
PARTIAL_UPDATE
,
entity
);
}
else
{
resp
.
addEntity
(
UPDATE
,
entity
);
}
resp
.
addEntity
(
updateType
,
entity
);
}
RequestContext
.
get
().
endMetricRecord
(
metric
);
...
...
@@ -623,7 +616,7 @@ public class EntityGraphMapper {
mapAttribute
(
attribute
,
attrValue
,
vertex
,
op
,
context
);
}
}
else
if
(
op
.
equals
(
UPDATE
))
{
}
else
if
(
op
.
equals
(
UPDATE
)
||
op
.
equals
(
PARTIAL_UPDATE
)
)
{
for
(
String
attrName
:
struct
.
getAttributes
().
keySet
())
{
AtlasAttribute
attribute
=
structType
.
getAttribute
(
attrName
);
...
...
@@ -665,7 +658,7 @@ public class EntityGraphMapper {
mapAttribute
(
attribute
,
attrValue
,
vertex
,
op
,
context
);
}
}
else
if
(
op
.
equals
(
UPDATE
))
{
}
else
if
(
op
.
equals
(
UPDATE
)
||
op
.
equals
(
PARTIAL_UPDATE
)
)
{
// relationship attributes mapping
for
(
String
attrName
:
entityType
.
getRelationshipAttributes
().
keySet
())
{
if
(
entity
.
hasRelationshipAttribute
(
attrName
))
{
...
...
@@ -1251,6 +1244,22 @@ public class EntityGraphMapper {
boolean
isReference
=
isReference
(
mapType
.
getValueType
());
boolean
isSoftReference
=
ctx
.
getAttribute
().
getAttributeDef
().
isSoftReferenced
();
if
(
PARTIAL_UPDATE
.
equals
(
ctx
.
getOp
())
&&
attribute
.
getAttributeDef
().
isAppendOnPartialUpdate
()
&&
MapUtils
.
isNotEmpty
(
currentMap
))
{
if
(
MapUtils
.
isEmpty
(
newVal
))
{
newVal
=
new
HashMap
<>(
currentMap
);
}
else
{
Map
<
Object
,
Object
>
mergedVal
=
new
HashMap
<>(
currentMap
);
for
(
Map
.
Entry
<
Object
,
Object
>
entry
:
newVal
.
entrySet
())
{
String
newKey
=
entry
.
getKey
().
toString
();
mergedVal
.
put
(
newKey
,
entry
.
getValue
());
}
newVal
=
mergedVal
;
}
}
boolean
isNewValNull
=
newVal
==
null
;
if
(
isNewValNull
)
{
...
...
@@ -1334,7 +1343,6 @@ public class EntityGraphMapper {
Cardinality
cardinality
=
attribute
.
getAttributeDef
().
getCardinality
();
List
<
Object
>
newElementsCreated
=
new
ArrayList
<>();
List
<
Object
>
currentElements
;
boolean
isNewElementsNull
=
newElements
==
null
;
if
(
isReference
&&
!
isSoftReference
)
{
currentElements
=
(
List
)
getCollectionElementsUsingRelationship
(
ctx
.
getReferringVertex
(),
attribute
);
...
...
@@ -1342,6 +1350,20 @@ public class EntityGraphMapper {
currentElements
=
(
List
)
getArrayElementsProperty
(
elementType
,
isSoftReference
,
ctx
.
getReferringVertex
(),
ctx
.
getVertexProperty
());
}
if
(
PARTIAL_UPDATE
.
equals
(
ctx
.
getOp
())
&&
attribute
.
getAttributeDef
().
isAppendOnPartialUpdate
()
&&
CollectionUtils
.
isNotEmpty
(
currentElements
))
{
if
(
CollectionUtils
.
isEmpty
(
newElements
))
{
newElements
=
new
ArrayList
<>(
currentElements
);
}
else
{
List
<
Object
>
mergedVal
=
new
ArrayList
<>(
currentElements
);
mergedVal
.
addAll
(
newElements
);
newElements
=
mergedVal
;
}
}
boolean
isNewElementsNull
=
newElements
==
null
;
if
(
isNewElementsNull
)
{
newElements
=
new
ArrayList
();
}
...
...
repository/src/test/java/org/apache/atlas/repository/store/graph/v2/AtlasComplexAttributesTest.java
View file @
f5cd728d
This diff is collapsed.
Click to expand it.
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