Search in sources :

Example 11 with QueryParams

use of org.apache.atlas.query.QueryParams in project incubator-atlas by apache.

the class MetadataDiscoveryResource method searchUsingQueryDSL.

/**
     * Search using query DSL format.
     *
     * @param dslQuery search query in DSL format.
     * @param limit number of rows to be returned in the result, used for pagination. maxlimit > limit > 0. -1 maps to atlas.search.defaultlimit property value
     * @param offset offset to the results returned, used for pagination. offset >= 0. -1 maps to offset 0
     * Limit and offset in API are used in conjunction with limit and offset in DSL query
     * Final limit = min(API limit, max(query limit - API offset, 0))
     * Final offset = API offset + query offset
     *
     * @return JSON representing the type and results.
     */
@GET
@Path("search/dsl")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response searchUsingQueryDSL(@QueryParam("query") String dslQuery, @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("limit") int limit, @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("offset") int offset) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> MetadataDiscoveryResource.searchUsingQueryDSL({}, {}, {})", dslQuery, limit, offset);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "MetadataDiscoveryResource.searchUsingQueryDSL(" + dslQuery + ", " + limit + ", " + offset + ")");
        }
        dslQuery = ParamChecker.notEmpty(dslQuery, "dslQuery cannot be null");
        QueryParams queryParams = validateQueryParams(limit, offset);
        final String jsonResultStr = discoveryService.searchByDSL(dslQuery, queryParams);
        JSONObject response = new DSLJSONResponseBuilder().results(jsonResultStr).query(dslQuery).build();
        return Response.ok(response).build();
    } catch (DiscoveryException | IllegalArgumentException e) {
        LOG.error("Unable to get entity list for dslQuery {}", dslQuery, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get entity list for dslQuery {}", dslQuery, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get entity list for dslQuery {}", dslQuery, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== MetadataDiscoveryResource.searchUsingQueryDSL({}, {}, {})", dslQuery, limit, offset);
        }
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) QueryParams(org.apache.atlas.query.QueryParams) DiscoveryException(org.apache.atlas.discovery.DiscoveryException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 12 with QueryParams

use of org.apache.atlas.query.QueryParams in project incubator-atlas by apache.

the class MetadataDiscoveryResource method searchUsingFullText.

/**
     * Search using full text search.
     *
     * @param query search query.
     * @param limit number of rows to be returned in the result, used for pagination. maxlimit > limit > 0. -1 maps to atlas.search.defaultlimit property value
     * @param offset offset to the results returned, used for pagination. offset >= 0. -1 maps to offset 0
     * @return JSON representing the type and results.
     */
@GET
@Path("search/fulltext")
@Consumes(Servlets.JSON_MEDIA_TYPE)
@Produces(Servlets.JSON_MEDIA_TYPE)
public Response searchUsingFullText(@QueryParam("query") String query, @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("limit") int limit, @DefaultValue(LIMIT_OFFSET_DEFAULT) @QueryParam("offset") int offset) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> MetadataDiscoveryResource.searchUsingFullText({}, {}, {})", query, limit, offset);
    }
    AtlasPerfTracer perf = null;
    try {
        if (AtlasPerfTracer.isPerfTraceEnabled(PERF_LOG)) {
            perf = AtlasPerfTracer.getPerfTracer(PERF_LOG, "MetadataDiscoveryResource.searchUsingFullText(" + query + ", " + limit + ", " + offset + ")");
        }
        query = ParamChecker.notEmpty(query, "query cannot be null or empty");
        QueryParams queryParams = validateQueryParams(limit, offset);
        final String jsonResultStr = discoveryService.searchByFullText(query, queryParams);
        JSONArray rowsJsonArr = new JSONArray(jsonResultStr);
        JSONObject response = new FullTextJSonResponseBuilder().results(rowsJsonArr).query(query).build();
        return Response.ok(response).build();
    } catch (DiscoveryException | IllegalArgumentException e) {
        LOG.error("Unable to get entity list for query {}", query, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.BAD_REQUEST));
    } catch (WebApplicationException e) {
        LOG.error("Unable to get entity list for query {}", query, e);
        throw e;
    } catch (Throwable e) {
        LOG.error("Unable to get entity list for query {}", query, e);
        throw new WebApplicationException(Servlets.getErrorResponse(e, Response.Status.INTERNAL_SERVER_ERROR));
    } finally {
        AtlasPerfTracer.log(perf);
        if (LOG.isDebugEnabled()) {
            LOG.debug("<== MetadataDiscoveryResource.searchUsingFullText({}, {}, {})", query, limit, offset);
        }
    }
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) WebApplicationException(javax.ws.rs.WebApplicationException) AtlasPerfTracer(org.apache.atlas.utils.AtlasPerfTracer) JSONArray(org.codehaus.jettison.json.JSONArray) QueryParams(org.apache.atlas.query.QueryParams) DiscoveryException(org.apache.atlas.discovery.DiscoveryException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 13 with QueryParams

use of org.apache.atlas.query.QueryParams in project incubator-atlas by apache.

the class CompiledQueryCacheKeyTest method testWithQueryParams.

@Test
public void testWithQueryParams() {
    CompiledQueryCacheKey e1 = new CompiledQueryCacheKey("query 1", new QueryParams(10, 10));
    CompiledQueryCacheKey e2 = new CompiledQueryCacheKey("query 1", new QueryParams(10, 10));
    CompiledQueryCacheKey e3 = new CompiledQueryCacheKey("query 2", new QueryParams(10, 10));
    assertKeysEqual(e1, e2);
    assertKeysDifferent(e2, e3);
}
Also used : QueryParams(org.apache.atlas.query.QueryParams) Test(org.testng.annotations.Test)

Example 14 with QueryParams

use of org.apache.atlas.query.QueryParams in project incubator-atlas by apache.

the class CompiledQueryCacheKeyTest method testOnlyDslDifferent.

@Test
public void testOnlyDslDifferent() {
    CompiledQueryCacheKey e1 = new CompiledQueryCacheKey("query 1", new QueryParams(10, 10));
    CompiledQueryCacheKey e2 = new CompiledQueryCacheKey("query 2", new QueryParams(10, 10));
    assertKeysDifferent(e1, e2);
}
Also used : QueryParams(org.apache.atlas.query.QueryParams) Test(org.testng.annotations.Test)

Example 15 with QueryParams

use of org.apache.atlas.query.QueryParams in project incubator-atlas by apache.

the class CompiledQueryCacheKeyTest method testMixOfQueryParamsAndNone.

@Test
public void testMixOfQueryParamsAndNone() {
    CompiledQueryCacheKey e1 = new CompiledQueryCacheKey("query 1", new QueryParams(10, 10));
    CompiledQueryCacheKey e2 = new CompiledQueryCacheKey("query 1");
    assertKeysDifferent(e1, e2);
}
Also used : QueryParams(org.apache.atlas.query.QueryParams) Test(org.testng.annotations.Test)

Aggregations

QueryParams (org.apache.atlas.query.QueryParams)15 Test (org.testng.annotations.Test)8 JSONObject (org.codehaus.jettison.json.JSONObject)6 JSONArray (org.codehaus.jettison.json.JSONArray)4 ArrayList (java.util.ArrayList)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 DiscoveryException (org.apache.atlas.discovery.DiscoveryException)2 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)2 AtlasSearchResult (org.apache.atlas.model.discovery.AtlasSearchResult)2 Referenceable (org.apache.atlas.typesystem.Referenceable)2 AttributeDefinition (org.apache.atlas.typesystem.types.AttributeDefinition)2 ClassType (org.apache.atlas.typesystem.types.ClassType)2 AtlasPerfTracer (org.apache.atlas.utils.AtlasPerfTracer)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)1