Source:
public JsonPostAggregation getJsonPostAggregation(String name, RexNode rexNode, RelNode rel) { if (rexNode instanceof RexCall) { List<JsonPostAggregation> fields = new ArrayList<>(); for (RexNode ele : ((RexCall) rexNode).getOperands()) { JsonPostAggregation field = getJsonPostAggregation("", ele, rel); if (field == null) { return null; } fields.add(field); } switch (rexNode.getKind()) { case PLUS: return new JsonArithmetic(name, "+", fields, null); case MINUS: return new JsonArithmetic(name, "-", fields, null); case DIVIDE: return new JsonArithmetic(name, "quotient", fields, null); case TIMES: return new JsonArithmetic(name, "*", fields, null); case CAST: return getJsonPostAggregation(name, ((RexCall) rexNode).getOperands().get(0), rel); default: } } else if (rexNode instanceof RexInputRef) { if (rel instanceof Aggregate) { Integer indexSkipGroup = ((RexInputRef) rexNode).getIndex() - ((Aggregate) rel).getGroupSet().cardinality(); AggregateCall aggCall = ((Aggregate) rel).getAggCallList().get(indexSkipGroup); if (aggCall.isDistinct() && aggCall.getAggregation().getKind().equals(SqlKind.COUNT)) { return new JsonHyperUniqueCardinality("", rel.getRowType().getFieldNames().get(((RexInputRef) rexNode).getIndex())); } } return new JsonFieldAccessor("", rel.getRowType().getFieldNames().get(((RexInputRef) rexNode).getIndex())); } else if (rexNode instanceof RexLiteral) { if (((RexLiteral) rexNode).getValue3() instanceof BigDecimal) { return new JsonConstant("", ((BigDecimal) ((RexLiteral) rexNode).getValue3()).doubleValue()); } } return null; }

Target:
public JsonPostAggregation getJsonPostAggregation(String name, RexNode rexNode, RelNode rel) { if (rexNode instanceof RexCall) { List<JsonPostAggregation> fields = new ArrayList<>(); for (RexNode ele : ((RexCall) rexNode).getOperands()) { JsonPostAggregation field = getJsonPostAggregation("", ele, rel); if (field == null) { throw new RuntimeException("Unchecked types that cannot be parsed as Post Aggregator"); } fields.add(field); } switch (rexNode.getKind()) { case PLUS: return new JsonArithmetic(name, "+", fields, null); case MINUS: return new JsonArithmetic(name, "-", fields, null); case DIVIDE: return new JsonArithmetic(name, "quotient", fields, null); case TIMES: return new JsonArithmetic(name, "*", fields, null); case CAST: return getJsonPostAggregation(name, ((RexCall) rexNode).getOperands().get(0), rel); default: } } else if (rexNode instanceof RexInputRef) { Integer indexSkipGroup = ((RexInputRef) rexNode).getIndex() - ((Aggregate) rel).getGroupCount(); AggregateCall aggCall = ((Aggregate) rel).getAggCallList().get(indexSkipGroup); if (aggCall.isDistinct() && aggCall.getAggregation().getKind().equals(SqlKind.COUNT)) { return new JsonHyperUniqueCardinality("", rel.getRowType().getFieldNames().get(((RexInputRef) rexNode).getIndex())); } return new JsonFieldAccessor("", rel.getRowType().getFieldNames().get(((RexInputRef) rexNode).getIndex())); } else if (rexNode instanceof RexLiteral) { if (((RexLiteral) rexNode).getValue3() instanceof BigDecimal) { return new JsonConstant("", ((BigDecimal) ((RexLiteral) rexNode).getValue3()).doubleValue()); } } throw new RuntimeException("Unchecked types that cannot be parsed as Post Aggregator"); }