Skip to content

Commit 32d0c95

Browse files
authored
Add support for NULL type fields in ExecuteInsert (#3490)
This PR adds support for inserting structs with NULL typed fields into the table via `ExecuteInsert` in the Direct Access API. Also adds a test for the same. This bug was introduced by #3484, which essentially shifts the Relational-layer from using Sql Type codes for internal operations to relying on Relational DataTypes for getting a richer information. Fixes: #3491
1 parent 12005f4 commit 32d0c95

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ public static Message toDynamicMessage(RelationalStruct struct, Descriptors.Desc
250250
}
251251
}
252252
break;
253+
case NULL:
254+
break;
253255
default:
254256
Assert.failUnchecked(ErrorCode.INTERNAL_ERROR, (String.format(Locale.ROOT, "Unexpected Column type <%s> for column <%s>",
255257
struct.getMetaData().getColumnType(i), columnName)));

fdb-relational-core/src/test/java/com/apple/foundationdb/relational/recordlayer/SimpleDirectAccessInsertionTests.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,31 @@ void insertNestedFields() throws SQLException {
146146
}
147147
}
148148

149+
@Test
150+
void insertWithExplicitNullFields() throws SQLException {
151+
try (RelationalConnection conn = DriverManager.getConnection("jdbc:embed://" + db.getDatabasePath().getPath()).unwrap(RelationalConnection.class)) {
152+
conn.setSchema(db.getSchemaName());
153+
154+
try (RelationalStatement s = conn.createStatement()) {
155+
final var struct = EmbeddedRelationalStruct.newBuilder()
156+
.addLong("ID", 1L)
157+
.addString("NAME", "Anthony Bourdain")
158+
.addObject("EMAIL", null)
159+
.build();
160+
int inserted = s.executeInsert("RESTAURANT_REVIEWER", struct);
161+
Assertions.assertThat(inserted).withFailMessage("incorrect insertion number!").isEqualTo(1);
162+
KeySet key = new KeySet()
163+
.setKeyColumn("ID", 1L);
164+
try (RelationalResultSet rrs = s.executeGet("RESTAURANT_REVIEWER", key, Options.NONE)) {
165+
ResultSetAssert.assertThat(rrs)
166+
.hasNextRow()
167+
.hasColumn("EMAIL", null)
168+
.hasNoNextRow();
169+
}
170+
}
171+
}
172+
}
173+
149174
@Test
150175
void insertMultipleTablesDontMix() throws SQLException {
151176
/*

0 commit comments

Comments
 (0)