All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aliyun.odps.table.optimizer.predicate.InPredicate Maven / Gradle / Ivy

package com.aliyun.odps.table.optimizer.predicate;

import java.io.Serializable;
import java.util.List;

/**
 * @author dingxin ([email protected])
 */
public class InPredicate extends Predicate {

  public enum Operator {
    /**
     * IN and NOT IN operators for set membership check
     */
    IN("in"),
    NOT_IN("not in");

    private final String description;

    Operator(String description) {
      this.description = description;
    }

    public String getDescription() {
      return description;
    }
  }

  private final Operator operator;
  private final Serializable operand;
  private final List set;

  public InPredicate(Operator operator, Serializable operand, List set) {
    super(PredicateType.IN);
    this.operator = operator;
    this.operand = operand;
    this.set = set;
  }

  public static InPredicate in(Serializable operand, List set) {
    return new InPredicate(Operator.IN, operand, set);
  }

  public static InPredicate notIn(Serializable operand, List set) {
    return new InPredicate(Operator.NOT_IN, operand, set);
  }

  public Operator getOperator() {
    return operator;
  }

  public Object getOperand() {
    return operand;
  }

  public List getSet() {
    return set;
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append(operand).append(" ").append(operator.getDescription()).append(" (");
    for (int i = 0; i < set.size(); i++) {
      sb.append(set.get(i).toString());
      if (i < set.size() - 1) {
        sb.append(", ");
      }
    }
    sb.append(")");
    return sb.toString();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy