SQL: Fix checkstyle / add missing hashCode (elastic/x-pack-elasticsearch#3323)

* Fix checkstyle / add missing hashCode
* Improve formatting

Original commit: elastic/x-pack-elasticsearch@a3ad2793bb
This commit is contained in:
Costin Leau 2017-12-14 17:17:26 +02:00 committed by GitHub
parent 59e6d34c29
commit 624a1530c0
10 changed files with 82 additions and 48 deletions

View File

@ -9,7 +9,6 @@
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]parser[/\\]SqlBase(Base(Listener|Visitor)|Lexer|Listener|Parser|Visitor).java" checks="." />
<suppress files="sql[/\\]server[/\\].*.java" checks="LineLength" />
<suppress files="sql[/\\]server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]sql[/\\]expression[/\\].*.java" checks="EqualsHashCode" />
<suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]common[/\\]action[/\\]XPackDeleteByQueryAction.java" checks="LineLength" />
<suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]ml[/\\]action[/\\]StopDatafeedAction.java" checks="LineLength" />

View File

@ -28,7 +28,7 @@ public abstract class Attribute extends NamedExpression {
public Attribute(Location location, String name, String qualifier, boolean nullable, ExpressionId id) {
this(location, name, qualifier, nullable, id, false);
}
public Attribute(Location location, String name, String qualifier, boolean nullable, ExpressionId id, boolean synthetic) {
super(location, name, emptyList(), id, synthetic);
this.qualifier = qualifier;
@ -43,6 +43,7 @@ public abstract class Attribute extends NamedExpression {
return qualifier == null ? name() : qualifier + "." + name();
}
@Override
public boolean nullable() {
return nullable;
}
@ -67,7 +68,7 @@ public abstract class Attribute extends NamedExpression {
public Attribute withNullability(boolean nullable) {
return Objects.equals(nullable(), nullable) ? this : clone(location(), name(), dataType(), qualifier(), nullable, id(), synthetic());
}
public Attribute withId(ExpressionId id) {
return Objects.equals(id(), id) ? this : clone(location(), name(), dataType(), qualifier(), nullable(), id, synthetic());
}
@ -89,6 +90,22 @@ public abstract class Attribute extends NamedExpression {
return other instanceof Attribute ? id().equals(((Attribute) other).id()) : false;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), qualifier, nullable);
}
@Override
public boolean equals(Object obj) {
if (super.equals(obj)) {
Attribute other = (Attribute) obj;
return Objects.equals(qualifier, other.qualifier)
&& Objects.equals(nullable, other.nullable);
}
return false;
}
@Override
public String toString() {
return name() + "{" + label() + "}" + "#" + id();

View File

@ -5,11 +5,11 @@
*/
package org.elasticsearch.xpack.sql.expression;
import java.util.Objects;
import org.elasticsearch.xpack.sql.tree.Location;
import org.elasticsearch.xpack.sql.type.DataType;
import java.util.Objects;
public abstract class TypedAttribute extends Attribute {
private final DataType dataType;
@ -27,23 +27,19 @@ public abstract class TypedAttribute extends Attribute {
public DataType dataType() {
return dataType;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), dataType);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
if (super.equals(obj)) {
TypedAttribute other = (TypedAttribute) obj;
return Objects.equals(dataType, other.dataType);
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
TypedAttribute other = (TypedAttribute) obj;
return Objects.equals(name(), other.name())
&& Objects.equals(id(), other.id())
&& Objects.equals(nullable(), other.nullable())
&& Objects.equals(dataType(), other.dataType())
&& Objects.equals(qualifier(), other.qualifier())
&& Objects.equals(synthetic(), other.synthetic());
return false;
}
}

View File

@ -34,18 +34,14 @@ public class UnresolvedAlias extends UnresolvedNamedExpression {
throw new UnresolvedException("nullable", this);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), child);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
UnresolvedAlias other = (UnresolvedAlias) obj;
return Objects.equals(child, other.child);
return super.equals(obj) && Objects.equals(child, ((UnresolvedAlias) obj).child);
}
@Override

View File

