Skip to content

Commit 247b596

Browse files
committed
update
1 parent f3af396 commit 247b596

File tree

8 files changed

+70
-13
lines changed

8 files changed

+70
-13
lines changed

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/typing/Type.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ private static Type fromProtoType(@Nullable Descriptors.GenericDescriptor descri
404404
@Nonnull Descriptors.FieldDescriptor.Type protoType,
405405
@Nonnull FieldDescriptorProto.Label protoLabel,
406406
boolean isNullable) {
407-
final var typeCode = TypeCode.fromProtobufInfo(protoType);
407+
final var typeCode = TypeCode.fromProtobufType(protoType);
408408
if (protoLabel == FieldDescriptorProto.Label.LABEL_REPEATED) {
409409
// collection type
410410
return fromProtoTypeToArray(descriptor, protoType, typeCode, false);
@@ -419,7 +419,7 @@ private static Type fromProtoType(@Nullable Descriptors.GenericDescriptor descri
419419
if (NullableArrayTypeUtils.describesWrappedArray(messageDescriptor)) {
420420
// find TypeCode of array elements
421421
final var elementField = messageDescriptor.findFieldByName(NullableArrayTypeUtils.getRepeatedFieldName());
422-
final var elementTypeCode = TypeCode.fromProtobufInfo(elementField.getType());
422+
final var elementTypeCode = TypeCode.fromProtobufType(elementField.getType());
423423
return fromProtoTypeToArray(descriptor, protoType, elementTypeCode, true);
424424
} else if (Uuid.MESSAGE_NAME.equals(messageDescriptor.getName())) {
425425
return Type.uuidType(isNullable);
@@ -802,7 +802,7 @@ private static BiMap<Class<?>, TypeCode> computeClassToTypeCodeMap() {
802802
* @return A corresponding {@link TypeCode} instance.
803803
*/
804804
@Nonnull
805-
public static TypeCode fromProtobufInfo(@Nonnull final Descriptors.FieldDescriptor.Type protobufType) {
805+
public static TypeCode fromProtobufType(@Nonnull final Descriptors.FieldDescriptor.Type protobufType) {
806806
switch (protobufType) {
807807
case DOUBLE:
808808
return TypeCode.DOUBLE;

fdb-relational-grpc/src/main/java/com/apple/foundationdb/relational/jdbc/RelationalResultSetFacade.java

+13-7
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,9 @@ public UUID getUUID(String columnLabel) throws SQLException {
301301
@Override
302302
@ExcludeFromJacocoGeneratedReport
303303
public UUID getUUID(int oneBasedColumn) throws SQLException {
304-
// Not implemented
305-
throw new SQLException("Not implemented getUUID");
304+
UUID s = TypeConversion.getUUID(this.delegate, this.rowIndex, oneBasedColumn);
305+
wasNull = s == null;
306+
return s;
306307
}
307308

308309
@Override
@@ -332,13 +333,18 @@ public Object getObject(int oneBasedColumn) throws SQLException {
332333
o = getBoolean(oneBasedColumn);
333334
break;
334335
case Types.BINARY:
336+
o = getBytes(oneBasedColumn);
337+
break;
338+
case Types.OTHER:
335339
int index = PositionalIndex.toProtobuf(oneBasedColumn);
336340
Column column = this.delegate.getRow(rowIndex).getColumns().getColumn(index);
337-
return column == null || !column.hasBinary() ? null : column.getBinary().toByteArray();
338-
case Types.OTHER:
339-
// Probably an enum, it's not clear exactly how we should handle this, but we currently only have one
340-
// thing which appears as OTHER
341-
o = getString(oneBasedColumn);
341+
if (column.hasUuid()) {
342+
o = getUUID(oneBasedColumn);
343+
} else {
344+
// Probably an enum, it's not clear exactly how we should handle this, but we currently only have one
345+
// thing which appears as OTHER
346+
o = getString(oneBasedColumn);
347+
}
342348
break;
343349
default:
344350
throw new SQLException("Unsupported type " + type);

fdb-relational-grpc/src/main/java/com/apple/foundationdb/relational/jdbc/TypeConversion.java

+17
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import com.apple.foundationdb.relational.jdbc.grpc.v1.column.ListColumn;
4545
import com.apple.foundationdb.relational.jdbc.grpc.v1.column.ListColumnMetadata;
4646
import com.apple.foundationdb.relational.jdbc.grpc.v1.column.Struct;
47+
import com.apple.foundationdb.relational.jdbc.grpc.v1.column.Uuid;
4748
import com.apple.foundationdb.relational.util.PositionalIndex;
4849
import com.google.common.annotations.VisibleForTesting;
4950
import com.google.protobuf.ByteString;
@@ -54,6 +55,7 @@
5455
import java.util.ArrayList;
5556
import java.util.List;
5657
import java.util.Map;
58+
import java.util.UUID;
5759
import java.util.function.BiFunction;
5860

5961
/**
@@ -80,6 +82,14 @@ static RelationalStruct getStruct(ResultSet resultSet, int rowIndex, int oneBase
8082
return column.hasStruct() ? new RelationalStructFacade(metadata, column.getStruct()) : null;
8183
}
8284

85+
static UUID getUUID(ResultSet resultSet, int rowIndex, int oneBasedColumn) throws SQLException {
86+
int index = PositionalIndex.toProtobuf(oneBasedColumn);
87+
var metadata =
88+
resultSet.getMetadata().getColumnMetadata().getColumnMetadata(index).getStructMetadata();
89+
Column column = resultSet.getRow(rowIndex).getColumns().getColumn(index);
90+
return column.hasUuid() ? new UUID(column.getUuid().getMostSignificantBits(), column.getUuid().getLeastSignificantBits()) : null;
91+
}
92+
8393
/**
8494
* Convert list of {@link RelationalStruct} to {@link ResultSet}.
8595
* @param structs List of {@link RelationalStruct} which are expected to be of type {@link RelationalStructFacade}.
@@ -415,6 +425,13 @@ private static Column toColumn(RelationalStruct relationalStruct, int oneBasedIn
415425
column = toColumn(relationalStruct.wasNull() ? null : (String) object,
416426
(value, protobuf) -> value == null ? protobuf.clearString() : protobuf.setString(value));
417427
break;
428+
} else if (object instanceof UUID) {
429+
column = toColumn(relationalStruct.wasNull() ? null : (UUID) object, (value, protobuf) ->
430+
value == null ? protobuf.clearUuid() : protobuf.setUuid(Uuid.newBuilder()
431+
.setMostSignificantBits(value.getMostSignificantBits())
432+
.setLeastSignificantBits(value.getLeastSignificantBits())
433+
.build()));
434+
break;
418435
}
419436
if (object == null) {
420437
column = toColumn(null, (value, protobuf) -> protobuf.clearString());

fdb-relational-grpc/src/main/proto/grpc/relational/jdbc/v1/column.proto

+7
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,16 @@ message Column {
8181
float float = 10;
8282
// Represents a null value. These can be typed, so the value is the java.sql.Types of the parameter
8383
int32 nullType = 11;
84+
Uuid uuid = 12;
8485
}
8586
}
8687

88+
// This mimics the java.UUID type
89+
message Uuid {
90+
int64 most_significant_bits = 1;
91+
int64 least_significant_bits = 2;
92+
}
93+
8794
// Deprecated
8895
enum NullColumn {
8996
// Null value.

fdb-relational-jdbc/src/main/java/com/apple/foundationdb/relational/jdbc/ParameterHelper.java

+18
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.apple.foundationdb.relational.api.exceptions.ErrorCode;
2525
import com.apple.foundationdb.relational.jdbc.grpc.v1.Parameter;
2626
import com.apple.foundationdb.relational.jdbc.grpc.v1.column.Column;
27+
import com.apple.foundationdb.relational.jdbc.grpc.v1.column.Uuid;
2728
import com.google.protobuf.ByteString;
2829

2930
import java.sql.Array;
@@ -91,6 +92,16 @@ public static Parameter ofBytes(byte[] bytes) {
9192
.build();
9293
}
9394

95+
public static Parameter ofUuid(UUID uuid) {
96+
return Parameter.newBuilder()
97+
.setJavaSqlTypesCode(Types.OTHER)
98+
.setParameter(Column.newBuilder().setUuid(Uuid.newBuilder()
99+
.setMostSignificantBits(uuid.getMostSignificantBits())
100+
.setLeastSignificantBits(uuid.getLeastSignificantBits())
101+
.build()))
102+
.build();
103+
}
104+
94105
public static Parameter ofNull(int sqlType) throws SQLException {
95106
return Parameter.newBuilder()
96107
.setJavaSqlTypesCode(Types.NULL)
@@ -145,6 +156,13 @@ public static Parameter ofObject(Object x) throws SQLException {
145156
return ofNull(Types.NULL); // TODO: THis would be generic null...
146157
case Types.ARRAY:
147158
return ofArray((Array)x);
159+
case Types.OTHER:
160+
if (x instanceof UUID) {
161+
return ofUuid((UUID)x);
162+
} else {
163+
throw new SQLException("setObject Unrecognized type OTHER of class: " + x.getClass().getName(),
164+
ErrorCode.UNSUPPORTED_OPERATION.getErrorCode());
165+
}
148166
default:
149167
throw new SQLException("setObject Not supported for type " + typeCodeFromObject,
150168
ErrorCode.UNSUPPORTED_OPERATION.getErrorCode());

fdb-relational-server/src/main/java/com/apple/foundationdb/relational/server/FRL.java

+9
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import java.util.Collections;
6464
import java.util.List;
6565
import java.util.Optional;
66+
import java.util.UUID;
6667

6768
/**
6869
* Temporary class. "The Relational Database".
@@ -254,6 +255,14 @@ private static void addPreparedStatementParameter(RelationalPreparedStatement re
254255
case Types.NULL:
255256
relationalPreparedStatement.setNull(index, parameter.getParameter().getNullType());
256257
break;
258+
case Types.OTHER:
259+
if (parameter.getParameter().hasUuid()) {
260+
final var uuidParameter = parameter.getParameter().getUuid();
261+
relationalPreparedStatement.setUUID(index, new UUID(uuidParameter.getMostSignificantBits(), uuidParameter.getLeastSignificantBits()));
262+
} else {
263+
throw new SQLException("Unsupported type OTHER");
264+
}
265+
break;
257266
case Types.ARRAY:
258267
final com.apple.foundationdb.relational.jdbc.grpc.v1.column.Array arrayProto = parameter.getParameter().getArray();
259268
final Array relationalArray = relationalPreparedStatement.getConnection().createArrayOf(

yaml-tests/src/main/java/com/apple/foundationdb/relational/yamltests/configs/MultiServerConfig.java

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public MultiServerConfig(final int initialConnection, ExternalServer externalSer
5050
@Override
5151
public void beforeAll() throws Exception {
5252
super.beforeAll();
53-
externalServer.start();
5453
}
5554

5655
@Override

yaml-tests/src/test/resources/uuid.yamsql

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1717
# See the License for the specific language governing permissions and
1818
# limitations under the License.
19-
19+
---
20+
options:
21+
supported_version: !current_version
2022
---
2123
schema_template:
2224
create table ta(a bigint, b uuid, primary key(a))
@@ -36,7 +38,6 @@ setup:
3638
- query: INSERT INTO TA(A) VALUES (7), (8)
3739
---
3840
test_block:
39-
supported_version: !current_version
4041
name: uuid-as-a-field-tests
4142
tests:
4243
-

0 commit comments

Comments
 (0)