-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add PG OID support #2736
feat: add PG OID support #2736
Changes from 30 commits
6b3f572
929abf4
4e7ea9d
0489d9a
e5a39c5
537de96
f9ea807
4cb354a
e505b9e
0184554
1d756a3
f6193f9
aed1223
bf2361b
57edce9
d7ba42b
50e2887
6258293
d94922f
bd82e0c
a0a2e8d
eaa05da
8e4ee03
ebf8723
358e8d3
1e99310
039079e
b21e262
6f971a7
5df12ca
4b12761
60712bd
19fbdfb
f3f6113
8ac2a16
231273e
80ade2e
ecb87e7
7444b29
8a9584b
f103f18
a8531fd
e74319c
248744b
629fb32
b72581c
d05695b
417a83c
2d6f4f3
d2b4862
b8074b5
cdd1c91
b63740d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,5 @@ docs/ | |
*.pyc | ||
|
||
.flattened-pom.xml | ||
.java-version | ||
.vscode/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,10 @@ protected String getPgJsonbInternal(int columnIndex) { | |
throw new UnsupportedOperationException("Not implemented"); | ||
} | ||
|
||
protected long getPgOidInternal(int columnIndex) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that you can remove this method (and the equivalent array methods below) as well, and instead just use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
throw new UnsupportedOperationException("Not implemented"); | ||
} | ||
|
||
protected abstract ByteArray getBytesInternal(int columnIndex); | ||
|
||
protected abstract Timestamp getTimestampInternal(int columnIndex); | ||
|
@@ -122,6 +126,14 @@ protected List<String> getPgJsonbListInternal(int columnIndex) { | |
throw new UnsupportedOperationException("Not implemented"); | ||
} | ||
|
||
protected long[] getPgOidArrayInternal(int columnIndex) { | ||
throw new UnsupportedOperationException("Not implemented"); | ||
} | ||
|
||
protected List<Long> getPgOidListInternal(int columnIndex) { | ||
throw new UnsupportedOperationException("Not implemented"); | ||
} | ||
|
||
protected abstract List<ByteArray> getBytesListInternal(int columnIndex); | ||
|
||
protected abstract List<Timestamp> getTimestampListInternal(int columnIndex); | ||
|
@@ -165,15 +177,20 @@ public boolean getBoolean(String columnName) { | |
|
||
@Override | ||
public long getLong(int columnIndex) { | ||
checkNonNullOfCodes(columnIndex, Arrays.asList(Code.ENUM, Code.INT64), columnIndex); | ||
return getLongInternal(columnIndex); | ||
checkNonNullOfCodes( | ||
columnIndex, Arrays.asList(Code.ENUM, Code.PG_OID, Code.INT64), columnIndex); | ||
return getColumnType(columnIndex).getCode() == Code.PG_OID | ||
? getPgOidInternal(columnIndex) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that this can be simplified to just calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
: getLongInternal(columnIndex); | ||
} | ||
|
||
@Override | ||
public long getLong(String columnName) { | ||
int columnIndex = getColumnIndex(columnName); | ||
checkNonNullOfCodes(columnIndex, Arrays.asList(Code.ENUM, Code.INT64), columnName); | ||
return getLongInternal(columnIndex); | ||
checkNonNullOfCodes(columnIndex, Arrays.asList(Code.ENUM, Code.PG_OID, Code.INT64), columnName); | ||
return getColumnType(columnIndex).getCode() == Code.PG_OID | ||
? getPgOidInternal(columnIndex) | ||
: getLongInternal(columnIndex); | ||
} | ||
|
||
@Override | ||
|
@@ -366,31 +383,43 @@ public List<Boolean> getBooleanList(String columnName) { | |
@Override | ||
public long[] getLongArray(int columnIndex) { | ||
checkNonNullOfCodes(columnIndex, Collections.singletonList(Code.ARRAY), columnIndex); | ||
checkArrayElementType(columnIndex, Arrays.asList(Code.ENUM, Code.INT64), columnIndex); | ||
return getLongArrayInternal(columnIndex); | ||
checkArrayElementType( | ||
columnIndex, Arrays.asList(Code.ENUM, Code.PG_OID, Code.INT64), columnIndex); | ||
return getColumnType(columnIndex).getArrayElementType().getCode() == Code.PG_OID | ||
? getPgOidArrayInternal(columnIndex) | ||
: getLongArrayInternal(columnIndex); | ||
} | ||
|
||
@Override | ||
public long[] getLongArray(String columnName) { | ||
int columnIndex = getColumnIndex(columnName); | ||
checkNonNullOfCodes(columnIndex, Collections.singletonList(Code.ARRAY), columnName); | ||
checkArrayElementType(columnIndex, Arrays.asList(Code.ENUM, Code.INT64), columnName); | ||
return getLongArrayInternal(columnIndex); | ||
checkArrayElementType( | ||
columnIndex, Arrays.asList(Code.ENUM, Code.PG_OID, Code.INT64), columnName); | ||
return getColumnType(columnIndex).getArrayElementType().getCode() == Code.PG_OID | ||
? getPgOidArrayInternal(columnIndex) | ||
: getLongArrayInternal(columnIndex); | ||
} | ||
|
||
@Override | ||
public List<Long> getLongList(int columnIndex) { | ||
checkNonNullOfCodes(columnIndex, Collections.singletonList(Code.ARRAY), columnIndex); | ||
checkArrayElementType(columnIndex, Arrays.asList(Code.ENUM, Code.INT64), columnIndex); | ||
return getLongListInternal(columnIndex); | ||
checkArrayElementType( | ||
columnIndex, Arrays.asList(Code.ENUM, Code.PG_OID, Code.INT64), columnIndex); | ||
return getColumnType(columnIndex).getArrayElementType().getCode() == Code.PG_OID | ||
? getPgOidListInternal(columnIndex) | ||
: getLongListInternal(columnIndex); | ||
} | ||
|
||
@Override | ||
public List<Long> getLongList(String columnName) { | ||
int columnIndex = getColumnIndex(columnName); | ||
checkNonNullOfCodes(columnIndex, Collections.singletonList(Code.ARRAY), columnName); | ||
checkArrayElementType(columnIndex, Arrays.asList(Code.ENUM, Code.INT64), columnName); | ||
return getLongListInternal(columnIndex); | ||
checkArrayElementType( | ||
columnIndex, Arrays.asList(Code.ENUM, Code.PG_OID, Code.INT64), columnName); | ||
return getColumnType(columnIndex).getArrayElementType().getCode() == Code.PG_OID | ||
? getPgOidListInternal(columnIndex) | ||
: getLongListInternal(columnIndex); | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,6 +114,9 @@ private Object writeReplace() { | |
case PG_JSONB: | ||
builder.set(fieldName).to(Value.pgJsonb((String) value)); | ||
break; | ||
case PG_OID: | ||
builder.set(fieldName).to(Value.pgOid((Long) value)); | ||
break; | ||
case BYTES: | ||
builder | ||
.set(fieldName) | ||
|
@@ -158,6 +161,9 @@ private Object writeReplace() { | |
case PG_JSONB: | ||
builder.set(fieldName).toPgJsonbArray((Iterable<String>) value); | ||
break; | ||
case PG_OID: | ||
builder.set(fieldName).toPgOidArray((Iterable<Long>) value); | ||
break; | ||
case BYTES: | ||
case PROTO: | ||
builder | ||
|
@@ -262,6 +268,7 @@ private static Object decodeValue(Type fieldType, com.google.protobuf.Value prot | |
checkType(fieldType, proto, KindCase.BOOL_VALUE); | ||
return proto.getBoolValue(); | ||
case INT64: | ||
case PG_OID: | ||
case ENUM: | ||
checkType(fieldType, proto, KindCase.STRING_VALUE); | ||
return Long.parseLong(proto.getStringValue()); | ||
|
@@ -319,6 +326,7 @@ private static Struct decodeStructValue(Type structType, ListValue structValue) | |
static Object decodeArrayValue(Type elementType, ListValue listValue) { | ||
switch (elementType.getCode()) { | ||
case INT64: | ||
case PG_OID: | ||
case ENUM: | ||
// For int64/float64/float32/enum types, use custom containers. | ||
// These avoid wrapper object creation for non-null arrays. | ||
|
@@ -460,6 +468,12 @@ protected String getPgJsonbInternal(int columnIndex) { | |
return (String) rowData.get(columnIndex); | ||
} | ||
|
||
@Override | ||
protected long getPgOidInternal(int columnIndex) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove and rely on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
ensureDecoded(columnIndex); | ||
return (Long) rowData.get(columnIndex); | ||
} | ||
|
||
@Override | ||
protected ByteArray getBytesInternal(int columnIndex) { | ||
ensureDecoded(columnIndex); | ||
|
@@ -563,6 +577,8 @@ protected Value getValueInternal(int columnIndex) { | |
return Value.json(isNull ? null : getJsonInternal(columnIndex)); | ||
case PG_JSONB: | ||
return Value.pgJsonb(isNull ? null : getPgJsonbInternal(columnIndex)); | ||
case PG_OID: | ||
return Value.pgOid(isNull ? null : getLongInternal(columnIndex)); | ||
case BYTES: | ||
return Value.internalBytes(isNull ? null : getLazyBytesInternal(columnIndex)); | ||
case PROTO: | ||
|
@@ -598,6 +614,8 @@ protected Value getValueInternal(int columnIndex) { | |
return Value.jsonArray(isNull ? null : getJsonListInternal(columnIndex)); | ||
case PG_JSONB: | ||
return Value.pgJsonbArray(isNull ? null : getPgJsonbListInternal(columnIndex)); | ||
case PG_OID: | ||
return Value.pgOidArray(isNull ? null : getLongListInternal(columnIndex)); | ||
case BYTES: | ||
return Value.bytesArray(isNull ? null : getBytesListInternal(columnIndex)); | ||
case PROTO: | ||
|
@@ -771,6 +789,18 @@ protected List<String> getPgJsonbListInternal(int columnIndex) { | |
return Collections.unmodifiableList((List<String>) rowData.get(columnIndex)); | ||
} | ||
|
||
@Override | ||
protected Int64Array getPgOidListInternal(int columnIndex) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove and use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
ensureDecoded(columnIndex); | ||
return (Int64Array) rowData.get(columnIndex); | ||
} | ||
|
||
@Override | ||
protected long[] getPgOidArrayInternal(int columnIndex) { | ||
ensureDecoded(columnIndex); | ||
return getPgOidListInternal(columnIndex).toPrimitiveArray(columnIndex); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") // We know ARRAY<BYTES> produces a List<LazyByteArray>. | ||
protected List<ByteArray> getBytesListInternal(int columnIndex) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should not be necessary to add the internal methods to this file, if those methods are given a default implementation that just throws UnsupportedOperationException
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These entries in
clirr-ignored-differences.xml
forStructReader
can be removed, as we don't have those methods anymore.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final nit (I promise :-)): I think that the two remaining additions to this file for getPgOid() and getPgOidArray() can also be removed, as these methods are no longer added to the
Value
class.