@Override
    public String toString() {
        final String escapedPartitionKeys =
                partitionKeys.stream()
                        .map(EncodingUtils::escapeIdentifier)
                        .collect(Collectors.joining(", "));

        final String distributedBy = distribution == null ? "" : distribution.toString();

        final String partitionedBy =
                !partitionKeys.isEmpty()
                        ? String.format("PARTITIONED BY (%s)", escapedPartitionKeys)
                        : "";

        final String serializedOptions =
                options.entrySet().stream()
                        .map(
                                entry ->
                                        String.format(
                                                "  '%s' = '%s'",
                                                EncodingUtils.escapeSingleQuotes(entry.getKey()),
                                                EncodingUtils.escapeSingleQuotes(entry.getValue())))
                        .collect(Collectors.joining(String.format(",%n")));

        return String.format(
                "%s%nCOMMENT '%s'%n%s%s%nWITH (%n%s%n)",
                schema != null ? schema : "",
                comment != null ? comment : "",
                distributedBy,
                partitionedBy,
                serializedOptions);
    }
@Test
    void testDistributedBy() {
        assertThat(getTableDescriptorBuilder().distributedByHash(3, "f0").build().toString())
                .contains("DISTRIBUTED BY HASH(`f0`) INTO 3 BUCKETS\n");
        assertThat(getTableDescriptorBuilder().distributedByHash("f0").build().toString())
                .contains("DISTRIBUTED BY HASH(`f0`)\n");
        assertThat(getTableDescriptorBuilder().distributedByRange(3, "f0").build().toString())
                .contains("DISTRIBUTED BY RANGE(`f0`) INTO 3 BUCKETS\n");
        assertThat(getTableDescriptorBuilder().distributedByRange("f0").build().toString())
                .contains("DISTRIBUTED BY RANGE(`f0`)\n");
        assertThat(getTableDescriptorBuilder().distributedBy(3, "f0").build().toString())
                .contains("DISTRIBUTED BY (`f0`) INTO 3 BUCKETS\n");
        assertThat(getTableDescriptorBuilder().distributedBy("f0").build().toString())
                .contains("DISTRIBUTED BY (`f0`)\n");
        assertThat(getTableDescriptorBuilder().distributedInto(3).build().toString())
                .contains("DISTRIBUTED INTO 3 BUCKETS\n");
    }