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
d9f62cb5
Commit
d9f62cb5
authored
Jun 15, 2017
by
rdsolani
Committed by
Madhan Neethiraj
Jun 16, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-1863: added support for default value for attributes
Signed-off-by:
Madhan Neethiraj
<
madhan@apache.org
>
parent
1de6016d
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
158 additions
and
9 deletions
+158
-9
AtlasStructDef.java
...n/java/org/apache/atlas/model/typedef/AtlasStructDef.java
+21
-2
AtlasArrayType.java
intg/src/main/java/org/apache/atlas/type/AtlasArrayType.java
+4
-0
AtlasEntityType.java
.../src/main/java/org/apache/atlas/type/AtlasEntityType.java
+8
-0
AtlasMapType.java
intg/src/main/java/org/apache/atlas/type/AtlasMapType.java
+4
-0
AtlasStructType.java
.../src/main/java/org/apache/atlas/type/AtlasStructType.java
+10
-1
AtlasType.java
intg/src/main/java/org/apache/atlas/type/AtlasType.java
+4
-0
TestUtilsV2.java
intg/src/test/java/org/apache/atlas/TestUtilsV2.java
+53
-0
TestAtlasArrayType.java
...c/test/java/org/apache/atlas/type/TestAtlasArrayType.java
+1
-1
AtlasStructDefStoreV1.java
...tlas/repository/store/graph/v1/AtlasStructDefStoreV1.java
+2
-0
EntityGraphMapper.java
...he/atlas/repository/store/graph/v1/EntityGraphMapper.java
+8
-5
AtlasEntityStoreV1Test.java
...las/repository/store/graph/v1/AtlasEntityStoreV1Test.java
+43
-0
No files found.
intg/src/main/java/org/apache/atlas/model/typedef/AtlasStructDef.java
View file @
d9f62cb5
...
...
@@ -271,16 +271,23 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
private
int
valuesMaxCount
;
private
boolean
isUnique
;
private
boolean
isIndexable
;
private
String
defaultValue
;
private
List
<
AtlasConstraintDef
>
constraints
;
public
AtlasAttributeDef
()
{
this
(
null
,
null
);
}
public
AtlasAttributeDef
(
String
name
,
String
typeName
)
{
this
(
name
,
typeName
,
false
,
Cardinality
.
SINGLE
,
COUNT_NOT_SET
,
COUNT_NOT_SET
,
false
,
false
,
null
);
}
public
AtlasAttributeDef
(
String
name
,
String
typeName
,
boolean
isOptional
,
Cardinality
cardinality
,
int
valuesMinCount
,
int
valuesMaxCount
,
boolean
isUnique
,
boolean
isIndexable
,
List
<
AtlasConstraintDef
>
constraints
)
{
this
(
name
,
typeName
,
isOptional
,
cardinality
,
valuesMinCount
,
valuesMaxCount
,
isUnique
,
isIndexable
,
null
,
constraints
);
}
public
AtlasAttributeDef
(
String
name
,
String
typeName
,
boolean
isOptional
,
Cardinality
cardinality
,
int
valuesMinCount
,
int
valuesMaxCount
,
boolean
isUnique
,
boolean
isIndexable
,
int
valuesMinCount
,
int
valuesMaxCount
,
boolean
isUnique
,
boolean
isIndexable
,
String
defaultValue
,
List
<
AtlasConstraintDef
>
constraints
)
{
setName
(
name
);
setTypeName
(
typeName
);
...
...
@@ -290,6 +297,7 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
setValuesMaxCount
(
valuesMaxCount
);
setIsUnique
(
isUnique
);
setIsIndexable
(
isIndexable
);
setDefaultValue
(
defaultValue
);
setConstraints
(
constraints
);
}
...
...
@@ -303,6 +311,7 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
setValuesMaxCount
(
other
.
getValuesMaxCount
());
setIsUnique
(
other
.
getIsUnique
());
setIsIndexable
(
other
.
getIsIndexable
());
setDefaultValue
(
other
.
getDefaultValue
());
setConstraints
(
other
.
getConstraints
());
}
}
...
...
@@ -365,6 +374,14 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
return
isIndexable
;
}
public
String
getDefaultValue
(){
return
defaultValue
;
}
public
void
setDefaultValue
(
String
defaultValue
){
this
.
defaultValue
=
defaultValue
;
}
public
void
setIsIndexable
(
boolean
idexable
)
{
isIndexable
=
idexable
;
}
...
...
@@ -409,6 +426,7 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
sb
.
append
(
", valuesMaxCount="
).
append
(
valuesMaxCount
);
sb
.
append
(
", isUnique="
).
append
(
isUnique
);
sb
.
append
(
", isIndexable="
).
append
(
isIndexable
);
sb
.
append
(
", defaultValue="
).
append
(
defaultValue
);
sb
.
append
(
", constraints=["
);
if
(
CollectionUtils
.
isNotEmpty
(
constraints
))
{
int
i
=
0
;
...
...
@@ -439,12 +457,13 @@ public class AtlasStructDef extends AtlasBaseTypeDef implements Serializable {
Objects
.
equals
(
name
,
that
.
name
)
&&
Objects
.
equals
(
typeName
,
that
.
typeName
)
&&
cardinality
==
that
.
cardinality
&&
Objects
.
equals
(
defaultValue
,
that
.
defaultValue
)
&&
Objects
.
equals
(
constraints
,
that
.
constraints
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
name
,
typeName
,
isOptional
,
cardinality
,
valuesMinCount
,
valuesMaxCount
,
isUnique
,
isIndexable
,
constraints
);
return
Objects
.
hash
(
name
,
typeName
,
isOptional
,
cardinality
,
valuesMinCount
,
valuesMaxCount
,
isUnique
,
isIndexable
,
defaultValue
,
constraints
);
}
@Override
...
...
intg/src/main/java/org/apache/atlas/type/AtlasArrayType.java
View file @
d9f62cb5
...
...
@@ -201,6 +201,10 @@ public class AtlasArrayType extends AtlasType {
return
null
;
}
if
(
obj
instanceof
String
){
obj
=
AtlasType
.
fromJson
(
obj
.
toString
(),
List
.
class
);
}
if
(
obj
instanceof
List
||
obj
instanceof
Set
)
{
List
<
Object
>
ret
=
new
ArrayList
<>();
...
...
intg/src/main/java/org/apache/atlas/type/AtlasEntityType.java
View file @
d9f62cb5
...
...
@@ -146,6 +146,14 @@ public class AtlasEntityType extends AtlasStructType {
}
@Override
public
AtlasEntity
createDefaultValue
(
Object
defaultValue
){
AtlasEntity
ret
=
new
AtlasEntity
(
entityDef
.
getName
());
populateDefaultValues
(
ret
);
return
ret
;
}
@Override
public
boolean
isValidValue
(
Object
obj
)
{
if
(
obj
!=
null
)
{
for
(
AtlasEntityType
superType
:
superTypes
)
{
...
...
intg/src/main/java/org/apache/atlas/type/AtlasMapType.java
View file @
d9f62cb5
...
...
@@ -148,6 +148,10 @@ public class AtlasMapType extends AtlasType {
return
null
;
}
if
(
obj
instanceof
String
)
{
obj
=
AtlasType
.
fromJson
(
obj
.
toString
(),
Map
.
class
);
}
if
(
obj
instanceof
Map
)
{
Map
<
Object
,
Object
>
ret
=
new
HashMap
<>();
...
...
intg/src/main/java/org/apache/atlas/type/AtlasStructType.java
View file @
d9f62cb5
...
...
@@ -186,6 +186,15 @@ public class AtlasStructType extends AtlasType {
return
ret
;
}
@Override
public
Object
createDefaultValue
(
Object
defaultValue
)
{
AtlasStruct
ret
=
new
AtlasStruct
(
structDef
.
getName
());
populateDefaultValues
(
ret
);
return
ret
;
}
public
Map
<
String
,
AtlasAttribute
>
getAllAttributes
()
{
return
allAttributes
;
}
...
...
@@ -480,7 +489,7 @@ public class AtlasStructType extends AtlasType {
if
(
attribute
!=
null
)
{
AtlasType
dataType
=
attribute
.
getAttributeType
();
ret
=
dataType
.
createDefaultValue
();
ret
=
dataType
.
createDefaultValue
(
attributeDef
.
getDefaultValue
()
);
}
}
...
...
intg/src/main/java/org/apache/atlas/type/AtlasType.java
View file @
d9f62cb5
...
...
@@ -66,6 +66,10 @@ public abstract class AtlasType {
return
createDefaultValue
();
}
public
Object
createDefaultValue
(
Object
val
){
return
val
==
null
?
createDefaultValue
()
:
getNormalizedValue
(
val
);
}
public
abstract
boolean
isValidValue
(
Object
obj
);
public
abstract
Object
getNormalizedValue
(
Object
obj
);
...
...
intg/src/test/java/org/apache/atlas/TestUtilsV2.java
View file @
d9f62cb5
...
...
@@ -35,6 +35,7 @@ import org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality
;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef
;
import
org.apache.atlas.model.typedef.AtlasTypesDef
;
import
org.apache.atlas.type.AtlasStructType
;
import
org.apache.atlas.type.AtlasTypeUtil
;
import
org.apache.commons.lang.RandomStringUtils
;
...
...
@@ -877,6 +878,58 @@ public final class TestUtilsV2 {
return
ret
;
}
public
static
AtlasEntityWithExtInfo
createprimitiveEntityV2
()
{
AtlasEntity
defaultprimitive
=
new
AtlasEntity
(
createPrimitiveEntityDef
());
defaultprimitive
.
setAttribute
(
"name"
,
"testname"
);
defaultprimitive
.
setAttribute
(
"description"
,
"test"
);
defaultprimitive
.
setAttribute
(
"check"
,
"check"
);
AtlasEntityWithExtInfo
ret
=
new
AtlasEntityWithExtInfo
(
defaultprimitive
);
return
ret
;
}
public
static
AtlasEntityDef
createPrimitiveEntityDef
()
{
AtlasEntityDef
newtestEntityDef
=
new
AtlasEntityDef
(
"newtest"
);
AtlasAttributeDef
attrName
=
new
AtlasAttributeDef
(
"name"
,
AtlasBaseTypeDef
.
ATLAS_TYPE_STRING
);
AtlasAttributeDef
attrDescription
=
new
AtlasAttributeDef
(
"description"
,
AtlasBaseTypeDef
.
ATLAS_TYPE_STRING
);
attrDescription
.
setIsOptional
(
false
);
AtlasAttributeDef
attrcheck
=
new
AtlasAttributeDef
(
"check"
,
AtlasBaseTypeDef
.
ATLAS_TYPE_STRING
);
attrcheck
.
setIsOptional
(
true
);
AtlasAttributeDef
attrSourceCode
=
new
AtlasAttributeDef
(
"sourcecode"
,
AtlasBaseTypeDef
.
ATLAS_TYPE_STRING
);
attrSourceCode
.
setDefaultValue
(
"Hello World"
);
attrSourceCode
.
setIsOptional
(
true
);
AtlasAttributeDef
attrCost
=
new
AtlasAttributeDef
(
"Cost"
,
AtlasBaseTypeDef
.
ATLAS_TYPE_INT
);
attrCost
.
setIsOptional
(
true
);
attrCost
.
setDefaultValue
(
"30"
);
AtlasAttributeDef
attrDiskUsage
=
new
AtlasAttributeDef
(
"diskUsage"
,
AtlasBaseTypeDef
.
ATLAS_TYPE_FLOAT
);
attrDiskUsage
.
setIsOptional
(
true
);
attrDiskUsage
.
setDefaultValue
(
"70.50"
);
AtlasAttributeDef
attrisStoreUse
=
new
AtlasAttributeDef
(
"isstoreUse"
,
AtlasBaseTypeDef
.
ATLAS_TYPE_BOOLEAN
);
attrisStoreUse
.
setIsOptional
(
true
);
attrisStoreUse
.
setDefaultValue
(
"true"
);
newtestEntityDef
.
addAttribute
(
attrName
);
newtestEntityDef
.
addAttribute
(
attrDescription
);
newtestEntityDef
.
addAttribute
(
attrcheck
);
newtestEntityDef
.
addAttribute
(
attrSourceCode
);
newtestEntityDef
.
addAttribute
(
attrCost
);
newtestEntityDef
.
addAttribute
(
attrDiskUsage
);
newtestEntityDef
.
addAttribute
(
attrisStoreUse
);
return
newtestEntityDef
;
}
public
static
AtlasEntity
createColumnEntity
(
AtlasEntity
tableEntity
)
{
return
createColumnEntity
(
tableEntity
,
"col"
+
seq
.
addAndGet
(
1
));
}
...
...
intg/src/test/java/org/apache/atlas/type/TestAtlasArrayType.java
View file @
d9f62cb5
...
...
@@ -59,7 +59,7 @@ public class TestAtlasArrayType {
};
invalidValues
=
new
Object
[]
{
new
String
[]
{
"1"
,
"abcd"
,
"3"
,
"xyz"
,
"5"
},
"1"
,
Byte
.
valueOf
((
byte
)
1
),
Short
.
valueOf
((
short
)
1
),
Byte
.
valueOf
((
byte
)
1
),
Short
.
valueOf
((
short
)
1
),
Integer
.
valueOf
(
1
),
Long
.
valueOf
(
1L
),
Float
.
valueOf
(
1
),
Double
.
valueOf
(
1
),
BigInteger
.
valueOf
(
1
),
BigDecimal
.
valueOf
(
1
),
};
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/AtlasStructDefStoreV1.java
View file @
d9f62cb5
...
...
@@ -511,6 +511,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
attribInfo
.
put
(
"isIndexable"
,
attributeDef
.
getIsIndexable
());
attribInfo
.
put
(
"isComposite"
,
attribute
.
isOwnedRef
());
attribInfo
.
put
(
"reverseAttributeName"
,
attribute
.
getInverseRefAttributeName
());
attribInfo
.
put
(
"defaultValue"
,
attributeDef
.
getDefaultValue
());
final
int
lower
;
final
int
upper
;
...
...
@@ -549,6 +550,7 @@ public class AtlasStructDefStoreV1 extends AtlasAbstractDefStoreV1 implements At
ret
.
setTypeName
((
String
)
attribInfo
.
get
(
"dataType"
));
ret
.
setIsUnique
((
Boolean
)
attribInfo
.
get
(
"isUnique"
));
ret
.
setIsIndexable
((
Boolean
)
attribInfo
.
get
(
"isIndexable"
));
ret
.
setDefaultValue
((
String
)
attribInfo
.
get
(
"defaultValue"
));
if
((
Boolean
)
attribInfo
.
get
(
"isComposite"
))
{
ret
.
addConstraint
(
new
AtlasConstraintDef
(
AtlasConstraintDef
.
CONSTRAINT_TYPE_OWNED_REF
));
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v1/EntityGraphMapper.java
View file @
d9f62cb5
...
...
@@ -33,7 +33,6 @@ import org.apache.atlas.model.instance.EntityMutations.EntityOperation;
import
org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef
;
import
org.apache.atlas.repository.Constants
;
import
org.apache.atlas.repository.RepositoryException
;
import
org.apache.atlas.repository.graph.AtlasGraphProvider
;
import
org.apache.atlas.repository.graph.GraphHelper
;
import
org.apache.atlas.repository.graphdb.AtlasEdge
;
import
org.apache.atlas.repository.graphdb.AtlasGraph
;
...
...
@@ -259,13 +258,17 @@ public class EntityGraphMapper {
private
void
mapAttribute
(
AtlasAttribute
attribute
,
Object
attrValue
,
AtlasVertex
vertex
,
EntityOperation
op
,
EntityMutationContext
context
)
throws
AtlasBaseException
{
if
(
attrValue
==
null
)
{
AtlasAttributeDef
attributeDef
=
attribute
.
getAttributeDef
();
AtlasType
attrType
=
attribute
.
getAttributeType
();
if
(
attrType
.
getTypeCategory
()
==
TypeCategory
.
PRIMITIVE
)
{
if
(
attribute
.
getAttributeDef
().
getIsOptional
()
)
{
attrValue
=
attrType
.
create
OptionalDefaultValue
(
);
if
(
attribute
Def
.
getDefaultValue
()
!=
null
)
{
attrValue
=
attrType
.
create
DefaultValue
(
attributeDef
.
getDefaultValue
()
);
}
else
{
attrValue
=
attrType
.
createDefaultValue
();
if
(
attribute
.
getAttributeDef
().
getIsOptional
())
{
attrValue
=
attrType
.
createOptionalDefaultValue
();
}
else
{
attrValue
=
attrType
.
createDefaultValue
();
}
}
}
}
...
...
repository/src/test/java/org/apache/atlas/repository/store/graph/v1/AtlasEntityStoreV1Test.java
View file @
d9f62cb5
...
...
@@ -77,6 +77,7 @@ import static org.apache.atlas.TestUtils.COLUMNS_ATTR_NAME;
import
static
org
.
apache
.
atlas
.
TestUtils
.
COLUMN_TYPE
;
import
static
org
.
apache
.
atlas
.
TestUtils
.
NAME
;
import
static
org
.
apache
.
atlas
.
TestUtils
.
randomString
;
import
static
org
.
apache
.
atlas
.
TestUtilsV2
.
STORAGE_DESC_TYPE
;
import
static
org
.
apache
.
atlas
.
TestUtilsV2
.
TABLE_TYPE
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
testng
.
Assert
.
assertEquals
;
...
...
@@ -104,6 +105,7 @@ public class AtlasEntityStoreV1Test {
private
AtlasEntitiesWithExtInfo
deptEntity
;
private
AtlasEntityWithExtInfo
dbEntity
;
private
AtlasEntityWithExtInfo
tblEntity
;
private
AtlasEntityWithExtInfo
primitiveEntity
;
AtlasEntityChangeNotifier
mockChangeNotifier
=
mock
(
AtlasEntityChangeNotifier
.
class
);
@Inject
...
...
@@ -130,6 +132,14 @@ public class AtlasEntityStoreV1Test {
deptEntity
=
TestUtilsV2
.
createDeptEg2
();
dbEntity
=
TestUtilsV2
.
createDBEntityV2
();
tblEntity
=
TestUtilsV2
.
createTableEntityV2
(
dbEntity
.
getEntity
());
AtlasTypesDef
typesDef11
=
new
AtlasTypesDef
();
List
primitiveEntityDef
=
new
ArrayList
<
AtlasEntityDef
>();
primitiveEntityDef
.
add
(
TestUtilsV2
.
createPrimitiveEntityDef
());
typesDef11
.
setEntityDefs
(
primitiveEntityDef
);
typeDefStore
.
createTypesDef
(
typesDef11
);
primitiveEntity
=
TestUtilsV2
.
createprimitiveEntityV2
();
}
@AfterClass
...
...
@@ -144,6 +154,39 @@ public class AtlasEntityStoreV1Test {
}
@Test
public
void
testDefaultValueForPrimitiveTypes
()
throws
Exception
{
init
();
EntityMutationResponse
response
=
entityStore
.
createOrUpdate
(
new
AtlasEntityStream
(
primitiveEntity
),
false
);
List
<
AtlasEntityHeader
>
entitiesCreatedResponse
=
response
.
getEntitiesByOperation
(
EntityOperation
.
CREATE
);
final
Map
<
EntityOperation
,
List
<
AtlasEntityHeader
>>
entitiesMutated
=
response
.
getMutatedEntities
();
List
<
AtlasEntityHeader
>
entitiesCreatedwithdefault
=
entitiesMutated
.
get
(
EntityOperation
.
CREATE
);
AtlasEntity
entityCreated
=
getEntityFromStore
(
entitiesCreatedResponse
.
get
(
0
));
Map
attributesMap
=
entityCreated
.
getAttributes
();
String
description
=
(
String
)
attributesMap
.
get
(
"description"
);
String
check
=
(
String
)
attributesMap
.
get
(
"check"
);
String
sourceCode
=
(
String
)
attributesMap
.
get
(
"sourcecode"
);
float
diskUsage
=
(
float
)
attributesMap
.
get
(
"diskUsage"
);
boolean
isstoreUse
=
(
boolean
)
attributesMap
.
get
(
"isstoreUse"
);
int
cost
=
(
int
)
attributesMap
.
get
(
"Cost"
);
assertEquals
(
description
,
"test"
);
assertEquals
(
check
,
"check"
);
//defaultValue
assertEquals
(
diskUsage
,
70.5f
);
assertEquals
(
isstoreUse
,
true
);
assertEquals
(
sourceCode
,
"Hello World"
);
assertEquals
(
cost
,
30
);
}
@Test
public
void
testCreate
()
throws
Exception
{
init
();
EntityMutationResponse
response
=
entityStore
.
createOrUpdate
(
new
AtlasEntityStream
(
deptEntity
),
false
);
...
...
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