use of io.crate.analyze.symbol.Function in project crate by crate.
the class CurrentSchemaFunctionTest method testEvaluateCurrentSchemaNotSupported.
public void testEvaluateCurrentSchemaNotSupported() throws Exception {
expectedException.expect(UnsupportedOperationException.class);
expectedException.expectMessage("Cannot evaluate CURRENT_SCHEMA function.");
Function function = (Function) sqlExpressions.asSymbol("current_schema()");
Scalar impl = (Scalar) functions.get(function.info().ident());
impl.evaluate();
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class ExpressionAnalyzerTest method testInSelfJoinCaseFunctionsThatLookTheSameMustNotReuseFunctionAllocation.
@Test
public void testInSelfJoinCaseFunctionsThatLookTheSameMustNotReuseFunctionAllocation() throws Exception {
TableInfo tableInfo = mock(TableInfo.class);
when(tableInfo.getReference(new ColumnIdent("id"))).thenReturn(new Reference(new ReferenceIdent(new TableIdent("doc", "t"), "id"), RowGranularity.DOC, DataTypes.INTEGER));
when(tableInfo.ident()).thenReturn(new TableIdent("doc", "t"));
TableRelation tr1 = new TableRelation(tableInfo);
TableRelation tr2 = new TableRelation(tableInfo);
Map<QualifiedName, AnalyzedRelation> sources = ImmutableMap.of(new QualifiedName("t1"), tr1, new QualifiedName("t2"), tr2);
ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(functions, SessionContext.SYSTEM_SESSION, paramTypeHints, new FullQualifedNameFieldProvider(sources), null);
Function andFunction = (Function) expressionAnalyzer.convert(SqlParser.createExpression("not t1.id = 1 and not t2.id = 1"), context);
Field t1Id = ((Field) ((Function) ((Function) andFunction.arguments().get(0)).arguments().get(0)).arguments().get(0));
Field t2Id = ((Field) ((Function) ((Function) andFunction.arguments().get(1)).arguments().get(0)).arguments().get(0));
assertTrue(t1Id.relation() != t2Id.relation());
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class SymbolFormatterTest method testFormat.
@Test
public void testFormat() throws Exception {
Function f = new Function(new FunctionInfo(new FunctionIdent("foo", Arrays.<DataType>asList(DataTypes.STRING, DataTypes.UNDEFINED)), DataTypes.DOUBLE), Arrays.<Symbol>asList(Literal.of("bar"), Literal.of(3.4)));
assertThat(SymbolFormatter.format("This Symbol is formatted %s", f), is("This Symbol is formatted foo('bar', 3.4)"));
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class AggregationTest method normalize.
protected Symbol normalize(String functionName, Symbol... args) {
DataType[] argTypes = new DataType[args.length];
for (int i = 0; i < args.length; i++) {
argTypes[i] = args[i].valueType();
}
AggregationFunction function = (AggregationFunction) functions.get(new FunctionIdent(functionName, Arrays.asList(argTypes)));
return function.normalizeSymbol(new Function(function.info(), Arrays.asList(args)), new TransactionContext(SessionContext.SYSTEM_SESSION));
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class WithinFunctionTest method testNormalizeWithStringLiteralAndReference.
@Test
public void testNormalizeWithStringLiteralAndReference() throws Exception {
Symbol normalized = normalize(FNAME, createReference("point", DataTypes.GEO_POINT), Literal.of("POLYGON ((5 5, 20 5, 30 30, 5 30, 5 5))"));
assertThat(normalized, instanceOf(Function.class));
Function function = (Function) normalized;
Symbol symbol = function.arguments().get(1);
assertThat(symbol.valueType(), equalTo(DataTypes.GEO_SHAPE));
}
Aggregations