|
18 | 18 |
|
19 | 19 | package org.apache.flink.formats.csv;
|
20 | 20 |
|
| 21 | +import org.apache.flink.table.api.config.ExecutionConfigOptions; |
21 | 22 | import org.apache.flink.table.planner.runtime.batch.sql.BatchFileSystemITCaseBase;
|
| 23 | +import org.apache.flink.table.planner.runtime.utils.BatchTestBase; |
22 | 24 | import org.apache.flink.types.Row;
|
| 25 | +import org.apache.flink.util.CollectionUtil; |
23 | 26 | import org.apache.flink.util.FileUtils;
|
24 | 27 |
|
| 28 | +import org.junit.Assert; |
25 | 29 | import org.junit.Test;
|
26 | 30 | import org.junit.experimental.runners.Enclosed;
|
27 | 31 | import org.junit.runner.RunWith;
|
@@ -90,4 +94,70 @@ public void testEscapeChar() throws Exception {
|
90 | 94 | Arrays.asList(Row.of("x5,5,1,1"), Row.of("x5,5,2,2")));
|
91 | 95 | }
|
92 | 96 | }
|
| 97 | + |
| 98 | + /** |
| 99 | + * IT case which checks for a bug in Jackson 2.10. When the 4000th character in csv file is the |
| 100 | + * new line character (\n) an exception will be thrown. After upgrading jackson to >= 2.11 this |
| 101 | + * bug should not exist anymore. |
| 102 | + */ |
| 103 | + public static class JacksonVersionUpgradeITCase extends BatchTestBase { |
| 104 | + |
| 105 | + @Test |
| 106 | + public void testCsvFileWithNewLineAt4000() throws Exception { |
| 107 | + StringBuilder csvContent = new StringBuilder("# "); |
| 108 | + for (int i = 0; i < 97; i++) { |
| 109 | + csvContent.append("-"); |
| 110 | + } |
| 111 | + csvContent.append("\n"); |
| 112 | + for (int i = 0; i < 50; i++) { |
| 113 | + for (int j = 0; j < 49; j++) { |
| 114 | + csvContent.append("a"); |
| 115 | + } |
| 116 | + csvContent.append(","); |
| 117 | + for (int j = 0; j < 49; j++) { |
| 118 | + csvContent.append("b"); |
| 119 | + } |
| 120 | + csvContent.append("\n"); |
| 121 | + } |
| 122 | + |
| 123 | + File tempCsvFile = File.createTempFile("new-line-at-4000", ".csv"); |
| 124 | + tempCsvFile.createNewFile(); |
| 125 | + FileUtils.writeFileUtf8(tempCsvFile, csvContent.toString()); |
| 126 | + |
| 127 | + tEnv().getConfig() |
| 128 | + .getConfiguration() |
| 129 | + .setInteger(ExecutionConfigOptions.TABLE_EXEC_RESOURCE_DEFAULT_PARALLELISM, 1); |
| 130 | + tEnv().executeSql( |
| 131 | + "CREATE TABLE T (\n" |
| 132 | + + " a VARCHAR,\n" |
| 133 | + + " b VARCHAR\n" |
| 134 | + + ") WITH (\n" |
| 135 | + + " 'connector' = 'filesystem',\n" |
| 136 | + + " 'path' = 'file://" |
| 137 | + + tempCsvFile.toString() |
| 138 | + + "',\n" |
| 139 | + + " 'format' = 'csv',\n" |
| 140 | + + " 'csv.allow-comments' = 'true'\n" |
| 141 | + + ")") |
| 142 | + .await(); |
| 143 | + List<Row> results = |
| 144 | + CollectionUtil.iteratorToList( |
| 145 | + tEnv().executeSql("SELECT a, b FROM T").collect()); |
| 146 | + |
| 147 | + Assert.assertEquals(50, results.size()); |
| 148 | + for (Row actual : results) { |
| 149 | + StringBuilder a = new StringBuilder(); |
| 150 | + for (int i = 0; i < 49; i++) { |
| 151 | + a.append("a"); |
| 152 | + } |
| 153 | + StringBuilder b = new StringBuilder(); |
| 154 | + for (int i = 0; i < 49; i++) { |
| 155 | + b.append("b"); |
| 156 | + } |
| 157 | + Assert.assertEquals(2, actual.getArity()); |
| 158 | + Assert.assertEquals(a.toString(), actual.getField(0)); |
| 159 | + Assert.assertEquals(b.toString(), actual.getField(1)); |
| 160 | + } |
| 161 | + } |
| 162 | + } |
93 | 163 | }
|
0 commit comments