presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/systemtables/PreparedStatementBuilder.java/PreparedStatementBuilder/toPredicate
class PreparedStatementBuilder:    private static String toPredicate(
            int columnIndex,
            String columnName,
            Type type,
            Domain domain,
            Set<Integer> uuidColumnIndexes,
            List<ValueBuffer> bindValues)
    {
        if (domain.getValues().isAll()) {
            return domain.isNullAllowed() ? "TRUE" : columnName + " IS NOT NULL";
        }
        if (domain.getValues().isNone()) {
            return domain.isNullAllowed() ? columnName + " IS NULL" : "FALSE";
        }

        return domain.getValues().getValuesProcessor().transform(
                ranges -> {
                    // Add disjuncts for ranges
                    List<String> disjuncts = new ArrayList<>();
                    List<Object> singleValues = new ArrayList<>();

                    // Add disjuncts for ranges
                    for (Range range : ranges.getOrderedRanges()) {
                        checkState(!range.isAll()); // Already checked
                        if (range.isSingleValue()) {
                            singleValues.add(range.getLow().getValue());
                        }
                        else {
                            List<String> rangeConjuncts = new ArrayList<>();
                            if (!range.getLow().isLowerUnbounded()) {
                                Object bindValue = getBindValue(columnIndex, uuidColumnIndexes, range.getLow().getValue());
                                switch (range.getLow().getBound()) {
                                    case ABOVE:
                                        rangeConjuncts.add(toBindPredicate(columnName, ">"));
                                        bindValues.add(ValueBuffer.create(columnIndex, type, bindValue));
                                        break;
                                    case EXACTLY:
                                        rangeConjuncts.add(toBindPredicate(columnName, ">="));
                                        bindValues.add(ValueBuffer.create(columnIndex, type, bindValue));
                                        break;
                                    case BELOW:
                                        throw new VerifyException("Low Marker should never use BELOW bound");
                                    default:
                                        throw new AssertionError("Unhandled bound: " + range.getLow().getBound());
                                }
                            }
                            if (!range.getHigh().isUpperUnbounded()) {
                                Object bindValue = getBindValue(columnIndex, uuidColumnIndexes, range.getHigh().getValue());
                                switch (range.getHigh().getBound()) {
                                    case ABOVE:
                                        throw new VerifyException("High Marker should never use ABOVE bound");
                                    case EXACTLY:
                                        rangeConjuncts.add(toBindPredicate(columnName, "<="));
                                        bindValues.add(ValueBuffer.create(columnIndex, type, bindValue));
                                        break;
                                    case BELOW:
                                        rangeConjuncts.add(toBindPredicate(columnName, "<"));
                                        bindValues.add(ValueBuffer.create(columnIndex, type, bindValue));
                                        break;
                                    default:
                                        throw new AssertionError("Unhandled bound: " + range.getHigh().getBound());
                                }
                            }
                            // If rangeConjuncts is null, then the range was ALL, which should already have been checked for
                            checkState(!rangeConjuncts.isEmpty());
                            disjuncts.add("(" + Joiner.on(" AND ").join(rangeConjuncts) + ")");
                        }
                    }

                    // Add back all of the possible single values either as an equality or an IN predicate
                    if (singleValues.size() == 1) {
                        disjuncts.add(toBindPredicate(columnName, "="));
                        bindValues.add(ValueBuffer.create(columnIndex, type, getBindValue(columnIndex, uuidColumnIndexes, getOnlyElement(singleValues))));
                    }
                    else if (singleValues.size() > 1) {
                        disjuncts.add(columnName + " IN (" + Joiner.on(",").join(nCopies(singleValues.size(), "?")) + ")");
                        for (Object singleValue : singleValues) {
                            bindValues.add(ValueBuffer.create(columnIndex, type, getBindValue(columnIndex, uuidColumnIndexes, singleValue)));
                        }
                    }

                    // Add nullability disjuncts
                    checkState(!disjuncts.isEmpty());
                    if (domain.isNullAllowed()) {
                        disjuncts.add(columnName + " IS NULL");
                    }

                    return "(" + Joiner.on(" OR ").join(disjuncts) + ")";
                },

                discreteValues -> {
                    String values = Joiner.on(",").join(nCopies(discreteValues.getValues().size(), "?"));
                    String predicate = columnName + (discreteValues.isWhiteList() ? "" : " NOT") + " IN (" + values + ")";
                    for (Object value : discreteValues.getValues()) {
                        bindValues.add(ValueBuffer.create(columnIndex, type, getBindValue(columnIndex, uuidColumnIndexes, value)));
                    }
                    if (domain.isNullAllowed()) {
                        predicate = "(" + predicate + " OR " + columnName + " IS NULL)";
                    }
                    return predicate;
                },

                allOrNone -> {
                    throw new IllegalStateException("Case should not be reachable");
                });
    }