forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Duplicate logical aggregate and relation for ESQL (elastic#107789)
We'll need to make changes for Aggregate, EsRelation, and UnresolvedRelation logical plans for TSDB. I think it's better to replicate these classes for ESQL only instead of modifying the existing classes in QL. I also add these classes to the forbid APIs in ESQL to avoid future mistakes.
- Loading branch information
Showing
25 changed files
with
363 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/Aggregate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
package org.elasticsearch.xpack.esql.plan.logical; | ||
|
||
import org.elasticsearch.xpack.ql.capabilities.Resolvables; | ||
import org.elasticsearch.xpack.ql.expression.Attribute; | ||
import org.elasticsearch.xpack.ql.expression.Expression; | ||
import org.elasticsearch.xpack.ql.expression.Expressions; | ||
import org.elasticsearch.xpack.ql.expression.NamedExpression; | ||
import org.elasticsearch.xpack.ql.plan.logical.LogicalPlan; | ||
import org.elasticsearch.xpack.ql.plan.logical.UnaryPlan; | ||
import org.elasticsearch.xpack.ql.tree.NodeInfo; | ||
import org.elasticsearch.xpack.ql.tree.Source; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class Aggregate extends UnaryPlan { | ||
|
||
private final List<Expression> groupings; | ||
private final List<? extends NamedExpression> aggregates; | ||
|
||
public Aggregate(Source source, LogicalPlan child, List<Expression> groupings, List<? extends NamedExpression> aggregates) { | ||
super(source, child); | ||
this.groupings = groupings; | ||
this.aggregates = aggregates; | ||
} | ||
|
||
@Override | ||
protected NodeInfo<Aggregate> info() { | ||
return NodeInfo.create(this, Aggregate::new, child(), groupings, aggregates); | ||
} | ||
|
||
@Override | ||
public Aggregate replaceChild(LogicalPlan newChild) { | ||
return new Aggregate(source(), newChild, groupings, aggregates); | ||
} | ||
|
||
public List<Expression> groupings() { | ||
return groupings; | ||
} | ||
|
||
public List<? extends NamedExpression> aggregates() { | ||
return aggregates; | ||
} | ||
|
||
@Override | ||
public boolean expressionsResolved() { | ||
return Resolvables.resolved(groupings) && Resolvables.resolved(aggregates); | ||
} | ||
|
||
@Override | ||
public List<Attribute> output() { | ||
return Expressions.asAttributes(aggregates); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(groupings, aggregates, child()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
|
||
if (obj == null || getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
|
||
Aggregate other = (Aggregate) obj; | ||
return Objects.equals(groupings, other.groupings) | ||
&& Objects.equals(aggregates, other.aggregates) | ||
&& Objects.equals(child(), other.child()); | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/EsRelation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
package org.elasticsearch.xpack.esql.plan.logical; | ||
|
||
import org.elasticsearch.xpack.ql.expression.Attribute; | ||
import org.elasticsearch.xpack.ql.expression.FieldAttribute; | ||
import org.elasticsearch.xpack.ql.index.EsIndex; | ||
import org.elasticsearch.xpack.ql.options.EsSourceOptions; | ||
import org.elasticsearch.xpack.ql.plan.logical.LeafPlan; | ||
import org.elasticsearch.xpack.ql.tree.NodeInfo; | ||
import org.elasticsearch.xpack.ql.tree.NodeUtils; | ||
import org.elasticsearch.xpack.ql.tree.Source; | ||
import org.elasticsearch.xpack.ql.type.EsField; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.Objects; | ||
|
||
public class EsRelation extends LeafPlan { | ||
|
||
private final EsIndex index; | ||
private final List<Attribute> attrs; | ||
private final EsSourceOptions esSourceOptions; | ||
private final boolean frozen; | ||
|
||
public EsRelation(Source source, EsIndex index, boolean frozen) { | ||
this(source, index, flatten(source, index.mapping()), EsSourceOptions.NO_OPTIONS, frozen); | ||
} | ||
|
||
public EsRelation(Source source, EsIndex index, List<Attribute> attributes) { | ||
this(source, index, attributes, EsSourceOptions.NO_OPTIONS, false); | ||
} | ||
|
||
public EsRelation(Source source, EsIndex index, List<Attribute> attributes, EsSourceOptions esSourceOptions) { | ||
this(source, index, attributes, esSourceOptions, false); | ||
} | ||
|
||
public EsRelation(Source source, EsIndex index, List<Attribute> attributes, EsSourceOptions esSourceOptions, boolean frozen) { | ||
super(source); | ||
this.index = index; | ||
this.attrs = attributes; | ||
Objects.requireNonNull(esSourceOptions); | ||
this.esSourceOptions = esSourceOptions; | ||
this.frozen = frozen; | ||
} | ||
|
||
@Override | ||
protected NodeInfo<EsRelation> info() { | ||
return NodeInfo.create(this, EsRelation::new, index, attrs, esSourceOptions, frozen); | ||
} | ||
|
||
private static List<Attribute> flatten(Source source, Map<String, EsField> mapping) { | ||
return flatten(source, mapping, null); | ||
} | ||
|
||
private static List<Attribute> flatten(Source source, Map<String, EsField> mapping, FieldAttribute parent) { | ||
List<Attribute> list = new ArrayList<>(); | ||
|
||
for (Entry<String, EsField> entry : mapping.entrySet()) { | ||
String name = entry.getKey(); | ||
EsField t = entry.getValue(); | ||
|
||
if (t != null) { | ||
FieldAttribute f = new FieldAttribute(source, parent, parent != null ? parent.name() + "." + name : name, t); | ||
list.add(f); | ||
// object or nested | ||
if (t.getProperties().isEmpty() == false) { | ||
list.addAll(flatten(source, t.getProperties(), f)); | ||
} | ||
} | ||
} | ||
return list; | ||
} | ||
|
||
public EsIndex index() { | ||
return index; | ||
} | ||
|
||
public EsSourceOptions esSourceOptions() { | ||
return esSourceOptions; | ||
} | ||
|
||
public boolean frozen() { | ||
return frozen; | ||
} | ||
|
||
@Override | ||
public List<Attribute> output() { | ||
return attrs; | ||
} | ||
|
||
@Override | ||
public boolean expressionsResolved() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(index, esSourceOptions, frozen); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
|
||
if (obj == null || getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
|
||
EsRelation other = (EsRelation) obj; | ||
return Objects.equals(index, other.index) && Objects.equals(esSourceOptions, other.esSourceOptions) && frozen == other.frozen; | ||
} | ||
|
||
@Override | ||
public String nodeString() { | ||
return nodeName() + "[" + index + "]" + NodeUtils.limitedToString(attrs); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.