SQL: Replace Node's reflection with explicit code (elastic/x-pack-elasticsearch#3490)

This isn't pretty but it removes our need to compile with parameter
names in the debug symbols and the use of reflection during tree
transforms. `instanceof` is still used. It does so by forcing all
subclasses of `Node` to implement two methods like this:

```
    @Override
    protected NodeInfo<PercentileRank, Expression> info() {
        return info(this, PercentileRank::new, field(), value());
    }

    @Override
    protected Expression replaceChildren(List<Expression> newChildren) {
        if (newChildren.size() != 2) {
            throw new IllegalArgumentException("Expected [2] children but got [" + newChildren.size() + "]");
        }
        return new PercentileRank(location(), newChildren.get(0), newChildren.get(1));
    }
```

Every. Single. One.

This is tedious and painful and you have to do each one perfectly,
but it *is* checked by the compiler so it is less scary then the reflection
based approach it is replacing. Marginally. It is still pretty terrifying because
it requires so many tiny changes. While the compiler *does* check that
you've made all the right methods it doesn't check that you've implemented
them correctly.

Technically relates elastic/x-pack-elasticsearch#2871 but doesn't really close the "OO all the things" spirit
of elastic/x-pack-elasticsearch#2871.

A change like this deserves a million tests. Instead, I've created a hacky
reflection based test that attempts to verify that all subclasses of `Node`
implement these method correctly for some test verifiable definition of
"correct".

Original commit: elastic/x-pack-elasticsearch@a69ab634f4
This commit is contained in:
Nik Everett 2018-01-17 12:49:47 -05:00 committed by GitHub
parent c3b82e5ee1
commit 74ae8e3373
186 changed files with 3526 additions and 644 deletions

View File

@ -11,10 +11,6 @@ dependencyLicenses {
ignoreSha 'rest-proto'
}
// TODO probably not a good thing to rely on. See https://github.com/elastic/x-pack-elasticsearch/issues/2871
compileJava.options.compilerArgs << "-parameters"
compileTestJava.options.compilerArgs << "-parameters"
/**********************************************
* SQL Parser regeneration *
**********************************************/

View File

@ -135,7 +135,7 @@ public class Scroller {
else {
action = () -> aggValues.column(aggPosition);
}
return new AggValueInput(a.expression(), action, a.innerKey());
return new AggValueInput(a.location(), a.expression(), action, a.innerKey());
}, AggPathInput.class).asProcessor();
// the input is provided through the value input above
supplier = () -> processor.process(null);
@ -288,7 +288,7 @@ public class Scroller {
throw new SqlIllegalArgumentException("Multi-level nested fields [%s] not supported yet", hitNames);
}
return new HitExtractorInput(l.expression(), he);
return new HitExtractorInput(l.location(), l.expression(), he);
}, ReferenceInput.class);
String hitName = null;
if (hitNames.size() == 1) {

View File

@ -6,10 +6,13 @@
package org.elasticsearch.xpack.sql.expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
import static java.util.Collections.singletonList;
import java.util.List;
public class Alias extends NamedExpression {
private final Expression child;
@ -39,6 +42,19 @@ public class Alias extends NamedExpression {
this.qualifier = qualifier;
}
@Override
protected NodeInfo<Alias> info() {
return NodeInfo.create(this, Alias::new, name(), qualifier, child, id(), synthetic());
}
@Override
public Expression replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 1) {
throw new IllegalArgumentException("expected [1] child but received [" + newChildren.size() + "]");
}
return new Alias(location(), name(), qualifier, newChildren.get(0), id(), synthetic());
}
public Expression child() {
return child;
}

View File

@ -12,6 +12,8 @@ import java.util.Objects;
import static java.util.Collections.emptyList;
import java.util.List;
/**
* {@link Expression}s that can be converted into Elasticsearch
* sorts, aggregations, or queries. They can also be extracted
@ -40,6 +42,11 @@ public abstract class Attribute extends NamedExpression {
this.nullable = nullable;
}
@Override
public final Expression replaceChildren(List<Expression> newChildren) {
throw new UnsupportedOperationException("this type of node doesn't have any children to replace");
}
public String qualifier() {
return qualifier;
}

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression;
import org.elasticsearch.xpack.sql.tree.Location;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
public abstract class BinaryExpression extends Expression {
@ -20,6 +21,15 @@ public abstract class BinaryExpression extends Expression {
this.right = right;
}
@Override
public final BinaryExpression replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 2) {
throw new IllegalArgumentException("expected [2] children but received [" + newChildren.size() + "]");
}
return replaceChildren(newChildren.get(0), newChildren.get(1));
}
protected abstract BinaryExpression replaceChildren(Expression newLeft, Expression newRight);
public Expression left() {
return left;
}

View File

@ -7,6 +7,7 @@ package org.elasticsearch.xpack.sql.expression;
import org.elasticsearch.xpack.sql.plan.logical.LogicalPlan;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.type.DataTypes;
@ -20,6 +21,11 @@ public class Exists extends SubQueryExpression {
super(location, query, id);
}
@Override
protected NodeInfo<Exists> info() {
return NodeInfo.create(this, Exists::new, query(), id());
}
@Override
protected SubQueryExpression clone(LogicalPlan newQuery) {
return new Exists(location(), newQuery);

View File

@ -10,7 +10,6 @@ import org.elasticsearch.xpack.sql.capabilities.Resolvable;
import org.elasticsearch.xpack.sql.capabilities.Resolvables;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.Node;
import org.elasticsearch.xpack.sql.tree.NodeUtils;
import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.util.StringUtils;
@ -122,6 +121,6 @@ public abstract class Expression extends Node<Expression> implements Resolvable
@Override
public String toString() {
return nodeName() + "[" + NodeUtils.propertiesToString(this, false) + "]";
return nodeName() + "[" + propertiesToString(false) + "]";
}
}

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression;
import org.elasticsearch.common.Strings;
import org.elasticsearch.xpack.sql.analysis.index.MappingException;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.type.KeywordType;
import org.elasticsearch.xpack.sql.type.NestedType;
@ -57,6 +58,12 @@ public class FieldAttribute extends TypedAttribute {
this.nestedParent = nestedPar;
}
@Override
protected NodeInfo<FieldAttribute> info() {
return NodeInfo.create(this, FieldAttribute::new,
parent, name(), dataType(), qualifier(), nullable(), id(), synthetic());
}
public FieldAttribute parent() {
return parent;
}

View File

@ -7,6 +7,8 @@ package org.elasticsearch.xpack.sql.expression;
import org.elasticsearch.xpack.sql.tree.Location;
import java.util.List;
import static java.util.Collections.emptyList;
public abstract class LeafExpression extends Expression {
@ -15,6 +17,11 @@ public abstract class LeafExpression extends Expression {
super(location, emptyList());
}
@Override
public final Expression replaceChildren(List<Expression> newChildren) {
throw new UnsupportedOperationException("this type of node doesn't have any children to replace");
}
public AttributeSet references() {
return AttributeSet.EMPTY;
}

View File

@ -7,6 +7,7 @@ package org.elasticsearch.xpack.sql.expression;
import org.elasticsearch.xpack.sql.SqlIllegalArgumentException;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.type.DataTypeConversion;
import org.elasticsearch.xpack.sql.type.DataTypes;
@ -14,19 +15,23 @@ import org.elasticsearch.xpack.sql.type.DataTypes;
import java.util.Objects;
public class Literal extends LeafExpression {
public static final Literal TRUE = Literal.of(Location.EMPTY, Boolean.TRUE);
public static final Literal FALSE = Literal.of(Location.EMPTY, Boolean.FALSE);
private final Object value;
private final DataType dataType;
public static final Literal TRUE = Literal.of(Location.EMPTY, Boolean.TRUE);
public static final Literal FALSE = Literal.of(Location.EMPTY, Boolean.FALSE);
public Literal(Location location, Object value, DataType dataType) {
super(location);
this.dataType = dataType;
this.value = DataTypeConversion.convert(value, dataType);
}
@Override
protected NodeInfo<Literal> info() {
return NodeInfo.create(this, Literal::new, value, dataType);
}
public Object value() {
return value;
}
@ -46,11 +51,6 @@ public class Literal extends LeafExpression {
return dataType;
}
@Override
public int hashCode() {
return Objects.hash(value, dataType);
}
@Override
public boolean resolved() {
return true;
@ -61,6 +61,12 @@ public class Literal extends LeafExpression {
return value;
}
@Override
public int hashCode() {
return Objects.hash(value, dataType);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.processor.definition.ConstantInput;
import org.elasticsearch.xpack.sql.expression.function.scalar.processor.definition.ProcessorDefinition;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
public class LiteralAttribute extends TypedAttribute {
@ -28,6 +29,12 @@ public class LiteralAttribute extends TypedAttribute {
return literal;
}
@Override
protected NodeInfo<LiteralAttribute> info() {
return NodeInfo.create(this, LiteralAttribute::new,
name(), qualifier(), nullable(), id(), synthetic(), dataType(), literal);
}
@Override
protected LiteralAttribute clone(Location location, String name, DataType dataType, String qualifier, boolean nullable,
ExpressionId id, boolean synthetic) {
@ -35,7 +42,7 @@ public class LiteralAttribute extends TypedAttribute {
}
public ProcessorDefinition asProcessorDefinition() {
return new ConstantInput(literal, literal.value());
return new ConstantInput(location(), literal, literal.value());
}
@Override

View File

@ -58,7 +58,13 @@ public abstract class NamedExpression extends Expression {
NamedExpression other = (NamedExpression) obj;
return Objects.equals(synthetic, other.synthetic)
&& Objects.equals(id, other.id)
&& Objects.equals(name(), other.name())
/*
* It is important that the line below be `name`
* and not `name()` because subclasses might override
* `name()` in ways that are not compatible with
* equality. Specifically the `Unresolved` subclasses.
*/
&& Objects.equals(name, other.name)
&& Objects.equals(children(), other.children());
}
}

