use of io.crate.analyze.symbol.Function in project crate by crate.
the class EvaluatingNormalizerTest method prepareFunctionTree.
/**
* prepare the following where clause as function symbol tree:
* <p>
* where test.dummy.load = 0.08 or name != 'x' and name != 'y'
* <p>
* test.dummy.load is a expression that can be evaluated on node level
* name would be a doc level reference and is untouched
*/
private Function prepareFunctionTree() {
Reference load_1 = dummyLoadInfo;
Literal<Double> d01 = Literal.of(0.08);
Function load_eq_01 = new Function(functionInfo(EqOperator.NAME, DataTypes.DOUBLE), Arrays.<Symbol>asList(load_1, d01));
Symbol name_ref = new Reference(new ReferenceIdent(new TableIdent(null, "foo"), "name"), RowGranularity.DOC, DataTypes.STRING);
Symbol x_literal = Literal.of("x");
Symbol y_literal = Literal.of("y");
Function name_eq_x = new Function(functionInfo(EqOperator.NAME, DataTypes.STRING), Arrays.<Symbol>asList(name_ref, x_literal));
Function name_neq_x = new Function(functionInfo(NotPredicate.NAME, DataTypes.BOOLEAN, true), Arrays.<Symbol>asList(name_eq_x));
Function name_eq_y = new Function(functionInfo(EqOperator.NAME, DataTypes.STRING), Arrays.<Symbol>asList(name_ref, y_literal));
Function name_neq_y = new Function(functionInfo(NotPredicate.NAME, DataTypes.BOOLEAN, true), Arrays.<Symbol>asList(name_eq_y));
Function op_and = new Function(functionInfo(AndOperator.NAME, DataTypes.BOOLEAN), Arrays.<Symbol>asList(name_neq_x, name_neq_y));
return new Function(functionInfo(OrOperator.NAME, DataTypes.BOOLEAN), Arrays.<Symbol>asList(load_eq_01, op_and));
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class DocLevelCollectTest method testCollectDocLevelWhereClause.
@Test
public void testCollectDocLevelWhereClause() throws Throwable {
EqOperator op = (EqOperator) functions.get(new FunctionIdent(EqOperator.NAME, ImmutableList.<DataType>of(DataTypes.INTEGER, DataTypes.INTEGER)));
List<Symbol> toCollect = Collections.<Symbol>singletonList(testDocLevelReference);
WhereClause whereClause = new WhereClause(new Function(op.info(), Arrays.<Symbol>asList(testDocLevelReference, Literal.of(2))));
RoutedCollectPhase collectNode = getCollectNode(toCollect, whereClause);
Bucket result = collect(collectNode);
assertThat(result, contains(isRow(2)));
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class HandlerSideLevelCollectTest method testInformationSchemaTables.
@Test
public void testInformationSchemaTables() throws Exception {
InformationSchemaInfo schemaInfo = internalCluster().getInstance(InformationSchemaInfo.class);
TableInfo tablesTableInfo = schemaInfo.getTableInfo("tables");
Routing routing = tablesTableInfo.getRouting(WhereClause.MATCH_ALL, null);
List<Symbol> toCollect = new ArrayList<>();
for (Reference reference : tablesTableInfo.columns()) {
toCollect.add(reference);
}
Symbol tableNameRef = toCollect.get(8);
FunctionImplementation eqImpl = functions.get(new FunctionIdent(EqOperator.NAME, ImmutableList.of(DataTypes.STRING, DataTypes.STRING)));
Function whereClause = new Function(eqImpl.info(), Arrays.asList(tableNameRef, Literal.of("shards")));
RoutedCollectPhase collectNode = collectNode(routing, toCollect, RowGranularity.DOC, new WhereClause(whereClause));
Bucket result = collect(collectNode);
assertThat(TestingHelpers.printedTable(result), is("NULL| NULL| strict| 0| 1| NULL| NULL| NULL| shards| sys| NULL\n"));
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class RegexpMatchCaseInsensitiveOperatorTest method normalizeSymbol.
private static Symbol normalizeSymbol(String source, String pattern) {
RegexpMatchCaseInsensitiveOperator op = new RegexpMatchCaseInsensitiveOperator();
Function function = new Function(op.info(), Arrays.<Symbol>asList(Literal.of(source), Literal.of(pattern)));
return op.normalizeSymbol(function, new TransactionContext(SessionContext.SYSTEM_SESSION));
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class AnyLikeOperatorTest method normalizeSymbol.
private static Symbol normalizeSymbol(String pattern, String... expressions) {
Literal patternLiteral = Literal.of(pattern);
Object[] value = new Object[expressions.length];
for (int i = 0; i < expressions.length; i++) {
value[i] = expressions[i] == null ? null : new BytesRef(expressions[i]);
}
Literal valuesLiteral = Literal.of(new ArrayType(DataTypes.STRING), value);
AnyLikeOperator impl = (AnyLikeOperator) new AnyLikeOperator.AnyLikeResolver().getForTypes(Arrays.asList(patternLiteral.valueType(), valuesLiteral.valueType()));
Function function = new Function(impl.info(), Arrays.<Symbol>asList(patternLiteral, valuesLiteral));
return impl.normalizeSymbol(function, new TransactionContext(SessionContext.SYSTEM_SESSION));
}
Aggregations