use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class OCommandExecutorSQLSelectTest method testSkipZeroOrdered.
@Test
public void testSkipZeroOrdered() {
OSQLSynchQuery sql = new OSQLSynchQuery("SELECT from alphabet ORDER BY letter SKIP 0");
List<ODocument> results = db.query(sql);
assertEquals(26, results.size());
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class OCommandExecutorSQLSelectTest method testLetOrder.
@Test
public void testLetOrder() {
OSQLSynchQuery sql = new OSQLSynchQuery("SELECT" + " source," + " $maxYear as maxYear" + " FROM" + " (" + " SELECT expand( $union ) " + " LET" + " $a = (SELECT 'A' as source, 2013 as year)," + " $b = (SELECT 'B' as source, 2012 as year)," + " $union = unionAll($a,$b) " + " ) " + " LET " + " $maxYear = max(year)" + " GROUP BY" + " source");
try {
List<ODocument> results = db.query(sql);
fail("Invalid query, usage of LET, aggregate functions and GROUP BY together is not supported");
} catch (OCommandSQLParsingException x) {
}
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class OCommandExecutorSQLSelectTest method testParamWithMatchesAndNot.
@Test
public void testParamWithMatchesAndNot() {
// issue #5229
Map<String, Object> params = new HashMap<String, Object>();
params.put("param1", "adm.*");
params.put("param2", "foo.*");
OSQLSynchQuery sql = new OSQLSynchQuery("select from OUser where (name matches :param1 and not (name matches :param2))");
List<ODocument> results = db.query(sql, params);
assertEquals(results.size(), 1);
params.put("param1", Pattern.quote("adm") + ".*");
results = db.query(sql, params);
assertEquals(results.size(), 1);
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class OCommandExecutorSQLSelectTest method testFilterAndOrderBy.
@Test
public void testFilterAndOrderBy() {
// issue http://www.prjhub.com/#/issues/6199
OSQLSynchQuery sql = new OSQLSynchQuery("SELECT FROM FilterAndOrderByTest WHERE active = true ORDER BY dc DESC");
List<ODocument> results = db.query(sql);
assertEquals(results.size(), 3);
Calendar cal = new GregorianCalendar();
Date date = results.get(0).field("dc");
cal.setTime(date);
assertEquals(cal.get(Calendar.YEAR), 2016);
date = results.get(1).field("dc");
cal.setTime(date);
assertEquals(cal.get(Calendar.YEAR), 2010);
date = results.get(2).field("dc");
cal.setTime(date);
assertEquals(cal.get(Calendar.YEAR), 2009);
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class OCommandExecutorSQLSelectTest method testParamWithMatchesQuoteRegex.
@Test
public void testParamWithMatchesQuoteRegex() {
// issue #5229
Map<String, Object> params = new HashMap<String, Object>();
// will not work
params.put("param1", ".*admin[name].*");
OSQLSynchQuery sql = new OSQLSynchQuery("select from matchesstuff where name matches :param1");
List<ODocument> results = db.query(sql, params);
assertEquals(results.size(), 0);
// should work
params.put("param1", Pattern.quote("admin[name]") + ".*");
results = db.query(sql, params);
assertEquals(results.size(), 1);
}
Aggregations