Search in sources :

Example 1 with QueryStatement

use of org.sagebionetworks.repo.web.query.QueryStatement in project Synapse-Repository-Services by Sage-Bionetworks.

the class NodeQueryServiceImpl method query.

@Override
public QueryResults query(String userId, String query, HttpServletRequest request) throws DatastoreException, ParseException, NotFoundException, UnauthorizedException {
    // Parse and validate the query
    QueryStatement stmt = new QueryStatement(query);
    // Convert from a query statement to a basic query
    BasicQuery basic = QueryTranslator.createBasicQuery(stmt);
    QueryResults results = executeQueryWithAnnotations(userId, basic, request);
    results.setResults(formulateResult(stmt, results.getResults()));
    return results;
}
Also used : BasicQuery(org.sagebionetworks.repo.model.query.BasicQuery) QueryStatement(org.sagebionetworks.repo.web.query.QueryStatement) QueryResults(org.sagebionetworks.repo.model.QueryResults) NodeQueryResults(org.sagebionetworks.repo.model.NodeQueryResults)

Example 2 with QueryStatement

use of org.sagebionetworks.repo.web.query.QueryStatement in project Synapse-Repository-Services by Sage-Bionetworks.

the class QueryParserTest method testWhereGreaterThanLong.

@Test
public void testWhereGreaterThanLong() throws Exception {
    QueryStatement stmt = new QueryStatement("select * from datasets where datasets.Number_of_Samples > 101");
    assertEquals("datasets", stmt.getTableName());
    assertNotNull(stmt.getSearchCondition());
    assertEquals(1, stmt.getSearchCondition().size());
    assertTrue(stmt.getSearchCondition().get(0) instanceof Expression);
    Expression expression = (Expression) stmt.getSearchCondition().get(0);
    assertEquals("Number_of_Samples", expression.getId().getFieldName());
    assertTrue(expression.getValue() instanceof Long);
    assertEquals(101, ((Long) expression.getValue()).longValue());
    assertEquals(Comparator.GREATER_THAN, expression.getCompare());
}
Also used : Expression(org.sagebionetworks.repo.model.query.Expression) QueryStatement(org.sagebionetworks.repo.web.query.QueryStatement) Test(org.junit.Test)

Example 3 with QueryStatement

use of org.sagebionetworks.repo.web.query.QueryStatement in project Synapse-Repository-Services by Sage-Bionetworks.

the class QueryParserTest method testMultipleWhere.

@Test
public void testMultipleWhere() throws Exception {
    QueryStatement stmt = new QueryStatement("select * from dataset where dataset.Species == \"Human\" and dataset.Disease == \"Cancer\"");
    assertEquals("dataset", stmt.getTableName());
    assertNotNull(stmt.getSearchCondition());
    assertEquals(2, stmt.getSearchCondition().size());
    // The results should be in postfix form
    // Next should be an expression.
    Expression expression = stmt.getSearchCondition().get(1);
    assertEquals("dataset", expression.getId().getTableName());
    assertEquals("Disease", expression.getId().getFieldName());
    assertEquals(Comparator.EQUALS, expression.getCompare());
    assertEquals("Cancer", expression.getValue());
    // Next should be an expression.
    expression = stmt.getSearchCondition().get(0);
    assertEquals("dataset", expression.getId().getTableName());
    assertEquals("Species", expression.getId().getFieldName());
    assertEquals(Comparator.EQUALS, expression.getCompare());
    assertEquals("Human", expression.getValue());
}
Also used : Expression(org.sagebionetworks.repo.model.query.Expression) QueryStatement(org.sagebionetworks.repo.web.query.QueryStatement) Test(org.junit.Test)

Example 4 with QueryStatement

use of org.sagebionetworks.repo.web.query.QueryStatement in project Synapse-Repository-Services by Sage-Bionetworks.

the class QueryParserTest method testSingleQuoteStringLiteral.

/**
 * @throws Exception
 */
@Test
public void testSingleQuoteStringLiteral() throws Exception {
    QueryStatement stmt = new QueryStatement("select * from layer where dataset.id == '123'");
    assertEquals("layer", stmt.getTableName());
    assertNotNull(stmt.getSearchCondition());
    assertEquals(1, stmt.getSearchCondition().size());
    assertTrue(stmt.getSearchCondition().get(0) instanceof Expression);
    Expression expression = (Expression) stmt.getSearchCondition().get(0);
    assertEquals("dataset", expression.getId().getTableName());
    assertEquals("id", expression.getId().getFieldName());
    assertEquals("123", expression.getValue());
}
Also used : Expression(org.sagebionetworks.repo.model.query.Expression) QueryStatement(org.sagebionetworks.repo.web.query.QueryStatement) Test(org.junit.Test)

Example 5 with QueryStatement

use of org.sagebionetworks.repo.web.query.QueryStatement in project Synapse-Repository-Services by Sage-Bionetworks.

the class QueryParserTest method testOrderBy.

/**
 * @throws Exception
 */
@Test
public void testOrderBy() throws Exception {
    QueryStatement stmt = new QueryStatement("select * from dataset order by name");
    assertEquals("dataset", stmt.getTableName());
    assertNull(stmt.getSortTable());
    assertEquals("name", stmt.getSortField());
}
Also used : QueryStatement(org.sagebionetworks.repo.web.query.QueryStatement) Test(org.junit.Test)

Aggregations

QueryStatement (org.sagebionetworks.repo.web.query.QueryStatement)36 Test (org.junit.Test)35 BasicQuery (org.sagebionetworks.repo.model.query.BasicQuery)14 Expression (org.sagebionetworks.repo.model.query.Expression)13 ArrayList (java.util.ArrayList)3 NodeQueryResults (org.sagebionetworks.repo.model.NodeQueryResults)1 QueryResults (org.sagebionetworks.repo.model.QueryResults)1