use of com.orientechnologies.orient.core.sql.OIndexSearchResult in project orientdb by orientechnologies.
the class OFilterOptimizerTest method testOptimizeFullOptimization.
@Test
public void testOptimizeFullOptimization() throws Exception {
final OSQLFilter filter = OSQLEngine.getInstance().parseCondition("a = 3", null, "WHERE");
final OSQLFilterCondition condition = filter.getRootCondition();
final OIndexSearchResult searchResult = new OIndexSearchResult(condition.getOperator(), ((OSQLFilterItemField) condition.getLeft()).getFieldChain(), 3);
optimizer.optimize(filter, searchResult);
Assert.assertNull(filter.getRootCondition());
}
use of com.orientechnologies.orient.core.sql.OIndexSearchResult in project orientdb by orientechnologies.
the class OFilterOptimizerTest method testOptimizePartialOptimizationMethod.
@Test
public void testOptimizePartialOptimizationMethod() throws Exception {
final OSQLFilter filter = OSQLEngine.getInstance().parseCondition("a = 3 and b.asFloat() > 3.14", null, "WHERE");
final OSQLFilterCondition condition = filter.getRootCondition();
final OIndexSearchResult searchResult = new OIndexSearchResult(((OSQLFilterCondition) condition.getLeft()).getOperator(), ((OSQLFilterItemField) ((OSQLFilterCondition) condition.getLeft()).getLeft()).getFieldChain(), 3);
optimizer.optimize(filter, searchResult);
Assert.assertEquals(filter.getRootCondition().toString(), "(b.asfloat > 3.14)");
}
use of com.orientechnologies.orient.core.sql.OIndexSearchResult in project orientdb by orientechnologies.
the class OLuceneOperatorUtil method buildOIndexSearchResult.
public static OIndexSearchResult buildOIndexSearchResult(OClass iSchemaClass, OSQLFilterCondition iCondition, List<OIndexSearchResult> iIndexSearchResults, OCommandContext context) {
if (iCondition.getLeft() instanceof Collection) {
OIndexSearchResult lastResult = null;
Collection left = (Collection) iCondition.getLeft();
int i = 0;
Object lastValue = null;
for (Object obj : left) {
if (obj instanceof OSQLFilterItemField) {
OSQLFilterItemField item = (OSQLFilterItemField) obj;
Object value = null;
if (iCondition.getRight() instanceof Collection) {
List<Object> right = (List<Object>) iCondition.getRight();
value = right.get(i);
} else {
value = iCondition.getRight();
}
if (lastResult == null) {
lastResult = new OIndexSearchResult(iCondition.getOperator(), item.getFieldChain(), value);
} else {
lastResult = lastResult.merge(new OIndexSearchResult(iCondition.getOperator(), item.getFieldChain(), value));
}
} else if (obj instanceof OSQLFilterItemVariable) {
OSQLFilterItemVariable item = (OSQLFilterItemVariable) obj;
Object value = null;
if (iCondition.getRight() instanceof Collection) {
List<Object> right = (List<Object>) iCondition.getRight();
value = right.get(i);
} else {
value = iCondition.getRight();
}
context.setVariable(item.toString(), value);
}
i++;
}
if (lastResult != null && OLuceneOperatorUtil.checkIndexExistence(iSchemaClass, lastResult))
iIndexSearchResults.add(lastResult);
return lastResult;
} else {
OIndexSearchResult result = OLuceneOperatorUtil.createIndexedProperty(iCondition, iCondition.getLeft());
if (result == null)
result = OLuceneOperatorUtil.createIndexedProperty(iCondition, iCondition.getRight());
if (result == null)
return null;
if (OLuceneOperatorUtil.checkIndexExistence(iSchemaClass, result))
iIndexSearchResults.add(result);
return result;
}
}
use of com.orientechnologies.orient.core.sql.OIndexSearchResult in project orientdb by orientechnologies.
the class OLuceneOperatorUtil method createIndexedProperty.
public static OIndexSearchResult createIndexedProperty(final OSQLFilterCondition iCondition, final Object iItem) {
if (iItem == null || !(iItem instanceof OSQLFilterItemField))
return null;
if (iCondition.getLeft() instanceof OSQLFilterItemField && iCondition.getRight() instanceof OSQLFilterItemField)
return null;
final OSQLFilterItemField item = (OSQLFilterItemField) iItem;
if (item.hasChainOperators() && !item.isFieldChain())
return null;
final Object origValue = iCondition.getLeft() == iItem ? iCondition.getRight() : iCondition.getLeft();
if (iCondition.getOperator() instanceof OQueryOperatorBetween || iCondition.getOperator() instanceof OQueryOperatorIn) {
return new OIndexSearchResult(iCondition.getOperator(), item.getFieldChain(), origValue);
}
final Object value = OSQLHelper.getValue(origValue);
if (value == null)
return null;
return new OIndexSearchResult(iCondition.getOperator(), item.getFieldChain(), value);
}
use of com.orientechnologies.orient.core.sql.OIndexSearchResult in project orientdb by orientechnologies.
the class OFilterOptimizerTest method testOptimizeFullOptimizationComplex.
@Test
public void testOptimizeFullOptimizationComplex() throws Exception {
final OSQLFilter filter = OSQLEngine.getInstance().parseCondition("a = 3 and b = 4", null, "WHERE");
final OSQLFilterCondition condition = filter.getRootCondition();
final OIndexSearchResult searchResult;
{
final OIndexSearchResult searchResult1;
{
final OSQLFilterCondition cnd = (OSQLFilterCondition) condition.getLeft();
searchResult1 = new OIndexSearchResult(cnd.getOperator(), ((OSQLFilterItemField) cnd.getLeft()).getFieldChain(), 3);
}
final OIndexSearchResult searchResult2;
{
final OSQLFilterCondition cnd = (OSQLFilterCondition) condition.getRight();
searchResult2 = new OIndexSearchResult(cnd.getOperator(), ((OSQLFilterItemField) cnd.getLeft()).getFieldChain(), 4);
}
searchResult = searchResult1.merge(searchResult2);
}
optimizer.optimize(filter, searchResult);
Assert.assertNull(filter.getRootCondition());
}
Aggregations