use of io.crate.analyze.symbol.Function in project crate by crate.
the class UnnestFunctionTest method execute.
private Bucket execute(String expr) {
Symbol functionSymbol = sqlExpressions.asSymbol(expr);
functionSymbol = sqlExpressions.normalize(functionSymbol);
Function function = (Function) functionSymbol;
TableFunctionImplementation tableFunction = (TableFunctionImplementation) functions.getSafe(function.info().ident());
return tableFunction.execute(function.arguments().stream().map(a -> (Input) a).collect(Collectors.toList()));
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class RandomFunctionTest method normalizeReference.
@Test
public void normalizeReference() {
Function function = new Function(random.info(), Collections.<Symbol>emptyList());
Function normalized = (Function) random.normalizeSymbol(function, new TransactionContext(SessionContext.SYSTEM_SESSION));
assertThat(normalized, sameInstance(function));
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class DistanceFunction method normalizeSymbol.
@Override
public Symbol normalizeSymbol(Function symbol, TransactionContext transactionContext) {
Symbol arg1 = symbol.arguments().get(0);
Symbol arg2 = symbol.arguments().get(1);
DataType arg1Type = arg1.valueType();
DataType arg2Type = arg2.valueType();
boolean arg1IsReference = true;
boolean literalConverted = false;
short numLiterals = 0;
if (arg1.symbolType().isValueSymbol()) {
numLiterals++;
arg1IsReference = false;
if (!arg1Type.equals(DataTypes.GEO_POINT)) {
literalConverted = true;
arg1 = Literal.convert(arg1, DataTypes.GEO_POINT);
}
} else {
validateType(arg1, arg1Type);
}
if (arg2.symbolType().isValueSymbol()) {
numLiterals++;
if (!arg2Type.equals(DataTypes.GEO_POINT)) {
literalConverted = true;
arg2 = Literal.convert(arg2, DataTypes.GEO_POINT);
}
} else {
validateType(arg2, arg2Type);
}
if (numLiterals == 2) {
return Literal.of(evaluate((Input) arg1, (Input) arg2));
}
// ensure reference is the first argument.
if (!arg1IsReference) {
return new Function(geoPointInfo, Arrays.asList(arg2, arg1));
}
if (literalConverted) {
return new Function(geoPointInfo, Arrays.asList(arg1, arg2));
}
return symbol;
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class IntersectsFunction method normalizeSymbol.
@Override
public Symbol normalizeSymbol(Function symbol, TransactionContext transactionContext) {
Symbol left = symbol.arguments().get(0);
Symbol right = symbol.arguments().get(1);
int numLiterals = 0;
boolean literalConverted = false;
if (left.symbolType().isValueSymbol()) {
numLiterals++;
Symbol converted = convertTo(DataTypes.GEO_SHAPE, (Literal) left);
literalConverted = converted != right;
left = converted;
}
if (right.symbolType().isValueSymbol()) {
numLiterals++;
Symbol converted = convertTo(DataTypes.GEO_SHAPE, (Literal) right);
literalConverted = literalConverted || converted != right;
right = converted;
}
if (numLiterals == 2) {
return Literal.of(evaluate((Input) left, (Input) right));
}
if (literalConverted) {
return new Function(SHAPE_INFO, Arrays.asList(left, right));
}
return symbol;
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class AndOperator method join.
public static Symbol join(Iterable<? extends Symbol> symbols) {
Iterator<? extends Symbol> it = symbols.iterator();
assert it.hasNext() : "argument symbols must have at least one item";
Symbol first = it.next();
while (it.hasNext()) {
first = new Function(INFO, Arrays.asList(first, it.next()));
}
return first;
}
Aggregations