[ https://issues.apache.org/jira/browse/FLINK-4506?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15529220#comment-15529220 ]
ASF GitHub Bot commented on FLINK-4506: --------------------------------------- Github user zentol commented on a diff in the pull request: https://github.com/apache/flink/pull/2477#discussion_r80887299 --- Diff: flink-java/src/test/java/org/apache/flink/api/java/io/CsvOutputFormatTest.java --- @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.api.java.io; + +import org.apache.commons.io.IOUtils; +import org.apache.flink.api.common.io.FileOutputFormat; +import org.apache.flink.api.java.tuple.Tuple3; +import org.apache.flink.core.fs.FSDataInputStream; +import org.apache.flink.core.fs.FileSystem; +import org.apache.flink.core.fs.Path; +import org.junit.Assert; +import org.junit.Test; + +import java.nio.charset.StandardCharsets; + +public class CsvOutputFormatTest { + + private static final Path PATH = new Path("csv_output_test_file.csv"); + + @Test + public void testNullAllow() throws Exception { + CsvOutputFormat<Tuple3<String, String, Integer>> csvOutputFormat = new CsvOutputFormat<Tuple3<String, String, Integer>>(PATH); + csvOutputFormat.setWriteMode(FileSystem.WriteMode.OVERWRITE); + csvOutputFormat.setOutputDirectoryMode(FileOutputFormat.OutputDirectoryMode.PARONLY); + csvOutputFormat.setAllowNullValues(true); + csvOutputFormat.open(0, 1); + csvOutputFormat.writeRecord(new Tuple3<String, String, Integer>("One", null, 8)); + csvOutputFormat.close(); + final FileSystem fs = PATH.getFileSystem(); + Assert.assertTrue(fs.exists(PATH)); + FSDataInputStream inputStream = fs.open(PATH); + String csvContent = IOUtils.toString(inputStream, StandardCharsets.UTF_8); + Assert.assertEquals("One,,8\n", csvContent); + fs.delete(PATH, true); + } + + @Test(expected = RuntimeException.class) + public void testNullDisallowOnDefault() throws Exception { + CsvOutputFormat<Tuple3<String, String, Integer>> csvOutputFormat = new CsvOutputFormat<Tuple3<String, String, Integer>>(PATH); + csvOutputFormat.setWriteMode(FileSystem.WriteMode.OVERWRITE); + csvOutputFormat.setOutputDirectoryMode(FileOutputFormat.OutputDirectoryMode.PARONLY); + csvOutputFormat.open(0, 1); + csvOutputFormat.writeRecord(new Tuple3<String, String, Integer>("One", null, 8)); + csvOutputFormat.close(); --- End diff -- The temporary file is created within `open()` and will not be cleaned up. > CsvOutputFormat defaults allowNullValues to false, even though doc and > declaration says true > -------------------------------------------------------------------------------------------- > > Key: FLINK-4506 > URL: https://issues.apache.org/jira/browse/FLINK-4506 > Project: Flink > Issue Type: Bug > Components: Batch Connectors and Input/Output Formats, Documentation > Reporter: Michael Wong > Assignee: Kirill Morozov > Priority: Minor > > In the constructor, it has this > {code} > this.allowNullValues = false; > {code} > But in the setAllowNullValues() method, the doc says the allowNullValues is > true by default. Also, in the declaration of allowNullValues, the value is > set to true. It probably makes the most sense to change the constructor. > {code} > /** > * Configures the format to either allow null values (writing an empty > field), > * or to throw an exception when encountering a null field. > * <p> > * by default, null values are allowed. > * > * @param allowNulls Flag to indicate whether the output format should > accept null values. > */ > public void setAllowNullValues(boolean allowNulls) { > this.allowNullValues = allowNulls; > } > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)