Skip to content

Commit 57b4798

Browse files
authored
Pass in schema into summary field batch codec (#19071)
## Description This PR passes in the schema to the summary field batch codec for schema based compression in summaries.
1 parent f7a838d commit 57b4798

File tree

5 files changed

+35
-20
lines changed

5 files changed

+35
-20
lines changed

packages/dds/tree/src/feature-libraries/chunked-forest/codec/schemaBasedEncoding.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export function treeShaper(
8383
fieldHandler: FieldShaper,
8484
schemaName: TreeNodeSchemaIdentifier,
8585
): NodeShape {
86-
const schema = fullSchema.nodeSchema.get(schemaName) ?? fail("missing schema");
86+
const schema = fullSchema.nodeSchema.get(schemaName) ?? fail("missing node schema");
8787

8888
if (schema instanceof ObjectNodeStoredSchema) {
8989
// TODO:Performance:

packages/dds/tree/src/shared-tree/sharedTree.ts

+16-6
Original file line numberDiff line numberDiff line change
@@ -192,24 +192,34 @@ export class SharedTree
192192
const schemaSummarizer = new SchemaSummarizer(runtime, schema, options, {
193193
getCurrentSeq: () => this.runtime.deltaManager.lastSequenceNumber,
194194
});
195-
const fieldBatchCodec = makeFieldBatchCodec(options, {
196-
// TODO: provide schema here to enable schema based compression.
195+
const opFieldBatchCodec = makeFieldBatchCodec(options, {
196+
// TODO: Currently unsure which schema should be passed if an op contains a schema edit, so it is not enabled.
197+
// This should eventually handle that case, and pass in the correct schema accordingly.
197198
// schema: {
198199
// schema,
199200
// policy: defaultSchemaPolicy,
200201
// },
201-
encodeType: TreeCompressionStrategy.Compressed,
202+
encodeType: options.summaryEncodeType,
203+
});
204+
205+
// Separate field batch codec created as summarization does not need to handle the case of an op containing a schema edit.
206+
const summaryFieldBatchCodec = makeFieldBatchCodec(options, {
207+
schema: {
208+
schema,
209+
policy: defaultSchemaPolicy,
210+
},
211+
encodeType: options.summaryEncodeType,
202212
});
203213
const forestSummarizer = new ForestSummarizer(
204214
forest,
205215
runtime.idCompressor,
206-
fieldBatchCodec,
216+
summaryFieldBatchCodec,
207217
options,
208218
);
209219
const removedRootsSummarizer = new DetachedFieldIndexSummarizer(removedRoots);
210220
const innerChangeFamily = new SharedTreeChangeFamily(
211221
runtime.idCompressor,
212-
fieldBatchCodec,
222+
opFieldBatchCodec,
213223
options,
214224
);
215225
const changeFamily = makeMitigatedChangeFamily(
@@ -250,7 +260,7 @@ export class SharedTree
250260
changeFamily,
251261
schema,
252262
forest,
253-
fieldBatchCodec,
263+
fieldBatchCodec: opFieldBatchCodec,
254264
events: this._events,
255265
removedRoots,
256266
});

packages/dds/tree/src/shared-tree/treeCheckout.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,12 @@ export function createTreeCheckout(
195195
idCompressor,
196196
args?.fieldBatchCodec ??
197197
makeFieldBatchCodec(defaultCodecOptions, {
198-
// TODO: provide schema here to enable schema based compression.
198+
// TODO: Currently unsure which schema should be passed if an op contains a schema edit, so it is not enabled.
199+
// This should eventually handle that case, and pass in the correct schema accordingly.
200+
// schema: {
201+
// schema,
202+
// policy: defaultSchemaPolicy,
203+
// },
199204
encodeType: TreeCompressionStrategy.Compressed,
200205
}),
201206
{ jsonValidator: noopValidator },

packages/dds/tree/src/test/snapshots/files/move-across-fields-tree-0-final.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
[
129129
1,
130130
[
131-
"Node",
131+
"move-across-fields.Node",
132132
false,
133133
[
134134
"foo",
@@ -331,7 +331,7 @@
331331
[
332332
1,
333333
[
334-
"Node",
334+
"move-across-fields.Node",
335335
false,
336336
[
337337
"foo",

packages/dds/tree/src/test/snapshots/testTrees.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,18 @@ export function generateTestTrees() {
157157
const tree2 = provider.trees[1].view;
158158

159159
// NOTE: we're using the old tree editing APIs here as the new
160-
// editable-tree-2 API doesn't support cross-field moves at the
160+
// flex-tree API doesn't support cross-field moves at the
161161
// time of writing
162+
163+
const schemaBuilder = new SchemaBuilder({ scope: "move-across-fields" });
164+
const nodeSchema = schemaBuilder.object("Node", {
165+
foo: SchemaBuilder.sequence(leaf.string),
166+
bar: SchemaBuilder.sequence(leaf.string),
167+
});
168+
const rootFieldSchema = SchemaBuilder.required(nodeSchema);
169+
const schema = schemaBuilder.intoSchema(rootFieldSchema);
162170
const initialState: JsonableTree = {
163-
type: brand("Node"),
171+
type: nodeSchema.name,
164172
fields: {
165173
foo: [
166174
{ type: leaf.string.name, value: "a" },
@@ -175,14 +183,6 @@ export function generateTestTrees() {
175183
},
176184
};
177185

178-
const schemaBuilder = new SchemaBuilder({ scope: "move-across-fields" });
179-
const nodeSchema = schemaBuilder.object("Node", {
180-
foo: SchemaBuilder.sequence(leaf.string),
181-
bar: SchemaBuilder.sequence(leaf.string),
182-
});
183-
const rootFieldSchema = SchemaBuilder.required(nodeSchema);
184-
const schema = schemaBuilder.intoSchema(rootFieldSchema);
185-
186186
tree1.updateSchema(intoStoredSchema(schema));
187187

188188
// Apply an edit to the tree which inserts a node with a value

0 commit comments

Comments
 (0)