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
ea653e03
Commit
ea653e03
authored
Jan 20, 2020
by
Sarath Subramanian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-3591: Improve user-defined attributes search
parent
eed7817e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
9 deletions
+35
-9
SearchProcessor.java
...main/java/org/apache/atlas/discovery/SearchProcessor.java
+26
-0
TestEntitiesREST.java
.../java/org/apache/atlas/web/adapters/TestEntitiesREST.java
+9
-9
No files found.
repository/src/main/java/org/apache/atlas/discovery/SearchProcessor.java
View file @
ea653e03
...
@@ -73,6 +73,8 @@ public abstract class SearchProcessor {
...
@@ -73,6 +73,8 @@ public abstract class SearchProcessor {
public
static
final
String
BRACE_OPEN_STR
=
"("
;
public
static
final
String
BRACE_OPEN_STR
=
"("
;
public
static
final
String
BRACE_CLOSE_STR
=
")"
;
public
static
final
String
BRACE_CLOSE_STR
=
")"
;
public
static
final
String
ALL_TYPE_QUERY
=
"[* TO *]"
;
public
static
final
String
ALL_TYPE_QUERY
=
"[* TO *]"
;
public
static
final
char
CUSTOM_ATTR_SEPARATOR
=
'='
;
public
static
final
String
CUSTOM_ATTR_SEARCH_FORMAT
=
"\"\\\"%s\\\":\\\"%s\\\"\""
;
private
static
final
Map
<
SearchParameters
.
Operator
,
String
>
OPERATOR_MAP
=
new
HashMap
<>();
private
static
final
Map
<
SearchParameters
.
Operator
,
String
>
OPERATOR_MAP
=
new
HashMap
<>();
private
static
final
Map
<
SearchParameters
.
Operator
,
VertexAttributePredicateGenerator
>
OPERATOR_PREDICATE_MAP
=
new
HashMap
<>();
private
static
final
Map
<
SearchParameters
.
Operator
,
VertexAttributePredicateGenerator
>
OPERATOR_PREDICATE_MAP
=
new
HashMap
<>();
...
@@ -493,8 +495,14 @@ public abstract class SearchProcessor {
...
@@ -493,8 +495,14 @@ public abstract class SearchProcessor {
String
qualifiedName
=
type
.
getQualifiedAttributeName
(
attrName
);
String
qualifiedName
=
type
.
getQualifiedAttributeName
(
attrName
);
String
escapeIndexQueryValue
=
AtlasAttribute
.
escapeIndexQueryValue
(
attrVal
);
String
escapeIndexQueryValue
=
AtlasAttribute
.
escapeIndexQueryValue
(
attrVal
);
// map '__customAttributes' 'CONTAINS' operator to 'EQ' operator (solr limitation for json serialized string search)
// map '__customAttributes' value from 'key1=value1' to '\"key1\":\"value1\"' (escape special characters and surround with quotes)
if
(
attrName
.
equals
(
CUSTOM_ATTRIBUTES_PROPERTY_KEY
)
&&
op
==
SearchParameters
.
Operator
.
CONTAINS
)
{
ret
=
String
.
format
(
OPERATOR_MAP
.
get
(
SearchParameters
.
Operator
.
EQ
),
qualifiedName
,
getCustomAttributeIndexQueryValue
(
escapeIndexQueryValue
));
}
else
{
ret
=
String
.
format
(
OPERATOR_MAP
.
get
(
op
),
qualifiedName
,
escapeIndexQueryValue
);
ret
=
String
.
format
(
OPERATOR_MAP
.
get
(
op
),
qualifiedName
,
escapeIndexQueryValue
);
}
}
}
}
catch
(
AtlasBaseException
ex
)
{
}
catch
(
AtlasBaseException
ex
)
{
LOG
.
warn
(
ex
.
getMessage
());
LOG
.
warn
(
ex
.
getMessage
());
}
}
...
@@ -502,6 +510,24 @@ public abstract class SearchProcessor {
...
@@ -502,6 +510,24 @@ public abstract class SearchProcessor {
return
ret
;
return
ret
;
}
}
private
String
getCustomAttributeIndexQueryValue
(
String
attrValue
)
{
String
ret
=
null
;
if
(
StringUtils
.
isNotEmpty
(
attrValue
))
{
int
separatorIdx
=
attrValue
.
indexOf
(
CUSTOM_ATTR_SEPARATOR
);
String
key
=
separatorIdx
!=
-
1
?
attrValue
.
substring
(
0
,
separatorIdx
)
:
null
;
String
value
=
key
!=
null
?
attrValue
.
substring
(
separatorIdx
+
1
)
:
null
;
if
(
key
!=
null
&&
value
!=
null
)
{
ret
=
String
.
format
(
CUSTOM_ATTR_SEARCH_FORMAT
,
key
,
value
);
}
else
{
ret
=
attrValue
;
}
}
return
ret
;
}
private
Predicate
toInMemoryPredicate
(
AtlasStructType
type
,
String
attrName
,
SearchParameters
.
Operator
op
,
String
attrVal
)
{
private
Predicate
toInMemoryPredicate
(
AtlasStructType
type
,
String
attrName
,
SearchParameters
.
Operator
op
,
String
attrVal
)
{
Predicate
ret
=
null
;
Predicate
ret
=
null
;
...
...
webapp/src/test/java/org/apache/atlas/web/adapters/TestEntitiesREST.java
View file @
ea653e03
...
@@ -156,12 +156,11 @@ public class TestEntitiesREST {
...
@@ -156,12 +156,11 @@ public class TestEntitiesREST {
@Test
@Test
public
void
testCustomAttributesSearch
()
throws
Exception
{
public
void
testCustomAttributesSearch
()
throws
Exception
{
AtlasEntity
dbWithCustomAttr
=
new
AtlasEntity
(
dbEntity
);
AtlasEntity
dbWithCustomAttr
=
new
AtlasEntity
(
dbEntity
);
HashMap
customAttr
=
new
HashMap
<
String
,
String
>()
{{
Map
customAttr
=
new
HashMap
<
String
,
String
>()
{{
put
(
"key1"
,
"value1"
);
}};
put
(
"key1"
,
"value1"
);
}};
dbWithCustomAttr
.
setCustomAttributes
(
customAttr
);
dbWithCustomAttr
.
setCustomAttributes
(
customAttr
);
AtlasEntitiesWithExtInfo
atlasEntitiesWithExtInfo
=
new
AtlasEntitiesWithExtInfo
(
dbWithCustomAttr
);
AtlasEntitiesWithExtInfo
atlasEntitiesWithExtInfo
=
new
AtlasEntitiesWithExtInfo
(
dbWithCustomAttr
);
EntityMutationResponse
response
=
entityREST
.
createOrUpdate
(
atlasEntitiesWithExtInfo
);
EntityMutationResponse
response
=
entityREST
.
createOrUpdate
(
atlasEntitiesWithExtInfo
);
...
@@ -169,13 +168,14 @@ public class TestEntitiesREST {
...
@@ -169,13 +168,14 @@ public class TestEntitiesREST {
searchParameters
=
new
SearchParameters
();
searchParameters
=
new
SearchParameters
();
searchParameters
.
setTypeName
(
"_ALL_ENTITY_TYPES"
);
searchParameters
.
setTypeName
(
"_ALL_ENTITY_TYPES"
);
SearchParameters
.
FilterCriteria
fc
=
new
SearchParameters
.
FilterCriteria
();
fc
.
setAttributeName
(
CUSTOM_ATTRIBUTES_PROPERTY_KEY
);
SearchParameters
.
FilterCriteria
filter
=
new
SearchParameters
.
FilterCriteria
();
fc
.
setOperator
(
SearchParameters
.
Operator
.
EQ
);
fc
.
setAttributeValue
(
"\"key1:value1\""
);
searchParameters
.
setEntityFilters
(
fc
);
filter
.
setAttributeName
(
CUSTOM_ATTRIBUTES_PROPERTY_KEY
);
filter
.
setOperator
(
SearchParameters
.
Operator
.
CONTAINS
);
filter
.
setAttributeValue
(
"key1=value1"
);
searchParameters
.
setEntityFilters
(
filter
);
AtlasSearchResult
res
=
discoveryREST
.
searchWithParameters
(
searchParameters
);
AtlasSearchResult
res
=
discoveryREST
.
searchWithParameters
(
searchParameters
);
...
...
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