use of io.crate.testing.SqlExpressions in project crate by crate.
the class InputCreatingVisitorTest method testNonDeterministicFunctionsReplacement.
@Test
public void testNonDeterministicFunctionsReplacement() throws Exception {
SqlExpressions sqlExpressions = new SqlExpressions(T3.SOURCES, T3.TR_1);
Function fn1 = (Function) sqlExpressions.asSymbol("random()");
Function fn2 = (Function) sqlExpressions.asSymbol("random()");
List<Symbol> inputSymbols = Arrays.<Symbol>asList(Literal.BOOLEAN_FALSE, sqlExpressions.asSymbol("upper(a)"), fn1, fn2);
Function newSameFn = (Function) sqlExpressions.asSymbol("random()");
Function newDifferentFn = (Function) sqlExpressions.asSymbol("random()");
InputCreatingVisitor.Context context = new InputCreatingVisitor.Context(inputSymbols);
Symbol replaced1 = InputCreatingVisitor.INSTANCE.process(fn1, context);
assertThat(replaced1, is(instanceOf(InputColumn.class)));
assertThat(((InputColumn) replaced1).index(), is(2));
Symbol replaced2 = InputCreatingVisitor.INSTANCE.process(fn2, context);
assertThat(replaced2, is(instanceOf(InputColumn.class)));
assertThat(((InputColumn) replaced2).index(), is(3));
Symbol replaced3 = InputCreatingVisitor.INSTANCE.process(newSameFn, context);
// not replaced
assertThat(replaced3, is(equalTo((Symbol) newSameFn)));
Symbol replaced4 = InputCreatingVisitor.INSTANCE.process(newDifferentFn, context);
// not replaced
assertThat(replaced4, is(equalTo((Symbol) newDifferentFn)));
}
use of io.crate.testing.SqlExpressions in project crate by crate.
the class InternalCountOperationTest method testCount.
@Test
public void testCount() throws Exception {
execute("create table t (name string) clustered into 1 shards with (number_of_replicas = 0)");
ensureYellow();
execute("insert into t (name) values ('Marvin'), ('Arthur'), ('Trillian')");
execute("refresh table t");
CountOperation countOperation = internalCluster().getDataNodeInstance(CountOperation.class);
assertThat(countOperation.count("t", 0, WhereClause.MATCH_ALL), is(3L));
Schemas schemas = internalCluster().getInstance(Schemas.class);
TableInfo tableInfo = schemas.getTableInfo(new TableIdent(null, "t"));
TableRelation tableRelation = new TableRelation(tableInfo);
Map<QualifiedName, AnalyzedRelation> tableSources = ImmutableMap.<QualifiedName, AnalyzedRelation>of(new QualifiedName(tableInfo.ident().name()), tableRelation);
SqlExpressions sqlExpressions = new SqlExpressions(tableSources, tableRelation);
WhereClause whereClause = new WhereClause(sqlExpressions.normalize(sqlExpressions.asSymbol("name = 'Marvin'")));
assertThat(countOperation.count("t", 0, whereClause), is(1L));
}
use of io.crate.testing.SqlExpressions in project crate by crate.
the class CurrentSchemaFunctionTest method testNormalizeCurrentSchemaDefaultSchema.
@Test
public void testNormalizeCurrentSchemaDefaultSchema() throws Exception {
sqlExpressions = new SqlExpressions(tableSources, new SessionContext(0, Option.NONE, null));
functions = sqlExpressions.getInstance(Functions.class);
assertNormalize("current_schema()", isLiteral("doc"), false);
}
Aggregations