clickhouse-java icon indicating copy to clipboard operation
clickhouse-java copied to clipboard

Param 'format_csv_null_representation' did not work when export data to csv file

Open Ryze0827 opened this issue 1 year ago • 0 comments

Describe the bug

When I use clickhouse java client to do some export work, I noticed that some column's value was null, but export to csv with value '\N'. I check the docs[https://clickhouse.com/docs/en/operations/settings/formats#format_csv_null_representation], and use it in my code, and the csv file still show the '\N' but 'NA'

Steps to reproduce

  1. Invoke the 'ClickHouseClient.dump()' method 2.Query result from sql console 【email Nullable(String)】 image 3.Export to csv file, and view it image

Expected behaviour

when email's value is null, export 'NA' but default value '\N'

Code example

public static void exportDataToCsvFile(String tableOrQuery, String filePath) throws ExecutionException, InterruptedException {
        ClickHouseClient
                .dump(readServer, tableOrQuery, ClickHouseFormat.CSVWithNames, ClickHouseCompression.fromFileName(filePath), filePath)
                .get();
    }

/**
 * add custom settings: format_csv_null_representation
*/
private static ClickHouseNode createReadServer() {
        return ClickHouseNode.builder(commonServer)
                    .addOption(ClickHouseClientOption.CUSTOM_SETTINGS.getKey(), "format_csv_null_representation=NA")
                    .build();
    }

Error log

Configuration

Environment

  • Client version: 0.4.0
  • Language version: jdk8

ClickHouse server

  • ClickHouse Server version: 23.6.1.1524

Ryze0827 avatar Jul 08 '24 08:07 Ryze0827