Skip to content

Commit 394cece

Browse files
authored
Preserve IntermingleTables flag in RecordLayerSchemaTemplate.toBuilder (#3482)
This preserves `IntermingleTables` when turning a `RecordLayerSchemaTemplate` to its `Builder`. It resolves #3483.
1 parent a2b4047 commit 394cece

File tree

2 files changed

+67
-3
lines changed

2 files changed

+67
-3
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.apple.foundationdb.relational.recordlayer.metadata.serde.RecordMetadataSerializer;
4040
import com.apple.foundationdb.relational.util.Assert;
4141

42+
import com.google.common.annotations.VisibleForTesting;
4243
import com.google.common.base.Supplier;
4344
import com.google.common.base.Suppliers;
4445
import com.google.common.collect.ImmutableList;
@@ -95,18 +96,22 @@ public final class RecordLayerSchemaTemplate implements SchemaTemplate {
9596
@Nonnull
9697
private final Supplier<String> transactionBoundMetadataSupplier;
9798

99+
private final boolean intermingleTables;
100+
98101
private RecordLayerSchemaTemplate(@Nonnull final String name,
99102
@Nonnull final Set<RecordLayerTable> tables,
100103
@Nonnull final Set<RecordLayerInvokedRoutine> invokedRoutines,
101104
int version,
102105
boolean enableLongRows,
103-
boolean storeRowVersions) {
106+
boolean storeRowVersions,
107+
boolean intermingleTables) {
104108
this.name = name;
105109
this.tables = ImmutableSet.copyOf(tables);
106110
this.invokedRoutines = ImmutableSet.copyOf(invokedRoutines);
107111
this.version = version;
108112
this.enableLongRows = enableLongRows;
109113
this.storeRowVersions = storeRowVersions;
114+
this.intermingleTables = intermingleTables;
110115
this.metaDataSupplier = Suppliers.memoize(this::buildRecordMetadata);
111116
this.tableIndexMappingSupplier = Suppliers.memoize(this::computeTableIndexMapping);
112117
this.indexesSupplier = Suppliers.memoize(this::computeIndexes);
@@ -120,13 +125,15 @@ private RecordLayerSchemaTemplate(@Nonnull final String name,
120125
int version,
121126
boolean enableLongRows,
122127
boolean storeRowVersions,
128+
boolean intermingleTables,
123129
@Nonnull final RecordMetaData cachedMetadata) {
124130
this.name = name;
125131
this.version = version;
126132
this.tables = ImmutableSet.copyOf(tables);
127133
this.invokedRoutines = ImmutableSet.copyOf(invokedRoutines);
128134
this.enableLongRows = enableLongRows;
129135
this.storeRowVersions = storeRowVersions;
136+
this.intermingleTables = intermingleTables;
130137
this.metaDataSupplier = Suppliers.memoize(() -> cachedMetadata);
131138
this.tableIndexMappingSupplier = Suppliers.memoize(this::computeTableIndexMapping);
132139
this.indexesSupplier = Suppliers.memoize(this::computeIndexes);
@@ -155,6 +162,11 @@ public boolean isStoreRowVersions() {
155162
return storeRowVersions;
156163
}
157164

165+
@VisibleForTesting
166+
public boolean isIntermingleTables() {
167+
return intermingleTables;
168+
}
169+
158170
@Nonnull
159171
@Override
160172
public Set<RecordLayerTable> getTables() {
@@ -560,10 +572,10 @@ public RecordLayerSchemaTemplate build() {
560572

561573
if (cachedMetadata != null) {
562574
return new RecordLayerSchemaTemplate(name, new LinkedHashSet<>(tables.values()),
563-
new LinkedHashSet<>(invokedRoutines.values()), version, enableLongRows, storeRowVersions, cachedMetadata);
575+
new LinkedHashSet<>(invokedRoutines.values()), version, enableLongRows, storeRowVersions, intermingleTables, cachedMetadata);
564576
} else {
565577
return new RecordLayerSchemaTemplate(name, new LinkedHashSet<>(tables.values()),
566-
new LinkedHashSet<>(invokedRoutines.values()), version, enableLongRows, storeRowVersions);
578+
new LinkedHashSet<>(invokedRoutines.values()), version, enableLongRows, storeRowVersions, intermingleTables);
567579
}
568580
}
569581

@@ -681,6 +693,7 @@ public Builder toBuilder() {
681693
.setName(name)
682694
.setVersion(version)
683695
.setEnableLongRows(enableLongRows)
696+
.setIntermingleTables(intermingleTables)
684697
.addTables(getTables())
685698
.addInvokedRoutines(getInvokedRoutines());
686699
}

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,57 @@ public void onlyQueriedSqlFunctionsAreCompiled() throws RelationalException {
433433
Assertions.assertTrue(peekingDeserializer.hasOneCompilationRequestFor("SqlFunction3"));
434434
}
435435

436+
@ParameterizedTest(name = "schema template builder preserving intermingledTables flag set to {0}")
437+
@ValueSource(booleans = {true, false})
438+
public void schemaTemplateToBuilderPreservesIntermingledTablesFlag(boolean intermingleTables) {
439+
var sampleRecordSchemaTemplate = RecordLayerSchemaTemplate.newBuilder()
440+
.setName("TestSchemaTemplate")
441+
.setVersion(42)
442+
.addAuxiliaryType(DataType.StructType.from(
443+
"Subtype",
444+
List.of(DataType.StructType.Field.from("field1", DataType.Primitives.INTEGER.type(), 0)),
445+
true))
446+
.setIntermingleTables(intermingleTables)
447+
.addTable(
448+
RecordLayerTable.newBuilder(intermingleTables)
449+
.setName("T1")
450+
.addColumn(RecordLayerColumn.newBuilder()
451+
.setName("COL1")
452+
.setDataType(
453+
DataType.StructType.from(
454+
"Subtype",
455+
List.of(DataType.StructType.Field.from("field1", DataType.Primitives.INTEGER.type(), 1)),
456+
true))
457+
.build())
458+
.build())
459+
.build();
460+
461+
// make sure the intermingleTables flag is preserved after creating the invoked routine in the builder
462+
// as well as in the built schema template.
463+
var builder = sampleRecordSchemaTemplate.toBuilder();
464+
Assertions.assertEquals(intermingleTables, builder.isIntermingleTables());
465+
sampleRecordSchemaTemplate = builder.build();
466+
Assertions.assertEquals(intermingleTables, sampleRecordSchemaTemplate.isIntermingleTables());
467+
468+
// add temporary invoked routine.
469+
builder.addInvokedRoutine(RecordLayerInvokedRoutine.newBuilder()
470+
.setName("SqlFunction1")
471+
.setDescription("CREATE FUNCTION SqlFunction1(IN Q BIGINT) AS SELECT * FROM T1 WHERE col1 < Q")
472+
.setTemporary(true)
473+
.withCompilableRoutine(CompiledFunctionStub::new)
474+
.build());
475+
476+
// build the schema template
477+
final var newSchemaTemplate = builder.build();
478+
479+
// make sure the intermingleTables flag is preserved after creating the invoked routine in the builder
480+
// as well as the built schema template.
481+
builder = newSchemaTemplate.toBuilder();
482+
Assertions.assertEquals(intermingleTables, builder.isIntermingleTables());
483+
sampleRecordSchemaTemplate = builder.build();
484+
Assertions.assertEquals(intermingleTables, sampleRecordSchemaTemplate.isIntermingleTables());
485+
}
486+
436487
@Nonnull
437488
private static RecordMetadataDeserializerWithPeekingFunctionSupplier recMetadataSampleWithFunctions(@Nonnull final String... functions) {
438489
final var schemaTemplateBuilder = RecordLayerSchemaTemplate.newBuilder()

0 commit comments

Comments
 (0)