Skip to content

feat: add PG OID support #2736

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

Merged
merged 53 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
6b3f572
feat: add PG OID support
tlhquynh Nov 20, 2023
929abf4
chore: fix lint errors
tlhquynh Nov 20, 2023
4e7ea9d
Resolved merge conflict from branch 'main' into pg-oid.
tlhquynh Dec 29, 2023
0489d9a
Merge branch 'main' into pg-oid
tlhquynh Mar 14, 2024
e5a39c5
Update PG.OID implementation according to recent changes.
tlhquynh Mar 18, 2024
537de96
Update PG.OID implementation according to recent changes.
tlhquynh Mar 18, 2024
f9ea807
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Mar 22, 2024
4cb354a
chore: keep session pool ordering when pinging (#2695)
olavloite Mar 15, 2024
e505b9e
deps: update dependency com.google.cloud:google-cloud-monitoring to v…
renovate-bot Mar 18, 2024
0184554
feat: allow attempt direct path xds via env var (#2950)
HailongWen Mar 19, 2024
1d756a3
build(deps): update dependency org.apache.maven.plugins:maven-compile…
renovate-bot Mar 19, 2024
f6193f9
build(deps): update dependency org.apache.maven.plugins:maven-assembl…
renovate-bot Mar 19, 2024
aed1223
deps: update dependency com.google.cloud:sdk-platform-java-config to …
renovate-bot Mar 19, 2024
bf2361b
refactor: move skip methods to abstract parser (#2948)
olavloite Mar 19, 2024
57edce9
fix: return type of max commit delay option. (#2953)
arpan14 Mar 19, 2024
d7ba42b
refactor: generalize skip methods (#2949)
olavloite Mar 19, 2024
50e2887
perf: keep comments when searching for params (#2951)
olavloite Mar 19, 2024
6258293
chore: randomize session pool order based on TPS (#2792)
olavloite Mar 19, 2024
d94922f
chore(main): release 6.62.0 (#2940)
release-please[bot] Mar 19, 2024
bd82e0c
chore(main): release 6.62.1-SNAPSHOT (#2957)
release-please[bot] Mar 19, 2024
a0a2e8d
chore(deps): update dependency com.google.cloud:google-cloud-spanner …
renovate-bot Mar 20, 2024
eaa05da
chore: add session pool options for multiplexed session. (#2960)
arpan14 Mar 22, 2024
8e4ee03
deps: update dependency com.google.cloud:google-cloud-trace to v2.38.…
renovate-bot Mar 24, 2024
ebf8723
chore: add new members in SessionImpl for multiplexed session. Add a …
arpan14 Mar 24, 2024
358e8d3
Update .gitignore to remove IDE specific files and remove unnecessary…
tlhquynh Mar 25, 2024
1e99310
Remove PG.OID external getters.
tlhquynh Mar 25, 2024
039079e
chore: generalise session pool class for multiplexed session. (#2964)
arpan14 Mar 25, 2024
b21e262
Merge branch 'main' into pg-oid
tlhquynh Mar 26, 2024
6f971a7
Merge branch 'main' into pg-oid
tlhquynh Mar 28, 2024
5df12ca
chore: emove unnecessary debug.
tlhquynh Mar 28, 2024
4b12761
chore: add multiplexed session implementations for CachedSession/Sess…
arpan14 Mar 28, 2024
60712bd
Remove internal PG.OID getters.
tlhquynh Apr 3, 2024
19fbdfb
deps: update dependency com.google.cloud:google-cloud-monitoring to v…
renovate-bot Mar 28, 2024
f3f6113
chore(main): release 6.62.1 (#2968)
release-please[bot] Mar 28, 2024
8ac2a16
chore(main): release 6.62.2-SNAPSHOT (#2983)
release-please[bot] Mar 28, 2024
231273e
feat: add support for transaction-level exclusion from change streams…
dengwe1 Mar 28, 2024
80ade2e
deps: update dependency com.google.cloud:google-cloud-trace to v2.39.…
renovate-bot Mar 29, 2024
ecb87e7
deps: update dependency commons-io:commons-io to v2.16.0 (#2986)
renovate-bot Mar 29, 2024
7444b29
deps: update dependency com.google.cloud:google-cloud-monitoring to v…
renovate-bot Mar 30, 2024
8a9584b
chore(deps): update dependency com.google.cloud:libraries-bom to v26.…
renovate-bot Mar 30, 2024
f103f18
chore(main): release 6.63.0 (#2985)
release-please[bot] Mar 30, 2024
a8531fd
chore(main): release 6.63.1-SNAPSHOT (#2991)
release-please[bot] Mar 30, 2024
e74319c
chore: clean up some warnings and malformed comments (#2977)
olavloite Apr 1, 2024
248744b
chore(deps): update dependency com.google.cloud:google-cloud-spanner …
renovate-bot Apr 1, 2024
629fb32
feat: add endpoint connection URL property (#2969)
olavloite Apr 2, 2024
b72581c
feat: support max_commit_delay in Connection API (#2954)
olavloite Apr 2, 2024
d05695b
chore: minor improvements to default benchmarks. (#2993)
arpan14 Apr 2, 2024
417a83c
build(deps): update dependency org.jacoco:jacoco-maven-plugin to v0.8…
renovate-bot Apr 3, 2024
2d6f4f3
chore: add regex to match unmanaged dependency check (#1941) (#2971)
gcf-owl-bot[bot] Apr 3, 2024
d2b4862
feat: Add SessionPoolOptions, SpannerOptions protos in executor proto…
gcf-owl-bot[bot] Apr 3, 2024
b8074b5
Merge branch 'main' into pg-oid
tlhquynh Apr 3, 2024
cdd1c91
Merge branch 'main' into pg-oid
tlhquynh Apr 4, 2024
b63740d
chore: Remove unused CLIRR entries
tlhquynh Apr 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ docs/
*.pyc

.flattened-pom.xml
.java-version
.vscode/
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,15 @@ public boolean getBoolean(String columnName) {

@Override
public long getLong(int columnIndex) {
checkNonNullOfCodes(columnIndex, Arrays.asList(Code.ENUM, Code.INT64), columnIndex);
checkNonNullOfCodes(
columnIndex, Arrays.asList(Code.ENUM, Code.PG_OID, Code.INT64), columnIndex);
return getLongInternal(columnIndex);
}

@Override
public long getLong(String columnName) {
int columnIndex = getColumnIndex(columnName);
checkNonNullOfCodes(columnIndex, Arrays.asList(Code.ENUM, Code.INT64), columnName);
checkNonNullOfCodes(columnIndex, Arrays.asList(Code.ENUM, Code.PG_OID, Code.INT64), columnName);
return getLongInternal(columnIndex);
}

Expand Down Expand Up @@ -366,30 +367,34 @@ 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);
checkArrayElementType(
columnIndex, Arrays.asList(Code.ENUM, Code.PG_OID, Code.INT64), columnIndex);
return 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);
checkArrayElementType(
columnIndex, Arrays.asList(Code.ENUM, Code.PG_OID, Code.INT64), columnName);
return 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);
checkArrayElementType(
columnIndex, Arrays.asList(Code.ENUM, Code.PG_OID, Code.INT64), columnIndex);
return 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);
checkArrayElementType(
columnIndex, Arrays.asList(Code.ENUM, Code.PG_OID, Code.INT64), columnName);
return getLongListInternal(columnIndex);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -563,6 +571,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:
Expand Down Expand Up @@ -598,6 +608,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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ private Object getAsObject(int columnIndex) {
case BOOL:
return getBooleanInternal(columnIndex);
case INT64:
case PG_OID:
case ENUM:
return getLongInternal(columnIndex);
case FLOAT32:
Expand Down Expand Up @@ -426,6 +427,7 @@ private Object getAsObject(int columnIndex) {
case BOOL:
return getBooleanListInternal(columnIndex);
case INT64:
case PG_OID:
case ENUM:
return getLongListInternal(columnIndex);
case FLOAT32:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public final class Type implements Serializable {
private static final Type TYPE_STRING = new Type(Code.STRING, null, null);
private static final Type TYPE_JSON = new Type(Code.JSON, null, null);
private static final Type TYPE_PG_JSONB = new Type(Code.PG_JSONB, null, null);
private static final Type TYPE_PG_OID = new Type(Code.PG_OID, null, null);
private static final Type TYPE_BYTES = new Type(Code.BYTES, null, null);
private static final Type TYPE_TIMESTAMP = new Type(Code.TIMESTAMP, null, null);
private static final Type TYPE_DATE = new Type(Code.DATE, null, null);
Expand All @@ -67,6 +68,7 @@ public final class Type implements Serializable {
private static final Type TYPE_ARRAY_STRING = new Type(Code.ARRAY, TYPE_STRING, null);
private static final Type TYPE_ARRAY_JSON = new Type(Code.ARRAY, TYPE_JSON, null);
private static final Type TYPE_ARRAY_PG_JSONB = new Type(Code.ARRAY, TYPE_PG_JSONB, null);
private static final Type TYPE_ARRAY_PG_OID = new Type(Code.ARRAY, TYPE_PG_OID, null);
private static final Type TYPE_ARRAY_BYTES = new Type(Code.ARRAY, TYPE_BYTES, null);
private static final Type TYPE_ARRAY_TIMESTAMP = new Type(Code.ARRAY, TYPE_TIMESTAMP, null);
private static final Type TYPE_ARRAY_DATE = new Type(Code.ARRAY, TYPE_DATE, null);
Expand Down Expand Up @@ -137,6 +139,11 @@ public static Type pgJsonb() {
return TYPE_PG_JSONB;
}

/** Returns the descriptor for the {@code PG_OID} type. */
public static Type pgOid() {
return TYPE_PG_OID;
}

/**
* To get the descriptor for the {@code PROTO} type.
*
Expand Down Expand Up @@ -198,6 +205,8 @@ public static Type array(Type elementType) {
return TYPE_ARRAY_JSON;
case PG_JSONB:
return TYPE_ARRAY_PG_JSONB;
case PG_OID:
return TYPE_ARRAY_PG_OID;
case BYTES:
return TYPE_ARRAY_BYTES;
case TIMESTAMP:
Expand Down Expand Up @@ -280,6 +289,7 @@ public enum Code {
STRING(TypeCode.STRING, "character varying"),
JSON(TypeCode.JSON, "unknown"),
PG_JSONB(TypeCode.JSON, "jsonb", TypeAnnotationCode.PG_JSONB),
PG_OID(TypeCode.INT64, "oid", TypeAnnotationCode.PG_OID),
PROTO(TypeCode.PROTO, "proto"),
ENUM(TypeCode.ENUM, "enum"),
BYTES(TypeCode.BYTES, "bytea"),
Expand Down Expand Up @@ -592,6 +602,8 @@ static Type fromProto(com.google.spanner.v1.Type proto) {
return json();
case PG_JSONB:
return pgJsonb();
case PG_OID:
return pgOid();
case BYTES:
return bytes();
case TIMESTAMP:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,20 @@ public static Value pgJsonb(@Nullable String v) {
return new PgJsonbImpl(v == null, v);
}

/**
* Returns an {@code PG_OID} value.
*
* @param v the value, which may be null
*/
public static Value pgOid(@Nullable Long v) {
return new PgOidImpl(v == null, v == null ? 0 : v);
}

/** Returns an {@code PG_OID} value. */
public static Value pgOid(long v) {
return new PgOidImpl(false, v);
}

/**
* Return a {@code PROTO} value for not null proto messages.
*
Expand Down Expand Up @@ -587,6 +601,40 @@ public static Value pgJsonbArray(@Nullable Iterable<String> v) {
return new PgJsonbArrayImpl(v == null, v == null ? null : immutableCopyOf(v));
}

/**
* Returns an {@code ARRAY<PG_OID>} value.
*
* @param v the source of element values, which may be null to produce a value for which {@code
* isNull()} is {@code true}
*/
public static Value pgOidArray(@Nullable long[] v) {
return pgOidArray(v, 0, v == null ? 0 : v.length);
}

/**
* Returns an {@code ARRAY<PG_OID>} value that takes its elements from a region of an array.
*
* @param v the source of element values, which may be null to produce a value for which {@code
* isNull()} is {@code true}
* @param pos the start position of {@code v} to copy values from. Ignored if {@code v} is {@code
* null}.
* @param length the number of values to copy from {@code v}. Ignored if {@code v} is {@code
* null}.
*/
public static Value pgOidArray(@Nullable long[] v, int pos, int length) {
return pgOidArrayFactory.create(v, pos, length);
}

/**
* Returns an {@code ARRAY<PG_OID>} value.
*
* @param v the source of element values. This may be {@code null} to produce a value for which
* {@code isNull()} is {@code true}. Individual elements may also be {@code null}.
*/
public static Value pgOidArray(@Nullable Iterable<Long> v) {
return pgOidArrayFactory.create(v);
}

/**
* Returns an {@code ARRAY<PROTO>} value.
*
Expand Down Expand Up @@ -1115,6 +1163,25 @@ Value newValue(boolean isNull, BitSet nulls, long[] values) {
return new Int64ArrayImpl(isNull, nulls, values);
}
};

private static final PrimitiveArrayValueFactory<long[], Long> pgOidArrayFactory =
new PrimitiveArrayValueFactory<long[], Long>() {
@Override
long[] newArray(int size) {
return new long[size];
}

@Override
void set(long[] arr, int i, Long value) {
arr[i] = value;
}

@Override
Value newValue(boolean isNull, BitSet nulls, long[] values) {
return new PgOidArrayImpl(isNull, nulls, values);
}
};

private static final PrimitiveArrayValueFactory<float[], Float> float32ArrayFactory =
new PrimitiveArrayValueFactory<float[], Float>() {
@Override
Expand Down Expand Up @@ -1822,6 +1889,41 @@ void valueToString(StringBuilder b) {
}
}

private static class PgOidImpl extends AbstractValue {
private final long value;

private PgOidImpl(boolean isNull, long value) {
super(isNull, Type.pgOid());
this.value = value;
}

@Override
public long getInt64() {
checkNotNull();
return value;
}

@Override
com.google.protobuf.Value valueToProto() {
return com.google.protobuf.Value.newBuilder().setStringValue(Long.toString(value)).build();
}

@Override
void valueToString(StringBuilder b) {
b.append(value);
}

@Override
boolean valueEquals(Value v) {
return ((PgOidImpl) v).value == value;
}

@Override
int valueHash() {
return Long.valueOf(value).hashCode();
}
}

private static class LazyBytesImpl extends AbstractObjectValue<LazyByteArray> {

private LazyBytesImpl(boolean isNull, LazyByteArray value) {
Expand Down Expand Up @@ -2457,6 +2559,48 @@ void appendElement(StringBuilder b, String element) {
}
}

private static class PgOidArrayImpl extends PrimitiveArrayImpl<Long> {
private final long[] values;

private PgOidArrayImpl(boolean isNull, BitSet nulls, long[] values) {
super(isNull, Type.pgOid(), nulls);
this.values = values;
}

@Override
public List<Long> getInt64Array() {
return getArray();
}

@Override
boolean valueEquals(Value v) {
PgOidArrayImpl that = (PgOidArrayImpl) v;
return Arrays.equals(values, that.values);
}

@Override
int size() {
return values.length;
}

@Override
Long getValue(int i) {
return values[i];
}

@Override
com.google.protobuf.Value getValueAsProto(int i) {
return com.google.protobuf.Value.newBuilder()
.setStringValue(Long.toString(values[i]))
.build();
}

@Override
int arrayHash() {
return Arrays.hashCode(values);
}
}

private static class LazyBytesArrayImpl extends AbstractArrayValue<LazyByteArray> {
private transient AbstractLazyInitializer<List<ByteArray>> bytesArray = defaultInitializer();

Expand Down Expand Up @@ -2790,6 +2934,8 @@ private Value getValue(int fieldIndex) {
return Value.numeric(value.getBigDecimal(fieldIndex));
case PG_NUMERIC:
return Value.pgNumeric(value.getString(fieldIndex));
case PG_OID:
return Value.pgOid(value.getLong(fieldIndex));
case DATE:
return Value.date(value.getDate(fieldIndex));
case TIMESTAMP:
Expand All @@ -2815,6 +2961,8 @@ private Value getValue(int fieldIndex) {
return Value.jsonArray(value.getJsonList(fieldIndex));
case PG_JSONB:
return Value.pgJsonbArray(value.getPgJsonbList(fieldIndex));
case PG_OID:
return Value.pgOidArray(value.getLongList(fieldIndex));
case BYTES:
case PROTO:
return Value.bytesArray(value.getBytesList(fieldIndex));
Expand Down
Loading