Search in sources :

Example 6 with QueryStatement

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

the class QueryParserTest method testCompoundIdWithSpaces.

/**
 * @throws Exception
 */
@Test
public void testCompoundIdWithSpaces() throws Exception {
    QueryStatement stmt = new QueryStatement("select * from dataset where dataset.\"Number of Samples\" == 100");
    assertEquals("dataset", 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("Number of Samples", expression.getId().getFieldName());
    assertEquals(new Long(100), expression.getValue());
}
Also used : Expression(org.sagebionetworks.repo.model.query.Expression) QueryStatement(org.sagebionetworks.repo.web.query.QueryStatement) Test(org.junit.Test)

Example 7 with QueryStatement

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

the class QueryParserTest method testSelectMultiple.

@Test
public void testSelectMultiple() throws Exception {
    QueryStatement stmt = new QueryStatement("select etag, name, id from enity where parentId == null");
    // This is what we expect the parser to find.
    List<String> expectedSelect = new ArrayList<String>();
    expectedSelect.add("etag");
    expectedSelect.add("name");
    expectedSelect.add("id");
    assertNotNull(stmt);
    assertNotNull(stmt.getSelect());
    assertEquals(expectedSelect, stmt.getSelect());
}
Also used : ArrayList(java.util.ArrayList) QueryStatement(org.sagebionetworks.repo.web.query.QueryStatement) Test(org.junit.Test)

Example 8 with QueryStatement

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

the class QueryParserTest method testWhereEqualsNumber.

/**
 * @throws Exception
 */
@Test
public void testWhereEqualsNumber() throws Exception {
    QueryStatement stmt = new QueryStatement("select * from dataset where \"Number of Samples\" == 100");
    assertEquals("dataset", 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());
    assertEquals(new Long(100), expression.getValue());
}
Also used : Expression(org.sagebionetworks.repo.model.query.Expression) QueryStatement(org.sagebionetworks.repo.web.query.QueryStatement) Test(org.junit.Test)

Example 9 with QueryStatement

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

the class QueryParserTest method testLayerQuery.

/**
 * @throws Exception
 */
@Test
public void testLayerQuery() 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 10 with QueryStatement

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

the class QueryParserTest method testNullValue.

@Test
public void testNullValue() throws Exception {
    QueryStatement stmt = new QueryStatement("select * from enity where parentId == null");
    assertNotNull(stmt.getSearchCondition());
    assertEquals(1, stmt.getSearchCondition().size());
    Expression expr = stmt.getSearchCondition().get(0);
    assertNotNull(expr);
    assertEquals("parentId", expr.getId().getFieldName());
    assertEquals(null, expr.getValue());
}
Also used : Expression(org.sagebionetworks.repo.model.query.Expression) 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