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
5dfe2023
Commit
5dfe2023
authored
Apr 03, 2017
by
Sarath Subramanian
Committed by
Madhan Neethiraj
Apr 12, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-1710: added entity-lookup API for entity create/update UI
Signed-off-by:
Madhan Neethiraj
<
madhan@apache.org
>
parent
8a32ccaa
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
9 deletions
+98
-9
AtlasSearchResult.java
...a/org/apache/atlas/model/discovery/AtlasSearchResult.java
+1
-1
AtlasDiscoveryService.java
...ava/org/apache/atlas/discovery/AtlasDiscoveryService.java
+4
-1
EntityDiscoveryService.java
...va/org/apache/atlas/discovery/EntityDiscoveryService.java
+44
-1
DiscoveryREST.java
...rc/main/java/org/apache/atlas/web/rest/DiscoveryREST.java
+49
-6
No files found.
intg/src/main/java/org/apache/atlas/model/discovery/AtlasSearchResult.java
View file @
5dfe2023
...
...
@@ -149,7 +149,7 @@ public class AtlasSearchResult implements Serializable {
}
}
public
enum
AtlasQueryType
{
DSL
,
FULL_TEXT
,
GREMLIN
,
BASIC
}
public
enum
AtlasQueryType
{
DSL
,
FULL_TEXT
,
GREMLIN
,
BASIC
,
ATTRIBUTE
}
@JsonAutoDetect
(
getterVisibility
=
PUBLIC_ONLY
,
setterVisibility
=
PUBLIC_ONLY
,
fieldVisibility
=
NONE
)
@JsonSerialize
(
include
=
JsonSerialize
.
Inclusion
.
NON_NULL
)
...
...
repository/src/main/java/org/apache/atlas/discovery/AtlasDiscoveryService.java
View file @
5dfe2023
...
...
@@ -46,9 +46,12 @@ public interface AtlasDiscoveryService {
* @param query search query.
* @param type entity type.
* @param classification classification name.
* @param attrName attribute name.
* @param attrValue attribute value.
* @param limit number of resultant rows (for pagination). [ limit > 0 ] and [ limit < maxlimit ]. -1 maps to atlas.search.defaultlimit property.
* @param offset offset to the results returned (for pagination). [ offset >= 0 ]. -1 maps to offset 0.
* @return AtlasSearchResult
*/
AtlasSearchResult
searchUsingBasicQuery
(
String
query
,
String
type
,
String
classification
,
int
limit
,
int
offset
)
throws
AtlasBaseException
;
AtlasSearchResult
searchUsingBasicQuery
(
String
query
,
String
type
,
String
classification
,
String
attrName
,
String
attrValue
,
int
limit
,
int
offset
)
throws
AtlasBaseException
;
}
repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java
View file @
5dfe2023
...
...
@@ -18,6 +18,7 @@
package
org
.
apache
.
atlas
.
discovery
;
import
org.apache.atlas.AtlasConfiguration
;
import
org.apache.atlas.AtlasErrorCode
;
import
org.apache.atlas.model.discovery.AtlasSearchResult.AtlasFullTextResult
;
import
org.apache.atlas.model.discovery.AtlasSearchResult.AtlasQueryType
;
import
org.apache.atlas.model.discovery.AtlasSearchResult.AttributeSearchResult
;
...
...
@@ -45,6 +46,8 @@ import org.apache.atlas.repository.graphdb.AtlasVertex;
import
org.apache.atlas.repository.store.graph.v1.EntityGraphRetriever
;
import
org.apache.atlas.type.AtlasClassificationType
;
import
org.apache.atlas.type.AtlasEntityType
;
import
org.apache.atlas.type.AtlasStructType
;
import
org.apache.atlas.type.AtlasStructType.AtlasAttribute
;
import
org.apache.atlas.type.AtlasTypeRegistry
;
import
org.apache.atlas.util.AtlasGremlinQueryProvider
;
import
org.apache.atlas.util.AtlasGremlinQueryProvider.AtlasGremlinQuery
;
...
...
@@ -156,7 +159,8 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
}
@Override
public
AtlasSearchResult
searchUsingBasicQuery
(
String
query
,
String
typeName
,
String
classification
,
int
limit
,
int
offset
)
throws
AtlasBaseException
{
public
AtlasSearchResult
searchUsingBasicQuery
(
String
query
,
String
typeName
,
String
classification
,
String
attrName
,
String
attrValue
,
int
limit
,
int
offset
)
throws
AtlasBaseException
{
AtlasSearchResult
ret
=
new
AtlasSearchResult
(
AtlasQueryType
.
BASIC
);
if
(
LOG
.
isDebugEnabled
())
{
...
...
@@ -166,6 +170,7 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
final
QueryParams
params
=
validateSearchParams
(
limit
,
offset
);
Set
<
String
>
typeNames
=
null
;
Set
<
String
>
classificationNames
=
null
;
String
attrQualifiedName
=
null
;
if
(
StringUtils
.
isNotEmpty
(
typeName
))
{
AtlasEntityType
entityType
=
typeRegistry
.
getEntityTypeByName
(
typeName
);
...
...
@@ -191,6 +196,36 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
ret
.
setClassification
(
classification
);
}
boolean
isAttributeSearch
=
StringUtils
.
isNotEmpty
(
attrName
)
&&
StringUtils
.
isNotEmpty
(
attrValue
);
if
(
isAttributeSearch
)
{
if
(
LOG
.
isDebugEnabled
())
{
LOG
.
debug
(
"Executing attribute search attrName: {} and attrValue: {}"
,
attrName
,
attrValue
);
}
AtlasEntityType
entityType
=
typeRegistry
.
getEntityTypeByName
(
typeName
);
if
(
entityType
!=
null
)
{
AtlasAttribute
attribute
=
entityType
.
getAttribute
(
attrName
);
if
(
attribute
==
null
)
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
UNKNOWN_ATTRIBUTE
,
attrName
,
typeName
);
}
attrQualifiedName
=
entityType
.
getAttribute
(
attrName
).
getQualifiedName
();
}
String
attrQuery
=
String
.
format
(
"%s AND (%s *)"
,
attrName
,
attrValue
.
replaceAll
(
"\\."
,
" "
));
if
(
StringUtils
.
isEmpty
(
query
))
{
query
=
attrQuery
;
}
else
{
query
=
String
.
format
(
"(%s) AND (%s)"
,
query
,
attrQuery
);
}
ret
.
setQueryType
(
AtlasQueryType
.
ATTRIBUTE
);
}
// if query was provided, perform indexQuery and filter for typeName & classification in memory; this approach
// results in a faster and accurate results than using CONTAINS/CONTAINS_PREFIX filter on entityText property
if
(
StringUtils
.
isNotEmpty
(
query
))
{
...
...
@@ -224,6 +259,14 @@ public class EntityDiscoveryService implements AtlasDiscoveryService {
}
}
if
(
isAttributeSearch
)
{
String
vertexAttrValue
=
vertex
.
getProperty
(
attrQualifiedName
,
String
.
class
);
if
(
StringUtils
.
isNotEmpty
(
vertexAttrValue
)
&&
!
vertexAttrValue
.
startsWith
(
attrValue
))
{
continue
;
}
}
resultIdx
++;
if
(
resultIdx
<=
startIdx
)
{
...
...
webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java
View file @
5dfe2023
...
...
@@ -17,6 +17,7 @@
*/
package
org
.
apache
.
atlas
.
web
.
rest
;
import
org.apache.atlas.AtlasErrorCode
;
import
org.apache.atlas.exception.AtlasBaseException
;
import
org.apache.atlas.discovery.AtlasDiscoveryService
;
import
org.apache.atlas.model.discovery.AtlasSearchResult
;
...
...
@@ -146,11 +147,11 @@ public class DiscoveryREST {
@Path
(
"/basic"
)
@Consumes
(
Servlets
.
JSON_MEDIA_TYPE
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasSearchResult
searchUsingBasic
(
@QueryParam
(
"query"
)
String
query
,
@QueryParam
(
"typeName"
)
String
typeName
,
@QueryParam
(
"classification"
)
String
classification
,
@QueryParam
(
"limit"
)
int
limit
,
@QueryParam
(
"offset"
)
int
offset
)
throws
AtlasBaseException
{
public
AtlasSearchResult
searchUsingBasic
(
@QueryParam
(
"query"
)
String
query
,
@QueryParam
(
"typeName"
)
String
typeName
,
@QueryParam
(
"classification"
)
String
classification
,
@QueryParam
(
"limit"
)
int
limit
,
@QueryParam
(
"offset"
)
int
offset
)
throws
AtlasBaseException
{
AtlasPerfTracer
perf
=
null
;
try
{
...
...
@@ -159,7 +160,49 @@ public class DiscoveryREST {
typeName
+
","
+
classification
+
","
+
limit
+
","
+
offset
+
")"
);
}
return
atlasDiscoveryService
.
searchUsingBasicQuery
(
query
,
typeName
,
classification
,
limit
,
offset
);
return
atlasDiscoveryService
.
searchUsingBasicQuery
(
query
,
typeName
,
classification
,
null
,
null
,
limit
,
offset
);
}
finally
{
AtlasPerfTracer
.
log
(
perf
);
}
}
/**
* Retrieve data for the specified attribute search query
* @param attrName Attribute name
* @param attrValue Attibute value to search on
* @param typeName limit the result to only entities of specified type or its sub-types
* @param limit limit the result set to only include the specified number of entries
* @param offset start offset of the result set (useful for pagination)
* @return Search results
* @throws AtlasBaseException
* @HTTP 200 On successful FullText lookup with some results, might return an empty list if execution succeeded
* without any results
* @HTTP 400 Invalid wildcard or query parameters
*/
@GET
@Path
(
"/attribute"
)
@Consumes
(
Servlets
.
JSON_MEDIA_TYPE
)
@Produces
(
Servlets
.
JSON_MEDIA_TYPE
)
public
AtlasSearchResult
searchUsingAttribute
(
@QueryParam
(
"stringName"
)
String
attrName
,
@QueryParam
(
"stringValue"
)
String
attrValue
,
@QueryParam
(
"typeName"
)
String
typeName
,
@QueryParam
(
"limit"
)
int
limit
,
@QueryParam
(
"offset"
)
int
offset
)
throws
AtlasBaseException
{
AtlasPerfTracer
perf
=
null
;
try
{
if
(
AtlasPerfTracer
.
isPerfTraceEnabled
(
PERF_LOG
))
{
perf
=
AtlasPerfTracer
.
getPerfTracer
(
PERF_LOG
,
"DiscoveryREST.searchUsingAttribute("
+
attrName
+
","
+
attrValue
+
","
+
typeName
+
","
+
limit
+
","
+
offset
+
")"
);
}
if
(
StringUtils
.
isEmpty
(
attrName
)
||
StringUtils
.
isEmpty
(
attrValue
))
{
throw
new
AtlasBaseException
(
AtlasErrorCode
.
INVALID_PARAMETERS
,
String
.
format
(
"attrName : {0}, attrValue: {1} for attribute search."
,
attrName
,
attrValue
));
}
return
atlasDiscoveryService
.
searchUsingBasicQuery
(
null
,
typeName
,
null
,
attrName
,
attrValue
,
limit
,
offset
);
}
finally
{
AtlasPerfTracer
.
log
(
perf
);
}
...
...
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