mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 09:22:49 -05:00
feat(redshift): load empty fields of non-character columns as NULL in COPY (#7324)
This commit is contained in:
1 parent
d4eeada135
commit
432fa4177e
5 files changed
+111
-13
No files matched your search
+8
-3
@@ -22,7 +22,7 @@ final class CopyRecordTransformer {
|
||||
|
||||
/** What a COPY column holds, as far as the date and time formats are concerned. */
|
||||
enum ColumnKind {
|
||||
DATE, TIMESTAMP, TEXT, OTHER
|
||||
DATE, TIMESTAMP, TEXT, CHAR, OTHER
|
||||
}
|
||||
|
||||
private record Field(int tokenEnd, byte[] value, boolean quoted) {
|
||||
@@ -221,8 +221,13 @@ final class CopyRecordTransformer {
|
||||
|
||||
private void writeField(Field field, int column, ByteArrayOutputStream out) {
|
||||
byte[] value = field.value();
|
||||
boolean emptyField = !field.quoted() && value.length == 0;
|
||||
boolean nonCharacter = columnKinds != null && column < columnKinds.size()
|
||||
&& columnKinds.get(column) != ColumnKind.TEXT
|
||||
&& columnKinds.get(column) != ColumnKind.CHAR;
|
||||
boolean nulled = (transforms.blanksAsNull() && isBlank(value))
|
||||
|| (transforms.emptyAsNull() && value.length == 0);
|
||||
|| (transforms.emptyAsNull() && value.length == 0)
|
||||
|| (emptyField && nonCharacter);
|
||||
if (nulled) {
|
||||
out.writeBytes(nullMarker);
|
||||
return;
|
||||
@@ -297,7 +302,7 @@ final class CopyRecordTransformer {
|
||||
CopyTemporalFormat format = switch (kind) {
|
||||
case DATE -> transforms.dateFormat();
|
||||
case TIMESTAMP -> transforms.timeFormat();
|
||||
case TEXT, OTHER -> null;
|
||||
case TEXT, CHAR, OTHER -> null;
|
||||
};
|
||||
if (format == null || !format.converts()) {
|
||||
return value;
|
||||
|
||||
+5
-1
@@ -646,7 +646,8 @@ public final class S3CopySimulator {
|
||||
|
||||
/**
|
||||
* 1082 = date, 1114 = timestamp, and 25 = text, 1043 = varchar for the character columns.
|
||||
* CHAR (1042 = bpchar) is left as OTHER so missing columns load as NULL, matching AWS FILLRECORD.
|
||||
* 1042 = bpchar (CHAR) has its own kind so missing columns load as NULL under FILLRECORD
|
||||
* while present empty fields remain character strings.
|
||||
* A timestamptz (1184) is read by PostgreSQL as it stands.
|
||||
*/
|
||||
static CopyRecordTransformer.ColumnKind kindOf(String typeOid) {
|
||||
@@ -659,6 +660,9 @@ public final class S3CopySimulator {
|
||||
if ("25".equals(typeOid) || "1043".equals(typeOid)) {
|
||||
return CopyRecordTransformer.ColumnKind.TEXT;
|
||||
}
|
||||
if ("1042".equals(typeOid)) {
|
||||
return CopyRecordTransformer.ColumnKind.CHAR;
|
||||
}
|
||||
return CopyRecordTransformer.ColumnKind.OTHER;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user