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
862ba9ba
Commit
862ba9ba
authored
Apr 22, 2020
by
Pinal Shah
Committed by
nixonrodrigues
Apr 23, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-3753 : Classification Search with wildcard in between strings causes issues.
Signed-off-by:
nixonrodrigues
<
nixon@apache.org
>
parent
16621dfc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
5 deletions
+50
-5
SearchProcessor.java
...main/java/org/apache/atlas/discovery/SearchProcessor.java
+9
-5
SearchPredicateUtil.java
.../main/java/org/apache/atlas/util/SearchPredicateUtil.java
+41
-0
No files found.
repository/src/main/java/org/apache/atlas/discovery/SearchProcessor.java
View file @
862ba9ba
...
...
@@ -79,7 +79,6 @@ public abstract class SearchProcessor {
public
static
final
char
CUSTOM_ATTR_SEPARATOR
=
'='
;
public
static
final
String
CUSTOM_ATTR_SEARCH_FORMAT
=
"\"\\\"%s\\\":\\\"%s\\\"\""
;
public
static
final
String
CUSTOM_ATTR_SEARCH_FORMAT_GRAPH
=
"\"%s\":\"%s\""
;
public
static
final
String
WILDCARD_CHAR
=
"*"
;
private
static
final
Map
<
SearchParameters
.
Operator
,
String
>
OPERATOR_MAP
=
new
HashMap
<>();
private
static
final
Map
<
SearchParameters
.
Operator
,
VertexAttributePredicateGenerator
>
OPERATOR_PREDICATE_MAP
=
new
HashMap
<>();
...
...
@@ -202,10 +201,11 @@ public abstract class SearchProcessor {
traitPredicate
=
PredicateUtils
.
andPredicate
(
SearchPredicateUtil
.
getIsNullOrEmptyPredicateGenerator
().
generatePredicate
(
TRAIT_NAMES_PROPERTY_KEY
,
null
,
List
.
class
),
SearchPredicateUtil
.
getIsNullOrEmptyPredicateGenerator
().
generatePredicate
(
PROPAGATED_TRAIT_NAMES_PROPERTY_KEY
,
null
,
List
.
class
));
}
else
if
(
context
.
isWildCardSearch
())
{
String
wildcardName
=
context
.
getClassificationName
();
wildcardName
=
wildcardName
.
replace
(
WILDCARD_CHAR
,
""
);
traitPredicate
=
PredicateUtils
.
orPredicate
(
SearchPredicateUtil
.
getContainsPredicateGenerator
().
generatePredicate
(
CLASSIFICATION_NAMES_KEY
,
wildcardName
,
String
.
class
),
SearchPredicateUtil
.
getContainsPredicateGenerator
().
generatePredicate
(
PROPAGATED_CLASSIFICATION_NAMES_KEY
,
wildcardName
,
String
.
class
));
//For wildcard search __classificationNames which of String type is taken instead of _traitNames which is of Array type
//No need to escape, as classification Names only support letters,numbers,space and underscore
String
regexString
=
getRegexString
(
"\\|"
+
context
.
getClassificationName
()
+
"\\|"
);
traitPredicate
=
PredicateUtils
.
orPredicate
(
SearchPredicateUtil
.
getRegexPredicateGenerator
().
generatePredicate
(
CLASSIFICATION_NAMES_KEY
,
regexString
,
String
.
class
),
SearchPredicateUtil
.
getRegexPredicateGenerator
().
generatePredicate
(
PROPAGATED_CLASSIFICATION_NAMES_KEY
,
regexString
,
String
.
class
));
}
else
{
traitPredicate
=
PredicateUtils
.
orPredicate
(
SearchPredicateUtil
.
getContainsAnyPredicateGenerator
().
generatePredicate
(
TRAIT_NAMES_PROPERTY_KEY
,
context
.
getClassificationTypes
(),
List
.
class
),
SearchPredicateUtil
.
getContainsAnyPredicateGenerator
().
generatePredicate
(
PROPAGATED_TRAIT_NAMES_PROPERTY_KEY
,
context
.
getClassificationTypes
(),
List
.
class
));
...
...
@@ -849,6 +849,10 @@ public abstract class SearchProcessor {
return
".*"
+
escapeRegExChars
(
attributeValue
)
+
".*"
;
}
private
static
String
getRegexString
(
String
value
)
{
return
".*"
+
value
.
replace
(
"*"
,
".*"
)
+
".*"
;
}
private
static
String
getSuffixRegex
(
String
attributeValue
)
{
return
".*"
+
escapeRegExChars
(
attributeValue
);
}
...
...
repository/src/main/java/org/apache/atlas/util/SearchPredicateUtil.java
View file @
862ba9ba
...
...
@@ -30,6 +30,8 @@ import org.slf4j.LoggerFactory;
import
java.math.BigDecimal
;
import
java.math.BigInteger
;
import
java.util.Collection
;
import
java.util.regex.Pattern
;
import
java.util.regex.Matcher
;
public
class
SearchPredicateUtil
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
SearchPredicateUtil
.
class
);
...
...
@@ -420,6 +422,35 @@ public class SearchPredicateUtil {
return
ret
;
}
public
static
VertexAttributePredicateGenerator
getRegexPredicateGenerator
()
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> getRegexPredicateGenerator"
);
}
VertexAttributePredicateGenerator
ret
=
new
VertexAttributePredicateGenerator
()
{
@Override
public
Predicate
generatePredicate
(
final
String
attrName
,
final
Object
attrVal
,
final
Class
attrClass
)
{
final
Predicate
ret
;
if
(
attrName
==
null
||
attrClass
==
null
||
attrVal
==
null
)
{
ret
=
ALWAYS_FALSE
;
}
else
if
(
String
.
class
.
isAssignableFrom
(
attrClass
))
{
ret
=
StringPredicate
.
getRegexPredicate
(
attrName
,
attrClass
,
(
String
)
attrVal
);
}
else
{
ret
=
ALWAYS_FALSE
;
}
return
ret
;
}
};
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"<== getRegexPredicateGenerator"
);
}
return
ret
;
}
public
static
VertexAttributePredicateGenerator
getLIKEPredicateGenerator
()
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"==> getLIKEPredicateGenerator"
);
...
...
@@ -1355,6 +1386,16 @@ public class SearchPredicateUtil {
}
};
}
static
VertexAttributePredicate
getRegexPredicate
(
String
attrName
,
Class
attrClass
,
String
value
)
{
return
new
StringPredicate
(
attrName
,
attrClass
,
value
)
{
protected
boolean
compareValue
(
Object
vertexAttrVal
)
{
Pattern
pattern
=
Pattern
.
compile
(
value
,
Pattern
.
CASE_INSENSITIVE
);
Matcher
matcher
=
pattern
.
matcher
((
String
)
vertexAttrVal
);
return
matcher
.
matches
();
}
};
}
}
public
static
Predicate
generateIsEntityVertexPredicate
(
AtlasTypeRegistry
typeRegistry
)
{
...
...
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