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
1dc7f549
Commit
1dc7f549
authored
Sep 08, 2017
by
apoorvnaik
Committed by
Madhan Neethiraj
Sep 13, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-2115: Basic search updates to fix performance regression
Signed-off-by:
Madhan Neethiraj
<
madhan@apache.org
>
parent
8348f221
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
280 additions
and
98 deletions
+280
-98
SearchParameters.java
...va/org/apache/atlas/model/discovery/SearchParameters.java
+3
-1
ClassificationSearchProcessor.java
...apache/atlas/discovery/ClassificationSearchProcessor.java
+57
-27
EntitySearchProcessor.java
...ava/org/apache/atlas/discovery/EntitySearchProcessor.java
+70
-32
SearchProcessor.java
...main/java/org/apache/atlas/discovery/SearchProcessor.java
+24
-26
SearchPredicateUtil.java
.../main/java/org/apache/atlas/util/SearchPredicateUtil.java
+126
-12
No files found.
intg/src/main/java/org/apache/atlas/model/discovery/SearchParameters.java
View file @
1dc7f549
...
@@ -344,7 +344,9 @@ public class SearchParameters {
...
@@ -344,7 +344,9 @@ public class SearchParameters {
LIKE
(
new
String
[]{
"like"
,
"LIKE"
}),
LIKE
(
new
String
[]{
"like"
,
"LIKE"
}),
STARTS_WITH
(
new
String
[]{
"startsWith"
,
"STARTSWITH"
,
"begins_with"
,
"BEGINS_WITH"
}),
STARTS_WITH
(
new
String
[]{
"startsWith"
,
"STARTSWITH"
,
"begins_with"
,
"BEGINS_WITH"
}),
ENDS_WITH
(
new
String
[]{
"endsWith"
,
"ENDSWITH"
,
"ends_with"
,
"BEGINS_WITH"
}),
ENDS_WITH
(
new
String
[]{
"endsWith"
,
"ENDSWITH"
,
"ends_with"
,
"BEGINS_WITH"
}),
CONTAINS
(
new
String
[]{
"contains"
,
"CONTAINS"
})
CONTAINS
(
new
String
[]{
"contains"
,
"CONTAINS"
}),
CONTAINS_ANY
(
new
String
[]{
"containsAny"
,
"CONTAINSANY"
,
"contains_any"
,
"CONTAINS_ANY"
}),
CONTAINS_ALL
(
new
String
[]{
"containsAll"
,
"CONTAINSALL"
,
"contains_all"
,
"CONTAINS_ALL"
})
;
;
static
final
Map
<
String
,
Operator
>
operatorsMap
=
new
HashMap
<>();
static
final
Map
<
String
,
Operator
>
operatorsMap
=
new
HashMap
<>();
...
...
repository/src/main/java/org/apache/atlas/discovery/ClassificationSearchProcessor.java
View file @
1dc7f549
...
@@ -30,8 +30,10 @@ import org.apache.atlas.repository.graphdb.AtlasVertex;
...
@@ -30,8 +30,10 @@ import org.apache.atlas.repository.graphdb.AtlasVertex;
import
org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1
;
import
org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1
;
import
org.apache.atlas.type.AtlasClassificationType
;
import
org.apache.atlas.type.AtlasClassificationType
;
import
org.apache.atlas.util.AtlasGremlinQueryProvider
;
import
org.apache.atlas.util.AtlasGremlinQueryProvider
;
import
org.apache.atlas.util.SearchPredicateUtil
;
import
org.apache.atlas.utils.AtlasPerfTracer
;
import
org.apache.atlas.utils.AtlasPerfTracer
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.Predicate
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -51,11 +53,14 @@ public class ClassificationSearchProcessor extends SearchProcessor {
...
@@ -51,11 +53,14 @@ public class ClassificationSearchProcessor extends SearchProcessor {
private
static
final
Logger
PERF_LOG
=
AtlasPerfTracer
.
getPerfLogger
(
"ClassificationSearchProcessor"
);
private
static
final
Logger
PERF_LOG
=
AtlasPerfTracer
.
getPerfLogger
(
"ClassificationSearchProcessor"
);
private
final
AtlasIndexQuery
indexQuery
;
private
final
AtlasIndexQuery
indexQuery
;
private
final
AtlasGraphQuery
allGraphQuery
;
private
final
AtlasGraphQuery
tagGraphQueryWithAttributes
;
private
final
AtlasGraphQuery
entityGraphQueryTraitNames
;
private
final
Predicate
entityPredicateTraitNames
;
private
final
String
gremlinTagFilterQuery
;
private
final
String
gremlinTagFilterQuery
;
private
final
Map
<
String
,
Object
>
gremlinQueryBindings
;
private
final
Map
<
String
,
Object
>
gremlinQueryBindings
;
public
ClassificationSearchProcessor
(
SearchContext
context
)
{
public
ClassificationSearchProcessor
(
SearchContext
context
)
{
super
(
context
);
super
(
context
);
...
@@ -88,19 +93,19 @@ public class ClassificationSearchProcessor extends SearchProcessor {
...
@@ -88,19 +93,19 @@ public class ClassificationSearchProcessor extends SearchProcessor {
this
.
indexQuery
=
graph
.
indexQuery
(
Constants
.
VERTEX_INDEX
,
indexQueryString
);
this
.
indexQuery
=
graph
.
indexQuery
(
Constants
.
VERTEX_INDEX
,
indexQueryString
);
constructInMemoryPredicate
(
classificationType
,
filterCriteria
,
indexAttributes
);
inMemoryPredicate
=
constructInMemoryPredicate
(
classificationType
,
filterCriteria
,
indexAttributes
);
}
else
{
}
else
{
indexQuery
=
null
;
indexQuery
=
null
;
}
}
AtlasGraphQuery
query
=
graph
.
query
().
in
(
Constants
.
TYPE_NAME_PROPERTY_KEY
,
typeAndSubTypes
);
allGraphQuery
=
toGraphFilterQuery
(
classificationType
,
filterCriteria
,
allAttributes
,
query
);
if
(
context
.
getSearchParameters
().
getTagFilters
()
!=
null
)
{
if
(
context
.
getSearchParameters
().
getTagFilters
()
!=
null
)
{
// Now filter on the tag attributes
// Now filter on the tag attributes
AtlasGremlinQueryProvider
queryProvider
=
AtlasGremlinQueryProvider
.
INSTANCE
;
AtlasGremlinQueryProvider
queryProvider
=
AtlasGremlinQueryProvider
.
INSTANCE
;
tagGraphQueryWithAttributes
=
toGraphFilterQuery
(
classificationType
,
filterCriteria
,
allAttributes
,
graph
.
query
().
in
(
Constants
.
TYPE_NAME_PROPERTY_KEY
,
typeAndSubTypes
));
entityGraphQueryTraitNames
=
null
;
entityPredicateTraitNames
=
null
;
gremlinQueryBindings
=
new
HashMap
<>();
gremlinQueryBindings
=
new
HashMap
<>();
StringBuilder
gremlinQuery
=
new
StringBuilder
();
StringBuilder
gremlinQuery
=
new
StringBuilder
();
...
@@ -122,6 +127,11 @@ public class ClassificationSearchProcessor extends SearchProcessor {
...
@@ -122,6 +127,11 @@ public class ClassificationSearchProcessor extends SearchProcessor {
LOG
.
debug
(
"gremlinTagFilterQuery={}"
,
gremlinTagFilterQuery
);
LOG
.
debug
(
"gremlinTagFilterQuery={}"
,
gremlinTagFilterQuery
);
}
}
}
else
{
}
else
{
tagGraphQueryWithAttributes
=
null
;
entityGraphQueryTraitNames
=
graph
.
query
().
in
(
Constants
.
TRAIT_NAMES_PROPERTY_KEY
,
typeAndSubTypes
);
entityPredicateTraitNames
=
SearchPredicateUtil
.
getContainsAnyPredicateGenerator
()
.
generatePredicate
(
Constants
.
TRAIT_NAMES_PROPERTY_KEY
,
classificationType
.
getTypeAndAllSubTypes
(),
List
.
class
);
gremlinTagFilterQuery
=
null
;
gremlinTagFilterQuery
=
null
;
gremlinQueryBindings
=
null
;
gremlinQueryBindings
=
null
;
}
}
...
@@ -176,38 +186,56 @@ public class ClassificationSearchProcessor extends SearchProcessor {
...
@@ -176,38 +186,56 @@ public class ClassificationSearchProcessor extends SearchProcessor {
}
}
getVerticesFromIndexQueryResult
(
queryResult
,
classificationVertices
);
getVerticesFromIndexQueryResult
(
queryResult
,
classificationVertices
);
// Do in-memory filtering before the graph query
CollectionUtils
.
filter
(
classificationVertices
,
inMemoryPredicate
);
}
else
{
}
else
{
Iterator
<
AtlasVertex
>
queryResult
=
allGraphQuery
.
vertices
(
qryOffset
,
limit
).
iterator
();
if
(
context
.
getSearchParameters
().
getTagFilters
()
==
null
)
{
// We can use single graph query to determine in this case
Iterator
<
AtlasVertex
>
queryResult
=
entityGraphQueryTraitNames
.
vertices
(
qryOffset
,
limit
).
iterator
();
if
(!
queryResult
.
hasNext
())
{
// no more results - end of search
if
(!
queryResult
.
hasNext
())
{
// no more results - end of search
break
;
break
;
}
}
getVertices
(
queryResult
,
classificationVertices
);
getVertices
(
queryResult
,
entityVertices
);
}
}
else
{
Iterator
<
AtlasVertex
>
queryResult
=
tagGraphQueryWithAttributes
.
vertices
(
qryOffset
,
limit
).
iterator
();
// Do in-memory filtering before the graph query
if
(!
queryResult
.
hasNext
())
{
// no more results - end of search
CollectionUtils
.
filter
(
classificationVertices
,
inMemoryPredicate
);
break
;
}
for
(
AtlasVertex
classificationVertex
:
classificationVertices
)
{
getVertices
(
queryResult
,
classificationVertices
);
Iterable
<
AtlasEdge
>
edges
=
classificationVertex
.
getEdges
(
AtlasEdgeDirection
.
IN
);
for
(
AtlasEdge
edge
:
edges
)
{
// Do in-memory filtering before the graph query
AtlasVertex
entityVertex
=
edge
.
getOutVertex
();
CollectionUtils
.
filter
(
classificationVertices
,
inMemoryPredicate
);
}
}
if
(
activeOnly
&&
AtlasGraphUtilsV1
.
getState
(
entityVertex
)
!=
AtlasEntity
.
Status
.
ACTIVE
)
{
// Since tag filters are present, we need to collect the entity vertices after filtering the classification
continue
;
// vertex results (as these might be lower in number)
}
if
(
CollectionUtils
.
isNotEmpty
(
classificationVertices
))
{
for
(
AtlasVertex
classificationVertex
:
classificationVertices
)
{
Iterable
<
AtlasEdge
>
edges
=
classificationVertex
.
getEdges
(
AtlasEdgeDirection
.
IN
);
String
guid
=
AtlasGraphUtilsV1
.
getIdFromVertex
(
entityVertex
);
for
(
AtlasEdge
edge
:
edges
)
{
AtlasVertex
entityVertex
=
edge
.
getOutVertex
();
if
(
processedGuids
.
contains
(
guid
))
{
if
(
activeOnly
&&
AtlasGraphUtilsV1
.
getState
(
entityVertex
)
!=
AtlasEntity
.
Status
.
ACTIVE
)
{
continue
;
continue
;
}
}
String
guid
=
AtlasGraphUtilsV1
.
getIdFromVertex
(
entityVertex
);
entityVertices
.
add
(
entityVertex
);
if
(
processedGuids
.
contains
(
guid
))
{
continue
;
}
processedGuids
.
add
(
guid
);
entityVertices
.
add
(
entityVertex
);
processedGuids
.
add
(
guid
);
}
}
}
}
}
...
@@ -254,6 +282,8 @@ public class ClassificationSearchProcessor extends SearchProcessor {
...
@@ -254,6 +282,8 @@ public class ClassificationSearchProcessor extends SearchProcessor {
LOG
.
warn
(
e
.
getMessage
(),
e
);
LOG
.
warn
(
e
.
getMessage
(),
e
);
}
}
}
}
}
else
if
(
entityPredicateTraitNames
!=
null
)
{
CollectionUtils
.
filter
(
entityVertices
,
entityPredicateTraitNames
);
}
}
super
.
filter
(
entityVertices
);
super
.
filter
(
entityVertices
);
...
...
repository/src/main/java/org/apache/atlas/discovery/EntitySearchProcessor.java
View file @
1dc7f549
...
@@ -24,12 +24,16 @@ import org.apache.atlas.repository.graphdb.AtlasIndexQuery;
...
@@ -24,12 +24,16 @@ import org.apache.atlas.repository.graphdb.AtlasIndexQuery;
import
org.apache.atlas.repository.graphdb.AtlasVertex
;
import
org.apache.atlas.repository.graphdb.AtlasVertex
;
import
org.apache.atlas.type.AtlasClassificationType
;
import
org.apache.atlas.type.AtlasClassificationType
;
import
org.apache.atlas.type.AtlasEntityType
;
import
org.apache.atlas.type.AtlasEntityType
;
import
org.apache.atlas.util.SearchPredicateUtil
;
import
org.apache.atlas.utils.AtlasPerfTracer
;
import
org.apache.atlas.utils.AtlasPerfTracer
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.Predicate
;
import
org.apache.commons.collections.PredicateUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
...
@@ -41,7 +45,8 @@ public class EntitySearchProcessor extends SearchProcessor {
...
@@ -41,7 +45,8 @@ public class EntitySearchProcessor extends SearchProcessor {
private
final
AtlasIndexQuery
indexQuery
;
private
final
AtlasIndexQuery
indexQuery
;
private
final
AtlasGraphQuery
graphQuery
;
private
final
AtlasGraphQuery
graphQuery
;
private
final
AtlasGraphQuery
filterGraphQuery
;
private
Predicate
graphQueryPredicate
;
private
Predicate
filterGraphQueryPredicate
;
public
EntitySearchProcessor
(
SearchContext
context
)
{
public
EntitySearchProcessor
(
SearchContext
context
)
{
super
(
context
);
super
(
context
);
...
@@ -54,10 +59,18 @@ public class EntitySearchProcessor extends SearchProcessor {
...
@@ -54,10 +59,18 @@ public class EntitySearchProcessor extends SearchProcessor {
final
Set
<
String
>
graphAttributes
=
new
HashSet
<>();
final
Set
<
String
>
graphAttributes
=
new
HashSet
<>();
final
Set
<
String
>
allAttributes
=
new
HashSet
<>();
final
Set
<
String
>
allAttributes
=
new
HashSet
<>();
final
AtlasClassificationType
classificationType
=
context
.
getClassificationType
();
final
AtlasClassificationType
classificationType
=
context
.
getClassificationType
();
final
boolean
filterClassification
=
classificationType
!=
null
&&
!
context
.
needClassificationProcessor
();
final
boolean
filterClassification
=
classificationType
!=
null
&&
!
context
.
needClassificationProcessor
();
final
Set
<
String
>
classificationTypeAndSubTypes
=
classificationType
!=
null
?
classificationType
.
getTypeAndAllSubTypes
()
:
Collections
.
EMPTY_SET
;
final
Predicate
typeNamePredicate
=
SearchPredicateUtil
.
getINPredicateGenerator
()
.
generatePredicate
(
Constants
.
TYPE_NAME_PROPERTY_KEY
,
typeAndSubTypes
,
String
.
class
);
final
Predicate
traitPredicate
=
SearchPredicateUtil
.
getContainsAnyPredicateGenerator
()
.
generatePredicate
(
Constants
.
TRAIT_NAMES_PROPERTY_KEY
,
classificationTypeAndSubTypes
,
List
.
class
);
final
Predicate
activePredicate
=
SearchPredicateUtil
.
getEQPredicateGenerator
()
.
generatePredicate
(
Constants
.
STATE_PROPERTY_KEY
,
"ACTIVE"
,
String
.
class
);
processSearchAttributes
(
entityType
,
filterCriteria
,
indexAttributes
,
graphAttributes
,
allAttributes
);
processSearchAttributes
(
entityType
,
filterCriteria
,
indexAttributes
,
graphAttributes
,
allAttributes
);
final
boolean
typeSearchByIndex
=
!
filterClassification
&&
typeAndSubTypesQryStr
.
length
()
<=
MAX_QUERY_STR_LENGTH_TYPES
;
final
boolean
typeSearchByIndex
=
!
filterClassification
&&
typeAndSubTypesQryStr
.
length
()
<=
MAX_QUERY_STR_LENGTH_TYPES
;
...
@@ -72,7 +85,7 @@ public class EntitySearchProcessor extends SearchProcessor {
...
@@ -72,7 +85,7 @@ public class EntitySearchProcessor extends SearchProcessor {
if
(
attrSearchByIndex
)
{
if
(
attrSearchByIndex
)
{
constructFilterQuery
(
indexQuery
,
entityType
,
filterCriteria
,
indexAttributes
);
constructFilterQuery
(
indexQuery
,
entityType
,
filterCriteria
,
indexAttributes
);
constructInMemoryPredicate
(
entityType
,
filterCriteria
,
indexAttributes
);
inMemoryPredicate
=
constructInMemoryPredicate
(
entityType
,
filterCriteria
,
indexAttributes
);
}
else
{
}
else
{
graphAttributes
.
addAll
(
indexAttributes
);
graphAttributes
.
addAll
(
indexAttributes
);
}
}
...
@@ -97,31 +110,71 @@ public class EntitySearchProcessor extends SearchProcessor {
...
@@ -97,31 +110,71 @@ public class EntitySearchProcessor extends SearchProcessor {
if
(!
typeSearchByIndex
)
{
if
(!
typeSearchByIndex
)
{
query
.
in
(
Constants
.
TYPE_NAME_PROPERTY_KEY
,
typeAndSubTypes
);
query
.
in
(
Constants
.
TYPE_NAME_PROPERTY_KEY
,
typeAndSubTypes
);
// Construct a parallel in-memory predicate
if
(
graphQueryPredicate
!=
null
)
{
graphQueryPredicate
=
PredicateUtils
.
andPredicate
(
graphQueryPredicate
,
typeNamePredicate
);
}
else
{
graphQueryPredicate
=
typeNamePredicate
;
}
}
}
// If we need to filter on the trait names then we need to build the query and equivalent in-memory predicate
if
(
filterClassification
)
{
if
(
filterClassification
)
{
query
.
in
(
Constants
.
TRAIT_NAMES_PROPERTY_KEY
,
classificationType
.
getTypeAndAllSubTypes
());
query
.
in
(
Constants
.
TRAIT_NAMES_PROPERTY_KEY
,
classificationTypeAndSubTypes
);
// Construct a parallel in-memory predicate
if
(
graphQueryPredicate
!=
null
)
{
graphQueryPredicate
=
PredicateUtils
.
andPredicate
(
graphQueryPredicate
,
traitPredicate
);
}
else
{
graphQueryPredicate
=
traitPredicate
;
}
}
}
graphQuery
=
toGraphFilterQuery
(
entityType
,
filterCriteria
,
graphAttributes
,
query
);
graphQuery
=
toGraphFilterQuery
(
entityType
,
filterCriteria
,
graphAttributes
,
query
);
// Prepare in-memory predicate for attribute filtering
Predicate
attributePredicate
=
constructInMemoryPredicate
(
entityType
,
filterCriteria
,
graphAttributes
);
if
(
attributePredicate
!=
null
)
{
if
(
graphQueryPredicate
!=
null
)
{
graphQueryPredicate
=
PredicateUtils
.
andPredicate
(
graphQueryPredicate
,
attributePredicate
);
}
else
{
graphQueryPredicate
=
attributePredicate
;
}
}
// Filter condition for the STATUS
if
(
context
.
getSearchParameters
().
getExcludeDeletedEntities
()
&&
this
.
indexQuery
==
null
)
{
if
(
context
.
getSearchParameters
().
getExcludeDeletedEntities
()
&&
this
.
indexQuery
==
null
)
{
graphQuery
.
has
(
Constants
.
STATE_PROPERTY_KEY
,
"ACTIVE"
);
graphQuery
.
has
(
Constants
.
STATE_PROPERTY_KEY
,
"ACTIVE"
);
if
(
graphQueryPredicate
!=
null
)
{
graphQueryPredicate
=
PredicateUtils
.
andPredicate
(
graphQueryPredicate
,
activePredicate
);
}
else
{
graphQueryPredicate
=
activePredicate
;
}
}
}
}
else
{
}
else
{
graphQuery
=
null
;
graphQuery
=
null
;
graphQueryPredicate
=
null
;
}
}
AtlasGraphQuery
query
=
context
.
getGraph
().
query
().
in
(
Constants
.
TYPE_NAME_PROPERTY_KEY
,
typeAndSubTypes
);
if
(
filterClassification
)
{
// Prepare the graph query and in-memory filter for the filtering phase
query
.
in
(
Constants
.
TRAIT_NAMES_PROPERTY_KEY
,
classificationType
.
getTypeAndAllSubTypes
());
filterGraphQueryPredicate
=
typeNamePredicate
;
Predicate
attributesPredicate
=
constructInMemoryPredicate
(
entityType
,
filterCriteria
,
allAttributes
);
if
(
attributesPredicate
!=
null
)
{
filterGraphQueryPredicate
=
PredicateUtils
.
andPredicate
(
filterGraphQueryPredicate
,
attributesPredicate
);
}
}
filterGraphQuery
=
toGraphFilterQuery
(
entityType
,
filterCriteria
,
allAttributes
,
query
);
if
(
filterClassification
)
{
filterGraphQueryPredicate
=
PredicateUtils
.
andPredicate
(
filterGraphQueryPredicate
,
traitPredicate
);
}
// Filter condition for the STATUS
if
(
context
.
getSearchParameters
().
getExcludeDeletedEntities
())
{
if
(
context
.
getSearchParameters
().
getExcludeDeletedEntities
())
{
filterGraphQuery
.
has
(
Constants
.
STATE_PROPERTY_KEY
,
"ACTIVE"
);
filterGraphQuery
Predicate
=
PredicateUtils
.
andPredicate
(
filterGraphQueryPredicate
,
activePredicate
);
}
}
}
}
...
@@ -172,18 +225,8 @@ public class EntitySearchProcessor extends SearchProcessor {
...
@@ -172,18 +225,8 @@ public class EntitySearchProcessor extends SearchProcessor {
// Do in-memory filtering before the graph query
// Do in-memory filtering before the graph query
CollectionUtils
.
filter
(
entityVertices
,
inMemoryPredicate
);
CollectionUtils
.
filter
(
entityVertices
,
inMemoryPredicate
);
if
(
graphQuery
!=
null
)
{
if
(
graphQueryPredicate
!=
null
)
{
Set
<
String
>
guids
=
getGuids
(
entityVertices
);
CollectionUtils
.
filter
(
entityVertices
,
graphQueryPredicate
);
entityVertices
.
clear
();
if
(
CollectionUtils
.
isNotEmpty
(
guids
))
{
AtlasGraphQuery
guidQuery
=
context
.
getGraph
().
query
().
in
(
Constants
.
GUID_PROPERTY_KEY
,
guids
);
guidQuery
.
addConditionsFrom
(
graphQuery
);
getVertices
(
guidQuery
.
vertices
().
iterator
(),
entityVertices
);
}
}
}
}
else
{
}
else
{
Iterator
<
AtlasVertex
>
queryResult
=
graphQuery
.
vertices
(
qryOffset
,
limit
).
iterator
();
Iterator
<
AtlasVertex
>
queryResult
=
graphQuery
.
vertices
(
qryOffset
,
limit
).
iterator
();
...
@@ -216,16 +259,11 @@ public class EntitySearchProcessor extends SearchProcessor {
...
@@ -216,16 +259,11 @@ public class EntitySearchProcessor extends SearchProcessor {
LOG
.
debug
(
"==> EntitySearchProcessor.filter({})"
,
entityVertices
.
size
());
LOG
.
debug
(
"==> EntitySearchProcessor.filter({})"
,
entityVertices
.
size
());
}
}
Set
<
String
>
guids
=
getGuids
(
entityVertices
);
// Since we already have the entity vertices, a in-memory filter will be faster than fetching the same
// vertices again with the required filtering
entityVertices
.
clear
();
if
(
filterGraphQueryPredicate
!=
null
)
{
LOG
.
debug
(
"Filtering in-memory"
);
if
(
CollectionUtils
.
isNotEmpty
(
guids
))
{
CollectionUtils
.
filter
(
entityVertices
,
filterGraphQueryPredicate
);
AtlasGraphQuery
query
=
context
.
getGraph
().
query
().
in
(
Constants
.
GUID_PROPERTY_KEY
,
guids
);
query
.
addConditionsFrom
(
filterGraphQuery
);
getVertices
(
query
.
vertices
().
iterator
(),
entityVertices
);
}
}
super
.
filter
(
entityVertices
);
super
.
filter
(
entityVertices
);
...
...
repository/src/main/java/org/apache/atlas/discovery/SearchProcessor.java
View file @
1dc7f549
...
@@ -23,18 +23,20 @@ import org.apache.atlas.exception.AtlasBaseException;
...
@@ -23,18 +23,20 @@ import org.apache.atlas.exception.AtlasBaseException;
import
org.apache.atlas.model.discovery.SearchParameters
;
import
org.apache.atlas.model.discovery.SearchParameters
;
import
org.apache.atlas.model.discovery.SearchParameters.FilterCriteria
;
import
org.apache.atlas.model.discovery.SearchParameters.FilterCriteria
;
import
org.apache.atlas.model.discovery.SearchParameters.FilterCriteria.Condition
;
import
org.apache.atlas.model.discovery.SearchParameters.FilterCriteria.Condition
;
import
org.apache.atlas.model.typedef.AtlasBaseTypeDef
;
import
org.apache.atlas.repository.Constants
;
import
org.apache.atlas.repository.Constants
;
import
org.apache.atlas.repository.graphdb.AtlasGraphQuery
;
import
org.apache.atlas.repository.graphdb.AtlasGraphQuery
;
import
org.apache.atlas.repository.graphdb.AtlasIndexQuery
;
import
org.apache.atlas.repository.graphdb.AtlasIndexQuery
;
import
org.apache.atlas.repository.graphdb.AtlasVertex
;
import
org.apache.atlas.repository.graphdb.AtlasVertex
;
import
org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1
;
import
org.apache.atlas.repository.store.graph.v1.AtlasGraphUtilsV1
;
import
org.apache.atlas.type.AtlasArrayType
;
import
org.apache.atlas.type.AtlasEntityType
;
import
org.apache.atlas.type.AtlasEntityType
;
import
org.apache.atlas.type.AtlasEnumType
;
import
org.apache.atlas.type.AtlasEnumType
;
import
org.apache.atlas.type.AtlasStructType
;
import
org.apache.atlas.type.AtlasStructType
;
import
org.apache.atlas.type.AtlasStructType.AtlasAttribute
;
import
org.apache.atlas.type.AtlasStructType.AtlasAttribute
;
import
org.apache.atlas.type.AtlasType
;
import
org.apache.atlas.type.AtlasType
;
import
org.apache.atlas.util.AtlasGremlinQueryProvider
;
import
org.apache.atlas.util.AtlasGremlinQueryProvider
;
import
org.apache.atlas.util.SearchPredicateUtil.
VertexAttributePredicateGenerator
;
import
org.apache.atlas.util.SearchPredicateUtil.
*
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.CollectionUtils
;
import
org.apache.commons.collections.Predicate
;
import
org.apache.commons.collections.Predicate
;
import
org.apache.commons.collections.PredicateUtils
;
import
org.apache.commons.collections.PredicateUtils
;
...
@@ -44,15 +46,7 @@ import org.slf4j.LoggerFactory;
...
@@ -44,15 +46,7 @@ import org.slf4j.LoggerFactory;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.math.BigInteger
;
import
java.util.ArrayList
;
import
java.util.*
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
import
static
org
.
apache
.
atlas
.
util
.
SearchPredicateUtil
.*;
import
static
org
.
apache
.
atlas
.
util
.
SearchPredicateUtil
.*;
...
@@ -269,14 +263,16 @@ public abstract class SearchProcessor {
...
@@ -269,14 +263,16 @@ public abstract class SearchProcessor {
}
}
}
}
protected
void
constructInMemoryPredicate
(
AtlasStructType
type
,
FilterCriteria
filterCriteria
,
Set
<
String
>
indexAttributes
)
{
protected
Predicate
constructInMemoryPredicate
(
AtlasStructType
type
,
FilterCriteria
filterCriteria
,
Set
<
String
>
indexAttributes
)
{
Predicate
ret
=
null
;
if
(
filterCriteria
!=
null
)
{
if
(
filterCriteria
!=
null
)
{
if
(
LOG
.
isDebugEnabled
())
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Processing Filters"
);
LOG
.
debug
(
"Processing Filters"
);
}
}
inMemoryPredicate
=
toInMemoryPredicate
(
type
,
filterCriteria
,
indexAttributes
);
ret
=
toInMemoryPredicate
(
type
,
filterCriteria
,
indexAttributes
);
}
}
return
ret
;
}
}
protected
void
constructGremlinFilterQuery
(
StringBuilder
gremlinQuery
,
Map
<
String
,
Object
>
queryBindings
,
AtlasStructType
structType
,
FilterCriteria
filterCriteria
)
{
protected
void
constructGremlinFilterQuery
(
StringBuilder
gremlinQuery
,
Map
<
String
,
Object
>
queryBindings
,
AtlasStructType
structType
,
FilterCriteria
filterCriteria
)
{
...
@@ -411,59 +407,61 @@ public abstract class SearchProcessor {
...
@@ -411,59 +407,61 @@ public abstract class SearchProcessor {
VertexAttributePredicateGenerator
predicate
=
OPERATOR_PREDICATE_MAP
.
get
(
op
);
VertexAttributePredicateGenerator
predicate
=
OPERATOR_PREDICATE_MAP
.
get
(
op
);
if
(
attribute
!=
null
&&
predicate
!=
null
)
{
if
(
attribute
!=
null
&&
predicate
!=
null
)
{
final
AtlasType
attrType
=
attribute
.
getAttributeType
();
final
AtlasType
attrType
=
attribute
.
getAttributeType
();
final
String
attributeType
=
attrType
.
getTypeName
().
toLowerCase
();
final
Class
attrClass
;
final
Class
attrClass
;
final
Object
attrValue
;
final
Object
attrValue
;
switch
(
attr
ibuteType
)
{
switch
(
attr
Type
.
getTypeName
()
)
{
case
"string"
:
case
AtlasBaseTypeDef
.
ATLAS_TYPE_STRING
:
attrClass
=
String
.
class
;
attrClass
=
String
.
class
;
attrValue
=
attrVal
;
attrValue
=
attrVal
;
break
;
break
;
case
"short"
:
case
AtlasBaseTypeDef
.
ATLAS_TYPE_SHORT
:
attrClass
=
Short
.
class
;
attrClass
=
Short
.
class
;
attrValue
=
Short
.
parseShort
(
attrVal
);
attrValue
=
Short
.
parseShort
(
attrVal
);
break
;
break
;
case
"int"
:
case
AtlasBaseTypeDef
.
ATLAS_TYPE_INT
:
attrClass
=
Integer
.
class
;
attrClass
=
Integer
.
class
;
attrValue
=
Integer
.
parseInt
(
attrVal
);
attrValue
=
Integer
.
parseInt
(
attrVal
);
break
;
break
;
case
"biginteger"
:
case
AtlasBaseTypeDef
.
ATLAS_TYPE_BIGINTEGER
:
attrClass
=
BigInteger
.
class
;
attrClass
=
BigInteger
.
class
;
attrValue
=
new
BigInteger
(
attrVal
);
attrValue
=
new
BigInteger
(
attrVal
);
break
;
break
;
case
"boolean"
:
case
AtlasBaseTypeDef
.
ATLAS_TYPE_BOOLEAN
:
attrClass
=
Boolean
.
class
;
attrClass
=
Boolean
.
class
;
attrValue
=
Boolean
.
parseBoolean
(
attrVal
);
attrValue
=
Boolean
.
parseBoolean
(
attrVal
);
break
;
break
;
case
"byte"
:
case
AtlasBaseTypeDef
.
ATLAS_TYPE_BYTE
:
attrClass
=
Byte
.
class
;
attrClass
=
Byte
.
class
;
attrValue
=
Byte
.
parseByte
(
attrVal
);
attrValue
=
Byte
.
parseByte
(
attrVal
);
break
;
break
;
case
"long"
:
case
AtlasBaseTypeDef
.
ATLAS_TYPE_LONG
:
case
"date"
:
case
AtlasBaseTypeDef
.
ATLAS_TYPE_DATE
:
attrClass
=
Long
.
class
;
attrClass
=
Long
.
class
;
attrValue
=
Long
.
parseLong
(
attrVal
);
attrValue
=
Long
.
parseLong
(
attrVal
);
break
;
break
;
case
"float"
:
case
AtlasBaseTypeDef
.
ATLAS_TYPE_FLOAT
:
attrClass
=
Float
.
class
;
attrClass
=
Float
.
class
;
attrValue
=
Float
.
parseFloat
(
attrVal
);
attrValue
=
Float
.
parseFloat
(
attrVal
);
break
;
break
;
case
"double"
:
case
AtlasBaseTypeDef
.
ATLAS_TYPE_DOUBLE
:
attrClass
=
Double
.
class
;
attrClass
=
Double
.
class
;
attrValue
=
Double
.
parseDouble
(
attrVal
);
attrValue
=
Double
.
parseDouble
(
attrVal
);
break
;
break
;
case
"bigdecimal"
:
case
AtlasBaseTypeDef
.
ATLAS_TYPE_BIGDECIMAL
:
attrClass
=
BigDecimal
.
class
;
attrClass
=
BigDecimal
.
class
;
attrValue
=
new
BigDecimal
(
attrVal
);
attrValue
=
new
BigDecimal
(
attrVal
);
break
;
break
;
default
:
default
:
if
(
attrType
instanceof
AtlasEnumType
)
{
if
(
attrType
instanceof
AtlasEnumType
)
{
attrClass
=
String
.
class
;
attrClass
=
String
.
class
;
}
else
if
(
attrType
instanceof
AtlasArrayType
)
{
attrClass
=
List
.
class
;
}
else
{
}
else
{
attrClass
=
Object
.
class
;
attrClass
=
Object
.
class
;
}
}
attrValue
=
attrVal
;
attrValue
=
attrVal
;
break
;
break
;
}
}
...
...
repository/src/main/java/org/apache/atlas/util/SearchPredicateUtil.java
View file @
1dc7f549
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