Skip to content

Commit

Permalink
feat: update simplified schema to sort the types by the most frequent…
Browse files Browse the repository at this point in the history
… first COMPASS-7139 (#209)
  • Loading branch information
Anemy authored Nov 6, 2023
1 parent ac1616d commit 376d199
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/schema-analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,12 @@ export type SimplifiedSchema = {

function simplifiedSchema(fields: SchemaAnalysisFieldsMap): SimplifiedSchema {
function finalizeSchemaFieldTypes(types: SchemaAnalysisFieldTypes): SimplifiedSchemaType[] {
return Object.values(types).map((type) => {
return Object.values(types).sort(
(a: SchemaAnalysisType, b: SchemaAnalysisType) => {
// Sort the types by what occurs most frequent first.
return b.count - a.count;
}
).map((type: SchemaAnalysisType) => {
return {
bsonType: type.bsonType, // Note: `Object` is replaced with `Document`.
...(isArrayType(type) ? {
Expand Down
4 changes: 2 additions & 2 deletions test/simplified-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import { allBSONTypesDoc } from './all-bson-types-fixture';
const docsFixture = [
{
foo: 1,
bar: 'test'
bar: 25
},
{
foo: 2,
bar: 25,
bar: 'test',
baz: true
},
{
Expand Down

0 comments on commit 376d199

Please sign in to comment.