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 float32 type #2894

Merged
merged 28 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1d64140
feat: float32 changes with unit and integration tests
arawind Dec 1, 2023
5a7fdc2
Merge branch 'main' into float32-v2
arawind Feb 15, 2024
1358bbb
Undo the changes to GceTestEnvConfig
arawind Feb 16, 2024
74b01e5
Update formatting and clirr
arawind Feb 16, 2024
6789155
Update the hashCode logic to account for NaN equality
arawind Feb 16, 2024
f1dbc8f
Prevent FLOAT32 integration tests from running on emulator and produc…
arawind Feb 19, 2024
5b493fa
Add a kokoro presubmit workflow to run on cloud-devel.
arawind Feb 20, 2024
80f80a9
Prevent FLOAT32 schema from being added if the env is not cloud-devel
arawind Feb 20, 2024
924ef75
Merge branch 'main' into float32-v2
arawind Feb 20, 2024
253c5f1
Merge branch 'main' into float32-v2
arawind Feb 22, 2024
fac44f0
Revert "Add a kokoro presubmit workflow to run on cloud-devel."
arawind Feb 22, 2024
391f735
Merge branch 'main' into float32-v2
arawind Feb 22, 2024
3e63abd
Fix integration tests for FLOAT32
arawind Feb 23, 2024
b64e627
Update float32UntypedParameters test to work with PG dialect too
arawind Feb 23, 2024
e18fd3f
Remove FLOAT32 changes in CreateMusicTables.sql as the type isn't ful…
arawind Feb 23, 2024
202b10c
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Feb 23, 2024
34a10e2
Merge branch 'float32-v2' of github.com:arawind/java-spanner into flo…
arawind Feb 23, 2024
fda3987
Split the parameters test in ITQueryTest into supported + currently-u…
arawind Feb 23, 2024
dbd12a9
Merge branch 'main' into float32-v2
arawind Feb 23, 2024
646e6eb
Minor changes in comments
arawind Feb 23, 2024
2988656
Split the Mutation.isNaN method to make it more readable
arawind Feb 23, 2024
738916c
Merge branch 'main' into float32-v2
arawind Feb 23, 2024
187182b
test: added some additional tests
olavloite Feb 23, 2024
7543083
Merge branch 'main' into float32-v2
arawind Feb 25, 2024
1057826
Update to resolve comments on PR#2894.
arawind Feb 25, 2024
dedf17e
Merge branch 'main' into float32-v2
arawind Feb 28, 2024
2dfe0df
Un-ignore the skipped FLOAT32 tests as the backend fixes have been de…
arawind Feb 28, 2024
8f6e21f
Un-ignore the float32 tests in ITQueryTest
arawind Feb 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Prev Previous commit
Next Next commit
Update to resolve comments on PR#2894.
Major change: Ensures that the new methods in interfaces do not break for older clients.

Minor changes: remove double cast; remove dependency on Truth assertions; remove unnecessary logic in Mutations::isNaN
  • Loading branch information
arawind committed Feb 25, 2024
commit 105782638b40c8b9b9fe1d51279790fd86b7557d
15 changes: 0 additions & 15 deletions google-cloud-spanner/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -507,21 +507,6 @@
</difference>

