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;
}
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());
}
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());
}
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());
}
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());
}
Aggregations