@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 testToString() {
        final Schema schema = Schema.newBuilder().column("f0", DataTypes.STRING()).build();

        final FormatDescriptor formatDescriptor =
                FormatDescriptor.forFormat("test-format").option(OPTION_A, false).build();

        final TableDescriptor tableDescriptor =
                TableDescriptor.forConnector("test-connector")
                        .schema(schema)
                        .distributedByRange(3, "f0")
                        .partitionedBy("f0")
                        .option(OPTION_A, true)
                        .format(formatDescriptor)
                        .comment("Test Comment")
                        .build();

        assertThat(formatDescriptor.toString()).isEqualTo("test-format[{a=false}]");
        assertThat(tableDescriptor.toString())
                .isEqualTo(
                        "(\n"
                                + "  `f0` STRING\n"
                                + ")\n"
                                + "COMMENT 'Test Comment'\n"
                                + "DISTRIBUTED BY RANGE(`f0`) INTO 3 BUCKETS\n"
                                + "PARTITIONED BY (`f0`)\n"
                                + "WITH (\n"
                                + "  'a' = 'true',\n"
                                + "  'connector' = 'test-connector',\n"
                                + "  'test-format.a' = 'false',\n"
                                + "  'format' = 'test-format'\n"
                                + ")");
    }