use of io.crate.expression.symbol.Function in project crate by crate.
the class ProjectSet method pruneOutputsExcept.
@Override
public LogicalPlan pruneOutputsExcept(TableStats tableStats, Collection<Symbol> outputsToKeep) {
HashSet<Symbol> toKeep = new HashSet<>();
LinkedHashSet<Symbol> newStandalone = new LinkedHashSet<>();
for (Symbol outputToKeep : outputsToKeep) {
SymbolVisitors.intersection(outputToKeep, standalone, newStandalone::add);
}
for (Function tableFunction : tableFunctions) {
SymbolVisitors.intersection(tableFunction, source.outputs(), toKeep::add);
}
toKeep.addAll(newStandalone);
LogicalPlan newSource = source.pruneOutputsExcept(tableStats, toKeep);
if (newSource == source) {
return this;
}
return new ProjectSet(newSource, tableFunctions, List.copyOf(newStandalone));
}
use of io.crate.expression.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(EqOperator.SIGNATURE, List.of(load_1, d01), EqOperator.RETURN_TYPE);
Symbol name_ref = new Reference(new ReferenceIdent(new RelationName(Schemas.DOC_SCHEMA_NAME, "foo"), "name"), RowGranularity.DOC, DataTypes.STRING, 0, null);
Symbol x_literal = Literal.of("x");
Symbol y_literal = Literal.of("y");
Function name_eq_x = new Function(EqOperator.SIGNATURE, List.of(name_ref, x_literal), EqOperator.RETURN_TYPE);
Function nameNeqX = new Function(NotPredicate.SIGNATURE, Collections.singletonList(name_eq_x), NotPredicate.SIGNATURE.getReturnType().createType());
Function name_eq_y = new Function(EqOperator.SIGNATURE, List.of(name_ref, y_literal), EqOperator.RETURN_TYPE);
Function nameNeqY = new Function(NotPredicate.SIGNATURE, Collections.singletonList(name_eq_y), NotPredicate.SIGNATURE.getReturnType().createType());
Function op_and = new Function(AndOperator.SIGNATURE, List.of(nameNeqX, nameNeqY), AndOperator.RETURN_TYPE);
return new Function(OrOperator.SIGNATURE, List.of(load_eq_01, op_and), OrOperator.RETURN_TYPE);
}
use of io.crate.expression.symbol.Function in project crate by crate.
the class GroupByAnalyzerTest method testGroupByHavingOtherColumnInAggregate.
@Test
public void testGroupByHavingOtherColumnInAggregate() throws Exception {
QueriedSelectRelation relation = analyze("select sum(floats), name from users group by name having max(bytes) = 4::char");
assertThat(relation.having(), isFunction("op_="));
Function havingFunction = (Function) relation.having();
assertThat(havingFunction.arguments().size(), is(2));
assertThat(havingFunction.arguments().get(0), isFunction("max"));
Function maxFunction = (Function) havingFunction.arguments().get(0);
assertThat(maxFunction.arguments().get(0), isReference("bytes"));
assertThat(havingFunction.arguments().get(1), isLiteral((byte) 4));
}
use of io.crate.expression.symbol.Function in project crate by crate.
the class GroupByAnalyzerTest method testGroupByHavingByGroupKey.
@Test
public void testGroupByHavingByGroupKey() throws Exception {
QueriedSelectRelation relation = analyze("select sum(floats), name from users group by name having name like 'Slartibart%'");
assertThat(relation.having(), isFunction(LikeOperators.OP_LIKE));
Function havingFunction = (Function) relation.having();
assertThat(havingFunction.arguments().size(), is(2));
assertThat(havingFunction.arguments().get(0), isReference("name"));
assertThat(havingFunction.arguments().get(1), isLiteral("Slartibart%"));
}
use of io.crate.expression.symbol.Function in project crate by crate.
the class InsertAnalyzerTest method testFromQueryWithOnDuplicateKeyValues.
@Test
public void testFromQueryWithOnDuplicateKeyValues() throws Exception {
var insert = "insert into users (id, name) (select id, name from users) " + "on conflict (id) do update set name = substr(excluded.name, 1, 1)";
AnalyzedInsertStatement statement = e.analyze(insert);
Assert.assertThat(statement.onDuplicateKeyAssignments().size(), is(1));
for (Map.Entry<Reference, Symbol> entry : statement.onDuplicateKeyAssignments().entrySet()) {
assertThat(entry.getKey(), isReference("name"));
assertThat(entry.getValue(), isFunction(SubstrFunction.NAME));
Function function = (Function) entry.getValue();
assertThat(function.arguments().get(0), instanceOf(InputColumn.class));
InputColumn inputColumn = (InputColumn) function.arguments().get(0);
assertThat(inputColumn.index(), is(1));
assertThat(inputColumn.valueType(), instanceOf(StringType.class));
}
}
Aggregations