fix(redshift): skip the header of every object in a COPY (#7266)

This commit is contained in:
Vũ Thế Huy authored and GitHub committed 2026-11-02 08:30:02 -04:00
1 parent 261072bf8a
commit b92340b243
3 files changed
+23 -5

No files matched your search

+1 -1
View File
@@ -766,7 +766,7 @@ order) through its own S3 service and streams the rows into the backing PostgreS
compatible with output from `UNLOAD ... MANIFEST`. Missing files marked `mandatory: true` abort the load.
When `mandatory` is omitted, it defaults to `false`. All entries in the manifest must reside in the same S3
bucket as the manifest file itself; cross-bucket manifest entries are rejected as an intentional deviation.
- `IGNOREHEADER` and `HEADER` skip lines from the first resolved object only.
- `IGNOREHEADER` and `HEADER` skip lines from the start of every resolved object, as AWS does for a parallel load of several files.
- `GZIP` is the only input compression recognized; `BZIP2`, `LZOP` and `ZSTD` are not.
- `IAM_ROLE '<role-arn>'` is supported. The role must be associated with the cluster (at
`CreateCluster` or through `ModifyClusterIamRoles`; connections opened before a change keep the
@@ -519,7 +519,8 @@ public final class S3CopySimulator {
JsonLinesToCsvConverter.convert(in, targetCols, copyDataOut, spec.jsonAutoIgnoreCase());
copyDataOut.flush();
} else {
if (i == 0 && spec.headerLines() > 0) {
// Every object has its own header, as in a parallel load of several files.
if (spec.headerLines() > 0) {
skipLines(in, spec.headerLines());
}
InputStream source = in;
@@ -1218,17 +1218,17 @@ class S3CopySimulatorTest {
}
@Test
void concatenatesPrefixObjectsInKeyOrderAndSkipsHeaderOnFirstOnly() throws Exception {
void concatenatesPrefixObjectsInKeyOrderAndSkipsTheHeaderOfEachObject() throws Exception {
when(s3.objectExists("wh", "p/")).thenReturn(false);
when(s3.listObjectsWithPrefixes(eq("wh"), eq("p/"), isNull(), anyInt(), any(), any())).thenReturn(
new S3Service.ListObjectsResult(List.of(
new S3Object("wh", "p/1", "h1|h2\n1|a\n".getBytes(StandardCharsets.US_ASCII), "text/plain"),
new S3Object("wh", "p/2", "2|b\n".getBytes(StandardCharsets.US_ASCII), "text/plain")),
new S3Object("wh", "p/2", "h1|h2\n2|b\n".getBytes(StandardCharsets.US_ASCII), "text/plain")),
List.of(), false, null));
when(s3.getObject("wh", "p/1")).thenReturn(
new S3Object("wh", "p/1", "h1|h2\n1|a\n".getBytes(StandardCharsets.US_ASCII), "text/plain"));
when(s3.getObject("wh", "p/2")).thenReturn(
new S3Object("wh", "p/2", "2|b\n".getBytes(StandardCharsets.US_ASCII), "text/plain"));
new S3Object("wh", "p/2", "h1|h2\n2|b\n".getBytes(StandardCharsets.US_ASCII), "text/plain"));
CopyStatementParser.S3CopyFrom spec = new CopyStatementParser.S3CopyFrom(
"t", List.of(), "wh", "p/", "|", 1, false, false, null, null);
@@ -1596,6 +1596,23 @@ class S3CopySimulatorTest {
assertEquals("1|\\N\n2|\\N|x\n", copyDataPayload(out.toByteArray()));
}
@Test
void streamCopyInput_skipsTheHeaderOfEveryObject() throws Exception {
CopyStatementParser.S3CopyFrom spec = new CopyStatementParser.S3CopyFrom(
"people", List.of(), "wh", "p/", "|", 1, false, false, null, null);
when(s3.getObject("wh", "p/a.txt")).thenReturn(new S3Object("wh", "p/a.txt",
"id|name\n1|a\n".getBytes(StandardCharsets.UTF_8), "text/plain"));
when(s3.getObject("wh", "p/b.txt")).thenReturn(new S3Object("wh", "p/b.txt",
"id|name\n2|b\n".getBytes(StandardCharsets.UTF_8), "text/plain"));
S3CopySimulator.CopyInput input =
new S3CopySimulator.CopyInput(spec, List.of("p/a.txt", "p/b.txt"), s3, null, null);
ByteArrayOutputStream out = new ByteArrayOutputStream();
S3CopySimulator.streamCopyInput(input, out);
assertEquals("1|a\n2|b\n", copyDataPayload(out.toByteArray()));
}
@Test
void streamCopyInput_transformsAfterGzipDecodeAndHeaderSkip() throws Exception {
CopyStatementParser.CopyTransforms transforms =