<!-- FLOAT32 -->
<difference>
<differenceType>7013</differenceType>
<className>com/google/cloud/spanner/AbstractStructReader</className>
<method>float[] getFloatArrayInternal(int)</method>
</difference>
<difference>
<differenceType>7013</differenceType>
<className>com/google/cloud/spanner/AbstractStructReader</className>
<method>float getFloatInternal(int)</method>
</difference>
<difference>
<differenceType>7013</differenceType>
<className>com/google/cloud/spanner/AbstractStructReader</className>
<method>java.util.List getFloatListInternal(int)</method>
</difference>
<difference>
<differenceType>7012</differenceType>
<className>com/google/cloud/spanner/StructReader</className>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public abstract class AbstractStructReader implements StructReader {

protected abstract long getLongInternal(int columnIndex);

protected abstract float getFloatInternal(int columnIndex);
protected float getFloatInternal(int columnIndex) {
throw new UnsupportedOperationException("Not implemented");
}

protected abstract double getDoubleInternal(int columnIndex);

Expand Down Expand Up @@ -96,9 +98,13 @@ protected Value getValueInternal(int columnIndex) {

protected abstract List<Long> getLongListInternal(int columnIndex);

protected abstract float[] getFloatArrayInternal(int columnIndex);
protected float[] getFloatArrayInternal(int columnIndex) {
throw new UnsupportedOperationException("Not implemented");
}

protected abstract List<Float> getFloatListInternal(int columnIndex);
protected List<Float> getFloatListInternal(int columnIndex) {
throw new UnsupportedOperationException("Not implemented");
}

protected abstract double[] getDoubleArrayInternal(int columnIndex);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,15 +393,13 @@ private boolean isNaN(Value value) {
// Checks if the Float64 value is either a "Double" or a "Float" NaN.
// Refer the comment above `areValuesEqual` for more details.
private boolean isFloat64NaN(Value value) {
return value.getType().equals(Type.float64())
&& (Double.isNaN(value.getFloat64()) || Float.isNaN((float) value.getFloat64()));
return value.getType().equals(Type.float64()) && Double.isNaN(value.getFloat64());
}

// Checks if the Float32 value is either a "Double" or a "Float" NaN.
// Refer the comment above `areValuesEqual` for more details.
private boolean isFloat32NaN(Value value) {
return value.getType().equals(Type.float32())
&& (Float.isNaN(value.getFloat32()) || Double.isNaN(value.getFloat32()));
return value.getType().equals(Type.float32()) && Float.isNaN(value.getFloat32());
}

static void toProto(Iterable<Mutation> mutations, List<com.google.spanner.v1.Mutation> out) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,17 @@ public interface StructReader {
* @param columnIndex index of the column
* @return the value of a non-{@code NULL} column with type {@link Type#float32()}.
*/
float getFloat(int columnIndex);
default float getFloat(int columnIndex) {
throw new UnsupportedOperationException("method should be overwritten");
}

/**
* @param columnName name of the column
* @return the value of a non-{@code NULL} column with type {@link Type#float32()}.
*/
float getFloat(String columnName);
default float getFloat(String columnName) {
throw new UnsupportedOperationException("method should be overwritten");
}

/**
* @param columnIndex index of the column
Expand Down Expand Up @@ -379,23 +383,29 @@ default Value getValue(String columnName) {
* @throws NullPointerException if any element of the array value is {@code NULL}. If the array
* may contain {@code NULL} values, use {@link #getFloatList(int)} instead.
*/
float[] getFloatArray(int columnIndex);
default float[] getFloatArray(int columnIndex) {
throw new UnsupportedOperationException("method should be overwritten");
}

/**
* @param columnName name of the column
* @return the value of a non-{@code NULL} column with type {@code Type.array(Type.float32())}.
* @throws NullPointerException if any element of the array value is {@code NULL}. If the array
* may contain {@code NULL} values, use {@link #getFloatList(String)} instead.
*/
float[] getFloatArray(String columnName);
default float[] getFloatArray(String columnName) {
throw new UnsupportedOperationException("method should be overwritten");
}

/**
* @param columnIndex index of the column
* @return the value of a non-{@code NULL} column with type {@code Type.array(Type.float32())} The
* list returned by this method is lazily constructed. Create a copy of it if you intend to
* access each element in the list multiple times.
*/
List<Float> getFloatList(int columnIndex);
default List<Float> getFloatList(int columnIndex) {
throw new UnsupportedOperationException("method should be overwritten");
}

/**
* @param columnName name of the column
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ public static Type int64() {

/**
* Returns the descriptor for the {@code FLOAT32} type: a floating point type with the same value
* domain as a Java {code float}.
* domain as a Java {@code float}.
*/
public static Type float32() {
return TYPE_FLOAT32;
}

/**
* Returns the descriptor for the {@code FLOAT64} type: a floating point type with the same value
* domain as a Java {code double}.
* domain as a Java {@code double}.
*/
public static Type float64() {
return TYPE_FLOAT64;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1456,14 +1456,6 @@ public String getString() {
return value.getStringValue();
}

@Override
public float getFloat32() {
checkNotNull();
Preconditions.checkState(
value.hasNumberValue(), "This value does not contain a number value");
return (float) value.getNumberValue();
}

@Override
public double getFloat64() {
checkNotNull();
Expand Down Expand Up @@ -1626,7 +1618,7 @@ public float getFloat32() {

@Override
com.google.protobuf.Value valueToProto() {
return com.google.protobuf.Value.newBuilder().setNumberValue((double) value).build();
return com.google.protobuf.Value.newBuilder().setNumberValue(value).build();
}

@Override
Expand Down Expand Up @@ -2037,8 +2029,6 @@ void valueToString(StringBuilder b) {
private static class PgNumericImpl extends AbstractObjectValue<String> {
private BigDecimal valueAsBigDecimal;
private NumberFormatException bigDecimalConversionError;
private Float valueAsFloat;
private NumberFormatException floatConversionError;
private Double valueAsDouble;
private NumberFormatException doubleConversionError;

Expand Down Expand Up @@ -2069,23 +2059,6 @@ public BigDecimal getNumeric() {
return valueAsBigDecimal;
}

@Override
public float getFloat32() {
checkNotNull();
if (floatConversionError != null) {
throw floatConversionError;
}
if (valueAsFloat == null) {
try {
valueAsFloat = Float.parseFloat(value);
} catch (NumberFormatException e) {
floatConversionError = e;
throw e;
}
}
return valueAsFloat;
}

@Override
public double getFloat64() {
checkNotNull();
Expand Down Expand Up @@ -2314,7 +2287,7 @@ Float getValue(int i) {

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

@Override
Expand Down Expand Up @@ -2698,8 +2671,6 @@ private static class PgNumericArrayImpl extends AbstractArrayValue<String> {

private List<BigDecimal> valuesAsBigDecimal;
private NumberFormatException bigDecimalConversionError;
private List<Float> valuesAsFloat;
private NumberFormatException floatConversionError;
private List<Double> valuesAsDouble;
private NumberFormatException doubleConversionError;

Expand Down Expand Up @@ -2733,26 +2704,6 @@ public List<BigDecimal> getNumericArray() {
return valuesAsBigDecimal;
}

@Override
public List<Float> getFloat32Array() {
checkNotNull();
if (floatConversionError != null) {
throw floatConversionError;
}
if (valuesAsFloat == null) {
try {
valuesAsFloat =
value.stream()
.map(v -> v == null ? null : Float.valueOf(v))
.collect(Collectors.toList());
} catch (NumberFormatException e) {
floatConversionError = e;
throw e;
}
}
return valuesAsFloat;
}

@Override
public List<Double> getFloat64Array() {
checkNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private void setRandomValue(Value.Builder builder, Type type) {
builder.setNumberValue(random.nextDouble());
break;
case FLOAT32:
builder.setNumberValue((double) random.nextFloat());
builder.setNumberValue(random.nextFloat());
break;
case INT64:
builder.setStringValue(String.valueOf(random.nextLong()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ public void testValueToProto() {
Value.int64(null).toProto());

assertEquals(
com.google.protobuf.Value.newBuilder().setNumberValue((double) 3.14f).build(),
com.google.protobuf.Value.newBuilder().setNumberValue(3.14f).build(),
Value.float32(3.14f).toProto());
assertEquals(
com.google.protobuf.Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build(),
Expand Down Expand Up @@ -1610,9 +1610,7 @@ public void testValueToProto() {
ListValue.newBuilder()
.addAllValues(
Arrays.asList(
com.google.protobuf.Value.newBuilder()
.setNumberValue((double) 3.14f)
.build(),
com.google.protobuf.Value.newBuilder().setNumberValue(3.14f).build(),
com.google.protobuf.Value.newBuilder()
.setNullValue(NullValue.NULL_VALUE)
.build())))
Expand Down Expand Up @@ -1784,7 +1782,7 @@ public void testValueToProto() {
.addAllValues(
Arrays.asList(
com.google.protobuf.Value.newBuilder()
.setNumberValue((double) 3.14f)
.setNumberValue(3.14f)
.build(),
com.google.protobuf.Value.newBuilder()
.setNullValue(NullValue.NULL_VALUE)
Expand Down