Skip to content
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: Support Interval Type #3416

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
52 changes: 52 additions & 0 deletions google-cloud-spanner/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,58 @@
<method>java.util.List getFloat32Array()</method>
</difference>

<!-- INTERVAL -->
<difference>
<differenceType>7012</differenceType>
<className>com/google/cloud/spanner/StructReader</className>
<method>com.google.cloud.spanner.Interval getInterval(int)</method>
</difference>
<difference>
<differenceType>7012</differenceType>
<className>com/google/cloud/spanner/StructReader</className>
<method>com.google.cloud.spanner.Interval getInterval(java.lang.String)</method>
</difference>
<difference>
<differenceType>7012</differenceType>
<className>com/google/cloud/spanner/StructReader</className>
<method>com.google.cloud.spanner.Interval[] getIntervalArray(int)</method>
</difference>
<difference>
<differenceType>7012</differenceType>
<className>com/google/cloud/spanner/StructReader</className>
<method>com.google.cloud.spanner.Interval[] getIntervalArray(java.lang.String)</method>
</difference>
<difference>
<differenceType>7012</differenceType>
<className>com/google/cloud/spanner/StructReader</className>
<method>java.util.List getIntervalList(int)</method>
</difference>
<difference>
<differenceType>7012</differenceType>
<className>com/google/cloud/spanner/StructReader</className>
<method>java.util.List getIntervalList(java.lang.String)</method>
</difference>
<difference>
<differenceType>7013</differenceType>
<className>com/google/cloud/spanner/AbstractStructReader</className>
<method>com.google.cloud.spanner.Interval getIntervalInternal(int)</method>
</difference>
<difference>
<differenceType>7013</differenceType>
<className>com/google/cloud/spanner/AbstractStructReader</className>
<method>java.util.List getIntervalListInternal(int)</method>
</difference>
<difference>
<differenceType>7013</differenceType>
<className>com/google/cloud/spanner/Value</className>
<method>com.google.cloud.spanner.Interval getInterval()</method>
</difference>
<difference>
<differenceType>7013</differenceType>
<className>com/google/cloud/spanner/Value</className>
<method>java.util.List getIntervalArray()</method>
</difference>