View File

@ -6,6 +6,7 @@
package org.elasticsearch.xpack.sql.expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import java.util.Objects;
@ -22,6 +23,16 @@ public class Order extends UnaryExpression {
this.direction = direction;
}
@Override
protected NodeInfo<Order> info() {
return NodeInfo.create(this, Order::new, child(), direction);
}
@Override
protected UnaryExpression replaceChild(Expression newChild) {
return new Order(location(), newChild, direction);
}
public OrderDirection direction() {
return direction;
}

View File

@ -7,6 +7,7 @@ package org.elasticsearch.xpack.sql.expression;
import org.elasticsearch.xpack.sql.plan.logical.LogicalPlan;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
public class ScalarSubquery extends SubQueryExpression {
@ -19,6 +20,11 @@ public class ScalarSubquery extends SubQueryExpression {
super(location, query, id);
}
@Override
protected NodeInfo<ScalarSubquery> info() {
return NodeInfo.create(this, ScalarSubquery::new, query(), id());
}
@Override
protected ScalarSubquery clone(LogicalPlan newQuery) {
return new ScalarSubquery(location(), newQuery);

View File

@ -6,6 +6,7 @@
package org.elasticsearch.xpack.sql.expression;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import org.elasticsearch.xpack.sql.plan.logical.LogicalPlan;
@ -26,6 +27,11 @@ public abstract class SubQueryExpression extends Expression {
this.id = id == null ? new ExpressionId() : id;
}
@Override
public final Expression replaceChildren(List<Expression> newChildren) {
throw new UnsupportedOperationException("this type of node doesn't have any children to replace");
}
public LogicalPlan query() {
return query;
}
@ -60,7 +66,7 @@ public abstract class SubQueryExpression extends Expression {
return false;
}
Exists other = (Exists) obj;
SubQueryExpression other = (SubQueryExpression) obj;
return Objects.equals(query(), other.query());
}
}

View File

@ -12,6 +12,8 @@ import java.util.Objects;
import static java.util.Collections.singletonList;
import java.util.List;
public abstract class UnaryExpression extends Expression {
private final Expression child;
@ -21,6 +23,15 @@ public abstract class UnaryExpression extends Expression {
this.child = child;
}
@Override
public final UnaryExpression replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 1) {
throw new IllegalArgumentException("expected [1] child but received [" + newChildren.size() + "]");
}
return replaceChild(newChildren.get(0));
}
protected abstract UnaryExpression replaceChild(Expression newChild);
public Expression child() {
return child;
}

View File

