use of io.crate.analyze.WhereClause in project crate by crate.
the class WhereClauseAnalyzerTest method test1ColPrimaryKey.
@Test
public void test1ColPrimaryKey() throws Exception {
WhereClause whereClause = analyzeSelectWhere("select name from users where id='jalla'");
assertThat(whereClause.docKeys().get(), contains(isDocKey("jalla")));
whereClause = analyzeSelectWhere("select name from users where 'jalla'=id");
assertThat(whereClause.docKeys().get(), contains(isDocKey("jalla")));
whereClause = analyzeSelectWhere("select name from users where id='jalla' and id='jalla'");
assertThat(whereClause.docKeys().get(), contains(isDocKey("jalla")));
whereClause = analyzeSelectWhere("select name from users where id='jalla' and (id='jalla' or 1=1)");
assertThat(whereClause.docKeys().get(), contains(isDocKey("jalla")));
// since the id is unique it is not possible to have a result here, this is not optimized and just results in
// no found primary keys
whereClause = analyzeSelectWhere("select name from users where id='jalla' and id='kelle'");
assertFalse(whereClause.docKeys().isPresent());
whereClause = analyzeSelectWhere("select name from users where id='jalla' or name = 'something'");
assertFalse(whereClause.docKeys().isPresent());
assertFalse(whereClause.noMatch());
whereClause = analyzeSelectWhere("select name from users where name = 'something'");
assertFalse(whereClause.docKeys().isPresent());
assertFalse(whereClause.noMatch());
}
use of io.crate.analyze.WhereClause in project crate by crate.
the class LuceneQueryBuilderTest method testEqOnArrayWithTooManyClauses.
@Test
public void testEqOnArrayWithTooManyClauses() throws Exception {
// should trigger the TooManyClauses exception
Object[] values = new Object[2000];
Arrays.fill(values, 10L);
SqlExpressions sqlExpressions = new SqlExpressions(sources, new Object[] { values });
Query query = convert(new WhereClause(expressions.normalize(sqlExpressions.asSymbol("y_array = ?"))));
assertThat(query, instanceOf(BooleanQuery.class));
BooleanQuery booleanQuery = (BooleanQuery) query;
assertThat(booleanQuery.clauses().get(0).getQuery(), instanceOf(TermsQuery.class));
assertThat(booleanQuery.clauses().get(1).getQuery(), instanceOf(GenericFunctionQuery.class));
}
use of io.crate.analyze.WhereClause in project crate by crate.
the class RoutedCollectPhase method replaceSymbols.
@Override
public void replaceSymbols(Function<Symbol, Symbol> replaceFunction) {
super.replaceSymbols(replaceFunction);
if (whereClause.hasQuery()) {
Symbol query = whereClause.query();
Symbol newQuery = replaceFunction.apply(query);
if (query != newQuery) {
whereClause = new WhereClause(newQuery, whereClause.docKeys().orElse(null), whereClause.partitions());
}
}
Lists2.replaceItems(toCollect, replaceFunction);
if (orderBy != null) {
orderBy.replace(replaceFunction);
}
}
use of io.crate.analyze.WhereClause in project crate by crate.
the class LuceneQueryBuilderTest method testEqOnTwoArraysBecomesGenericFunctionQueryAllValuesNull.
@Test
public void testEqOnTwoArraysBecomesGenericFunctionQueryAllValuesNull() throws Exception {
SqlExpressions sqlExpressions = new SqlExpressions(sources, new Object[] { new Object[] { null, null, null } });
Query query = convert(new WhereClause(expressions.normalize(sqlExpressions.asSymbol("y_array = ?"))));
assertThat(query, instanceOf(GenericFunctionQuery.class));
}
use of io.crate.analyze.WhereClause in project crate by crate.
the class PlannerTest method testAllocateRouting.
@Test
public void testAllocateRouting() throws Exception {
TableIdent custom = new TableIdent("custom", "t1");
TableInfo tableInfo1 = TestingTableInfo.builder(custom, shardRouting("t1")).add("id", DataTypes.INTEGER, null).build();
TableInfo tableInfo2 = TestingTableInfo.builder(custom, shardRoutingForReplicas("t1")).add("id", DataTypes.INTEGER, null).build();
Planner.Context plannerContext = new Planner.Context(e.planner, clusterService, UUID.randomUUID(), null, normalizer, new TransactionContext(SessionContext.SYSTEM_SESSION), 0, 0);
WhereClause whereClause = new WhereClause(new Function(new FunctionInfo(new FunctionIdent(EqOperator.NAME, Arrays.<DataType>asList(DataTypes.INTEGER, DataTypes.INTEGER)), DataTypes.BOOLEAN), Arrays.asList(tableInfo1.getReference(new ColumnIdent("id")), Literal.of(2))));
plannerContext.allocateRouting(tableInfo1, WhereClause.MATCH_ALL, null);
plannerContext.allocateRouting(tableInfo2, whereClause, null);
// 2 routing allocations with different where clause must result in 2 allocated routings
java.lang.reflect.Field tableRoutings = Planner.Context.class.getDeclaredField("tableRoutings");
tableRoutings.setAccessible(true);
Multimap<TableIdent, Planner.TableRouting> routing = (Multimap<TableIdent, Planner.TableRouting>) tableRoutings.get(plannerContext);
assertThat(routing.size(), is(2));
// The routings must be the same after merging the locations
Iterator<Planner.TableRouting> iterator = routing.values().iterator();
Routing routing1 = iterator.next().routing;
Routing routing2 = iterator.next().routing;
assertThat(routing1, is(routing2));
}
Aggregations