presto-raptor-legacy/src/main/java/io/prestosql/plugin/raptor/legacy/metadata/ShardPredicate.java/ShardPredicate/create
class ShardPredicate:    public static ShardPredicate create(TupleDomain<RaptorColumnHandle> tupleDomain)
    {
        StringJoiner predicate = new StringJoiner(" AND ").setEmptyValue("true");
        ImmutableList.Builder<JDBCType> types = ImmutableList.builder();
        ImmutableList.Builder<Object> values = ImmutableList.builder();

        for (Entry<RaptorColumnHandle, Domain> entry : tupleDomain.getDomains().get().entrySet()) {
            Domain domain = entry.getValue();
            if (domain.isNullAllowed() || domain.isAll()) {
                continue;
            }
            RaptorColumnHandle handle = entry.getKey();
            Type type = handle.getColumnType();

            JDBCType jdbcType = jdbcType(type);
            if (jdbcType == null) {
                continue;
            }

            if (handle.isShardUuid()) {
                predicate.add(createShardPredicate(types, values, domain, jdbcType));
                continue;
            }

            if (!domain.getType().isOrderable()) {
                continue;
            }

            StringJoiner columnPredicate = new StringJoiner(" OR ", "(", ")").setEmptyValue("true");
            Ranges ranges = domain.getValues().getRanges();

            // prevent generating complicated metadata queries
            if (ranges.getRangeCount() > MAX_RANGE_COUNT) {
                continue;
            }

            for (Range range : ranges.getOrderedRanges()) {
                Object minValue = null;
                Object maxValue = null;
                if (range.isSingleValue()) {
                    minValue = range.getSingleValue();
                    maxValue = range.getSingleValue();
                }
                else {
                    if (!range.getLow().isLowerUnbounded()) {
                        minValue = range.getLow().getValue();
                    }
                    if (!range.getHigh().isUpperUnbounded()) {
                        maxValue = range.getHigh().getValue();
                    }
                }

                String min;
                String max;
                if (handle.isBucketNumber()) {
                    min = "bucket_number";
                    max = "bucket_number";
                }
                else {
                    min = minColumn(handle.getColumnId());
                    max = maxColumn(handle.getColumnId());
                }

                StringJoiner rangePredicate = new StringJoiner(" AND ", "(", ")").setEmptyValue("true");
                if (minValue != null) {
                    rangePredicate.add(format("(%s >= ? OR %s IS NULL)", max, max));
                    types.add(jdbcType);
                    values.add(minValue);
                }
                if (maxValue != null) {
                    rangePredicate.add(format("(%s <= ? OR %s IS NULL)", min, min));
                    types.add(jdbcType);
                    values.add(maxValue);
                }
                columnPredicate.add(rangePredicate.toString());
            }
            predicate.add(columnPredicate.toString());
        }
        return new ShardPredicate(predicate.toString(), types.build(), values.build());
    }