<!-- (Internal change, use stream timeout) -->
<difference>
<differenceType>7012</differenceType>
Expand Down
11 changes: 11 additions & 0 deletions google-cloud-spanner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@
<version>${graal-sdk.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
sagarwaal marked this conversation as resolved.
Show resolved Hide resolved
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value</artifactId>
<version>1.10.4</version>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down Expand Up @@ -455,6 +460,12 @@
<artifactId>opentelemetry-sdk-testing</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>24.1.0</version>
<scope>compile</scope>
sagarwaal marked this conversation as resolved.
Show resolved Hide resolved
</dependency>
</dependencies>
<profiles>
<profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@ protected Date getDateInternal(int columnIndex) {
return currRow().getDateInternal(columnIndex);
}

@Override
protected Interval getIntervalInternal(int columnIndex) {
return currRow().getIntervalInternal(columnIndex);
}

@Override
protected Value getValueInternal(int columnIndex) {
return currRow().getValueInternal(columnIndex);
Expand Down Expand Up @@ -514,6 +519,11 @@ protected List<Date> getDateListInternal(int columnIndex) {
return currRow().getDateListInternal(columnIndex);
}

@Override
protected List<Interval> getIntervalListInternal(int columnIndex) {
return currRow().getIntervalListInternal(columnIndex);
}

@Override
protected List<Struct> getStructListInternal(int columnIndex) {
return currRow().getStructListInternal(columnIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ protected String getPgJsonbInternal(int columnIndex) {

protected abstract Date getDateInternal(int columnIndex);

protected abstract Interval getIntervalInternal(int columnIndex);

protected <T extends AbstractMessage> T getProtoMessageInternal(int columnIndex, T message) {
throw new UnsupportedOperationException("Not implemented");
}
Expand Down Expand Up @@ -128,6 +130,8 @@ protected List<String> getPgJsonbListInternal(int columnIndex) {

protected abstract List<Date> getDateListInternal(int columnIndex);

protected abstract List<Interval> getIntervalListInternal(int columnIndex);

protected abstract List<Struct> getStructListInternal(int columnIndex);

@Override
Expand Down Expand Up @@ -299,6 +303,19 @@ public Date getDate(String columnName) {
return getDateInternal(columnIndex);
}

@Override
public Interval getInterval(int columnIndex) {
checkNonNullOfType(columnIndex, Type.interval(), columnIndex);
return getIntervalInternal(columnIndex);
}

@Override
public Interval getInterval(String columnName) {
int columnIndex = getColumnIndex(columnName);
checkNonNullOfType(columnIndex, Type.interval(), columnName);
return getIntervalInternal(columnIndex);
}

@Override
public <T extends ProtocolMessageEnum> T getProtoEnum(
int columnIndex, Function<Integer, ProtocolMessageEnum> method) {
Expand Down Expand Up @@ -583,6 +600,19 @@ public List<Date> getDateList(String columnName) {
return getDateListInternal(columnIndex);
}

@Override
public List<Interval> getIntervalList(int columnIndex) {
checkNonNullOfType(columnIndex, Type.array(Type.interval()), columnIndex);
return getIntervalListInternal(columnIndex);
}

@Override
public List<Interval> getIntervalList(String columnName) {
int columnIndex = getColumnIndex(columnName);
checkNonNullOfType(columnIndex, Type.array(Type.interval()), columnName);
return getIntervalListInternal(columnIndex);
}

@Override
public List<Struct> getStructList(int columnIndex) {
checkNonNullArrayOfStruct(columnIndex, columnIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,18 @@ public Date getDate(String columnName) {
return delegate.get().getDate(columnName);
}

@Override
public Interval getInterval(int columnIndex) {
checkValidState();
return delegate.get().getInterval(columnIndex);
}

@Override
public Interval getInterval(String columnName) {
checkValidState();
return delegate.get().getInterval(columnName);
}

@Override
public boolean[] getBooleanArray(int columnIndex) {
checkValidState();
Expand Down Expand Up @@ -409,6 +421,18 @@ public List<Date> getDateList(String columnName) {
return delegate.get().getDateList(columnName);
}

@Override
public List<Interval> getIntervalList(int columnIndex) {
checkValidState();
return delegate.get().getIntervalList(columnIndex);
}

@Override
public List<Interval> getIntervalList(String columnName) {
checkValidState();
return delegate.get().getIntervalList(columnName);
}

@Override
public <T extends AbstractMessage> List<T> getProtoMessageList(int columnIndex, T message) {
checkValidState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ private Object writeReplace() {
case DATE:
builder.set(fieldName).to((Date) value);
break;
case INTERVAL:
builder.set(fieldName).to((Interval) value);
break;
case ARRAY:
final Type elementType = fieldType.getArrayElementType();
switch (elementType.getCode()) {
Expand Down Expand Up @@ -184,6 +187,9 @@ private Object writeReplace() {
case DATE:
builder.set(fieldName).toDateArray((Iterable<Date>) value);
break;
case INTERVAL:
builder.set(fieldName).toIntervalArray((Iterable<Interval>) value);
break;
case STRUCT:
builder.set(fieldName).toStructArray(elementType, (Iterable<Struct>) value);
break;
Expand Down Expand Up @@ -298,6 +304,9 @@ private static Object decodeValue(Type fieldType, com.google.protobuf.Value prot
case DATE:
checkType(fieldType, proto, KindCase.STRING_VALUE);
return Date.parseDate(proto.getStringValue());
case INTERVAL:
checkType(fieldType, proto, KindCase.STRING_VALUE);
return Interval.parseFromString(proto.getStringValue());
case ARRAY:
checkType(fieldType, proto, KindCase.LIST_VALUE);
ListValue listValue = proto.getListValue();
Expand Down Expand Up @@ -347,6 +356,7 @@ static Object decodeArrayValue(Type elementType, ListValue listValue) {
case BYTES:
case TIMESTAMP:
case DATE:
case INTERVAL:
case STRUCT:
case PROTO:
return Lists.transform(listValue.getValuesList(), input -> decodeValue(elementType, input));
Expand Down Expand Up @@ -503,6 +513,11 @@ protected Date getDateInternal(int columnIndex) {
return (Date) rowData.get(columnIndex);
}

protected Interval getIntervalInternal(int columnIndex) {
sagarwaal marked this conversation as resolved.
Show resolved Hide resolved
ensureDecoded(columnIndex);
return (Interval) rowData.get(columnIndex);
}

private boolean isUnrecognizedType(int columnIndex) {
return type.getStructFields().get(columnIndex).getType().getCode() == Code.UNRECOGNIZED;
}
Expand Down Expand Up @@ -624,6 +639,8 @@ protected Value getValueInternal(int columnIndex) {
return Value.timestamp(isNull ? null : getTimestampInternal(columnIndex));
case DATE:
return Value.date(isNull ? null : getDateInternal(columnIndex));
case INTERVAL:
return Value.interval(isNull ? null : getIntervalInternal(columnIndex));
case STRUCT:
return Value.struct(isNull ? null : getStructInternal(columnIndex));
case UNRECOGNIZED:
Expand Down Expand Up @@ -664,6 +681,8 @@ protected Value getValueInternal(int columnIndex) {
return Value.timestampArray(isNull ? null : getTimestampListInternal(columnIndex));
case DATE:
return Value.dateArray(isNull ? null : getDateListInternal(columnIndex));
case INTERVAL:
return Value.intervalArray(isNull ? null : getIntervalListInternal(columnIndex));
case STRUCT:
return Value.structArray(
elementType, isNull ? null : getStructListInternal(columnIndex));
Expand Down Expand Up @@ -847,6 +866,13 @@ protected List<Date> getDateListInternal(int columnIndex) {
return Collections.unmodifiableList((List<Date>) rowData.get(columnIndex));
}

@Override
@SuppressWarnings("unchecked") // We know ARRAY<Interval> produces a List<Interval>.
protected List<Interval> getIntervalListInternal(int columnIndex) {
ensureDecoded(columnIndex);
return Collections.unmodifiableList((List<Interval>) rowData.get(columnIndex));
}

@Override
@SuppressWarnings("unchecked") // We know ARRAY<STRUCT<...>> produces a List<STRUCT>.
protected List<Struct> getStructListInternal(int columnIndex) {
Expand Down
Loading
Loading