break; default: opStr = expr.getOpType().toString();
@Override public String toString() { return "(" + lhs.toString() + opType.toString() + rhs.toString() + ")"; } }
@Override public String toString() { // TODO: Change toString() for OP_NOT to say (col is not null) // instead of ((col is null) not). If any one relies on expr.toString() might be useful return "(" + expr.toString() + opType.toString() + ")"; }
break; default: opStr = expr.getOpType().toString();
private String getHCatComparisonString(Expression expr) { if (expr instanceof BinaryExpression) { // call getHCatComparisonString on lhs and rhs, and and join the // results with OpType string // we can just use OpType.toString() on all Expression types except // Equal, NotEqualt since Equal has '==' in toString() and // we need '=' String opStr = null; switch (expr.getOpType()) { case OP_EQ: opStr = " = "; break; default: opStr = expr.getOpType().toString(); } BinaryExpression be = (BinaryExpression) expr; return "(" + getHCatComparisonString(be.getLhs()) + opStr + getHCatComparisonString(be.getRhs()) + ")"; } else { // should be a constant or column return expr.toString(); } }
private String getHCatComparisonString(Expression expr) { if (expr instanceof BinaryExpression) { // call getHCatComparisonString on lhs and rhs, and and join the // results with OpType string // we can just use OpType.toString() on all Expression types except // Equal, NotEqualt since Equal has '==' in toString() and // we need '=' String opStr = null; switch (expr.getOpType()) { case OP_EQ: opStr = " = "; break; default: opStr = expr.getOpType().toString(); } BinaryExpression be = (BinaryExpression) expr; return "(" + getHCatComparisonString(be.getLhs()) + opStr + getHCatComparisonString(be.getRhs()) + ")"; } else { // should be a constant or column return expr.toString(); } }
/** * Return cql where clauses for the corresponding partition filter. Make sure the data format matches * Only support the following Pig data types: int, long, float, double, boolean and chararray * */ private String partitionFilterToWhereClauseString(Expression expression) throws IOException { Expression.BinaryExpression be = (Expression.BinaryExpression) expression; OpType op = expression.getOpType(); String opString = op.toString(); switch (op) { case OP_EQ: opString = " = "; case OP_GE: case OP_GT: case OP_LE: case OP_LT: String name = be.getLhs().toString(); String value = be.getRhs().toString(); return String.format("%s %s %s", name, opString, value); case OP_AND: return String.format("%s AND %s", partitionFilterToWhereClauseString(be.getLhs()), partitionFilterToWhereClauseString(be.getRhs())); default: throw new IOException("Unsupported expression type: " + opString); } }