From 4429defcb14d78b2574929b8959fd1908bf8a8e2 Mon Sep 17 00:00:00 2001 From: Costin Leau Date: Thu, 17 Aug 2017 17:29:32 +0300 Subject: [PATCH] Fix hierarchy of Percentile/PercentileRank Original commit: elastic/x-pack-elasticsearch@b56e65a01010b7b367a5eb75ce08af577f5f20ed --- .../function/aggregate/Percentile.java | 24 ++----------------- .../function/aggregate/PercentileRank.java | 22 +---------------- 2 files changed, 3 insertions(+), 43 deletions(-) diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/function/aggregate/Percentile.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/function/aggregate/Percentile.java index 89493ac681d..96b9207ecb2 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/function/aggregate/Percentile.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/function/aggregate/Percentile.java @@ -6,17 +6,14 @@ package org.elasticsearch.xpack.sql.expression.function.aggregate; 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.type.DataType; import org.elasticsearch.xpack.sql.type.DataTypes; -import java.util.Objects; - import static java.util.Collections.singletonList; -public class Percentile extends AggregateFunction implements EnclosedAgg { +public class Percentile extends NumericAggregate implements EnclosedAgg { private final Expression percent; @@ -27,9 +24,7 @@ public class Percentile extends AggregateFunction implements EnclosedAgg { @Override protected TypeResolution resolveType() { - TypeResolution resolution = field().dataType().isNumeric() ? TypeResolution.TYPE_RESOLVED : - new TypeResolution("Function '%s' cannot be applied on a non-numeric expression ('%s' of type '%s')", - functionName(), Expressions.name(field()), field().dataType().esName()); + TypeResolution resolution = super.resolveType(); if (TypeResolution.TYPE_RESOLVED.equals(resolution)) { resolution = percent().dataType().isNumeric() ? TypeResolution.TYPE_RESOLVED : @@ -51,19 +46,4 @@ public class Percentile extends AggregateFunction implements EnclosedAgg { public String innerName() { return "[" + Double.toString(Foldables.doubleValueOf(percent)) + "]"; } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj == null || getClass() != obj.getClass()) { - return false; - } - - Percentile other = (Percentile) obj; - return Objects.equals(field(), other.field()) - && Objects.equals(percent, other.percent); - } } \ No newline at end of file diff --git a/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/function/aggregate/PercentileRank.java b/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/function/aggregate/PercentileRank.java index b14557eb3a0..8ed75e4ac52 100644 --- a/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/function/aggregate/PercentileRank.java +++ b/sql/server/src/main/java/org/elasticsearch/xpack/sql/expression/function/aggregate/PercentileRank.java @@ -6,14 +6,11 @@ package org.elasticsearch.xpack.sql.expression.function.aggregate; 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.type.DataType; import org.elasticsearch.xpack.sql.type.DataTypes; -import java.util.Objects; - import static java.util.Collections.singletonList; public class PercentileRank extends AggregateFunction implements EnclosedAgg { @@ -27,9 +24,7 @@ public class PercentileRank extends AggregateFunction implements EnclosedAgg { @Override protected TypeResolution resolveType() { - TypeResolution resolution = field().dataType().isNumeric() ? TypeResolution.TYPE_RESOLVED : - new TypeResolution("Function '%s' cannot be applied on a non-numeric expression ('%s' of type '%s')", - functionName(), Expressions.name(field()), field().dataType().esName()); + TypeResolution resolution = super.resolveType(); if (TypeResolution.TYPE_RESOLVED.equals(resolution)) { resolution = value.dataType().isNumeric() ? TypeResolution.TYPE_RESOLVED : @@ -51,19 +46,4 @@ public class PercentileRank extends AggregateFunction implements EnclosedAgg { public String innerName() { return "[" + Double.toString(Foldables.doubleValueOf(value)) + "]"; } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - - if (obj == null || getClass() != obj.getClass()) { - return false; - } - - PercentileRank other = (PercentileRank) obj; - return Objects.equals(field(), other.field()) - && Objects.equals(value, other.value); - } } \ No newline at end of file