@ -49,7 +49,7 @@ public class UnresolvedAttribute extends Attribute implements Unresolvable {
public boolean resolved() {
return false;
}
@Override
protected Attribute clone(Location location, String name, DataType dataType, String qualifier, boolean nullable, ExpressionId id, boolean synthetic) {
return this;
@ -83,7 +83,7 @@ public class UnresolvedAttribute extends Attribute implements Unresolvable {
public String unresolvedMessage() {
return unresolvedMsg;
}
public static String errorMessage(String name, List<String> potentialMatches) {
String msg = "Unknown column [" + name + "]";
if (!CollectionUtils.isEmpty(potentialMatches)) {
@ -92,6 +92,11 @@ public class UnresolvedAttribute extends Attribute implements Unresolvable {
return msg;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), resolutionMetadata, unresolvedMsg);
}
@Override
public boolean equals(Object obj) {
if (super.equals(obj)) {

View File

@ -31,18 +31,19 @@ public class UnresolvedStar extends UnresolvedNamedExpression {
return qualifier;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), qualifier);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
if (super.equals(obj)) {
UnresolvedStar other = (UnresolvedStar) obj;
return Objects.equals(qualifier, other.qualifier);
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
UnresolvedStar other = (UnresolvedStar) obj;
return Objects.equals(qualifier, other.qualifier);
return false;
}
private String message() {

View File

@ -26,6 +26,11 @@ public abstract class FunctionAttribute extends TypedAttribute {
return functionId;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), functionId);
}
@Override
public boolean equals(Object obj) {
return super.equals(obj) && Objects.equals(functionId, ((FunctionAttribute) obj).functionId());

View File

@ -15,7 +15,7 @@ import org.elasticsearch.xpack.sql.type.DataType;
import java.util.Objects;
public class AggregateFunctionAttribute extends FunctionAttribute {
private final String propertyPath;
AggregateFunctionAttribute(Location location, String name, DataType dataType, ExpressionId id, String functionId, String propertyPath) {
@ -26,11 +26,11 @@ public class AggregateFunctionAttribute extends FunctionAttribute {
super(location, name, dataType, qualifier, nullable, id, synthetic, functionId);
this.propertyPath = propertyPath;
}
public String propertyPath() {
return propertyPath;
}
@Override
protected Expression canonicalize() {
return new AggregateFunctionAttribute(location(), "<none>", dataType(), null, true, id(), false, "<none>", null);
@ -46,7 +46,12 @@ public class AggregateFunctionAttribute extends FunctionAttribute {
public AggregateFunctionAttribute withFunctionId(String functionId, String propertyPath) {
return new AggregateFunctionAttribute(location(), name(), dataType(), qualifier(), nullable(), id(), synthetic(), functionId, propertyPath);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), propertyPath);
}
@Override
public boolean equals(Object obj) {
return super.equals(obj) && Objects.equals(propertyPath(), ((AggregateFunctionAttribute) obj).propertyPath());

View File

@ -58,8 +58,8 @@ public class Cast extends UnaryScalarFunction {
@Override
protected TypeResolution resolveType() {
return DataTypeConversion.canConvert(from(), to()) ?
TypeResolution.TYPE_RESOLVED :
new TypeResolution("Cannot cast %s to %s", from(), to());
TypeResolution.TYPE_RESOLVED :
new TypeResolution("Cannot cast %s to %s", from(), to());
}
@Override
@ -77,6 +77,11 @@ public class Cast extends UnaryScalarFunction {
return new UnaryProcessorDefinition(this, ProcessorDefinitions.toProcessorDefinition(field()), new CastProcessor(DataTypeConversion.conversionFor(from(), to())));
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), dataType);
}
@Override
public boolean equals(Object obj) {
return super.equals(obj) && Objects.equals(dataType, ((Cast) obj).dataType());

View File

@ -38,11 +38,11 @@ public class ScalarFunctionAttribute extends FunctionAttribute {
public ScriptTemplate script() {
return script;
}
public Expression orderBy() {
return orderBy;
}
public ProcessorDefinition processorDef() {
return processorDef;
}
@ -59,6 +59,11 @@ public class ScalarFunctionAttribute extends FunctionAttribute {
processorDef);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), orderBy);
}
@Override
public boolean equals(Object obj) {
return super.equals(obj) && Objects.equals(orderBy, ((ScalarFunctionAttribute) obj).orderBy());