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
0ed9f0e2
Commit
0ed9f0e2
authored
Aug 25, 2018
by
Sarath Subramanian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-2838: Replace GraphHelper.encodeProperty() with AtlasGraphUtilsV2.encodeProperty()
parent
b6a664df
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
43 deletions
+41
-43
AtlasStructType.java
.../src/main/java/org/apache/atlas/type/AtlasStructType.java
+7
-4
GraphBackedSearchIndexer.java
...ache/atlas/repository/graph/GraphBackedSearchIndexer.java
+3
-2
GraphHelper.java
...n/java/org/apache/atlas/repository/graph/GraphHelper.java
+10
-21
AtlasGraphUtilsV2.java
...he/atlas/repository/store/graph/v2/AtlasGraphUtilsV2.java
+2
-6
AtlasStructDefStoreV2.java
...tlas/repository/store/graph/v2/AtlasStructDefStoreV2.java
+19
-10
No files found.
intg/src/main/java/org/apache/atlas/type/AtlasStructType.java
View file @
0ed9f0e2
...
...
@@ -863,10 +863,13 @@ public class AtlasStructType extends AtlasType {
// Keys copied from org.janusgraph.graphdb.types.system.SystemTypeManager.RESERVED_CHARS
// JanusGraph checks that these chars are not part of any keys hence encoding
private
static
String
[][]
RESERVED_CHAR_ENCODE_MAP
=
new
String
[][]
{
new
String
[]
{
"{"
,
"_o"
},
new
String
[]
{
"}"
,
"_c"
},
new
String
[]
{
"\""
,
"_q"
},
// also including Titan reserved characters to support migrated property keys
private
static
String
[][]
RESERVED_CHAR_ENCODE_MAP
=
new
String
[][]{
new
String
[]
{
"{"
,
"_o"
},
new
String
[]
{
"}"
,
"_c"
},
new
String
[]
{
"\""
,
"_q"
},
new
String
[]
{
"$"
,
"_d"
},
//titan reserved character
new
String
[]
{
"%"
,
"_p"
},
//titan reserved characters
};
private
static
final
char
[]
IDX_QRY_OFFENDING_CHARS
=
{
'@'
,
'/'
,
' '
,
'-'
};
...
...
repository/src/main/java/org/apache/atlas/repository/graph/GraphBackedSearchIndexer.java
View file @
0ed9f0e2
...
...
@@ -42,6 +42,7 @@ import org.apache.atlas.repository.graphdb.AtlasGraph;
import
org.apache.atlas.repository.graphdb.AtlasGraphIndex
;
import
org.apache.atlas.repository.graphdb.AtlasGraphManagement
;
import
org.apache.atlas.repository.graphdb.AtlasPropertyKey
;
import
org.apache.atlas.repository.store.graph.v2.AtlasGraphUtilsV2
;
import
org.apache.atlas.type.AtlasArrayType
;
import
org.apache.atlas.type.AtlasClassificationType
;
import
org.apache.atlas.type.AtlasEntityType
;
...
...
@@ -315,7 +316,7 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang
}
private
void
createIndexForAttribute
(
AtlasGraphManagement
management
,
String
typeName
,
AtlasAttributeDef
attributeDef
)
{
final
String
propertyName
=
GraphHelper
.
encodePropertyKey
(
typeName
+
"."
+
attributeDef
.
getName
());
final
String
propertyName
=
AtlasGraphUtilsV2
.
encodePropertyKey
(
typeName
+
"."
+
attributeDef
.
getName
());
AtlasCardinality
cardinality
=
toAtlasCardinality
(
attributeDef
.
getCardinality
());
boolean
isUnique
=
attributeDef
.
getIsUnique
();
boolean
isIndexable
=
attributeDef
.
getIsIndexable
();
...
...
@@ -729,7 +730,7 @@ public class GraphBackedSearchIndexer implements SearchIndexer, ActiveStateChang
}
private
void
cleanupIndexForAttribute
(
AtlasGraphManagement
management
,
String
typeName
,
AtlasAttributeDef
attributeDef
)
{
final
String
propertyName
=
GraphHelper
.
encodePropertyKey
(
typeName
+
"."
+
attributeDef
.
getName
());
final
String
propertyName
=
AtlasGraphUtilsV2
.
encodePropertyKey
(
typeName
+
"."
+
attributeDef
.
getName
());
String
attribTypeName
=
attributeDef
.
getTypeName
();
boolean
isBuiltInType
=
AtlasTypeUtil
.
isBuiltInType
(
attribTypeName
);
boolean
isArrayType
=
isArrayType
(
attribTypeName
);
...
...
repository/src/main/java/org/apache/atlas/repository/graph/GraphHelper.java
View file @
0ed9f0e2
...
...
@@ -647,7 +647,7 @@ public final class GraphHelper {
}
public
static
<
T
extends
AtlasElement
>
void
setProperty
(
T
element
,
String
propertyName
,
Object
value
)
{
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
String
actualPropertyName
=
AtlasGraphUtilsV2
.
encodePropertyKey
(
propertyName
);
String
elementStr
=
null
;
...
...
@@ -688,7 +688,7 @@ public final class GraphHelper {
* @return
*/
public
static
<
T
>
T
getSingleValuedProperty
(
AtlasElement
element
,
String
propertyName
,
Class
<
T
>
clazz
)
{
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
String
actualPropertyName
=
AtlasGraphUtilsV2
.
encodePropertyKey
(
propertyName
);
if
(
LOG
.
isTraceEnabled
())
{
LOG
.
trace
(
"Reading property {} from {}"
,
actualPropertyName
,
string
(
element
));
...
...
@@ -699,7 +699,7 @@ public final class GraphHelper {
public
static
Object
getProperty
(
AtlasVertex
<?,?>
vertex
,
String
propertyName
)
{
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
String
actualPropertyName
=
AtlasGraphUtilsV2
.
encodePropertyKey
(
propertyName
);
if
(
LOG
.
isTraceEnabled
())
{
LOG
.
trace
(
"Reading property {} from {}"
,
actualPropertyName
,
string
(
vertex
));
...
...
@@ -714,7 +714,7 @@ public final class GraphHelper {
}
public
static
Object
getProperty
(
AtlasEdge
<?,?>
edge
,
String
propertyName
)
{
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
String
actualPropertyName
=
AtlasGraphUtilsV2
.
encodePropertyKey
(
propertyName
);
if
(
LOG
.
isTraceEnabled
())
{
LOG
.
trace
(
"Reading property {} from {}"
,
actualPropertyName
,
string
(
edge
));
...
...
@@ -740,7 +740,7 @@ public final class GraphHelper {
* @param value
*/
public
static
void
addProperty
(
AtlasVertex
vertex
,
String
propertyName
,
Object
value
)
{
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
String
actualPropertyName
=
AtlasGraphUtilsV2
.
encodePropertyKey
(
propertyName
);
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Adding property {} = \"{}\" to vertex {}"
,
actualPropertyName
,
value
,
string
(
vertex
));
...
...
@@ -1686,7 +1686,7 @@ public final class GraphHelper {
// map elements for primitive types
public
static
Map
<
String
,
Object
>
getPrimitiveMap
(
AtlasVertex
instanceVertex
,
String
propertyName
)
{
Map
<
String
,
Object
>
ret
=
instanceVertex
.
getProperty
(
encodePropertyKey
(
propertyName
),
Map
.
class
);
Map
<
String
,
Object
>
ret
=
instanceVertex
.
getProperty
(
AtlasGraphUtilsV2
.
encodePropertyKey
(
propertyName
),
Map
.
class
);
if
(
ret
==
null
)
{
ret
=
new
HashMap
<>();
...
...
@@ -1788,17 +1788,6 @@ public final class GraphHelper {
}});
public
static
String
encodePropertyKey
(
String
key
)
{
if
(
StringUtils
.
isBlank
(
key
))
{
return
key
;
}
for
(
String
str
:
RESERVED_CHARS_ENCODE_MAP
.
keySet
())
{
key
=
key
.
replace
(
str
,
RESERVED_CHARS_ENCODE_MAP
.
get
(
str
));
}
return
key
;
}
public
static
String
decodePropertyKey
(
String
key
)
{
if
(
StringUtils
.
isBlank
(
key
))
{
return
key
;
...
...
@@ -1840,25 +1829,25 @@ public final class GraphHelper {
public
static
void
setListPropertyFromElementIds
(
AtlasVertex
<?,
?>
instanceVertex
,
String
propertyName
,
List
<
AtlasElement
>
elements
)
{
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
String
actualPropertyName
=
AtlasGraphUtilsV2
.
encodePropertyKey
(
propertyName
);
instanceVertex
.
setPropertyFromElementsIds
(
actualPropertyName
,
elements
);
}
public
static
void
setPropertyFromElementId
(
AtlasVertex
<?,
?>
instanceVertex
,
String
propertyName
,
AtlasElement
value
)
{
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
String
actualPropertyName
=
AtlasGraphUtilsV2
.
encodePropertyKey
(
propertyName
);
instanceVertex
.
setPropertyFromElementId
(
actualPropertyName
,
value
);
}
public
static
void
setListProperty
(
AtlasVertex
instanceVertex
,
String
propertyName
,
ArrayList
<
String
>
value
)
{
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
String
actualPropertyName
=
AtlasGraphUtilsV2
.
encodePropertyKey
(
propertyName
);
instanceVertex
.
setListProperty
(
actualPropertyName
,
value
);
}
public
static
List
<
String
>
getListProperty
(
AtlasVertex
instanceVertex
,
String
propertyName
)
{
String
actualPropertyName
=
GraphHelper
.
encodePropertyKey
(
propertyName
);
String
actualPropertyName
=
AtlasGraphUtilsV2
.
encodePropertyKey
(
propertyName
);
return
instanceVertex
.
getListProperty
(
actualPropertyName
);
}
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasGraphUtilsV2.java
View file @
0ed9f0e2
...
...
@@ -151,15 +151,11 @@ public class AtlasGraphUtilsV2 {
}
public
static
String
encodePropertyKey
(
String
key
)
{
String
ret
=
AtlasStructType
.
AtlasAttribute
.
encodePropertyKey
(
key
);
return
ret
;
return
AtlasAttribute
.
encodePropertyKey
(
key
);
}
public
static
String
decodePropertyKey
(
String
key
)
{
String
ret
=
AtlasStructType
.
AtlasAttribute
.
decodePropertyKey
(
key
);
return
ret
;
return
AtlasAttribute
.
decodePropertyKey
(
key
);
}
/**
...
...
repository/src/main/java/org/apache/atlas/repository/store/graph/v2/AtlasStructDefStoreV2.java
View file @
0ed9f0e2
...
...
@@ -347,17 +347,23 @@ public class AtlasStructDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasStructDe
if
(
StringUtils
.
isEmpty
(
attributeDef
.
getName
()))
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
MISSING_MANDATORY_ATTRIBUTE
,
structDef
.
getName
(),
"name"
);
}
if
(
StringUtils
.
isEmpty
(
attributeDef
.
getTypeName
()))
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
MISSING_MANDATORY_ATTRIBUTE
,
structDef
.
getName
(),
"typeName"
);
}
String
propertyKey
=
AtlasGraphUtilsV2
.
getTypeDefPropertyKey
(
structDef
,
attributeDef
.
getName
());
String
encodedPropertyKey
=
AtlasGraphUtilsV2
.
encodePropertyKey
(
propertyKey
);
AtlasGraphUtilsV2
.
setProperty
(
vertex
,
p
ropertyKey
,
toJsonFromAttribute
(
structType
.
getAttribute
(
attributeDef
.
getName
())));
vertex
.
setProperty
(
encodedP
ropertyKey
,
toJsonFromAttribute
(
structType
.
getAttribute
(
attributeDef
.
getName
())));
attrNames
.
add
(
attributeDef
.
getName
());
}
AtlasGraphUtilsV2
.
setProperty
(
vertex
,
AtlasGraphUtilsV2
.
getTypeDefPropertyKey
(
structDef
),
attrNames
);
String
typeNamePropertyKey
=
AtlasGraphUtilsV2
.
getTypeDefPropertyKey
(
structDef
);
String
encodedtypeNamePropertyKey
=
AtlasGraphUtilsV2
.
encodePropertyKey
(
typeNamePropertyKey
);
vertex
.
setProperty
(
encodedtypeNamePropertyKey
,
attrNames
);
}
public
static
void
updateVertexPreUpdate
(
AtlasStructDef
structDef
,
AtlasStructType
structType
,
...
...
@@ -427,24 +433,27 @@ public class AtlasStructDefStoreV2 extends AtlasAbstractDefStoreV2<AtlasStructDe
}
}
public
static
AtlasStructDef
toStructDef
(
AtlasVertex
vertex
,
AtlasStructDef
structDef
,
AtlasTypeDefGraphStoreV2
typeDefStore
)
throws
AtlasBaseException
{
AtlasStructDef
ret
=
(
structDef
!=
null
)
?
structDef
:
new
AtlasStructDef
();
public
static
AtlasStructDef
toStructDef
(
AtlasVertex
vertex
,
AtlasStructDef
structDef
,
AtlasTypeDefGraphStoreV2
typeDefStore
)
throws
AtlasBaseException
{
AtlasStructDef
ret
=
(
structDef
!=
null
)
?
structDef
:
new
AtlasStructDef
();
typeDefStore
.
vertexToTypeDef
(
vertex
,
ret
);
List
<
AtlasAttributeDef
>
attributeDefs
=
new
ArrayList
<>();
List
<
String
>
attrNames
=
vertex
.
getProperty
(
AtlasGraphUtilsV2
.
getTypeDefPropertyKey
(
ret
),
List
.
class
);
String
typePropertyKey
=
AtlasGraphUtilsV2
.
getTypeDefPropertyKey
(
ret
);
String
encodedTypePropertyKey
=
AtlasGraphUtilsV2
.
encodePropertyKey
(
typePropertyKey
);
List
<
String
>
attrNames
=
vertex
.
getProperty
(
encodedTypePropertyKey
,
List
.
class
);
if
(
CollectionUtils
.
isNotEmpty
(
attrNames
))
{
for
(
String
attrName
:
attrNames
)
{
String
propertyKey
=
AtlasGraphUtilsV2
.
getTypeDefPropertyKey
(
ret
,
attrName
);
String
attribJson
=
vertex
.
getProperty
(
GraphHelper
.
encodePropertyKey
(
propertyKey
),
String
.
class
);
String
attrPropertyKey
=
AtlasGraphUtilsV2
.
getTypeDefPropertyKey
(
ret
,
attrName
);
String
encodedAttrPropertyKey
=
AtlasGraphUtilsV2
.
encodePropertyKey
(
attrPropertyKey
);
String
attrJson
=
vertex
.
getProperty
(
encodedAttrPropertyKey
,
String
.
class
);
attributeDefs
.
add
(
toAttributeDefFromJson
(
structDef
,
AtlasType
.
fromJson
(
attribJson
,
Map
.
class
),
typeDefStore
));
attributeDefs
.
add
(
toAttributeDefFromJson
(
structDef
,
AtlasType
.
fromJson
(
attrJson
,
Map
.
class
),
typeDefStore
));
}
}
ret
.
setAttributeDefs
(
attributeDefs
);
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