@Override
public Expression visitLeave(DivideParseNode node, List<Expression> children) throws SQLException {
for (int i = 1; i < children.size(); i++) { // Compile time check for divide by zero and null
Expression child = children.get(i);
if (child.getDataType() != null && child instanceof LiteralExpression) {
LiteralExpression literal = (LiteralExpression)child;
if (literal.getDataType() == PDataType.DECIMAL) {
if (PDataType.DECIMAL.compareTo(literal.getValue(), BigDecimal.ZERO) == 0) {
throw new SQLExceptionInfo.Builder(SQLExceptionCode.DIVIDE_BY_ZERO).build().buildException();
}
} else {
if (literal.getDataType().compareTo(literal.getValue(), 0L, PDataType.LONG) == 0) {
throw new SQLExceptionInfo.Builder(SQLExceptionCode.DIVIDE_BY_ZERO).build().buildException();
}
}
}
}