diff --git a/docs/ReleaseNotes.md b/docs/ReleaseNotes.md index ed2262b5de..1b68f51f39 100644 --- a/docs/ReleaseNotes.md +++ b/docs/ReleaseNotes.md @@ -30,7 +30,7 @@ Users performing online updates are encouraged to update from [4.0.559.4](#40559 * **Performance** Improvement 4 [(Issue #NNN)](https://github.com/FoundationDB/fdb-record-layer/issues/NNN) * **Performance** Improvement 5 [(Issue #NNN)](https://github.com/FoundationDB/fdb-record-layer/issues/NNN) * **Feature** Feature 1 [(Issue #NNN)](https://github.com/FoundationDB/fdb-record-layer/issues/NNN) -* **Feature** Feature 2 [(Issue #NNN)](https://github.com/FoundationDB/fdb-record-layer/issues/NNN) +* **Feature** Add enum column support to relational server [(Issue #3073)](https://github.com/FoundationDB/fdb-record-layer/issues/3073) * **Feature** Feature 3 [(Issue #NNN)](https://github.com/FoundationDB/fdb-record-layer/issues/NNN) * **Feature** Feature 4 [(Issue #NNN)](https://github.com/FoundationDB/fdb-record-layer/issues/NNN) * **Feature** Feature 5 [(Issue #NNN)](https://github.com/FoundationDB/fdb-record-layer/issues/NNN) diff --git a/fdb-relational-grpc/src/main/java/com/apple/foundationdb/relational/jdbc/RelationalResultSetFacade.java b/fdb-relational-grpc/src/main/java/com/apple/foundationdb/relational/jdbc/RelationalResultSetFacade.java index 24af60488c..1e699b0ad5 100644 --- a/fdb-relational-grpc/src/main/java/com/apple/foundationdb/relational/jdbc/RelationalResultSetFacade.java +++ b/fdb-relational-grpc/src/main/java/com/apple/foundationdb/relational/jdbc/RelationalResultSetFacade.java @@ -320,6 +320,11 @@ public Object getObject(int oneBasedColumn) throws SQLException { int index = PositionalIndex.toProtobuf(oneBasedColumn); Column column = this.delegate.getRow(rowIndex).getColumns().getColumn(index); return column == null || !column.hasBinary() ? null : column.getBinary().toByteArray(); + case Types.OTHER: + // Probably an enum, it's not clear exactly how we should handle this, but we currently only have one + // thing which appears as OTHER + o = getString(oneBasedColumn); + break; default: throw new SQLException("Unsupported type " + type); } diff --git a/fdb-relational-grpc/src/main/java/com/apple/foundationdb/relational/jdbc/TypeConversion.java b/fdb-relational-grpc/src/main/java/com/apple/foundationdb/relational/jdbc/TypeConversion.java index bef4cb0759..2b14f74bc1 100644 --- a/fdb-relational-grpc/src/main/java/com/apple/foundationdb/relational/jdbc/TypeConversion.java +++ b/fdb-relational-grpc/src/main/java/com/apple/foundationdb/relational/jdbc/TypeConversion.java @@ -283,6 +283,21 @@ private static Column toColumn(RelationalStruct relationalStruct, int oneBasedIn column = toColumn(relationalStruct.wasNull() ? null : d, (a, b) -> a == null ? b.clearDouble() : b.setDouble(a)); break; + case Types.OTHER: + final Object object = relationalStruct.getObject(oneBasedIndex); + if (object instanceof String) { + // an enum. Enums are effectively just strings with a constraint, but this is how some other + // databases support them. + column = toColumn(relationalStruct.wasNull() ? null : (String) object, + (value, protobuf) -> value == null ? protobuf.clearString() : protobuf.setString(value)); + break; + } + if (object == null) { + column = toColumn(null, (value, protobuf) -> protobuf.clearString()); + break; + } + throw new SQLException("java.sql.Type=" + columnType + " not supported with " + object.getClass(), + ErrorCode.UNSUPPORTED_OPERATION.getErrorCode()); default: throw new SQLException("java.sql.Type=" + columnType + " not supported", ErrorCode.UNSUPPORTED_OPERATION.getErrorCode()); diff --git a/yaml-tests/src/test/java/YamlIntegrationTests.java b/yaml-tests/src/test/java/YamlIntegrationTests.java index e8757de0e7..f4875705dc 100644 --- a/yaml-tests/src/test/java/YamlIntegrationTests.java +++ b/yaml-tests/src/test/java/YamlIntegrationTests.java @@ -251,9 +251,6 @@ void arrays(YamlTest.Runner runner) throws Exception { } @TestTemplate - @ExcludeYamlTestConfig( - value = YamlTestConfigFilters.DO_NOT_USE_JDBC, - reason = "JDBC does not support enums") public void insertEnum(YamlTest.Runner runner) throws Exception { runner.runYamsql("insert-enum.yamsql"); } @@ -303,7 +300,6 @@ public void recursiveCte(YamlTest.Runner runner) throws Exception { } @TestTemplate - @ExcludeYamlTestConfig(value = YamlTestConfigFilters.DO_NOT_USE_JDBC, reason = "JDBC does not support enums") public void enumTest(YamlTest.Runner runner) throws Exception { runner.runYamsql("enum.yamsql"); } diff --git a/yaml-tests/src/test/resources/enum.yamsql b/yaml-tests/src/test/resources/enum.yamsql index 66e6e775bf..5f02b209a5 100644 --- a/yaml-tests/src/test/resources/enum.yamsql +++ b/yaml-tests/src/test/resources/enum.yamsql @@ -16,7 +16,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +--- +options: + supported_version: !current_version --- schema_template: CREATE TYPE AS ENUM MOOD ( 'JOYFUL', 'HAPPY', 'RELAXED', 'INDIFFERENT', 'CONFUSED', 'SAD', 'ANXIOUS', 'ANGRY' ) diff --git a/yaml-tests/src/test/resources/insert-enum.yamsql b/yaml-tests/src/test/resources/insert-enum.yamsql index 4398a42da6..56e944bed3 100644 --- a/yaml-tests/src/test/resources/insert-enum.yamsql +++ b/yaml-tests/src/test/resources/insert-enum.yamsql @@ -16,7 +16,9 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - +--- +options: + supported_version: !current_version --- schema_template: CREATE TYPE AS ENUM "WHATEVER" ( 'OWNING', 'WEAK', 'VALIDATING' )