private Object getExpressionValue(Expression expr) { switch(expr.getOpType()) { case TERM_COL: return ((Column) expr).getName(); case TERM_CONST: return getSearchArgObjValue(((Const) expr).getValue()); default: throw new RuntimeException("Unsupported expression type: " + expr.getOpType() + " in " + expr); } }
@VisibleForTesting SearchArgument getSearchArgument(Expression expr) { if (expr == null) { return null; } Builder builder = SearchArgumentFactory.newBuilder(); boolean beginWithAnd = !(expr.getOpType().equals(OpType.OP_AND) || expr.getOpType().equals(OpType.OP_OR) || expr.getOpType().equals(OpType.OP_NOT)); if (beginWithAnd) { builder.startAnd(); } buildSearchArgument(expr, builder); if (beginWithAnd) { builder.end(); } SearchArgument sArg = builder.build(); return sArg; }
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); } }
Expression lhs = ((BinaryExpression) expr).getLhs(); Expression rhs = ((BinaryExpression) expr).getRhs(); switch (expr.getOpType()) { case OP_AND: builder.startAnd(); builder.in(getColumnName(lhs), getSearchArgObjValues(in.getValues()).toArray()); default: throw new RuntimeException("Unsupported binary expression type: " + expr.getOpType() + " in " + expr); switch (expr.getOpType()) { case OP_NULL: builder.isNull(getColumnName(unaryExpr)); default: throw new RuntimeException("Unsupported unary expression type: " + expr.getOpType() + " in " + expr); throw new RuntimeException("Unsupported expression type: " + expr.getOpType() + " in " + expr);
private com.netflix.iceberg.expressions.Expression convert(Expression e) throws IOException { OpType op = e.getOpType();