@ -6,20 +6,36 @@
package org.elasticsearch.xpack.sql.expression;
import org.elasticsearch.xpack.sql.capabilities.UnresolvedException;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import java.util.Objects;
import static java.util.Collections.singletonList;
import java.util.List;
public class UnresolvedAlias extends UnresolvedNamedExpression {
private final Expression child;
public UnresolvedAlias(Expression child) {
super(child.location(), singletonList(child));
public UnresolvedAlias(Location location, Expression child) {
super(location, singletonList(child));
this.child = child;
}
@Override
protected NodeInfo<UnresolvedAlias> info() {
return NodeInfo.create(this, UnresolvedAlias::new, child);
}
@Override
public Expression replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 1) {
throw new IllegalArgumentException("expected [1] child but received [" + newChildren.size() + "]");
}
return new UnresolvedAlias(location(), newChildren.get(0));
}
public Expression child() {
return child;
}
@ -36,12 +52,20 @@ public class UnresolvedAlias extends UnresolvedNamedExpression {
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), child);
return Objects.hash(child);
}
@Override
public boolean equals(Object obj) {
return super.equals(obj) && Objects.equals(child, ((UnresolvedAlias) obj).child);
/*
* Intentionally not calling the superclass
* equals because it uses id which we always
* mutate when we make a clone.
*/
if (obj == null || obj.getClass() != getClass()) {
return false;
}
return Objects.equals(child, ((UnresolvedAlias) obj).child);
}
@Override

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression;
import org.elasticsearch.xpack.sql.capabilities.Unresolvable;
import org.elasticsearch.xpack.sql.capabilities.UnresolvedException;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.util.CollectionUtils;
@ -44,6 +45,11 @@ public class UnresolvedAttribute extends Attribute implements Unresolvable {
this.resolutionMetadata = resolutionMetadata;
}
@Override
protected NodeInfo<UnresolvedAttribute> info() {
return NodeInfo.create(this, UnresolvedAttribute::new,
name(), qualifier(), id(), unresolvedMsg, resolutionMetadata);
}
public Object resolutionMetadata() {
return resolutionMetadata;

View File

@ -7,11 +7,13 @@ package org.elasticsearch.xpack.sql.expression;
import org.elasticsearch.xpack.sql.capabilities.UnresolvedException;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import java.util.Objects;
import static java.util.Collections.emptyList;
import java.util.List;
public class UnresolvedStar extends UnresolvedNamedExpression {
// typically used for nested fields or inner/dotted fields
@ -22,6 +24,16 @@ public class UnresolvedStar extends UnresolvedNamedExpression {
this.qualifier = qualifier;
}
@Override
protected NodeInfo<UnresolvedStar> info() {
return NodeInfo.create(this, UnresolvedStar::new, qualifier);
}
@Override
public Expression replaceChildren(List<Expression> newChildren) {
throw new UnsupportedOperationException("this type of node doesn't have any children to replace");
}
@Override
public boolean nullable() {
throw new UnresolvedException("nullable", this);
@ -33,17 +45,24 @@ public class UnresolvedStar extends UnresolvedNamedExpression {
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), qualifier);
return Objects.hash(qualifier);
}
@Override
public boolean equals(Object obj) {
if (super.equals(obj)) {
UnresolvedStar other = (UnresolvedStar) obj;
return Objects.equals(qualifier, other.qualifier);
/*
* Intentionally not calling the superclass
* equals because it uses id which we always
* mutate when we make a clone. So we need
* to ignore it in equals for the transform
* tests to pass.
*/
if (obj == null || obj.getClass() != getClass()) {
return false;
}
return false;
UnresolvedStar other = (UnresolvedStar) obj;
return Objects.equals(qualifier, other.qualifier);
}
private String message() {

View File

@ -6,13 +6,17 @@
package org.elasticsearch.xpack.sql.expression.function;
import org.elasticsearch.xpack.sql.expression.Attribute;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.Function;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.type.DataTypes;
import static java.util.Collections.emptyList;
import java.util.List;
/**
* Function referring to the {@code _score} in a search. Only available
* in the search context, and only at the "root" so it can't be combined
@ -23,6 +27,16 @@ public class Score extends Function {
super(location, emptyList());
}
@Override
protected NodeInfo<Score> info() {
return NodeInfo.create(this);
}
@Override
public Expression replaceChildren(List<Expression> newChildren) {
throw new UnsupportedOperationException("this type of node doesn't have any children to replace");
}
@Override
public DataType dataType() {
return DataTypes.FLOAT;
@ -32,4 +46,18 @@ public class Score extends Function {
public Attribute toAttribute() {
return new ScoreAttribute(location());
}
@Override
public boolean equals(Object obj) {
if (obj == null || obj.getClass() != getClass()) {
return false;
}
Score other = (Score) obj;
return location().equals(other.location());
}
@Override
public int hashCode() {
return location().hashCode();
}
}

View File

@ -9,6 +9,7 @@ import org.elasticsearch.xpack.sql.expression.Attribute;
import org.elasticsearch.xpack.sql.expression.ExpressionId;
import org.elasticsearch.xpack.sql.expression.function.FunctionAttribute;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.type.DataTypes;
@ -19,7 +20,7 @@ public class ScoreAttribute extends FunctionAttribute {
/**
* Constructor for normal use.
*/
ScoreAttribute(Location location) {
public ScoreAttribute(Location location) {
this(location, "SCORE()", DataTypes.FLOAT, null, false, null, false);
}
@ -31,6 +32,11 @@ public class ScoreAttribute extends FunctionAttribute {
super(location, name, dataType, qualifier, nullable, id, synthetic, "SCORE");
}
@Override
protected NodeInfo<ScoreAttribute> info() {
return NodeInfo.create(this);
}
@Override
protected Attribute clone(Location location, String name, DataType dataType, String qualifier, boolean nullable,
ExpressionId id, boolean synthetic) {

View File

@ -10,10 +10,12 @@ import org.elasticsearch.xpack.sql.capabilities.UnresolvedException;
import org.elasticsearch.xpack.sql.expression.Attribute;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.util.CollectionUtils;
import java.util.List;
import java.util.Objects;
public class UnresolvedFunction extends Function implements Unresolvable {
@ -44,6 +46,17 @@ public class UnresolvedFunction extends Function implements Unresolvable {
this.unresolvedMsg = unresolvedMessage == null ? errorMessage(name, null) : unresolvedMessage;
}
@Override
protected NodeInfo<UnresolvedFunction> info() {
return NodeInfo.create(this, UnresolvedFunction::new,
name, distinct, children(), analyzed, unresolvedMsg);
}
@Override
public Expression replaceChildren(List<Expression> newChildren) {
return new UnresolvedFunction(location(), name, distinct, newChildren, analyzed, unresolvedMsg);
}
@Override
public boolean resolved() {
return false;
@ -92,6 +105,24 @@ public class UnresolvedFunction extends Function implements Unresolvable {
return UNRESOLVED_PREFIX + functionName() + functionArgs();
}
@Override
public boolean equals(Object obj) {
if (obj == null || obj.getClass() != getClass()) {
return false;
}
UnresolvedFunction other = (UnresolvedFunction) obj;
return name.equals(other.name)
&& distinct == other.distinct
&& children().equals(other.children())
&& analyzed == other.analyzed
&& unresolvedMsg.equals(other.unresolvedMsg);
}
@Override
public int hashCode() {
return Objects.hash(name, distinct, children(), analyzed, unresolvedMsg);
}
public static String errorMessage(String name, List<String> potentialMatches) {
String msg = "Unknown function [" + name + "]";
if (!CollectionUtils.isEmpty(potentialMatches)) {

View File

@ -11,6 +11,7 @@ import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.util.CollectionUtils;
import java.util.List;
import java.util.Objects;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
@ -48,4 +49,19 @@ public abstract class AggregateFunction extends Function {
}
return lazyAttribute;
}
@Override
public boolean equals(Object obj) {
if (false == super.equals(obj)) {
return false;
}
AggregateFunction other = (AggregateFunction) obj;
return Objects.equals(other.field(), field())
&& Objects.equals(other.parameters(), parameters());
}
@Override
public int hashCode() {
return Objects.hash(field(), parameters());
}
}

View File

@ -10,6 +10,7 @@ import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.ExpressionId;
import org.elasticsearch.xpack.sql.expression.function.FunctionAttribute;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
import java.util.Objects;
@ -23,12 +24,18 @@ public class AggregateFunctionAttribute extends FunctionAttribute {
this(location, name, dataType, null, false, id, false, functionId, propertyPath);
}
AggregateFunctionAttribute(Location location, String name, DataType dataType, String qualifier,
public AggregateFunctionAttribute(Location location, String name, DataType dataType, String qualifier,
boolean nullable, ExpressionId id, boolean synthetic, String functionId, String propertyPath) {
super(location, name, dataType, qualifier, nullable, id, synthetic, functionId);
this.propertyPath = propertyPath;
}
@Override
protected NodeInfo<AggregateFunctionAttribute> info() {
return NodeInfo.create(this, AggregateFunctionAttribute::new,
name(), dataType(), qualifier(), nullable(), id(), synthetic(), functionId(), propertyPath);
}
public String propertyPath() {
return propertyPath;
}

View File

@ -5,8 +5,11 @@
*/
package org.elasticsearch.xpack.sql.expression.function.aggregate;
import java.util.List;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
public class Avg extends NumericAggregate implements EnclosedAgg {
@ -15,6 +18,19 @@ public class Avg extends NumericAggregate implements EnclosedAgg {
super(location, field);
}
@Override
protected NodeInfo<Avg> info() {
return NodeInfo.create(this, Avg::new, field());
}
@Override
public Avg replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 1) {
throw new IllegalArgumentException("expected [1] child but received [" + newChildren.size() + "]");
}
return new Avg(location(), newChildren.get(0));
}
@Override
public String innerName() {
return "avg";

View File

@ -5,8 +5,10 @@
*/
package org.elasticsearch.xpack.sql.expression.function.aggregate;
import java.util.List;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
public class Correlation extends NumericAggregate implements MatrixStatsEnclosed {
@ -14,6 +16,19 @@ public class Correlation extends NumericAggregate implements MatrixStatsEnclosed
super(location, field);
}
@Override
protected NodeInfo<Correlation> info() {
return NodeInfo.create(this, Correlation::new, field());
}
@Override
public Correlation replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 1) {
throw new IllegalArgumentException("expected [1] child but received [" + newChildren.size() + "]");
}
return new Correlation(location(), newChildren.get(0));
}
@Override
public String innerName() {
return "correlation";

View File

@ -5,9 +5,12 @@
*/
package org.elasticsearch.xpack.sql.expression.function.aggregate;
import java.util.List;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.NamedExpression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.type.DataTypes;
@ -20,6 +23,19 @@ public class Count extends AggregateFunction {
this.distinct = distinct;
}
@Override
protected NodeInfo<Count> info() {
return NodeInfo.create(this, Count::new, field(), distinct);
}
@Override
public Count replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 1) {
throw new IllegalArgumentException("expected [1] child but received [" + newChildren.size() + "]");
}
return new Count(location(), newChildren.get(0), distinct);
}
public boolean distinct() {
return distinct;
}

View File

@ -5,8 +5,10 @@
*/
package org.elasticsearch.xpack.sql.expression.function.aggregate;
import java.util.List;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
public class Covariance extends NumericAggregate implements MatrixStatsEnclosed {
@ -14,6 +16,19 @@ public class Covariance extends NumericAggregate implements MatrixStatsEnclosed
super(location, field);
}
@Override
protected NodeInfo<Covariance> info() {
return NodeInfo.create(this, Covariance::new, field());
}
@Override
public Covariance replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 1) {
throw new IllegalArgumentException("expected [1] child but received [" + newChildren.size() + "]");
}
return new Covariance(location(), newChildren.get(0));
}
@Override
public String innerName() {
return "covariance";

View File

@ -5,12 +5,27 @@
*/
package org.elasticsearch.xpack.sql.expression.function.aggregate;
import java.util.List;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
public class ExtendedStats extends CompoundNumericAggregate {
public ExtendedStats(Location location, Expression field) {
super(location, field);
}
@Override
protected NodeInfo<ExtendedStats> info() {
return NodeInfo.create(this, ExtendedStats::new, field());
}
@Override
public ExtendedStats replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 1) {
throw new IllegalArgumentException("expected [1] child but received [" + newChildren.size() + "]");
}
return new ExtendedStats(location(), newChildren.get(0));
}
}

View File

@ -5,9 +5,12 @@
*/
package org.elasticsearch.xpack.sql.expression.function.aggregate;
import java.util.List;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.Function;
import org.elasticsearch.xpack.sql.querydsl.agg.AggPath;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
public class InnerAggregate extends AggregateFunction {
@ -19,17 +22,31 @@ public class InnerAggregate extends AggregateFunction {
private final Expression innerKey;
public InnerAggregate(AggregateFunction inner, CompoundNumericAggregate outer) {
this(inner, outer, null);
this(inner.location(), inner, outer, null);
}
public InnerAggregate(AggregateFunction inner, CompoundNumericAggregate outer, Expression innerKey) {
super(inner.location(), outer.field(), outer.arguments());
public InnerAggregate(Location location, AggregateFunction inner, CompoundNumericAggregate outer, Expression innerKey) {
super(location, outer.field(), outer.arguments());
this.inner = inner;
this.outer = outer;
this.innerId = ((EnclosedAgg) inner).innerName();
this.innerKey = innerKey;
}
@Override
protected NodeInfo<InnerAggregate> info() {
return NodeInfo.create(this, InnerAggregate::new, inner, outer, innerKey);
}
@Override
public Expression replaceChildren(List<Expression> newChildren) {
/* I can't figure out how rewriting this one's children ever worked because its
* are all twisted up in `outer`. Refusing to rewrite it doesn't break anything
* that I can see right now so lets just go with it and hope for the best.
* Maybe someone will make this make sense one day! */
throw new UnsupportedOperationException("can't be rewritten");
}
public AggregateFunction inner() {
return inner;
}

View File

@ -5,8 +5,10 @@
*/
package org.elasticsearch.xpack.sql.expression.function.aggregate;
import java.util.List;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
public class Kurtosis extends NumericAggregate implements MatrixStatsEnclosed {
@ -14,6 +16,19 @@ public class Kurtosis extends NumericAggregate implements MatrixStatsEnclosed {
super(location, field);
}
@Override
protected NodeInfo<Kurtosis> info() {
return NodeInfo.create(this, Kurtosis::new, field());
}
@Override
public Kurtosis replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 1) {
throw new IllegalArgumentException("expected [1] child but received [" + newChildren.size() + "]");
}
return new Kurtosis(location(), newChildren.get(0));
}
@Override
public String innerName() {
return "kurtosis";

View File

@ -5,8 +5,10 @@
*/
package org.elasticsearch.xpack.sql.expression.function.aggregate;
import java.util.List;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
public class MatrixCount extends NumericAggregate implements MatrixStatsEnclosed {
@ -14,6 +16,19 @@ public class MatrixCount extends NumericAggregate implements MatrixStatsEnclosed
super(location, field);
}
@Override
protected NodeInfo<MatrixCount> info() {
return NodeInfo.create(this, MatrixCount::new, field());
}
@Override
public MatrixCount replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 1) {
throw new IllegalArgumentException("expected [1] child but received [" + newChildren.size() + "]");
}
return new MatrixCount(location(), newChildren.get(0));
}
@Override
public String innerName() {
return "matrix_count";

View File

@ -5,8 +5,10 @@
*/
package org.elasticsearch.xpack.sql.expression.function.aggregate;
import java.util.List;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
public class MatrixMean extends NumericAggregate implements MatrixStatsEnclosed {
@ -14,6 +16,16 @@ public class MatrixMean extends NumericAggregate implements MatrixStatsEnclosed
super(location, field);
}
@Override
protected NodeInfo<MatrixMean> info() {
return NodeInfo.create(this, MatrixMean::new, field());
}
@Override
public MatrixMean replaceChildren(List<Expression> newChildren) {
return new MatrixMean(location(), newChildren.get(0));
}
@Override
public String innerName() {
return "matrix_mean";

View File

@ -5,12 +5,27 @@
*/
package org.elasticsearch.xpack.sql.expression.function.aggregate;
import java.util.List;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
public class MatrixStats extends CompoundNumericAggregate {
public MatrixStats(Location location, Expression field) {
super(location, field);
}
@Override
protected NodeInfo<MatrixStats> info() {
return NodeInfo.create(this, MatrixStats::new, field());
}
@Override
public MatrixStats replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 1) {
throw new IllegalArgumentException("expected [1] child but received [" + newChildren.size() + "]");
}
return new MatrixStats(location(), newChildren.get(0));
}
}

View File

@ -5,8 +5,10 @@
*/
package org.elasticsearch.xpack.sql.expression.function.aggregate;
import java.util.List;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
public class MatrixVariance extends NumericAggregate implements MatrixStatsEnclosed {
@ -14,6 +16,19 @@ public class MatrixVariance extends NumericAggregate implements MatrixStatsEnclo
super(location, field);
}
@Override
protected NodeInfo<MatrixVariance> info() {
return NodeInfo.create(this, MatrixVariance::new, field());
}
@Override
public MatrixVariance replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 1) {
throw new IllegalArgumentException("expected [1] child but received [" + newChildren.size() + "]");
}
return new MatrixVariance(location(), newChildren.get(0));
}
@Override
public String innerName() {
return "matrix_variance";

View File

@ -5,8 +5,10 @@
*/
package org.elasticsearch.xpack.sql.expression.function.aggregate;
import java.util.List;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
public class Max extends NumericAggregate implements EnclosedAgg {
@ -15,6 +17,16 @@ public class Max extends NumericAggregate implements EnclosedAgg {
super(location, field);
}
@Override
protected NodeInfo<Max> info() {
return NodeInfo.create(this, Max::new, field());
}
@Override
public Max replaceChildren(List<Expression> newChildren) {
return new Max(location(), newChildren.get(0));
}
@Override
public DataType dataType() {
return field().dataType();

View File

@ -5,8 +5,10 @@
*/
package org.elasticsearch.xpack.sql.expression.function.aggregate;
import java.util.List;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.type.DataTypes;
@ -16,6 +18,19 @@ public class Mean extends NumericAggregate implements MatrixStatsEnclosed {
super(location, field);
}
@Override
protected NodeInfo<Mean> info() {
return NodeInfo.create(this, Mean::new, field());
}
@Override
public Mean replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 1) {
throw new IllegalArgumentException("expected [1] child but received [" + newChildren.size() + "]");
}
return new Mean(location(), newChildren.get(0));
}
@Override
public DataType dataType() {
return DataTypes.DOUBLE;

View File

@ -5,8 +5,10 @@
*/
package org.elasticsearch.xpack.sql.expression.function.aggregate;
import java.util.List;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
public class Min extends NumericAggregate implements EnclosedAgg {
@ -15,6 +17,19 @@ public class Min extends NumericAggregate implements EnclosedAgg {
super(location, field);
}
@Override
protected NodeInfo<Min> info() {
return NodeInfo.create(this, Min::new, field());
}
@Override
public Min replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 1) {
throw new IllegalArgumentException("expected [1] child but received [" + newChildren.size() + "]");
}
return new Min(location(), newChildren.get(0));
}
@Override
public DataType dataType() {
return field().dataType();

View File

@ -13,7 +13,7 @@ import org.elasticsearch.xpack.sql.type.DataTypes;
import java.util.List;
class NumericAggregate extends AggregateFunction {
abstract class NumericAggregate extends AggregateFunction {
NumericAggregate(Location location, Expression field, List<Expression> parameters) {
super(location, field, parameters);

View File

@ -9,9 +9,12 @@ import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.Expressions;
import org.elasticsearch.xpack.sql.expression.Foldables;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.type.DataTypes;
import java.util.List;
import static java.util.Collections.singletonList;
public class Percentile extends NumericAggregate implements EnclosedAgg {
@ -23,6 +26,19 @@ public class Percentile extends NumericAggregate implements EnclosedAgg {
this.percent = percent;
}
@Override
protected NodeInfo<Percentile> info() {
return NodeInfo.create(this, Percentile::new, field(), percent);
}
@Override
public Percentile replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 2) {
throw new IllegalArgumentException("expected [2] children but received [" + newChildren.size() + "]");
}
return new Percentile(location(), newChildren.get(0), newChildren.get(1));
}
@Override
protected TypeResolution resolveType() {
TypeResolution resolution = super.resolveType();

View File

@ -9,9 +9,12 @@ import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.Expressions;
import org.elasticsearch.xpack.sql.expression.Foldables;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.type.DataTypes;
import java.util.List;
import static java.util.Collections.singletonList;
public class PercentileRank extends AggregateFunction implements EnclosedAgg {
@ -23,6 +26,19 @@ public class PercentileRank extends AggregateFunction implements EnclosedAgg {
this.value = value;
}
@Override
protected NodeInfo<PercentileRank> info() {
return NodeInfo.create(this, PercentileRank::new, field(), value);
}
@Override
public Expression replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 2) {
throw new IllegalArgumentException("expected [2] children but received [" + newChildren.size() + "]");
}
return new PercentileRank(location(), newChildren.get(0), newChildren.get(1));
}
@Override
protected TypeResolution resolveType() {
TypeResolution resolution = super.resolveType();

View File

@ -7,7 +7,7 @@ package org.elasticsearch.xpack.sql.expression.function.aggregate;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import java.util.List;
public class PercentileRanks extends CompoundNumericAggregate {
@ -19,6 +19,19 @@ public class PercentileRanks extends CompoundNumericAggregate {
this.values = values;
}
@Override
protected NodeInfo<PercentileRanks> info() {
return NodeInfo.create(this, PercentileRanks::new, field(), values);
}
@Override
public PercentileRanks replaceChildren(List<Expression> newChildren) {
if (newChildren.size() < 2) {
throw new IllegalArgumentException("expected at least [2] children but received [" + newChildren.size() + "]");
}
return new PercentileRanks(location(), newChildren.get(0), newChildren.subList(1, newChildren.size()));
}
public List<Expression> values() {
return values;
}

View File

@ -7,7 +7,7 @@ package org.elasticsearch.xpack.sql.expression.function.aggregate;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import java.util.List;
public class Percentiles extends CompoundNumericAggregate {
@ -19,6 +19,19 @@ public class Percentiles extends CompoundNumericAggregate {
this.percents = percents;
}
@Override
protected NodeInfo<Percentiles> info() {
return NodeInfo.create(this, Percentiles::new, field(), percents);
}
@Override
public Percentiles replaceChildren(List<Expression> newChildren) {
if (newChildren.size() < 2) {
throw new IllegalArgumentException("expected more than one child but received [" + newChildren.size() + "]");
}
return new Percentiles(location(), newChildren.get(0), newChildren.subList(1, newChildren.size()));
}
public List<Expression> percents() {
return percents;
}

View File

@ -5,8 +5,10 @@
*/
package org.elasticsearch.xpack.sql.expression.function.aggregate;
import java.util.List;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
public class Skewness extends NumericAggregate implements MatrixStatsEnclosed {
@ -14,6 +16,19 @@ public class Skewness extends NumericAggregate implements MatrixStatsEnclosed {
super(location, field);
}
@Override
protected NodeInfo<Skewness> info() {
return NodeInfo.create(this, Skewness::new, field());
}
@Override
public Skewness replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 1) {
throw new IllegalArgumentException("expected [1] child but received [" + newChildren.size() + "]");
}
return new Skewness(location(), newChildren.get(0));
}
@Override
public String innerName() {
return "skewness";

View File

@ -5,8 +5,10 @@
*/
package org.elasticsearch.xpack.sql.expression.function.aggregate;
import java.util.List;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
public class Stats extends CompoundNumericAggregate {
@ -14,6 +16,19 @@ public class Stats extends CompoundNumericAggregate {
super(location, field);
}
@Override
protected NodeInfo<Stats> info() {
return NodeInfo.create(this, Stats::new, field());
}
@Override
public Stats replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 1) {
throw new IllegalArgumentException("expected [1] child but received [" + newChildren.size() + "]");
}
return new Stats(location(), newChildren.get(0));
}
public static boolean isTypeCompatible(Expression e) {
return e instanceof Min || e instanceof Max || e instanceof Avg || e instanceof Sum;
}

View File

@ -5,8 +5,10 @@
*/
package org.elasticsearch.xpack.sql.expression.function.aggregate;
import java.util.List;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
public class StddevPop extends NumericAggregate implements ExtendedStatsEnclosed {
@ -14,6 +16,19 @@ public class StddevPop extends NumericAggregate implements ExtendedStatsEnclosed
super(location, field);
}
@Override
protected NodeInfo<StddevPop> info() {
return NodeInfo.create(this, StddevPop::new, field());
}
@Override
public StddevPop replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 1) {
throw new IllegalArgumentException("expected [1] child but received [" + newChildren.size() + "]");
}
return new StddevPop(location(), newChildren.get(0));
}
@Override
public String innerName() {
return "std_deviation";

View File

@ -5,8 +5,10 @@
*/
package org.elasticsearch.xpack.sql.expression.function.aggregate;
import java.util.List;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
public class Sum extends NumericAggregate implements EnclosedAgg {
@ -15,6 +17,19 @@ public class Sum extends NumericAggregate implements EnclosedAgg {
super(location, field);
}
@Override
protected NodeInfo<Sum> info() {
return NodeInfo.create(this, Sum::new, field());
}
@Override
public Sum replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 1) {
throw new IllegalArgumentException("expected [1] child but received [" + newChildren.size() + "]");
}
return new Sum(location(), newChildren.get(0));
}
@Override
public DataType dataType() {
return field().dataType();

View File

@ -5,8 +5,10 @@
*/
package org.elasticsearch.xpack.sql.expression.function.aggregate;
import java.util.List;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
public class SumOfSquares extends NumericAggregate implements ExtendedStatsEnclosed {
@ -14,6 +16,19 @@ public class SumOfSquares extends NumericAggregate implements ExtendedStatsEnclo
super(location, field);
}
@Override
protected NodeInfo<SumOfSquares> info() {
return NodeInfo.create(this, SumOfSquares::new, field());
}
@Override
public SumOfSquares replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 1) {
throw new IllegalArgumentException("expected [1] child but received [" + newChildren.size() + "]");
}
return new SumOfSquares(location(), newChildren.get(0));
}
@Override
public String innerName() {
return "sum_of_squares";

View File

@ -5,8 +5,10 @@
*/
package org.elasticsearch.xpack.sql.expression.function.aggregate;
import java.util.List;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
public class VarPop extends NumericAggregate implements ExtendedStatsEnclosed {
@ -14,6 +16,19 @@ public class VarPop extends NumericAggregate implements ExtendedStatsEnclosed {
super(location, field);
}
@Override
protected NodeInfo<VarPop> info() {
return NodeInfo.create(this, VarPop::new, field());
}
@Override
public VarPop replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 1) {
throw new IllegalArgumentException("expected [1] child but received [" + newChildren.size() + "]");
}
return new VarPop(location(), newChildren.get(0));
}
@Override
public String innerName() {
return "variance";

View File

@ -10,6 +10,7 @@ import org.elasticsearch.xpack.sql.expression.function.scalar.script.ScriptTempl
import org.elasticsearch.xpack.sql.tree.Location;
import java.util.Arrays;
import java.util.List;
public abstract class BinaryScalarFunction extends ScalarFunction {
@ -21,6 +22,16 @@ public abstract class BinaryScalarFunction extends ScalarFunction {
this.right = right;
}
@Override
public final BinaryScalarFunction replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 2) {
throw new IllegalArgumentException("expected [2] children but received [" + newChildren.size() + "]");
}
return replaceChildren(newChildren.get(0), newChildren.get(1));
}
protected abstract BinaryScalarFunction replaceChildren(Expression newLeft, Expression newRight);
public Expression left() {
return left;
}

View File

@ -13,6 +13,7 @@ import org.elasticsearch.xpack.sql.expression.function.scalar.processor.definiti
import org.elasticsearch.xpack.sql.expression.function.scalar.script.Params;
import org.elasticsearch.xpack.sql.expression.function.scalar.script.ScriptTemplate;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.type.DataTypeConversion;
import org.elasticsearch.xpack.sql.type.DataTypes;
@ -20,7 +21,6 @@ import org.elasticsearch.xpack.sql.type.DataTypes;
import java.util.Objects;
public class Cast extends UnaryScalarFunction {
private final DataType dataType;
public Cast(Location location, Expression field, DataType dataType) {
@ -28,6 +28,16 @@ public class Cast extends UnaryScalarFunction {
this.dataType = dataType;
}
@Override
protected NodeInfo<Cast> info() {
return NodeInfo.create(this, Cast::new, field(), dataType);
}
@Override
protected UnaryScalarFunction replaceChild(Expression newChild) {
return new Cast(location(), newChild, dataType);
}
public DataType from() {
return field().dataType();
}
@ -75,7 +85,7 @@ public class Cast extends UnaryScalarFunction {
@Override
protected ProcessorDefinition makeProcessorDefinition() {
return new UnaryProcessorDefinition(this, ProcessorDefinitions.toProcessorDefinition(field()),
return new UnaryProcessorDefinition(location(), this, ProcessorDefinitions.toProcessorDefinition(field()),
new CastProcessor(DataTypeConversion.conversionFor(from(), to())));
}
@ -86,7 +96,15 @@ public class Cast extends UnaryScalarFunction {
@Override
public boolean equals(Object obj) {
return super.equals(obj) && Objects.equals(dataType, ((Cast) obj).dataType());
if (this == obj) {
return true;
}
if (obj == null || obj.getClass() != getClass()) {
return false;
}
Cast other = (Cast) obj;
return Objects.equals(dataType, other.dataType())
&& Objects.equals(field(), other.field());
}
@Override

View File

@ -8,10 +8,12 @@ package org.elasticsearch.xpack.sql.expression.function.scalar;
import org.elasticsearch.xpack.sql.expression.Attribute;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.ExpressionId;
import org.elasticsearch.xpack.sql.expression.NamedExpression;
import org.elasticsearch.xpack.sql.expression.function.FunctionAttribute;
import org.elasticsearch.xpack.sql.expression.function.scalar.processor.definition.ProcessorDefinition;
import org.elasticsearch.xpack.sql.expression.function.scalar.script.ScriptTemplate;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
import java.util.Objects;
@ -27,15 +29,23 @@ public class ScalarFunctionAttribute extends FunctionAttribute {
this(location, name, dataType, null, true, id, false, functionId, script, orderBy, processorDef);
}
ScalarFunctionAttribute(Location location, String name, DataType dataType, String qualifier,
public ScalarFunctionAttribute(Location location, String name, DataType dataType, String qualifier,
boolean nullable, ExpressionId id, boolean synthetic, String functionId, ScriptTemplate script,
Expression orderBy, ProcessorDefinition processorDef) {
super(location, name, dataType, qualifier, nullable, id, synthetic, functionId);
this.script = script;
this.orderBy = orderBy;
this.processorDef = processorDef;
}
@Override
protected NodeInfo<ScalarFunctionAttribute> info() {
return NodeInfo.create(this, ScalarFunctionAttribute::new,
name(), dataType(), qualifier(), nullable(), id(), synthetic(),
functionId(), script, orderBy, processorDef);
}
public ScriptTemplate script() {
return script;
}

View File

@ -11,6 +11,8 @@ import org.elasticsearch.xpack.sql.tree.Location;
import static java.util.Collections.singletonList;
import java.util.List;
public abstract class UnaryScalarFunction extends ScalarFunction {
private final Expression field;
@ -25,6 +27,15 @@ public abstract class UnaryScalarFunction extends ScalarFunction {
this.field = field;
}
@Override
public final UnaryScalarFunction replaceChildren(List<Expression> newChildren) {
if (newChildren.size() != 1) {
throw new IllegalArgumentException("expected [1] child but received [" + newChildren.size() + "]");
}
return replaceChild(newChildren.get(0));
}
protected abstract UnaryScalarFunction replaceChild(Expression newChild);
public Expression field() {
return field;
}

View File

@ -8,16 +8,26 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.arithmetic;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.arithmetic.BinaryArithmeticProcessor.BinaryArithmeticOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
/**
* Addition function ({@code a + b}).
*/
public class Add extends ArithmeticFunction {
public Add(Location location, Expression left, Expression right) {
super(location, left, right, BinaryArithmeticOperation.ADD);
}
@Override
protected NodeInfo<Add> info() {
return NodeInfo.create(this, Add::new, left(), right());
}
@Override
protected Add replaceChildren(Expression left, Expression right) {
return new Add(location(), left, right);
}
@Override
public Number fold() {
return Arithmetics.add((Number) left().fold(), (Number) right().fold());

View File

@ -16,6 +16,7 @@ import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.type.DataTypeConversion;
import java.util.Locale;
import java.util.Objects;
import static java.lang.String.format;
import static org.elasticsearch.xpack.sql.expression.function.scalar.script.ParamsBuilder.paramsBuilder;
@ -74,7 +75,7 @@ public abstract class ArithmeticFunction extends BinaryScalarFunction {
@Override
protected final BinaryArithmeticProcessorDefinition makeProcessorDefinition() {
return new BinaryArithmeticProcessorDefinition(this,
return new BinaryArithmeticProcessorDefinition(location(), this,
ProcessorDefinitions.toProcessorDefinition(left()),
ProcessorDefinitions.toProcessorDefinition(right()), operation);
}
@ -110,4 +111,20 @@ public abstract class ArithmeticFunction extends BinaryScalarFunction {
protected boolean useParanthesis() {
return !(left() instanceof Literal) || !(right() instanceof Literal);
}
@Override
public boolean equals(Object obj) {
if (obj == null || obj.getClass() != getClass()) {
return false;
}
ArithmeticFunction other = (ArithmeticFunction) obj;
return Objects.equals(other.left(), left())
&& Objects.equals(other.right(), right())
&& Objects.equals(other.operation, operation);
}
@Override
public int hashCode() {
return Objects.hash(left(), right(), operation);
}
}

View File

@ -9,26 +9,33 @@ import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.arithmetic.BinaryArithmeticProcessor.BinaryArithmeticOperation;
import org.elasticsearch.xpack.sql.expression.function.scalar.processor.definition.BinaryProcessorDefinition;
import org.elasticsearch.xpack.sql.expression.function.scalar.processor.definition.ProcessorDefinition;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import java.util.Objects;
public class BinaryArithmeticProcessorDefinition extends BinaryProcessorDefinition {
private final BinaryArithmeticOperation operation;
public BinaryArithmeticProcessorDefinition(Expression expression, ProcessorDefinition left,
public BinaryArithmeticProcessorDefinition(Location location, Expression expression, ProcessorDefinition left,
ProcessorDefinition right, BinaryArithmeticOperation operation) {
super(expression, left, right);
super(location, expression, left, right);
this.operation = operation;
}
@Override
protected NodeInfo<BinaryArithmeticProcessorDefinition> info() {
return NodeInfo.create(this, BinaryArithmeticProcessorDefinition::new,
expression(), left(), right(), operation);
}
public BinaryArithmeticOperation operation() {
return operation;
}
@Override
protected BinaryProcessorDefinition replaceChildren(ProcessorDefinition left, ProcessorDefinition right) {
return new BinaryArithmeticProcessorDefinition(expression(), left, right, operation);
return new BinaryArithmeticProcessorDefinition(location(), expression(), left, right, operation);
}
@Override

View File

@ -6,8 +6,10 @@
package org.elasticsearch.xpack.sql.expression.function.scalar.arithmetic;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.BinaryScalarFunction;
import org.elasticsearch.xpack.sql.expression.function.scalar.arithmetic.BinaryArithmeticProcessor.BinaryArithmeticOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.type.DataTypeConversion;
@ -20,6 +22,16 @@ public class Div extends ArithmeticFunction {
super(location, left, right, BinaryArithmeticOperation.DIV);
}
@Override
protected NodeInfo<Div> info() {
return NodeInfo.create(this, Div::new, left(), right());
}
@Override
protected BinaryScalarFunction replaceChildren(Expression newLeft, Expression newRight) {
return new Div(location(), newLeft, newRight);
}
@Override
public Object fold() {
return Arithmetics.div((Number) left().fold(), (Number) right().fold());

View File

@ -6,8 +6,10 @@
package org.elasticsearch.xpack.sql.expression.function.scalar.arithmetic;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.BinaryScalarFunction;
import org.elasticsearch.xpack.sql.expression.function.scalar.arithmetic.BinaryArithmeticProcessor.BinaryArithmeticOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
/**
* <a href="https://en.wikipedia.org/wiki/Modulo_operation">Modulo</a>
@ -19,6 +21,16 @@ public class Mod extends ArithmeticFunction {
super(location, left, right, BinaryArithmeticOperation.MOD);
}
@Override
protected NodeInfo<Mod> info() {
return NodeInfo.create(this, Mod::new, left(), right());
}
@Override
protected BinaryScalarFunction replaceChildren(Expression newLeft, Expression newRight) {
return new Mod(location(), newLeft, newRight);
}
@Override
public Object fold() {
return Arithmetics.mod((Number) left().fold(), (Number) right().fold());

View File

@ -6,8 +6,10 @@
package org.elasticsearch.xpack.sql.expression.function.scalar.arithmetic;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.BinaryScalarFunction;
import org.elasticsearch.xpack.sql.expression.function.scalar.arithmetic.BinaryArithmeticProcessor.BinaryArithmeticOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
/**
* Multiplication function ({@code a * b}).
@ -18,6 +20,16 @@ public class Mul extends ArithmeticFunction {
super(location, left, right, BinaryArithmeticOperation.MUL);
}
@Override
protected NodeInfo<Mul> info() {
return NodeInfo.create(this, Mul::new, left(), right());
}
@Override
protected BinaryScalarFunction replaceChildren(Expression newLeft, Expression newRight) {
return new Mul(location(), newLeft, newRight);
}
@Override
public Object fold() {
return Arithmetics.mul((Number) left().fold(), (Number) right().fold());

View File

@ -13,17 +13,27 @@ import org.elasticsearch.xpack.sql.expression.function.scalar.processor.definiti
import org.elasticsearch.xpack.sql.expression.function.scalar.processor.definition.ProcessorDefinitions;
import org.elasticsearch.xpack.sql.expression.function.scalar.processor.definition.UnaryProcessorDefinition;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
/**
* Negation function (@{code -x}).
*/
public class Neg extends UnaryScalarFunction {
public Neg(Location location, Expression field) {
super(location, field);
}
@Override
protected NodeInfo<Neg> info() {
return NodeInfo.create(this, Neg::new, field());
}
@Override
protected UnaryScalarFunction replaceChild(Expression newChild) {
return new Neg(location(), newChild);
}
@Override
protected TypeResolution resolveType() {
return Expressions.typeMustBeNumeric(field());
@ -47,7 +57,7 @@ public class Neg extends UnaryScalarFunction {
@Override
protected ProcessorDefinition makeProcessorDefinition() {
return new UnaryProcessorDefinition(this, ProcessorDefinitions.toProcessorDefinition(field()),
return new UnaryProcessorDefinition(location(), this, ProcessorDefinitions.toProcessorDefinition(field()),
new UnaryArithmeticProcessor(UnaryArithmeticOperation.NEGATE));
}
}

View File

@ -6,8 +6,10 @@
package org.elasticsearch.xpack.sql.expression.function.scalar.arithmetic;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.BinaryScalarFunction;
import org.elasticsearch.xpack.sql.expression.function.scalar.arithmetic.BinaryArithmeticProcessor.BinaryArithmeticOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
/**
* Subtraction function ({@code a - b}).
@ -18,6 +20,16 @@ public class Sub extends ArithmeticFunction {
super(location, left, right, BinaryArithmeticOperation.SUB);
}
@Override
protected NodeInfo<Sub> info() {
return NodeInfo.create(this, Sub::new, left(), right());
}
@Override
protected BinaryScalarFunction replaceChildren(Expression newLeft, Expression newRight) {
return new Sub(location(), newLeft, newRight);
}
@Override
public Object fold() {
return Arithmetics.sub((Number) left().fold(), (Number) right().fold());

View File

@ -17,11 +17,13 @@ import org.elasticsearch.xpack.sql.expression.function.scalar.processor.definiti
import org.elasticsearch.xpack.sql.expression.function.scalar.script.ParamsBuilder;
import org.elasticsearch.xpack.sql.expression.function.scalar.script.ScriptTemplate;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.type.DataTypes;
import org.joda.time.DateTimeZone;
import java.time.temporal.ChronoField;
import java.util.Objects;
import static org.elasticsearch.xpack.sql.expression.function.scalar.script.ParamsBuilder.paramsBuilder;
import static org.elasticsearch.xpack.sql.expression.function.scalar.script.ScriptTemplate.formatTemplate;
@ -42,6 +44,12 @@ public abstract class DateTimeFunction extends UnaryScalarFunction {
this.name = sb.toString();
}
@Override
protected final NodeInfo<DateTimeFunction> info() {
return NodeInfo.create(this, ctorForInfo(), field(), timeZone());
}
protected abstract NodeInfo.NodeCtor2<Expression, DateTimeZone, DateTimeFunction> ctorForInfo();
public DateTimeZone timeZone() {
return timeZone;
}
@ -112,7 +120,7 @@ public abstract class DateTimeFunction extends UnaryScalarFunction {
@Override
protected final ProcessorDefinition makeProcessorDefinition() {
return new UnaryProcessorDefinition(this, ProcessorDefinitions.toProcessorDefinition(field()),
return new UnaryProcessorDefinition(location(), this, ProcessorDefinitions.toProcessorDefinition(field()),
new DateTimeProcessor(extractor(), timeZone));
}
@ -131,4 +139,19 @@ public abstract class DateTimeFunction extends UnaryScalarFunction {
public String name() {
return name;
}
@Override
public boolean equals(Object obj) {
if (obj == null || obj.getClass() != getClass()) {
return false;
}
DateTimeFunction other = (DateTimeFunction) obj;
return Objects.equals(other.field(), field())
&& Objects.equals(other.timeZone, timeZone);
}
@Override
public int hashCode() {
return Objects.hash(field(), timeZone);
}
}

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.datetime;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DateTimeProcessor.DateTimeExtractor;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo.NodeCtor2;
import org.joda.time.DateTimeZone;
import java.time.temporal.ChronoField;
@ -17,6 +18,16 @@ public class DayOfMonth extends DateTimeFunction {
super(location, field, timeZone);
}
@Override
protected NodeCtor2<Expression, DateTimeZone, DateTimeFunction> ctorForInfo() {
return DayOfMonth::new;
}
@Override
protected DayOfMonth replaceChild(Expression newChild) {
return new DayOfMonth(location(), newChild, timeZone());
}
@Override
public String dateTimeFormat() {
return "d";

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.datetime;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DateTimeProcessor.DateTimeExtractor;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo.NodeCtor2;
import org.joda.time.DateTimeZone;
import java.time.temporal.ChronoField;
@ -17,6 +18,16 @@ public class DayOfWeek extends DateTimeFunction {
super(location, field, timeZone);
}
@Override
protected NodeCtor2<Expression, DateTimeZone, DateTimeFunction> ctorForInfo() {
return DayOfWeek::new;
}
@Override
protected DayOfWeek replaceChild(Expression newChild) {
return new DayOfWeek(location(), newChild, timeZone());
}
@Override
public String dateTimeFormat() {
return "e";

View File

@ -6,8 +6,10 @@
package org.elasticsearch.xpack.sql.expression.function.scalar.datetime;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.UnaryScalarFunction;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DateTimeProcessor.DateTimeExtractor;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo.NodeCtor2;
import org.joda.time.DateTimeZone;
import java.time.temporal.ChronoField;
@ -17,6 +19,16 @@ public class DayOfYear extends DateTimeFunction {
super(location, field, timeZone);
}
@Override
protected NodeCtor2<Expression, DateTimeZone, DateTimeFunction> ctorForInfo() {
return DayOfYear::new;
}
@Override
protected UnaryScalarFunction replaceChild(Expression newChild) {
return new DayOfYear(location(), newChild, timeZone());
}
@Override
public String dateTimeFormat() {
return "D";

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.datetime;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DateTimeProcessor.DateTimeExtractor;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo.NodeCtor2;
import org.joda.time.DateTimeZone;
import java.time.temporal.ChronoField;
@ -17,6 +18,16 @@ public class HourOfDay extends DateTimeFunction {
super(location, field, timeZone);
}
@Override
protected NodeCtor2<Expression, DateTimeZone, DateTimeFunction> ctorForInfo() {
return HourOfDay::new;
}
@Override
protected HourOfDay replaceChild(Expression newChild) {
return new HourOfDay(location(), newChild, timeZone());
}
@Override
public String dateTimeFormat() {
return "hour";

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.datetime;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DateTimeProcessor.DateTimeExtractor;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo.NodeCtor2;
import org.joda.time.DateTimeZone;
import java.time.temporal.ChronoField;
@ -18,6 +19,16 @@ public class MinuteOfDay extends DateTimeFunction {
super(location, field, timeZone);
}
@Override
protected NodeCtor2<Expression, DateTimeZone, DateTimeFunction> ctorForInfo() {
return MinuteOfDay::new;
}
@Override
protected MinuteOfDay replaceChild(Expression newChild) {
return new MinuteOfDay(location(), newChild, timeZone());
}
@Override
public String dateTimeFormat() {
throw new UnsupportedOperationException("is there a format for it?");

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.datetime;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DateTimeProcessor.DateTimeExtractor;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo.NodeCtor2;
import org.joda.time.DateTimeZone;
import java.time.temporal.ChronoField;
@ -17,6 +18,16 @@ public class MinuteOfHour extends DateTimeFunction {
super(location, field, timeZone);
}
@Override
protected NodeCtor2<Expression, DateTimeZone, DateTimeFunction> ctorForInfo() {
return MinuteOfHour::new;
}
@Override
protected MinuteOfHour replaceChild(Expression newChild) {
return new MinuteOfHour(location(), newChild, timeZone());
}
@Override
public String dateTimeFormat() {
return "m";

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.datetime;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DateTimeProcessor.DateTimeExtractor;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo.NodeCtor2;
import org.joda.time.DateTimeZone;
import java.time.temporal.ChronoField;
@ -17,6 +18,16 @@ public class MonthOfYear extends DateTimeFunction {
super(location, field, timeZone);
}
@Override
protected NodeCtor2<Expression, DateTimeZone, DateTimeFunction> ctorForInfo() {
return MonthOfYear::new;
}
@Override
protected MonthOfYear replaceChild(Expression newChild) {
return new MonthOfYear(location(), newChild, timeZone());
}
@Override
public String dateTimeFormat() {
return "M";

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.datetime;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DateTimeProcessor.DateTimeExtractor;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo.NodeCtor2;
import org.joda.time.DateTimeZone;
import java.time.temporal.ChronoField;
@ -17,6 +18,16 @@ public class SecondOfMinute extends DateTimeFunction {
super(location, field, timeZone);
}
@Override
protected NodeCtor2<Expression, DateTimeZone, DateTimeFunction> ctorForInfo() {
return SecondOfMinute::new;
}
@Override
protected SecondOfMinute replaceChild(Expression newChild) {
return new SecondOfMinute(location(), newChild, timeZone());
}
@Override
public String dateTimeFormat() {
return "s";

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.datetime;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DateTimeProcessor.DateTimeExtractor;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo.NodeCtor2;
import org.joda.time.DateTimeZone;
import java.time.temporal.ChronoField;
@ -17,6 +18,16 @@ public class WeekOfWeekYear extends DateTimeFunction {
super(location, field, timeZone);
}
@Override
protected NodeCtor2<Expression, DateTimeZone, DateTimeFunction> ctorForInfo() {
return WeekOfWeekYear::new;
}
@Override
protected WeekOfWeekYear replaceChild(Expression newChild) {
return new WeekOfWeekYear(location(), newChild, timeZone());
}
@Override
public String dateTimeFormat() {
return "w";

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.datetime;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.datetime.DateTimeProcessor.DateTimeExtractor;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo.NodeCtor2;
import org.joda.time.DateTimeZone;
import java.time.temporal.ChronoField;
@ -17,6 +18,16 @@ public class Year extends DateTimeHistogramFunction {
super(location, field, timeZone);
}
@Override
protected NodeCtor2<Expression, DateTimeZone, DateTimeFunction> ctorForInfo() {
return Year::new;
}
@Override
protected Year replaceChild(Expression newChild) {
return new Year(location(), newChild, timeZone());
}
@Override
public String dateTimeFormat() {
return "year";

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.math;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
/**
@ -19,6 +20,16 @@ public class ACos extends MathFunction {
super(location, field);
}
@Override
protected NodeInfo<ACos> info() {
return NodeInfo.create(this, ACos::new, field());
}
@Override
protected ACos replaceChild(Expression newChild) {
return new ACos(location(), newChild);
}
@Override
protected MathOperation operation() {
return MathOperation.ACOS;

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.math;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
/**
* <a href="https://en.wikipedia.org/wiki/Inverse_trigonometric_functions">Arc sine</a>
@ -18,6 +19,16 @@ public class ASin extends MathFunction {
super(location, field);
}
@Override
protected NodeInfo<ASin> info() {
return NodeInfo.create(this, ASin::new, field());
}
@Override
protected ASin replaceChild(Expression newChild) {
return new ASin(location(), newChild);
}
@Override
protected MathOperation operation() {
return MathOperation.ASIN;

View File

@ -8,7 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.math;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
/**
* <a href="https://en.wikipedia.org/wiki/Inverse_trigonometric_functions">Arc tangent</a>
@ -19,6 +19,16 @@ public class ATan extends MathFunction {
super(location, field);
}
@Override
protected NodeInfo<ATan> info() {
return NodeInfo.create(this, ATan::new, field());
}
@Override
protected ATan replaceChild(Expression newChild) {
return new ATan(location(), newChild);
}
@Override
protected MathOperation operation() {
return MathOperation.ATAN;

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.math;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
/**
@ -19,6 +20,16 @@ public class Abs extends MathFunction {
super(location, field);
}
@Override
protected NodeInfo<Abs> info() {
return NodeInfo.create(this, Abs::new, field());
}
@Override
protected Abs replaceChild(Expression newChild) {
return new Abs(location(), newChild);
}
@Override
protected MathOperation operation() {
return MathOperation.ABS;

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.math;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
/**
* <a href="https://en.wikipedia.org/wiki/Cube_root">Cube root</a>
@ -18,6 +19,16 @@ public class Cbrt extends MathFunction {
super(location, field);
}
@Override
protected NodeInfo<Cbrt> info() {
return NodeInfo.create(this, Cbrt::new, field());
}
@Override
protected Cbrt replaceChild(Expression newChild) {
return new Cbrt(location(), newChild);
}
@Override
protected MathOperation operation() {
return MathOperation.CBRT;

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.math;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.type.DataTypeConversion;
@ -20,6 +21,16 @@ public class Ceil extends MathFunction {
super(location, field);
}
@Override
protected NodeInfo<Ceil> info() {
return NodeInfo.create(this, Ceil::new, field());
}
@Override
protected Ceil replaceChild(Expression newChild) {
return new Ceil(location(), newChild);
}
@Override
protected MathOperation operation() {
return MathOperation.CEIL;

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.math;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
/**
* <a href="https://en.wikipedia.org/wiki/Trigonometric_functions#cosine">Cosine</a>
@ -18,6 +19,16 @@ public class Cos extends MathFunction {
super(location, field);
}
@Override
protected NodeInfo<Cos> info() {
return NodeInfo.create(this, Cos::new, field());
}
@Override
protected Cos replaceChild(Expression newChild) {
return new Cos(location(), newChild);
}
@Override
protected MathOperation operation() {
return MathOperation.COS;

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.math;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
/**
* <a href="https://en.wikipedia.org/wiki/Hyperbolic_function">Hyperbolic cosine</a>
@ -18,6 +19,16 @@ public class Cosh extends MathFunction {
super(location, field);
}
@Override
protected NodeInfo<Cosh> info() {
return NodeInfo.create(this, Cosh::new, field());
}
@Override
protected Cosh replaceChild(Expression newChild) {
return new Cosh(location(), newChild);
}
@Override
protected MathOperation operation() {
return MathOperation.COSH;

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.math;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
/**
* Convert from <a href="https://en.wikipedia.org/wiki/Radian">radians</a>
@ -18,6 +19,16 @@ public class Degrees extends MathFunction {
super(location, field);
}
@Override
protected NodeInfo<Degrees> info() {
return NodeInfo.create(this, Degrees::new, field());
}
@Override
protected Degrees replaceChild(Expression newChild) {
return new Degrees(location(), newChild);
}
@Override
protected String mathFunction() {
return "toDegrees";

View File

@ -6,11 +6,13 @@
package org.elasticsearch.xpack.sql.expression.function.scalar.math;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.Literal;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
import org.elasticsearch.xpack.sql.expression.function.scalar.script.Params;
import org.elasticsearch.xpack.sql.expression.function.scalar.script.ScriptTemplate;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataTypes;
import org.elasticsearch.xpack.sql.util.StringUtils;
@ -22,6 +24,16 @@ public class E extends MathFunction {
super(location, new Literal(location, Math.E, DataTypes.DOUBLE));
}
@Override
protected NodeInfo<E> info() {
return NodeInfo.create(this);
}
@Override
protected E replaceChild(Expression field) {
throw new UnsupportedOperationException("this node doesn't have any children");
}
@Override
public Object fold() {
return Math.E;

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.math;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
/**
* <a href="https://en.wikipedia.org/wiki/Exponential_function">e<sup>x</sup></a>
@ -18,6 +19,16 @@ public class Exp extends MathFunction {
super(location, field);
}
@Override
protected NodeInfo<Exp> info() {
return NodeInfo.create(this, Exp::new, field());
}
@Override
protected Exp replaceChild(Expression newChild) {
return new Exp(location(), newChild);
}
@Override
protected MathOperation operation() {
return MathOperation.EXP;

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.math;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
/**
* <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#expm1-double-">e<sup>x</sup> + 1</a>
@ -18,6 +19,16 @@ public class Expm1 extends MathFunction {
super(location, field);
}
@Override
protected NodeInfo<Expm1> info() {
return NodeInfo.create(this, Expm1::new, field());
}
@Override
protected Expm1 replaceChild(Expression newChild) {
return new Expm1(location(), newChild);
}
@Override
protected MathOperation operation() {
return MathOperation.EXPM1;

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.math;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.type.DataTypeConversion;
@ -20,6 +21,16 @@ public class Floor extends MathFunction {
super(location, field);
}
@Override
protected NodeInfo<Floor> info() {
return NodeInfo.create(this, Floor::new, field());
}
@Override
protected Floor replaceChild(Expression newChild) {
return new Floor(location(), newChild);
}
@Override
protected MathOperation operation() {
return MathOperation.FLOOR;

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.math;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
/**
* <a href="https://en.wikipedia.org/wiki/Natural_logarithm">Natural logarithm</a>
@ -18,6 +19,16 @@ public class Log extends MathFunction {
super(location, field);
}
@Override
protected NodeInfo<Log> info() {
return NodeInfo.create(this, Log::new, field());
}
@Override
protected Log replaceChild(Expression newChild) {
return new Log(location(), newChild);
}
@Override
protected MathOperation operation() {
return MathOperation.LOG;

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.math;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
/**
* <a href="https://en.wikipedia.org/wiki/Logarithm">Logarithm</a>
@ -18,6 +19,16 @@ public class Log10 extends MathFunction {
super(location, field);
}
@Override
protected NodeInfo<Log10> info() {
return NodeInfo.create(this, Log10::new, field());
}
@Override
protected Log10 replaceChild(Expression newChild) {
return new Log10(location(), newChild);
}
@Override
protected MathOperation operation() {
return MathOperation.LOG10;

View File

@ -16,6 +16,7 @@ import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.type.DataTypes;
import java.util.Locale;
import java.util.Objects;
import static java.lang.String.format;
@ -50,8 +51,23 @@ public abstract class MathFunction extends UnaryScalarFunction {
@Override
protected final ProcessorDefinition makeProcessorDefinition() {
return new UnaryProcessorDefinition(this, ProcessorDefinitions.toProcessorDefinition(field()), new MathProcessor(operation()));
return new UnaryProcessorDefinition(location(), this,
ProcessorDefinitions.toProcessorDefinition(field()), new MathProcessor(operation()));
}
protected abstract MathOperation operation();
@Override
public boolean equals(Object obj) {
if (obj == null || obj.getClass() != getClass()) {
return false;
}
MathFunction other = (MathFunction) obj;
return Objects.equals(other.field(), field());
}
@Override
public int hashCode() {
return Objects.hash(field());
}
}

View File

@ -6,11 +6,13 @@
package org.elasticsearch.xpack.sql.expression.function.scalar.math;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.Literal;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
import org.elasticsearch.xpack.sql.expression.function.scalar.script.Params;
import org.elasticsearch.xpack.sql.expression.function.scalar.script.ScriptTemplate;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataTypes;
import org.elasticsearch.xpack.sql.util.StringUtils;
@ -22,6 +24,16 @@ public class Pi extends MathFunction {
super(location, new Literal(location, Math.PI, DataTypes.DOUBLE));
}
@Override
protected NodeInfo<Pi> info() {
return NodeInfo.create(this);
}
@Override
protected Pi replaceChild(Expression field) {
throw new UnsupportedOperationException("this node doesn't have any children");
}
@Override
public Object fold() {
return Math.PI;

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.math;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
/**
* Convert from <a href="https://en.wikipedia.org/wiki/Degree_(angle)">degrees</a>
@ -18,6 +19,16 @@ public class Radians extends MathFunction {
super(location, field);
}
@Override
protected NodeInfo<Radians> info() {
return NodeInfo.create(this, Radians::new, field());
}
@Override
protected Radians replaceChild(Expression newChild) {
return new Radians(location(), newChild);
}
@Override
protected String mathFunction() {
return "toRadians";

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.math;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import org.elasticsearch.xpack.sql.type.DataType;
import org.elasticsearch.xpack.sql.type.DataTypeConversion;
@ -23,6 +24,16 @@ public class Round extends MathFunction {
super(location, field);
}
@Override
protected NodeInfo<Round> info() {
return NodeInfo.create(this, Round::new, field());
}
@Override
protected Round replaceChild(Expression newChild) {
return new Round(location(), newChild);
}
@Override
protected MathOperation operation() {
return MathOperation.ROUND;

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.math;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
/**
* <a href="https://en.wikipedia.org/wiki/Trigonometric_functions#sine">Sine</a>
@ -18,6 +19,16 @@ public class Sin extends MathFunction {
super(location, field);
}
@Override
protected NodeInfo<Sin> info() {
return NodeInfo.create(this, Sin::new, field());
}
@Override
protected Sin replaceChild(Expression newChild) {
return new Sin(location(), newChild);
}
@Override
protected MathOperation operation() {
return MathOperation.SIN;

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.math;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
/**
* <a href="https://en.wikipedia.org/wiki/Hyperbolic_function">Hyperbolic sine</a>
@ -18,6 +19,16 @@ public class Sinh extends MathFunction {
super(location, field);
}
@Override
protected NodeInfo<Sinh> info() {
return NodeInfo.create(this, Sinh::new, field());
}
@Override
protected Sinh replaceChild(Expression newChild) {
return new Sinh(location(), newChild);
}
@Override
protected MathOperation operation() {
return MathOperation.SINH;

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.math;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
/**
* <a href="https://en.wikipedia.org/wiki/Square_root">Square root</a>
@ -18,6 +19,16 @@ public class Sqrt extends MathFunction {
super(location, field);
}
@Override
protected NodeInfo<Sqrt> info() {
return NodeInfo.create(this, Sqrt::new, field());
}
@Override
protected Sqrt replaceChild(Expression newChild) {
return new Sqrt(location(), newChild);
}
@Override
protected MathOperation operation() {
return MathOperation.SQRT;

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.math;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.math.MathProcessor.MathOperation;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
/**
* <a href="https://en.wikipedia.org/wiki/Trigonometric_functions#sine">Tangent</a>
@ -18,6 +19,16 @@ public class Tan extends MathFunction {
super(location, field);
}
@Override
protected NodeInfo<Tan> info() {
return NodeInfo.create(this, Tan::new, field());
}
@Override
protected Tan replaceChild(Expression newChild) {
return new Tan(location(), newChild);
}
@Override
protected MathOperation operation() {
return MathOperation.TAN;

View File

@ -6,10 +6,17 @@
package org.elasticsearch.xpack.sql.expression.function.scalar.processor.definition;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
public class AggNameInput extends CommonNonExecutableInput<String> {
public AggNameInput(Expression expression, String context) {
super(expression, context);
public AggNameInput(Location location, Expression expression, String context) {
super(location, expression, context);
}
@Override
protected NodeInfo<AggNameInput> info() {
return NodeInfo.create(this, AggNameInput::new, expression(), context());
}
@Override

View File

@ -5,10 +5,10 @@
*/
package org.elasticsearch.xpack.sql.expression.function.scalar.processor.definition;
import org.elasticsearch.xpack.sql.execution.search.SqlSourceBuilder;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.processor.runtime.Processor;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import java.util.Objects;
public class AggPathInput extends CommonNonExecutableInput<String> {
@ -18,19 +18,24 @@ public class AggPathInput extends CommonNonExecutableInput<String> {
private final Processor action;
public AggPathInput(Expression expression, String context) {
this(expression, context, null, null);
this(Location.EMPTY, expression, context, null, null);
}
public AggPathInput(Expression expression, String context, String innerKey) {
this(expression, context, innerKey, null);
this(Location.EMPTY, expression, context, innerKey, null);
}
public AggPathInput(Expression expression, String context, String innerKey, Processor action) {
super(expression, context);
public AggPathInput(Location location, Expression expression, String context, String innerKey, Processor action) {
super(location, expression, context);
this.innerKey = innerKey;
this.action = action;
}
@Override
protected NodeInfo<AggPathInput> info() {
return NodeInfo.create(this, AggPathInput::new, expression(), context(), innerKey, action);
}
public String innerKey() {
return innerKey;
}

View File

@ -10,7 +10,8 @@ import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.expression.function.scalar.processor.runtime.MatrixFieldProcessor;
import org.elasticsearch.xpack.sql.expression.function.scalar.processor.runtime.Processor;
import org.elasticsearch.xpack.sql.expression.function.scalar.processor.runtime.SuppliedProcessor;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
import java.util.Objects;
import java.util.function.Supplier;
@ -19,12 +20,17 @@ public class AggValueInput extends LeafInput<Supplier<Object>> {
private final String innerKey;
private final Processor matrixProcessor;
public AggValueInput(Expression expression, Supplier<Object> context, String innerKey) {
super(expression, context);
public AggValueInput(Location location, Expression expression, Supplier<Object> context, String innerKey) {
super(location, expression, context);
this.innerKey = innerKey;
this.matrixProcessor = innerKey != null ? new MatrixFieldProcessor(innerKey) : null;
}
@Override
protected NodeInfo<AggValueInput> info() {
return NodeInfo.create(this, AggValueInput::new, expression(), context(), innerKey);
}
public String innerKey() {
return innerKey;
}

View File

@ -8,14 +8,21 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.processor.definit
import org.elasticsearch.xpack.sql.execution.search.SqlSourceBuilder;
import org.elasticsearch.xpack.sql.expression.Attribute;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.tree.NodeInfo;
/**
* An input that must first be rewritten against the rest of the query
* before it can be further processed.
*/
public class AttributeInput extends NonExecutableInput<Attribute> {
public AttributeInput(Expression expression, Attribute context) {
super(expression, context);
public AttributeInput(Location location, Expression expression, Attribute context) {
super(location, expression, context);
}
@Override
protected NodeInfo<AttributeInput> info() {
return NodeInfo.create(this, AttributeInput::new, expression(), context());
}
@Override
@ -25,7 +32,7 @@ public class AttributeInput extends NonExecutableInput<Attribute> {
@Override
public ProcessorDefinition resolveAttributes(AttributeResolver resolver) {
return new ReferenceInput(expression(), resolver.resolve(context()));
return new ReferenceInput(location(), expression(), resolver.resolve(context()));
}
@Override

View File

@ -7,19 +7,28 @@ package org.elasticsearch.xpack.sql.expression.function.scalar.processor.definit
import org.elasticsearch.xpack.sql.execution.search.SqlSourceBuilder;
import org.elasticsearch.xpack.sql.expression.Expression;
import org.elasticsearch.xpack.sql.tree.Location;
import java.util.Arrays;
import java.util.List;
public abstract class BinaryProcessorDefinition extends ProcessorDefinition {
private final ProcessorDefinition left, right;
public BinaryProcessorDefinition(Expression expression, ProcessorDefinition left, ProcessorDefinition right) {
super(expression, Arrays.asList(left, right));
public BinaryProcessorDefinition(Location location, Expression expression, ProcessorDefinition left, ProcessorDefinition right) {
super(location, expression, Arrays.asList(left, right));
this.left = left;
this.right = right;
}
@Override
public final ProcessorDefinition replaceChildren(List<ProcessorDefinition> newChildren) {
if (newChildren.size() != 2) {
throw new IllegalArgumentException("expected [2] children but received [" + newChildren.size() + "]");
}
return replaceChildren(newChildren.get(0), newChildren.get(1));
}
public ProcessorDefinition left() {
return left;
}

Some files were not shown because too many files have changed in this diff Show More