use of io.crate.expression.symbol.Function in project crate by crate.
the class DocLevelCollectTest method testCollectDocLevelWhereClause.
@Test
public void testCollectDocLevelWhereClause() throws Throwable {
List<Symbol> arguments = Arrays.asList(testDocLevelReference, Literal.of(2));
EqOperator op = (EqOperator) functions.get(null, EqOperator.NAME, arguments, SearchPath.pathWithPGCatalogAndDoc());
List<Symbol> toCollect = Collections.singletonList(testDocLevelReference);
WhereClause whereClause = new WhereClause(new Function(op.signature(), arguments, EqOperator.RETURN_TYPE));
RoutedCollectPhase collectNode = getCollectNode(toCollect, whereClause);
Bucket result = collect(collectNode);
assertThat(result, contains(isRow(2)));
}
use of io.crate.expression.symbol.Function in project crate by crate.
the class AbstractTableFunctionsTest method assertCompile.
public void assertCompile(String functionExpression, java.util.function.Function<Scalar, Matcher<Scalar>> matcher) {
Symbol functionSymbol = sqlExpressions.asSymbol(functionExpression);
functionSymbol = sqlExpressions.normalize(functionSymbol);
assertThat("function expression was normalized, compile would not be hit", functionSymbol, not(instanceOf(Literal.class)));
Function function = (Function) functionSymbol;
Scalar scalar = (Scalar) sqlExpressions.nodeCtx.functions().getQualified(function, txnCtx.sessionSettings().searchPath());
assertThat("Function implementation not found using full qualified lookup", scalar, Matchers.notNullValue());
Scalar compiled = scalar.compile(function.arguments());
assertThat(compiled, matcher.apply(scalar));
}
use of io.crate.expression.symbol.Function in project crate by crate.
the class AbstractTableFunctionsTest method execute.
protected Iterable<Row> execute(String expr) {
Symbol functionSymbol = sqlExpressions.normalize(sqlExpressions.asSymbol(expr));
var function = (Function) functionSymbol;
var functionImplementation = (TableFunctionImplementation<?>) sqlExpressions.nodeCtx.functions().getQualified(function, txnCtx.sessionSettings().searchPath());
if (functionImplementation.returnType().numElements() > 1) {
// See classdocs of TableFunctionImplementation for an explanation
assertThat("If the rowType has multiple elements, the returnType of the boundSignature " + "must be an exact match of the returnType", functionImplementation.boundSignature().getReturnType().createType(), is(functionImplementation.returnType()));
}
// noinspection unchecked,rawtypes
return functionImplementation.evaluate(txnCtx, null, function.arguments().stream().map(a -> (Input) a).toArray(Input[]::new));
}
use of io.crate.expression.symbol.Function in project crate by crate.
the class JoinPhaseTest method setup.
@Before
public void setup() {
topNProjection = new TopNProjection(10, 0, Collections.emptyList());
jobId = UUID.randomUUID();
mp1 = new MergePhase(jobId, 2, "merge", 1, 1, Collections.emptyList(), List.of(DataTypes.STRING), List.of(), DistributionInfo.DEFAULT_BROADCAST, null);
mp2 = new MergePhase(jobId, 3, "merge", 1, 1, Collections.emptyList(), List.of(DataTypes.STRING), List.of(), DistributionInfo.DEFAULT_BROADCAST, null);
joinCondition = new Function(EqOperator.SIGNATURE, List.of(new InputColumn(0, DataTypes.STRING), new InputColumn(1, DataTypes.STRING)), EqOperator.RETURN_TYPE);
}
use of io.crate.expression.symbol.Function in project crate by crate.
the class RelationAnalyzer method visitTableFunction.
@Override
public AnalyzedRelation visitTableFunction(TableFunction node, StatementAnalysisContext statementContext) {
RelationAnalysisContext context = statementContext.currentRelationContext();
ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(statementContext.transactionContext(), nodeCtx, statementContext.paramTyeHints(), FieldProvider.UNSUPPORTED, null);
ExpressionAnalysisContext expressionContext = context.expressionAnalysisContext();
// we support `FROM scalar()` but not `FROM 'literal'` -> we turn off eager normalization
// so we can distinguish between Function and Literal.
final boolean allowEagerNormalizeOriginalValue = expressionContext.isEagerNormalizationAllowed();
expressionContext.allowEagerNormalize(false);
Symbol symbol = expressionAnalyzer.convert(node.functionCall(), expressionContext);
expressionContext.allowEagerNormalize(allowEagerNormalizeOriginalValue);
if (!(symbol instanceof Function)) {
throw new UnsupportedOperationException(String.format(Locale.ENGLISH, "Symbol '%s' is not supported in FROM clause", node.name()));
}
Function function = (Function) symbol;
FunctionImplementation functionImplementation = nodeCtx.functions().getQualified(function, statementContext.sessionContext().searchPath());
assert functionImplementation != null : "Function implementation not found using full qualified lookup";
TableFunctionImplementation<?> tableFunction = TableFunctionFactory.from(functionImplementation);
TableFunctionRelation tableRelation = new TableFunctionRelation(tableFunction, function);
context.addSourceRelation(tableRelation);
return tableRelation;
}
Aggregations