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.
- Loading branch information
Showing
9 changed files
with
237 additions
and
4 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
22 changes: 22 additions & 0 deletions
22
...ugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/search/SearchUtils.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,22 @@ | ||
/* | ||
* 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.search; | ||
|
||
import org.elasticsearch.xpack.esql.core.expression.Attribute; | ||
import org.elasticsearch.xpack.esql.core.expression.MetadataAttribute; | ||
import org.elasticsearch.xpack.esql.core.tree.Source; | ||
import org.elasticsearch.xpack.esql.core.type.DataTypes; | ||
|
||
class SearchUtils { | ||
|
||
private SearchUtils() {} | ||
|
||
static Attribute scoreField(Source source) { | ||
return new MetadataAttribute(source, "_score", DataTypes.DOUBLE, false); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...sql/src/main/java/org/elasticsearch/xpack/esql/plan/physical/search/EsScoreQueryExec.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,74 @@ | ||
/* | ||
* 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.physical.search; | ||
|
||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.index.IndexMode; | ||
import org.elasticsearch.index.query.QueryBuilder; | ||
import org.elasticsearch.xpack.esql.core.expression.Attribute; | ||
import org.elasticsearch.xpack.esql.core.expression.Expression; | ||
import org.elasticsearch.xpack.esql.core.expression.MetadataAttribute; | ||
import org.elasticsearch.xpack.esql.core.index.EsIndex; | ||
import org.elasticsearch.xpack.esql.core.tree.NodeInfo; | ||
import org.elasticsearch.xpack.esql.core.tree.NodeUtils; | ||
import org.elasticsearch.xpack.esql.core.tree.Source; | ||
import org.elasticsearch.xpack.esql.core.type.DataTypes; | ||
import org.elasticsearch.xpack.esql.core.type.EsField; | ||
import org.elasticsearch.xpack.esql.plan.physical.EsQueryExec; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
public class EsScoreQueryExec extends EsQueryExec { | ||
|
||
static final EsField SCORE_FIELD = new EsField("_score", DataTypes.DOUBLE, Map.of(), false); | ||
|
||
public EsScoreQueryExec(Source source, | ||
EsIndex index, | ||
List<Attribute> attrs, | ||
QueryBuilder query, | ||
Expression limit, | ||
List<FieldSort> sorts, | ||
Integer estimatedRowSize) { | ||
super(source, index, IndexMode.STANDARD, attrs, query, limit, sorts, estimatedRowSize); | ||
} | ||
|
||
public static boolean isScoreAttribute(Attribute attr) { | ||
return attr instanceof MetadataAttribute && SCORE_FIELD.getName().equals(attr.name()); | ||
} | ||
|
||
@Override | ||
protected NodeInfo<EsQueryExec> info() { | ||
return NodeInfo.create(this, EsScoreQueryExec::new, index(), attrs(), query(), limit(), sorts(), estimatedRowSize()); | ||
} | ||
|
||
public EsScoreQueryExec withLimit(Expression limit) { | ||
return Objects.equals(this.limit(), limit) | ||
? this | ||
: new EsScoreQueryExec(source(), index(), attrs(), query(), limit, sorts(), estimatedRowSize()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
|
||
if (obj == null || getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
|
||
return super.equals(obj); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return super.hashCode(); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/physical/search/RankExec.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,66 @@ | ||
/* | ||
* 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.physical.search; | ||
|
||
import org.elasticsearch.xpack.esql.core.expression.Attribute; | ||
import org.elasticsearch.xpack.esql.core.expression.Expression; | ||
import org.elasticsearch.xpack.esql.core.tree.NodeInfo; | ||
import org.elasticsearch.xpack.esql.core.tree.Source; | ||
import org.elasticsearch.xpack.esql.plan.physical.PhysicalPlan; | ||
import org.elasticsearch.xpack.esql.plan.physical.UnaryExec; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class RankExec extends UnaryExec { | ||
|
||
private final Expression query; | ||
|
||
public RankExec(Source source, PhysicalPlan child, Expression query) { | ||
super(source, child); | ||
this.query = query; | ||
} | ||
|
||
@Override | ||
protected NodeInfo<RankExec> info() { | ||
return NodeInfo.create(this, RankExec::new, child(), query); | ||
} | ||
|
||
@Override | ||
public RankExec replaceChild(PhysicalPlan newChild) { | ||
return new RankExec(source(), newChild, query); | ||
} | ||
|
||
public Expression query() { | ||
return query; | ||
} | ||
|
||
@Override | ||
public List<Attribute> output() { | ||
return child().output(); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(query, child()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (this == obj) { | ||
return true; | ||
} | ||
|
||
if (obj == null || getClass() != obj.getClass()) { | ||
return false; | ||
} | ||
|
||
RankExec other = (RankExec) obj; | ||
return Objects.equals(query, other.query) && Objects.equals(child(), other.child()); | ||
} | ||
} |
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