Skip to content

Commit 8ee1c54

Browse files
authored
Remove FieldDescription in Struct/ArrayMetadata in favour of DataType (#3484)
This basically #3395 put over main, minus the UUID support. I think bringing this in as a "enhancement" separately will declutter the future UUID support PR.
1 parent 0092bcd commit 8ee1c54

File tree

60 files changed

+1265
-1428
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1265
-1428
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
package com.apple.foundationdb.relational.api;
2222

2323
import com.apple.foundationdb.relational.api.exceptions.ErrorCode;
24+
import com.apple.foundationdb.relational.api.metadata.DataType;
2425

26+
import javax.annotation.Nonnull;
2527
import java.sql.SQLException;
2628
import java.sql.Wrapper;
2729

@@ -59,4 +61,13 @@ default StructMetaData getElementStructMetaData() throws SQLException {
5961
* @throws SQLException if the type of the column is not an array, or if something else goes wrong.
6062
*/
6163
ArrayMetaData getElementArrayMetaData() throws SQLException;
64+
65+
/**
66+
* Get the {@link DataType} object equivalent of this metadata.
67+
*
68+
* @return the datatype object.
69+
* @throws SQLException if something goes wrong.
70+
*/
71+
@Nonnull
72+
DataType.ArrayType asRelationalType() throws SQLException;
6273
}

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

Lines changed: 0 additions & 205 deletions
This file was deleted.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public interface RelationalArrayBuilder {
4242

4343
RelationalArrayBuilder addString(@Nonnull String value) throws SQLException;
4444

45-
RelationalArrayBuilder addLong(@Nonnull long value) throws SQLException;
45+
RelationalArrayBuilder addLong(long value) throws SQLException;
46+
47+
RelationalArrayBuilder addObject(@Nonnull Object value) throws SQLException;
4648

4749
RelationalArrayBuilder addStruct(RelationalStruct struct) throws SQLException;
4850
}

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

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,14 @@
2121
package com.apple.foundationdb.relational.api;
2222

2323
import com.apple.foundationdb.annotation.API;
24-
2524
import com.apple.foundationdb.relational.api.exceptions.ErrorCode;
2625
import com.apple.foundationdb.relational.api.exceptions.RelationalException;
27-
26+
import com.apple.foundationdb.relational.api.metadata.DataType;
2827
import com.google.common.base.Suppliers;
2928

3029
import javax.annotation.Nonnull;
30+
import java.sql.DatabaseMetaData;
3131
import java.sql.SQLException;
32-
import java.sql.Types;
3332
import java.util.Objects;
3433
import java.util.function.Supplier;
3534

@@ -39,41 +38,42 @@
3938
@API(API.Status.EXPERIMENTAL)
4039
public final class RelationalArrayMetaData implements ArrayMetaData {
4140

42-
private final FieldDescription element;
41+
private final DataType.ArrayType type;
4342

4443
private final Supplier<Integer> hashCodeSupplier;
4544

46-
private RelationalArrayMetaData(@Nonnull FieldDescription element) {
47-
this.element = element;
45+
private RelationalArrayMetaData(@Nonnull DataType.ArrayType type) {
46+
this.type = type;
4847
this.hashCodeSupplier = Suppliers.memoize(this::calculateHashCode);
4948
}
5049

51-
public static RelationalArrayMetaData ofPrimitive(int sqlType, int nullable) {
52-
return new RelationalArrayMetaData(FieldDescription.primitive("VALUE", sqlType, nullable));
53-
}
54-
55-
public static RelationalArrayMetaData ofStruct(@Nonnull StructMetaData metaData, int nullable) {
56-
return new RelationalArrayMetaData(FieldDescription.struct("VALUE", nullable, metaData));
50+
@Nonnull
51+
public static RelationalArrayMetaData of(@Nonnull DataType.ArrayType type) {
52+
return new RelationalArrayMetaData(type);
5753
}
5854

5955
@Override
60-
public int isElementNullable() throws SQLException {
61-
return element.isNullable();
56+
public int isElementNullable() {
57+
if (type.getElementType().isNullable()) {
58+
return DatabaseMetaData.columnNullable;
59+
} else {
60+
return DatabaseMetaData.columnNoNulls;
61+
}
6262
}
6363

6464
@Override
6565
public String getElementName() throws SQLException {
66-
return element.getName();
66+
return "VALUE";
6767
}
6868

6969
@Override
7070
public int getElementType() throws SQLException {
71-
return element.getSqlTypeCode();
71+
return type.getElementType().getJdbcSqlCode();
7272
}
7373

7474
@Override
75-
public String getElementTypeName() throws SQLException {
76-
return SqlTypeNamesSupport.getSqlTypeName(element.getSqlTypeCode());
75+
public String getElementTypeName() {
76+
return SqlTypeNamesSupport.getSqlTypeName(type.getElementType().getJdbcSqlCode());
7777
}
7878

7979
/**
@@ -86,10 +86,10 @@ public String getElementTypeName() throws SQLException {
8686
*/
8787
@Override
8888
public StructMetaData getElementStructMetaData() throws SQLException {
89-
if (element.getSqlTypeCode() != Types.STRUCT) {
89+
if (type.getElementType().getCode() != DataType.Code.STRUCT) {
9090
throw new RelationalException("Element is not of STRUCT type", ErrorCode.CANNOT_CONVERT_TYPE).toSqlException();
9191
}
92-
return element.getFieldMetaData();
92+
return RelationalStructMetaData.of((DataType.StructType) type.getElementType());
9393
}
9494

9595
/**
@@ -102,15 +102,21 @@ public StructMetaData getElementStructMetaData() throws SQLException {
102102
*/
103103
@Override
104104
public ArrayMetaData getElementArrayMetaData() throws SQLException {
105-
if (element.getSqlTypeCode() != Types.ARRAY) {
105+
if (type.getElementType().getCode() != DataType.Code.ARRAY) {
106106
throw new RelationalException("Element is not of ARRAY type", ErrorCode.CANNOT_CONVERT_TYPE).toSqlException();
107107
}
108-
return element.getArrayMetaData();
108+
return RelationalArrayMetaData.of((DataType.ArrayType) type.getElementType());
109+
}
110+
111+
@Nonnull
112+
@Override
113+
public DataType.ArrayType asRelationalType() throws SQLException {
114+
return type;
109115
}
110116

111117
@Nonnull
112-
public FieldDescription getElementField() {
113-
return element;
118+
public DataType getElementDataType() {
119+
return type.getElementType();
114120
}
115121

116122
@Override
@@ -132,7 +138,7 @@ public boolean equals(Object other) {
132138
if (otherMetadata == this) {
133139
return true;
134140
}
135-
return element.equals(otherMetadata.element);
141+
return type.equals(otherMetadata.type);
136142
}
137143

138144
@Override
@@ -141,7 +147,7 @@ public int hashCode() {
141147
}
142148

143149
private int calculateHashCode() {
144-
return Objects.hash(element);
150+
return Objects.hash(type);
145151
}
146152

147153
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ public interface RelationalStructBuilder {
4040

4141
RelationalStructBuilder addBoolean(String fieldName, boolean b) throws SQLException;
4242

43-
RelationalStructBuilder addShort(String fieldName, short b) throws SQLException;
44-
4543
RelationalStructBuilder addLong(String fieldName, long l) throws SQLException;
4644

4745
RelationalStructBuilder addFloat(String fieldName, float f) throws SQLException;
@@ -52,7 +50,7 @@ public interface RelationalStructBuilder {
5250

5351
RelationalStructBuilder addString(String fieldName, @Nullable String s) throws SQLException;
5452

55-
RelationalStructBuilder addObject(String fieldName, @Nullable Object obj, int targetSqlType) throws SQLException;
53+
RelationalStructBuilder addObject(String fieldName, @Nullable Object obj) throws SQLException;
5654

5755
RelationalStructBuilder addStruct(String fieldName, @Nonnull RelationalStruct struct) throws SQLException;
5856

0 commit comments

Comments
 (0)