Skip to content

Commit 0e56d68

Browse files
committed
update
1 parent f31c6ed commit 0e56d68

21 files changed

+57
-50
lines changed

fdb-relational-api/src/main/java/com/apple/foundationdb/relational/api/RelationalArrayMetaData.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,16 @@ public final class RelationalArrayMetaData implements ArrayMetaData {
4242

4343
private final Supplier<Integer> hashCodeSupplier;
4444

45-
public RelationalArrayMetaData(@Nonnull DataType.ArrayType type) {
45+
private RelationalArrayMetaData(@Nonnull DataType.ArrayType type) {
4646
this.type = type;
4747
this.hashCodeSupplier = Suppliers.memoize(this::calculateHashCode);
4848
}
4949

50+
@Nonnull
51+
public static RelationalArrayMetaData of(@Nonnull DataType.ArrayType type) {
52+
return new RelationalArrayMetaData(type);
53+
}
54+
5055
@Override
5156
public int isElementNullable() {
5257
if (type.getElementType().isNullable()) {
@@ -80,11 +85,11 @@ public String getElementTypeName() {
8085
* @throws SQLException if the type of the column is not a struct, or if something else goes wrong.
8186
*/
8287
@Override
83-
public RelationalStructMetaData getElementStructMetaData() throws SQLException {
88+
public StructMetaData getElementStructMetaData() throws SQLException {
8489
if (type.getElementType().getCode() != DataType.Code.STRUCT) {
8590
throw new RelationalException("Element is not of STRUCT type", ErrorCode.CANNOT_CONVERT_TYPE).toSqlException();
8691
}
87-
return new RelationalStructMetaData((DataType.StructType) type.getElementType());
92+
return RelationalStructMetaData.of((DataType.StructType) type.getElementType());
8893
}
8994

9095
/**
@@ -100,7 +105,7 @@ public ArrayMetaData getElementArrayMetaData() throws SQLException {
100105
if (type.getElementType().getCode() != DataType.Code.ARRAY) {
101106
throw new RelationalException("Element is not of ARRAY type", ErrorCode.CANNOT_CONVERT_TYPE).toSqlException();
102107
}
103-
return new RelationalArrayMetaData((DataType.ArrayType) type.getElementType());
108+
return RelationalArrayMetaData.of((DataType.ArrayType) type.getElementType());
104109
}
105110

106111
@Nonnull

fdb-relational-api/src/main/java/com/apple/foundationdb/relational/api/RelationalStructMetaData.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,17 @@ public class RelationalStructMetaData implements StructMetaData {
4848
private final int leadingPhantomColumnOffset;
4949
private final Supplier<Integer> hashCodeSupplier;
5050

51-
public RelationalStructMetaData(@Nonnull DataType.StructType type) {
51+
private RelationalStructMetaData(@Nonnull DataType.StructType type) {
5252
this.type = type;
5353
this.leadingPhantomColumnOffset = countLeadingPhantomColumns();
5454
this.hashCodeSupplier = Suppliers.memoize(this::calculateHashCode);
5555
}
5656

57+
@Nonnull
58+
public static RelationalStructMetaData of(@Nonnull DataType.StructType type) {
59+
return new RelationalStructMetaData(type);
60+
}
61+
5762
@Override
5863
public String getTypeName() {
5964
return type.getName();
@@ -115,7 +120,7 @@ public String getColumnTypeName(int oneBasedColumn) throws SQLException {
115120
public StructMetaData getStructMetaData(int oneBasedColumn) throws SQLException {
116121
final DataType type = getField(oneBasedColumn).getType();
117122
if (type.getCode() == DataType.Code.STRUCT) {
118-
return new RelationalStructMetaData((DataType.StructType) type);
123+
return RelationalStructMetaData.of((DataType.StructType) type);
119124
}
120125
throw new InvalidColumnReferenceException("Position <" + oneBasedColumn + "> is not a struct type").toSqlException();
121126
}
@@ -124,7 +129,7 @@ public StructMetaData getStructMetaData(int oneBasedColumn) throws SQLException
124129
public ArrayMetaData getArrayMetaData(int oneBasedColumn) throws SQLException {
125130
final DataType type = getField(oneBasedColumn).getType();
126131
if (type.getCode() == DataType.Code.ARRAY) {
127-
return new RelationalArrayMetaData((DataType.ArrayType) type);
132+
return RelationalArrayMetaData.of((DataType.ArrayType) type);
128133
}
129134
throw new InvalidColumnReferenceException("Position <" + oneBasedColumn + "> is not an array type").toSqlException();
130135
}
@@ -150,7 +155,7 @@ public boolean isWrapperFor(Class<?> iface) {
150155
}
151156

152157
@Nonnull
153-
public List<DataType.StructType.Field> getFields() {
158+
private List<DataType.StructType.Field> getFields() {
154159
return ImmutableList.copyOf(type.getFields());
155160
}
156161

fdb-relational-core/src/main/java/com/apple/foundationdb/relational/api/EmbeddedRelationalArray.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ private Builder(@Nonnull DataType elementType) {
5757
@Override
5858
public EmbeddedRelationalArray build() throws SQLException {
5959
if (elementType == null) {
60-
return new RowArray(List.of(), new RelationalArrayMetaData(DataType.ArrayType.from(DataType.Primitives.NULL.type())));
60+
return new RowArray(List.of(), RelationalArrayMetaData.of(DataType.ArrayType.from(DataType.Primitives.NULL.type())));
6161
}
62-
return new RowArray(elements, new RelationalArrayMetaData(DataType.ArrayType.from(elementType, false)));
62+
return new RowArray(elements, RelationalArrayMetaData.of(DataType.ArrayType.from(elementType, false)));
6363
}
6464

6565
@Override

fdb-relational-core/src/main/java/com/apple/foundationdb/relational/api/EmbeddedRelationalStruct.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public EmbeddedRelationalStruct build() {
4949
// between the two - rather than confusing the downstream planner.
5050
final var name = "ANONYMOUS_STRUCT_" + UUID.randomUUID().toString().replace("-", "_");
5151
final var type = DataType.StructType.from(name, fields, false);
52-
return new ImmutableRowStruct(new ArrayRow(elements.toArray()), new RelationalStructMetaData(type));
52+
return new ImmutableRowStruct(new ArrayRow(elements.toArray()), RelationalStructMetaData.of(type));
5353
}
5454

5555
@Override

fdb-relational-core/src/main/java/com/apple/foundationdb/relational/api/RowArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public RelationalResultSet getResultSet(long oneBasedIndex, int count) throws SQ
7474
DataType.StructType.Field.from("INDEX", DataType.Primitives.INTEGER.type(), 0),
7575
DataType.StructType.Field.from("VALUE", arrayMetaData.getRelationalDataType().getElementType(), 1)
7676
), true);
77-
return new IteratorResultSet(new RelationalStructMetaData(type), slice.iterator(), 0);
77+
return new IteratorResultSet(RelationalStructMetaData.of(type), slice.iterator(), 0);
7878
}
7979

8080
@Override

fdb-relational-core/src/main/java/com/apple/foundationdb/relational/recordlayer/CatalogMetaData.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public RelationalResultSet getSchemas(String catalogStr, String schemaPattern) t
9696
DataType.StructType.Field.from("TABLE_CATALOG", DataType.Primitives.NULLABLE_STRING.type(), 0),
9797
DataType.StructType.Field.from("TABLE_SCHEM", DataType.Primitives.NULLABLE_STRING.type(), 1)
9898
), true);
99-
return new IteratorResultSet(new RelationalStructMetaData(schemasStructType), simplifiedRows.iterator(), 0);
99+
return new IteratorResultSet(RelationalStructMetaData.of(schemasStructType), simplifiedRows.iterator(), 0);
100100
} catch (SQLException sqle) {
101101
throw new RelationalException(sqle);
102102
}
@@ -142,7 +142,7 @@ public RelationalResultSet getTables(String database, String schema, String tabl
142142
DataType.StructType.Field.from("TABLE_VERSION", DataType.Primitives.NULLABLE_LONG.type(), 3)
143143

144144
), true);
145-
return new IteratorResultSet(new RelationalStructMetaData(tablesStructType), tableList.iterator(), 0);
145+
return new IteratorResultSet(RelationalStructMetaData.of(tablesStructType), tableList.iterator(), 0);
146146
});
147147
}
148148

@@ -171,7 +171,7 @@ public RelationalResultSet getPrimaryKeys(String database, String schema, String
171171
DataType.StructType.Field.from("KEY_SEQ", DataType.Primitives.NULLABLE_INTEGER.type(), 4),
172172
DataType.StructType.Field.from("PK_NAME", DataType.Primitives.NULLABLE_STRING.type(), 5)
173173
), true);
174-
return new IteratorResultSet(new RelationalStructMetaData(primaryKeysStructType), rows.iterator(), 0);
174+
return new IteratorResultSet(RelationalStructMetaData.of(primaryKeysStructType), rows.iterator(), 0);
175175
});
176176
}
177177

@@ -265,7 +265,7 @@ public RelationalResultSet getColumns(String database, String schema, String tab
265265
DataType.StructType.Field.from("IS_AUTOINCREMENT", DataType.Primitives.NULLABLE_STRING.type(), 22),
266266
DataType.StructType.Field.from("IS_GENERATEDCOLUMN", DataType.Primitives.NULLABLE_STRING.type(), 23)
267267
), true);
268-
return new IteratorResultSet(new RelationalStructMetaData(columnsStructType), columnDefs.iterator(), 0);
268+
return new IteratorResultSet(RelationalStructMetaData.of(columnsStructType), columnDefs.iterator(), 0);
269269
});
270270
}
271271

@@ -334,7 +334,7 @@ public RelationalResultSet getIndexInfo(String database, String schema, String t
334334
DataType.StructType.Field.from("PAGES", DataType.Primitives.NULLABLE_INTEGER.type(), 11),
335335
DataType.StructType.Field.from("FILTER_CONDITION", DataType.Primitives.NULLABLE_STRING.type(), 12)
336336
), true);
337-
return new IteratorResultSet(new RelationalStructMetaData(indexInfoStructType), indexDefs.iterator(), 0);
337+
return new IteratorResultSet(RelationalStructMetaData.of(indexInfoStructType), indexDefs.iterator(), 0);
338338
});
339339
}
340340

fdb-relational-core/src/main/java/com/apple/foundationdb/relational/recordlayer/EmbeddedRelationalConnection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ public SQLWarning getWarnings() throws SQLException {
363363
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
364364
final var dataType = SqlTypeNamesSupport.getDataTypeFromSqlTypeName(typeName);
365365
if (dataType != null) {
366-
return new RowArray(Arrays.stream(elements).collect(Collectors.toList()), new RelationalArrayMetaData(DataType.ArrayType.from(dataType, false)));
366+
return new RowArray(Arrays.stream(elements).collect(Collectors.toList()), RelationalArrayMetaData.of(DataType.ArrayType.from(dataType, false)));
367367
} else if (elements.length == 0) {
368368
throw new RelationalException("Cannot determine the complete component type of array of struct since it has no elements!", ErrorCode.INTERNAL_ERROR).toSqlException();
369369
} else {
@@ -373,7 +373,7 @@ public Array createArrayOf(String typeName, Object[] elements) throws SQLExcepti
373373
} else if (elementType.getJdbcSqlCode() != SqlTypeNamesSupport.getSqlTypeCode(typeName)) {
374374
throw new RelationalException("Element of the array is expected to be of type " + typeName, ErrorCode.DATATYPE_MISMATCH).toSqlException();
375375
}
376-
return new RowArray(Arrays.stream(elements).collect(Collectors.toList()), new RelationalArrayMetaData(DataType.ArrayType.from(elementType, false)));
376+
return new RowArray(Arrays.stream(elements).collect(Collectors.toList()), RelationalArrayMetaData.of(DataType.ArrayType.from(elementType, false)));
377377
}
378378
}
379379

fdb-relational-core/src/main/java/com/apple/foundationdb/relational/recordlayer/RecordStoreIndex.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public StructMetaData getMetaData() throws RelationalException {
7474
final RecordType recType = table.loadRecordType(Options.NONE);
7575
final List<Descriptors.FieldDescriptor> fields = indexStruct.validate(recType.getDescriptor());
7676
final Type.Record record = ProtobufDdlUtil.recordFromFieldDescriptors(fields);
77-
return new RelationalStructMetaData((DataType.StructType) DataTypeUtils.toRelationalType(record));
77+
return RelationalStructMetaData.of((DataType.StructType) DataTypeUtils.toRelationalType(record));
7878
}
7979

8080
@Override

fdb-relational-core/src/main/java/com/apple/foundationdb/relational/recordlayer/RecordTypeTable.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public StructMetaData getMetaData() throws RelationalException {
124124
});
125125
orderedFieldMap.putAll(descriptorLookupMap);
126126
final Type.Record record = Type.Record.fromFieldDescriptorsMap(orderedFieldMap);
127-
return new RelationalStructMetaData((DataType.StructType) DataTypeUtils.toRelationalType(record));
127+
return RelationalStructMetaData.of((DataType.StructType) DataTypeUtils.toRelationalType(record));
128128
}
129129

130130
@Override
@@ -198,7 +198,7 @@ public static Message toDynamicMessage(RelationalStruct struct, Descriptors.Desc
198198
Assert.thatUnchecked(valueDescriptor != null, ErrorCode.CANNOT_CONVERT_TYPE, "Invalid enum value: %s", maybeEnumValue);
199199
builder.setField(fd, valueDescriptor);
200200
}
201-
break;
201+
continue;
202202
}
203203
switch (field.getType().getCode()) {
204204
case BOOLEAN:
@@ -240,7 +240,7 @@ public static Message toDynamicMessage(RelationalStruct struct, Descriptors.Desc
240240
if (fd.getType() == Descriptors.FieldDescriptor.Type.MESSAGE) {
241241
Assert.thatUnchecked(NullableArrayUtils.isWrappedArrayDescriptor(fd.getMessageType()));
242242
// wrap array in a struct and call toDynamicMessage again
243-
final var wrapper = new ImmutableRowStruct(new ArrayRow(array), new RelationalStructMetaData(
243+
final var wrapper = new ImmutableRowStruct(new ArrayRow(array), RelationalStructMetaData.of(
244244
DataType.StructType.from("STRUCT", List.of(
245245
DataType.StructType.Field.from(NullableArrayUtils.REPEATED_FIELD_NAME, array.getMetaData().getRelationalDataType(), 0)
246246
), true)));

fdb-relational-core/src/main/java/com/apple/foundationdb/relational/recordlayer/catalog/RecordLayerStoreCatalog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ private void putSchema(@Nonnull final RecordLayerSchema schema, @Nonnull final F
410410
}
411411

412412
private static StructMetaData getMetaData(Descriptors.Descriptor descriptor) throws RelationalException {
413-
return new RelationalStructMetaData((DataType.StructType) DataTypeUtils.toRelationalType(ProtobufDdlUtil.recordFromDescriptor(descriptor)));
413+
return RelationalStructMetaData.of((DataType.StructType) DataTypeUtils.toRelationalType(ProtobufDdlUtil.recordFromDescriptor(descriptor)));
414414
}
415415

416416
@Nonnull

0 commit comments

Comments
 (0)