@Override public void meet(SqlCase node) throws RuntimeException { super.meet(node); List<Entry> entries = node.getEntries(); for (SqlCase.Entry e : entries) { if (e.getCondition() instanceof SqlNull) { node.removeEntry(e); } else if (e.getCondition() instanceof FalseValue) { node.removeEntry(e); } else if (e.getCondition() instanceof TrueValue) { node.truncateEntries(e); break; } } entries = node.getEntries(); if (entries.isEmpty()) { replace(node, new SqlNull()); } else if (entries.size() == 1) { Entry entry = entries.get(0); if (entry.getCondition() instanceof TrueValue) { replace(node, entry.getResult().clone()); } else if (entry.getCondition() instanceof FalseValue) { replace(node, new SqlNull()); } else if (entry.getCondition() instanceof SqlNot) { SqlNot not = (SqlNot) entry.getCondition(); if (not.getArg() instanceof SqlIsNull) { SqlIsNull is = (SqlIsNull) not.getArg(); if (is.getArg().equals(entry.getResult())) { replace(node, entry.getResult().clone()); } } } } }
@Override public void meet(SqlIsNull node) throws RuntimeException { super.meet(node); SqlExpr arg = node.getArg(); if (arg instanceof SqlNull) { replace(node, new TrueValue()); } else if (arg instanceof SqlConstant<?>) { replace(node, new FalseValue()); } else if (arg instanceof SqlCase) { SqlExpr rep = null; SqlExpr prev = null; SqlCase scase = (SqlCase) arg; for (Entry entry : scase.getEntries()) { SqlExpr condition = entry.getCondition(); if (rep == null) { rep = and(condition.clone(), isNull(entry.getResult().clone())); prev = not(condition.clone()); } else { rep = or(rep, and(and(prev.clone(), condition.clone()), isNull(entry.getResult().clone()))); prev = and(prev, not(condition.clone())); } } replace(node, or(rep, prev.clone())); } }