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[/\\]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[/\\].*.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[/\\]common[/\\]action[/\\]XPackDeleteByQueryAction.java" checks="LineLength" />
<suppress files="plugin[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]xpack[/\\]ml[/\\]action[/\\]StopDatafeedAction.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) { public Attribute(Location location, String name, String qualifier, boolean nullable, ExpressionId id) {
this(location, name, qualifier, nullable, id, false); this(location, name, qualifier, nullable, id, false);
} }
public Attribute(Location location, String name, String qualifier, boolean nullable, ExpressionId id, boolean synthetic) { public Attribute(Location location, String name, String qualifier, boolean nullable, ExpressionId id, boolean synthetic) {
super(location, name, emptyList(), id, synthetic); super(location, name, emptyList(), id, synthetic);
this.qualifier = qualifier; this.qualifier = qualifier;
@ -43,6 +43,7 @@ public abstract class Attribute extends NamedExpression {
return qualifier == null ? name() : qualifier + "." + name(); return qualifier == null ? name() : qualifier + "." + name();
} }
@Override
public boolean nullable() { public boolean nullable() {
return nullable; return nullable;
} }
@ -67,7 +68,7 @@ public abstract class Attribute extends NamedExpression {
public Attribute withNullability(boolean nullable) { public Attribute withNullability(boolean nullable) {
return Objects.equals(nullable(), nullable) ? this : clone(location(), name(), dataType(), qualifier(), nullable, id(), synthetic()); return Objects.equals(nullable(), nullable) ? this : clone(location(), name(), dataType(), qualifier(), nullable, id(), synthetic());
} }
public Attribute withId(ExpressionId id) { public Attribute withId(ExpressionId id) {
return Objects.equals(id(), id) ? this : clone(location(), name(), dataType(), qualifier(), nullable(), id, synthetic()); 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; 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 @Override
public String toString() { public String toString() {
return name() + "{" + label() + "}" + "#" + id(); return name() + "{" + label() + "}" + "#" + id();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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