Repository: incubator-atlas Updated Branches: refs/heads/master 2bbbd1a5a -> 670a4c001
ATLAS-1630: basic search implementation (#2) Signed-off-by: Madhan Neethiraj <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/670a4c00 Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/670a4c00 Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/670a4c00 Branch: refs/heads/master Commit: 670a4c00158bcde1e99986a719c84cebcf6336c9 Parents: 2bbbd1a Author: Sarath Subramanian <[email protected]> Authored: Sat Mar 4 00:49:01 2017 -0800 Committer: Madhan Neethiraj <[email protected]> Committed: Sat Mar 4 01:16:59 2017 -0800 ---------------------------------------------------------------------- .../atlas/model/discovery/AtlasSearchResult.java | 4 ++++ .../atlas/discovery/EntityDiscoveryService.java | 9 +++++++-- .../org/apache/atlas/web/rest/DiscoveryREST.java | 19 ++++++++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/670a4c00/intg/src/main/java/org/apache/atlas/model/discovery/AtlasSearchResult.java ---------------------------------------------------------------------- diff --git a/intg/src/main/java/org/apache/atlas/model/discovery/AtlasSearchResult.java b/intg/src/main/java/org/apache/atlas/model/discovery/AtlasSearchResult.java index 8928bdf..bf1c80e 100644 --- a/intg/src/main/java/org/apache/atlas/model/discovery/AtlasSearchResult.java +++ b/intg/src/main/java/org/apache/atlas/model/discovery/AtlasSearchResult.java @@ -52,6 +52,10 @@ public class AtlasSearchResult implements Serializable { public AtlasSearchResult() {} + public AtlasSearchResult(AtlasQueryType queryType) { + this(null, queryType); + } + public AtlasSearchResult(String queryText, AtlasQueryType queryType) { setQueryText(queryText); setQueryType(queryType); http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/670a4c00/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java ---------------------------------------------------------------------- diff --git a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java index 90f084d..08a433c 100644 --- a/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java +++ b/repository/src/main/java/org/apache/atlas/discovery/EntityDiscoveryService.java @@ -158,7 +158,7 @@ public class EntityDiscoveryService implements AtlasDiscoveryService { @Override public AtlasSearchResult searchUsingBasicQuery(String query, String typeName, String classification, int limit, int offset) throws AtlasBaseException { - AtlasSearchResult ret = new AtlasSearchResult(query, AtlasQueryType.BASIC); + AtlasSearchResult ret = new AtlasSearchResult(AtlasQueryType.BASIC); if (LOG.isDebugEnabled()) { LOG.debug("Executing basic search query: {} with type: {} and classification: {}", query, typeName, classification); @@ -197,7 +197,12 @@ public class EntityDiscoveryService implements AtlasDiscoveryService { ret.setClassification(classification); } - basicQuery += String.format(gremlinQueryProvider.getQuery(AtlasGremlinQuery.BASIC_SEARCH_QUERY_FILTER), query); + if (StringUtils.isNotEmpty(query)) { + basicQuery += String.format(gremlinQueryProvider.getQuery(AtlasGremlinQuery.BASIC_SEARCH_QUERY_FILTER), query); + + ret.setQueryText(query); + } + basicQuery += String.format(gremlinQueryProvider.getQuery(AtlasGremlinQuery.TO_RANGE_LIST), params.offset(), params.limit()); try { http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/670a4c00/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java ---------------------------------------------------------------------- diff --git a/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java b/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java index 4dd8bf5..ecb8d30 100644 --- a/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java +++ b/webapp/src/main/java/org/apache/atlas/web/rest/DiscoveryREST.java @@ -21,6 +21,7 @@ import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.discovery.AtlasDiscoveryService; import org.apache.atlas.model.discovery.AtlasSearchResult; import org.apache.atlas.web.util.Servlets; +import org.apache.commons.lang3.StringUtils; import javax.inject.Inject; import javax.inject.Singleton; @@ -46,6 +47,8 @@ public class DiscoveryREST { /** * Retrieve data for the specified DSL * @param query DSL query + * @param type limit the result to only entities of specified type or its sub-types + * @param classification limit the result to only entities tagged with the given classification or 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 @@ -59,10 +62,24 @@ public class DiscoveryREST { @Consumes(Servlets.JSON_MEDIA_TYPE) @Produces(Servlets.JSON_MEDIA_TYPE) public AtlasSearchResult searchUsingDSL(@QueryParam("query") String query, + @QueryParam("type") String type, + @QueryParam("classification") String classification, @QueryParam("limit") int limit, @QueryParam("offset") int offset) throws AtlasBaseException { + String queryStr = query == null ? "" : query; + + if (StringUtils.isNoneEmpty(type)) { + queryStr = type + " " + queryStr; + } + + if (StringUtils.isNoneEmpty(classification)) { + // isa works with a type name only - like hive_column isa PII; it doesn't work with more complex query + if (StringUtils.isEmpty(query)) { + queryStr += (" isa " + classification); + } + } - AtlasSearchResult ret = atlasDiscoveryService.searchUsingDslQuery(query, limit, offset); + AtlasSearchResult ret = atlasDiscoveryService.searchUsingDslQuery(queryStr, limit, offset); return ret; }
