-
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 7 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
17.0.9 | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
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. Same as above: Remove file from GitHub and add the filename to .gitignore 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. |
||
"java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx2G -Xms100m -Xlog:disable", | ||
"java.compile.nullAnalysis.mode": "automatic" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,6 +192,63 @@ | |
<className>com/google/cloud/spanner/StructReader</className> | ||
<method>java.util.List getPgJsonbList(java.lang.String)</method> | ||
</difference> | ||
<!-- PG OID --> | ||
<difference> | ||
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. 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. These entries in 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. 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. 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 |
||
<differenceType>7013</differenceType> | ||
<className>com/google/cloud/spanner/AbstractStructReader</className> | ||
<method>long[] getPgOidArrayInternal(int)</method> | ||
</difference> | ||
<difference> | ||
<differenceType>7013</differenceType> | ||
<className>com/google/cloud/spanner/AbstractStructReader</className> | ||
<method>long getPgOidInternal(int)</method> | ||
</difference> | ||
<difference> | ||
<differenceType>7013</differenceType> | ||
<className>com/google/cloud/spanner/AbstractStructReader</className> | ||
<method>java.util.List getPgOidListInternal(int)</method> | ||
</difference> | ||
<difference> | ||
<differenceType>7012</differenceType> | ||
<className>com/google/cloud/spanner/StructReader</className> | ||
<method>long getPgOid(int)</method> | ||
</difference> | ||
<difference> | ||
<differenceType>7012</differenceType> | ||
<className>com/google/cloud/spanner/StructReader</className> | ||
<method>long getPgOid(java.lang.String)</method> | ||
</difference> | ||
<difference> | ||
<differenceType>7012</differenceType> | ||
<className>com/google/cloud/spanner/StructReader</className> | ||
<method>long[] getPgOidArray(int)</method> | ||
</difference> | ||
<difference> | ||
<differenceType>7012</differenceType> | ||
<className>com/google/cloud/spanner/StructReader</className> | ||
<method>long[] getPgOidArray(java.lang.String)</method> | ||
</difference> | ||
<difference> | ||
<differenceType>7012</differenceType> | ||
<className>com/google/cloud/spanner/StructReader</className> | ||
<method>java.util.List getPgOidList(int)</method> | ||
</difference> | ||
<difference> | ||
<differenceType>7012</differenceType> | ||
<className>com/google/cloud/spanner/StructReader</className> | ||
<method>java.util.List getPgOidList(java.lang.String)</method> | ||
</difference> | ||
<difference> | ||
<differenceType>7013</differenceType> | ||
<className>com/google/cloud/spanner/Value</className> | ||
<method>long getPgOid()</method> | ||
</difference> | ||
<difference> | ||
<differenceType>7013</differenceType> | ||
<className>com/google/cloud/spanner/Value</className> | ||
<method>java.util.List getPgOidArray()</method> | ||
</difference> | ||
|
||
<difference> | ||
<differenceType>7012</differenceType> | ||
<className>com/google/cloud/spanner/StructReader</className> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,8 @@ protected String getPgJsonbInternal(int columnIndex) { | |
throw new UnsupportedOperationException("Not implemented"); | ||
} | ||
|
||
protected abstract 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. Add a default implementation for this and the other methods that are being added to this class. The default implementation should just throw UnsupportedOperationException. This prevents this change from being a breaking change, as anyone who has a class that extends AbstractStructReader does not get a compile error. That should also remove the requirement to add the method names to clirr-ignored-differences.xml 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. |
||
|
||
protected abstract ByteArray getBytesInternal(int columnIndex); | ||
|
||
protected abstract Timestamp getTimestampInternal(int columnIndex); | ||
|
@@ -122,6 +124,10 @@ protected List<String> getPgJsonbListInternal(int columnIndex) { | |
throw new UnsupportedOperationException("Not implemented"); | ||
} | ||
|
||
protected abstract long[] getPgOidArrayInternal(int columnIndex); | ||
|
||
protected abstract List<Long> getPgOidListInternal(int columnIndex); | ||
|
||
protected abstract List<ByteArray> getBytesListInternal(int columnIndex); | ||
|
||
protected abstract List<Timestamp> getTimestampListInternal(int columnIndex); | ||
|
@@ -259,6 +265,19 @@ public String getPgJsonb(String columnName) { | |
return getPgJsonbInternal(columnIndex); | ||
} | ||
|
||
@Override | ||
public long getPgOid(int columnIndex) { | ||
checkNonNullOfType(columnIndex, Type.pgOid(), columnIndex); | ||
return getPgOidInternal(columnIndex); | ||
} | ||
|
||
@Override | ||
public long getPgOid(String columnName) { | ||
int columnIndex = getColumnIndex(columnName); | ||
checkNonNullOfType(columnIndex, Type.pgOid(), columnName); | ||
return 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. Would it be worth considering not adding any of this at all, and instead instruct users that they have to get PG.OID values in the same way as INT64? So just call getLong(..) and the other corresponding methods. This is otherwise all just a copy-paste of those methods, and there's no additional validation of the values that we are getting. @skuruppu Any thoughts on this? 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. |
||
|
||
@Override | ||
public ByteArray getBytes(int columnIndex) { | ||
checkNonNullOfCodes(columnIndex, Arrays.asList(Code.PROTO, Code.BYTES), columnIndex); | ||
|
@@ -505,6 +524,32 @@ public List<String> getPgJsonbList(String columnName) { | |
return getPgJsonbListInternal(columnIndex); | ||
} | ||
|
||
@Override | ||
public long[] getPgOidArray(int columnIndex) { | ||
checkNonNullOfType(columnIndex, Type.array(Type.pgOid()), columnIndex); | ||
return getPgOidArrayInternal(columnIndex); | ||
} | ||
|
||
@Override | ||
public long[] getPgOidArray(String columnName) { | ||
int columnIndex = getColumnIndex(columnName); | ||
checkNonNullOfType(columnIndex, Type.array(Type.pgOid()), columnName); | ||
return getPgOidArrayInternal(columnIndex); | ||
} | ||
|
||
@Override | ||
public List<Long> getPgOidList(int columnIndex) { | ||
checkNonNullOfType(columnIndex, Type.array(Type.pgOid()), columnIndex); | ||
return getPgOidListInternal(columnIndex); | ||
} | ||
|
||
@Override | ||
public List<Long> getPgOidList(String columnName) { | ||
int columnIndex = getColumnIndex(columnName); | ||
checkNonNullOfType(columnIndex, Type.array(Type.pgOid()), columnName); | ||
return getPgOidListInternal(columnIndex); | ||
} | ||
|
||
@Override | ||
public List<ByteArray> getBytesList(int columnIndex) { | ||
checkNonNullOfCodes(columnIndex, Collections.singletonList(Code.ARRAY), columnIndex); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
import com.google.cloud.spanner.AbstractResultSet.Float64Array; | ||
import com.google.cloud.spanner.AbstractResultSet.Int64Array; | ||
import com.google.cloud.spanner.AbstractResultSet.LazyByteArray; | ||
import com.google.cloud.spanner.AbstractResultSet.PgOidArray; | ||
import com.google.cloud.spanner.Type.Code; | ||
import com.google.cloud.spanner.Type.StructField; | ||
import com.google.common.base.Preconditions; | ||
|
@@ -114,6 +115,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 +162,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 +269,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()); | ||
|
@@ -339,6 +347,8 @@ static Object decodeArrayValue(Type elementType, ListValue listValue) { | |
case STRUCT: | ||
case PROTO: | ||
return Lists.transform(listValue.getValuesList(), input -> decodeValue(elementType, input)); | ||
case PG_OID: | ||
return new PgOidArray(listValue); | ||
default: | ||
throw new AssertionError("Unhandled type code: " + elementType.getCode()); | ||
} | ||
|
@@ -460,6 +470,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 +579,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 : getPgOidInternal(columnIndex)); | ||
case BYTES: | ||
return Value.internalBytes(isNull ? null : getLazyBytesInternal(columnIndex)); | ||
case PROTO: | ||
|
@@ -598,6 +616,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 : getPgOidListInternal(columnIndex)); | ||
case BYTES: | ||
return Value.bytesArray(isNull ? null : getBytesListInternal(columnIndex)); | ||
case PROTO: | ||
|
@@ -771,6 +791,18 @@ protected List<String> getPgJsonbListInternal(int columnIndex) { | |
return Collections.unmodifiableList((List<String>) rowData.get(columnIndex)); | ||
} | ||
|
||
@Override | ||
protected PgOidArray getPgOidListInternal(int columnIndex) { | ||
ensureDecoded(columnIndex); | ||
return (PgOidArray) 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.
Remove this file (and potentially add the file name to .gitignore to prevent it from being included in commits in the future)
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.