use of io.crate.analyze.symbol.Function in project crate by crate.
the class InsertPlannerTest method testInsertFromQueryWithPartitionedColumn.
@Test
public void testInsertFromQueryWithPartitionedColumn() throws Exception {
Merge planNode = e.plan("insert into users (id, date) (select id, date from parted_pks)");
Collect queryAndFetch = (Collect) planNode.subPlan();
RoutedCollectPhase collectPhase = ((RoutedCollectPhase) queryAndFetch.collectPhase());
List<Symbol> toCollect = collectPhase.toCollect();
assertThat(toCollect.size(), is(2));
assertThat(toCollect.get(0), isFunction("to_long"));
assertThat(((Function) toCollect.get(0)).arguments().get(0), isReference("_doc['id']"));
assertThat((Reference) toCollect.get(1), equalTo(new Reference(new ReferenceIdent(TableDefinitions.PARTED_PKS_IDENT, "date"), RowGranularity.PARTITION, DataTypes.TIMESTAMP)));
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class LogFunctionTest method testNormalizeReference.
@Test
public void testNormalizeReference() throws Exception {
Reference dB = createReference("dB", DataTypes.DOUBLE);
LogFunction log10 = getFunction(LogFunction.NAME, DataTypes.DOUBLE);
Function function = new Function(log10.info(), Arrays.<Symbol>asList(dB));
Function normalized = (Function) log10.normalizeSymbol(function, transactionContext);
assertThat(normalized, Matchers.sameInstance(function));
LogFunction ln = getFunction(LogFunction.LnFunction.NAME, DataTypes.DOUBLE);
function = new Function(ln.info(), Arrays.<Symbol>asList(dB));
normalized = (Function) ln.normalizeSymbol(function, transactionContext);
assertThat(normalized, Matchers.sameInstance(function));
LogFunction logBase = getFunction(LogFunction.NAME, DataTypes.DOUBLE, DataTypes.LONG);
function = new Function(logBase.info(), Arrays.<Symbol>asList(dB, Literal.of(10L)));
normalized = (Function) logBase.normalizeSymbol(function, transactionContext);
assertThat(normalized, Matchers.sameInstance(function));
Reference base = createReference("base", DataTypes.INTEGER);
function = new Function(logBase.info(), Arrays.<Symbol>asList(dB, base));
normalized = (Function) logBase.normalizeSymbol(function, transactionContext);
assertThat(normalized, Matchers.sameInstance(function));
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class MultiSourceAggregationConsumer method removeAggregationsAndLimitsFromMSS.
private static void removeAggregationsAndLimitsFromMSS(MultiSourceSelect mss, SplitPoints splitPoints) {
QuerySpec querySpec = mss.querySpec();
List<Symbol> outputs = Lists2.concatUnique(splitPoints.toCollect(), extractFieldsFromJoinConditions(mss));
querySpec.outputs(outputs);
querySpec.hasAggregates(false);
// Limit & offset must be applied after the aggregation, so remove it from mss and sources.
// OrderBy can be ignored because it's also applied after aggregation but there is always only 1 row so it
// wouldn't have any effect.
removeLimitOffsetAndOrder(querySpec);
for (RelationSource relationSource : mss.sources().values()) {
removeLimitOffsetAndOrder(relationSource.querySpec());
}
// need to change the types on the fields of the MSS to match the new outputs
ListIterator<Field> fieldsIt = mss.fields().listIterator();
Iterator<Function> outputsIt = splitPoints.aggregates().iterator();
while (fieldsIt.hasNext()) {
Field field = fieldsIt.next();
Symbol output = outputsIt.next();
fieldsIt.set(new Field(field.relation(), field.path(), output.valueType()));
}
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class WithinFunction method normalizeSymbol.
@Override
public Symbol normalizeSymbol(Function symbol, TransactionContext transactionContext) {
Symbol left = symbol.arguments().get(0);
Symbol right = symbol.arguments().get(1);
boolean literalConverted = false;
short numLiterals = 0;
if (left.symbolType().isValueSymbol()) {
numLiterals++;
Symbol converted = convertTo(DataTypes.GEO_POINT, (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 ExpressionAnalyzerTest method testSwapFunctionLeftSide.
@Test
public void testSwapFunctionLeftSide() throws Exception {
SqlExpressions expressions = new SqlExpressions(T3.SOURCES);
Function cmp = (Function) expressions.normalize(expressions.asSymbol("8 + 5 > t1.x"));
// the comparison was swapped so the field is on the left side
assertThat(cmp.info().ident().name(), is("op_<"));
assertThat(cmp.arguments().get(0), isField("x"));
}
Aggregations