Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
import com.apple.foundationdb.record.RecordCoreException;
import com.apple.foundationdb.record.RecordCursor;
import com.apple.foundationdb.record.RecordMetaData;
import com.apple.foundationdb.record.RecordMetaDataOptionsProto;

Check notice on line 31 in fdb-relational-core/src/main/java/com/apple/foundationdb/relational/recordlayer/RecordTypeTable.java

View workflow job for this annotation

GitHub Actions / coverage

File coverage: 88.3% (144/163 lines) | Changed lines: 100.0% (7/7 lines)
import com.apple.foundationdb.record.TupleFieldsProto;
import com.apple.foundationdb.record.TupleRange;
import com.apple.foundationdb.record.metadata.MetaDataException;
import com.apple.foundationdb.record.metadata.RecordType;
Expand Down Expand Up @@ -228,6 +229,16 @@
builder.setField(fd, ByteString.copyFrom(bytes));
}
break;
case UUID:
final var uuid = struct.getUUID(i + 1);
if (uuid != null) {
builder.setField(fd,
TupleFieldsProto.UUID.newBuilder()
.setMostSignificantBits(uuid.getMostSignificantBits())
.setLeastSignificantBits(uuid.getLeastSignificantBits())
.build());
}
break;
case STRUCT:
var subStruct = struct.getStruct(i + 1);
if (subStruct != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* TableSerDeTest.java
*
* This source file is part of the FoundationDB open source project
*
* Copyright 2015-2026 Apple Inc. and the FoundationDB project authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.
*/

package com.apple.foundationdb.relational.recordlayer;

import com.apple.foundationdb.relational.api.EmbeddedRelationalStruct;
import com.apple.foundationdb.relational.api.KeySet;
import com.apple.foundationdb.relational.api.Options;
import com.apple.foundationdb.relational.api.RelationalResultSet;
import com.apple.foundationdb.relational.api.RelationalStatement;
import com.apple.foundationdb.relational.utils.ResultSetAssert;
import com.apple.foundationdb.relational.utils.SimpleDatabaseRule;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.sql.SQLException;
import java.util.Map;
import java.util.UUID;

/**
* Tests for serializing and deserializing {@link RecordTypeTable}s.
*/
class RecordTypeTableSerDeTest {
@RegisterExtension
@Order(0)
public final EmbeddedRelationalExtension relationalExtension = new EmbeddedRelationalExtension();

@RegisterExtension
@Order(1)
public final SimpleDatabaseRule db = new SimpleDatabaseRule(RecordTypeTableSerDeTest.class,
"""
CREATE TABLE t1(a bigint, b string, c bytes, d boolean, e integer, f float, g double, h uuid, PRIMARY KEY(a))
""");

@RegisterExtension
@Order(2)
public final RelationalConnectionRule connection = new RelationalConnectionRule(db::getConnectionUri)
.withOptions(Options.NONE)
.withSchema(db.getSchemaName());

private void roundTripT1(Map<String, Object> fieldData) throws SQLException {
try (RelationalStatement statement = connection.createStatement()) {
var builder = EmbeddedRelationalStruct.newBuilder();
for (Map.Entry<String, Object> entry : fieldData.entrySet()) {
builder.addObject(entry.getKey(), entry.getValue());
}
statement.executeInsert("T1", builder.build());
try (RelationalResultSet getRes = statement.executeGet("T1", new KeySet().setKeyColumn("A", fieldData.get("A")), Options.NONE)) {
ResultSetAssert.assertThat(getRes)
.hasNextRow()
.row()
.containsColumnsByName(fieldData);
ResultSetAssert.assertThat(getRes).hasNoNextRow();
}
}
}

@Test
void setLongKey() throws SQLException {
roundTripT1(Map.of("A", 100L));
}

@Test
void setString() throws SQLException {
roundTripT1(Map.of("A", 101L, "B", "hello"));
}

@Test
void setBytes() throws SQLException {
roundTripT1(Map.of("A", 102L, "C", new byte[]{0x01, 0x02}));
}

@Test
void setBoolean() throws SQLException {
roundTripT1(Map.of("A", 103L, "D", true));
}

@Test
void setInt() throws SQLException {
roundTripT1(Map.of("A", 104L, "E", 42));
}

@Test
void setFloat() throws SQLException {
roundTripT1(Map.of("A", 105L, "F", 3.14f));
}

@Test
void setDouble() throws SQLException {
roundTripT1(Map.of("A", 106L, "G", 2.72d));
}

@Test
void setUuid() throws SQLException {
roundTripT1(Map.of("A", 107L, "H", UUID.randomUUID()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.UUID;

public class UniqueIndexTests {

Expand All @@ -53,9 +54,10 @@
CREATE TABLE T3(t3_p bigint, t3_a bigint, t3_b bigint, primary key(t3_p))
CREATE UNIQUE INDEX mv3 AS SELECT t3_a FROM t3
CREATE UNIQUE INDEX mv4 AS SELECT t3_b FROM t3
CREATE TYPE AS STRUCT ST1(st1_a bigint)
CREATE TYPE AS STRUCT ST1(st1_a bigint, st1_b uuid)
CREATE TABLE T4(t4_p bigint, t4_st1 st1 array, primary key(t4_p))
CREATE UNIQUE INDEX mv5 AS SELECT v.st1_a from t4 t, (SELECT u.st1_a from t.t4_st1 u) v
CREATE UNIQUE INDEX mv5b AS SELECT v.st1_b from t4 t, (SELECT u.st1_b from t.t4_st1 u) v
CREATE TABLE T5(t5_p bigint, t5_a bigint, t5_b bigint, t5_c bigint, t5_d bigint, primary key(t5_p))
CREATE UNIQUE INDEX mv6 AS SELECT t5_a, t5_b, t5_c, t5_d from t5 order by t5_d, t5_c
""";
Expand Down Expand Up @@ -210,6 +212,33 @@
checkErrorOnNonUniqueInsertionsToTable(nonUniqueRecord, "T4");
}

@Test
public void insertToArrayNestedUuidFieldMarkedUnique() throws Exception {

Check warning on line 216 in fdb-relational-core/src/test/java/com/apple/foundationdb/relational/recordlayer/UniqueIndexTests.java

View check run for this annotation

fdb.teamscale.io / Teamscale | Findings

fdb-relational-core/src/test/java/com/apple/foundationdb/relational/recordlayer/UniqueIndexTests.java#L216

[New] `insertToArrayNestedUuidFieldMarkedUnique` should have package visibility https://fdb.teamscale.io/findings/details/foundationdb-fdb-record-layer?id=5BE8DB9C1066431987D9F0C3904DE115&t=FORK_MR%2F4243%2Falecgrieser%2F04240-struct-to-dynamic-message-uuid%3AHEAD
final var records = new ArrayList<RelationalStruct>();
final UUID nonUniqueUuid = UUID.randomUUID();
for (var i = 0; i < 5; i++) {
var builder = EmbeddedRelationalStruct.newBuilder();
builder.addLong("T4_P", i);
var ST1ArrayBuilder = EmbeddedRelationalArray.newBuilder();
for (var j = 0; j < 5; j++) {
ST1ArrayBuilder.addStruct(EmbeddedRelationalStruct.newBuilder().addUuid("ST1_B", (i == 2 && j == 3) ? nonUniqueUuid : UUID.randomUUID()).build());
}
builder.addArray("T4_ST1", ST1ArrayBuilder.build());
records.add(builder.build());
}
insertUniqueRecordsToTable(records, "T4");
final var nonUniqueRecord = List.of(EmbeddedRelationalStruct.newBuilder()
.addLong("T4_P", 5)
.addArray("T4_ST1", EmbeddedRelationalArray.newBuilder()
.addStruct(EmbeddedRelationalStruct.newBuilder()
.addUuid("ST1_B", nonUniqueUuid)
.build()
).build()
).build()
);
checkErrorOnNonUniqueInsertionsToTable(nonUniqueRecord, "T4");
}

@Test
public void insertToTableWithUniqueCoveringIndexWithValueExp() throws Exception {
final var uniqueOnARecords = new ArrayList<RelationalStruct>();
Expand Down
Loading