Skip to content

Commit

Permalink
Import Lombok and override the equals and hashCode methods for expres…
Browse files Browse the repository at this point in the history
…sion and plan nodes (#703)

Signed-off-by: Lantao Jin <[email protected]>
  • Loading branch information
LantaoJin authored Sep 26, 2024
1 parent 0b248ec commit 38ca314
Show file tree
Hide file tree
Showing 62 changed files with 510 additions and 740 deletions.
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ lazy val pplSparkIntegration = (project in file("ppl-spark-integration"))
"org.scalatest" %% "scalatest-flatspec" % "3.2.15" % "test",
"org.scalatestplus" %% "mockito-4-6" % "3.2.15.0" % "test",
"com.stephenn" %% "scalatest-json-jsonassert" % "0.2.5" % "test",
"com.github.sbt" % "junit-interface" % "0.13.3" % "test"),
"com.github.sbt" % "junit-interface" % "0.13.3" % "test",
"org.projectlombok" % "lombok" % "1.18.30",
),
libraryDependencies ++= deps(sparkVersion),
// ANTLR settings
Antlr4 / antlr4Version := "4.8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@

package org.opensearch.sql.ast;

import lombok.EqualsAndHashCode;
import lombok.ToString;

import java.util.List;

/** AST node. */
@EqualsAndHashCode
@ToString
public abstract class Node {

public <R, C> R accept(AbstractNodeVisitor<R, C> visitor, C context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

package org.opensearch.sql.ast.expression;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.opensearch.sql.ast.AbstractNodeVisitor;

import java.util.Collections;
Expand All @@ -16,6 +19,9 @@
* Expression node of aggregate functions. Params include aggregate function name (AVG, SUM, MAX
* etc.) and the field to aggregate.
*/
@Getter
@EqualsAndHashCode(callSuper = false)
@RequiredArgsConstructor
public class AggregateFunction extends UnresolvedExpression {
private final String funcName;
private final UnresolvedExpression field;
Expand Down Expand Up @@ -51,37 +57,11 @@ public AggregateFunction(String funcName, UnresolvedExpression field, Boolean di
this.distinct = distinct;
}

public AggregateFunction(String funcName, UnresolvedExpression field, List<UnresolvedExpression> argList) {
this.funcName = funcName;
this.field = field;
this.argList = argList;
}

@Override
public List<UnresolvedExpression> getChild() {
return Collections.singletonList(field);
}

public String getFuncName() {
return funcName;
}

public UnresolvedExpression getField() {
return field;
}

public List<UnresolvedExpression> getArgList() {
return argList;
}

public UnresolvedExpression getCondition() {
return condition;
}

public Boolean getDistinct() {
return distinct;
}

@Override
public <R, C> R accept(AbstractNodeVisitor<R, C> nodeVisitor, C context) {
return nodeVisitor.visitAggregateFunction(this, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

package org.opensearch.sql.ast.expression;

import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.opensearch.sql.ast.AbstractNodeVisitor;

/**
Expand All @@ -13,40 +18,22 @@
* eventually. This can avoid restoring the info in toString() method which is inaccurate because
* original info is already lost.
*/
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Getter
@RequiredArgsConstructor
@ToString
public class Alias extends UnresolvedExpression {

/** Original field name. */
private String name;
private final String name;

/** Expression aliased. */
private UnresolvedExpression delegated;
private final UnresolvedExpression delegated;

/** Optional field alias. */
private String alias;

public Alias(String name, UnresolvedExpression delegated, String alias) {
this.name = name;
this.delegated = delegated;
this.alias = alias;
}

public Alias(String name, UnresolvedExpression delegated) {
this.name = name;
this.delegated = delegated;
}

public String getName() {
return name;
}

public UnresolvedExpression getDelegated() {
return delegated;
}

public String getAlias() {
return alias;
}

@Override
public <T, C> T accept(AbstractNodeVisitor<T, C> nodeVisitor, C context) {
return nodeVisitor.visitAlias(this, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@

package org.opensearch.sql.ast.expression;

import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.opensearch.sql.ast.AbstractNodeVisitor;
import org.opensearch.sql.ast.Node;

import java.util.Collections;
import java.util.List;

/** Represent the All fields which is been used in SELECT *. */
@ToString
@EqualsAndHashCode(callSuper = false)
public class AllFields extends UnresolvedExpression {
public static final AllFields INSTANCE = new AllFields();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@

package org.opensearch.sql.ast.expression;

import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.opensearch.sql.ast.AbstractNodeVisitor;

import java.util.Arrays;
import java.util.List;

/** Expression node of logic AND. */
@ToString
@EqualsAndHashCode(callSuper = true)
public class And extends BinaryExpression {

public And(UnresolvedExpression left, UnresolvedExpression right) {
super(left,right);
super(left, right);
}

@Override
public <R, C> R accept(AbstractNodeVisitor<R, C> nodeVisitor, C context) {
return nodeVisitor.visitAnd(this, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,30 @@

package org.opensearch.sql.ast.expression;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.opensearch.sql.ast.AbstractNodeVisitor;

import java.util.Arrays;
import java.util.List;

/** Argument. */
@Getter
@ToString
@RequiredArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class Argument extends UnresolvedExpression {
private final String name;
private final Literal value;

public Argument(String name, Literal value) {
this.name = name;
this.value = value;
}

// private final DataType valueType;
@Override
public List<UnresolvedExpression> getChild() {
return Arrays.asList(value);
}

public String getName() {
return name;
}

public Literal getValue() {
return value;
}

@Override
public <R, C> R accept(AbstractNodeVisitor<R, C> nodeVisitor, C context) {
return nodeVisitor.visitArgument(this, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@
package org.opensearch.sql.ast.expression;

import com.google.common.collect.ImmutableList;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import org.opensearch.sql.ast.AbstractNodeVisitor;

import java.util.List;

/** Expression node that includes a list of Expression nodes. */
@Getter
@ToString
@EqualsAndHashCode(callSuper = false)
@AllArgsConstructor
public class AttributeList extends UnresolvedExpression {
private List<UnresolvedExpression> attrList;
private final List<UnresolvedExpression> attrList;

@Override
public List<UnresolvedExpression> getChild() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@

package org.opensearch.sql.ast.expression;

import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.opensearch.sql.ast.AbstractNodeVisitor;
import org.opensearch.sql.ast.Node;

import java.util.Arrays;
import java.util.List;

/** Unresolved expression for BETWEEN. */
@Getter
@Setter
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@ToString
public class Between extends UnresolvedExpression {

/** Value for range check. */
Expand All @@ -23,12 +33,6 @@ public class Between extends UnresolvedExpression {
/** Upper bound of the range (inclusive). */
private UnresolvedExpression upperBound;

public Between(UnresolvedExpression value, UnresolvedExpression lowerBound, UnresolvedExpression upperBound) {
this.value = value;
this.lowerBound = lowerBound;
this.upperBound = upperBound;
}

@Override
public List<? extends Node> getChild() {
return Arrays.asList(value, lowerBound, upperBound);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,22 @@

package org.opensearch.sql.ast.expression;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Arrays;
import java.util.List;

@Getter
@EqualsAndHashCode(callSuper = false)
@RequiredArgsConstructor
public abstract class BinaryExpression extends UnresolvedExpression {
private UnresolvedExpression left;
private UnresolvedExpression right;

public BinaryExpression(UnresolvedExpression left, UnresolvedExpression right) {
this.left = left;
this.right = right;
}
private final UnresolvedExpression left;
private final UnresolvedExpression right;

@Override
public List<UnresolvedExpression> getChild() {
return Arrays.asList(left, right);
}

public UnresolvedExpression getLeft() {
return left;
}

public UnresolvedExpression getRight() {
return right;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@
package org.opensearch.sql.ast.expression;

import com.google.common.collect.ImmutableList;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import org.opensearch.sql.ast.AbstractNodeVisitor;
import org.opensearch.sql.ast.Node;

import java.util.List;

/** AST node that represents CASE clause similar as Switch statement in programming language. */
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Getter
@ToString
public class Case extends UnresolvedExpression {

/** Value to be compared by WHEN statements. Null in the case of CASE WHEN conditions. */
Expand All @@ -26,24 +34,6 @@ public class Case extends UnresolvedExpression {
/** Expression that represents ELSE statement result. */
private UnresolvedExpression elseClause;

public Case(UnresolvedExpression caseValue, List<When> whenClauses, UnresolvedExpression elseClause) {
this.caseValue =caseValue;
this.whenClauses = whenClauses;
this.elseClause = elseClause;
}

public UnresolvedExpression getCaseValue() {
return caseValue;
}

public List<When> getWhenClauses() {
return whenClauses;
}

public UnresolvedExpression getElseClause() {
return elseClause;
}

@Override
public List<? extends Node> getChild() {
ImmutableList.Builder<Node> children = ImmutableList.builder();
Expand Down
Loading

0 comments on commit 38ca314

Please sign in to comment.