Repository navigation
perf(client-engine): split render and data-mapper prerequisites #29658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tensordreams
wants to merge
12
commits into
v7
Choose a base branch
from
prisma-client-perf-render-datamapper-prereqs
base: v7
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
fa2c9d0
Fast path static template SQL rendering
tensordreams 1627893
Cache flat template SQL rendering
tensordreams 7e24d71
Render tuple placeholders without map joins
tensordreams e12f0aa
Inline non-flat SQL template rendering
tensordreams dbc06eb
Inline SQL template chunk planning
tensordreams 992da56
Skip chunk rebuild within parameter limit
tensordreams 7f2f126
Map simple query results directly
tensordreams ab18214
Reuse direct mapper field entries
tensordreams a7e032d
Cache direct result field mappings
tensordreams a41a0e7
Cache result mappings by column shape
tensordreams dd27a35
test(client-engine): cover direct nested result mapping
tensordreams 5696906
refactor(client-engine): reuse query execution helper
tensordreams File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
packages/client-engine-runtime/src/interpreter/data-mapper.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| import { ColumnTypeEnum } from '@prisma/driver-adapter-utils' | ||
| import { expect, test } from 'vitest' | ||
|
|
||
| import type { ResultNode } from '../query-plan' | ||
| import { applyDataMap, applyDataMapToResultSet, DataMapperError } from './data-mapper' | ||
| import { serializeSql } from './serialize-sql' | ||
|
|
||
| test('maps result sets directly like serialized SQL rows', () => { | ||
| const resultSet = { | ||
| columnTypes: [ColumnTypeEnum.Int32, ColumnTypeEnum.Text], | ||
| columnNames: ['id', 'name'], | ||
| rows: [ | ||
| [1, 'Alice'], | ||
| [2, 'Bob'], | ||
| ], | ||
| } | ||
| const structure = { | ||
| type: 'object', | ||
| serializedName: null, | ||
| skipNulls: false, | ||
| fields: { | ||
| id: { type: 'field', dbName: 'id', fieldType: { type: 'int', arity: 'scalar' } }, | ||
| name: { type: 'field', dbName: 'name', fieldType: { type: 'string', arity: 'scalar' } }, | ||
| }, | ||
| } satisfies ResultNode | ||
|
|
||
| expect(applyDataMapToResultSet(resultSet, structure, {})).toEqual( | ||
| applyDataMap(serializeSql(resultSet), structure, {}), | ||
| ) | ||
| }) | ||
|
|
||
| test('direct result-set mapping uses the last duplicate column name', () => { | ||
| const resultSet = { | ||
| columnTypes: [ColumnTypeEnum.Int32, ColumnTypeEnum.Int32], | ||
| columnNames: ['id', 'id'], | ||
| rows: [[1, 2]], | ||
| } | ||
| const structure = { | ||
| type: 'object', | ||
| serializedName: null, | ||
| skipNulls: false, | ||
| fields: { | ||
| id: { type: 'field', dbName: 'id', fieldType: { type: 'int', arity: 'scalar' } }, | ||
| }, | ||
| } satisfies ResultNode | ||
|
|
||
| expect(applyDataMapToResultSet(resultSet, structure, {})).toEqual( | ||
| applyDataMap(serializeSql(resultSet), structure, {}), | ||
| ) | ||
| }) | ||
|
|
||
| test('maps nested row objects directly like serialized SQL rows', () => { | ||
| const resultSet = { | ||
| columnTypes: [ColumnTypeEnum.Int32, ColumnTypeEnum.Text], | ||
| columnNames: ['id', 'author_name'], | ||
| rows: [[1, 'Alice']], | ||
| } | ||
| const structure = { | ||
| type: 'object', | ||
| serializedName: null, | ||
| skipNulls: false, | ||
| fields: { | ||
| id: { type: 'field', dbName: 'id', fieldType: { type: 'int', arity: 'scalar' } }, | ||
| author: { | ||
| type: 'object', | ||
| serializedName: null, | ||
| skipNulls: false, | ||
| fields: { | ||
| name: { type: 'field', dbName: 'author_name', fieldType: { type: 'string', arity: 'scalar' } }, | ||
| }, | ||
| }, | ||
| }, | ||
| } satisfies ResultNode | ||
|
|
||
| expect(applyDataMapToResultSet(resultSet, structure, {})).toEqual( | ||
| applyDataMap(serializeSql(resultSet), structure, {}), | ||
| ) | ||
| }) | ||
|
|
||
| test('maps JSON value objects directly like serialized SQL rows', () => { | ||
| const resultSet = { | ||
| columnTypes: [ColumnTypeEnum.Json], | ||
| columnNames: ['profile'], | ||
| rows: [['{"display_name":"Alice"}']], | ||
| } | ||
| const structure = { | ||
| type: 'object', | ||
| serializedName: null, | ||
| skipNulls: false, | ||
| fields: { | ||
| profile: { | ||
| type: 'object', | ||
| serializedName: 'profile', | ||
| skipNulls: false, | ||
| fields: { | ||
| displayName: { type: 'field', dbName: 'display_name', fieldType: { type: 'string', arity: 'scalar' } }, | ||
| }, | ||
| }, | ||
| }, | ||
| } satisfies ResultNode | ||
|
|
||
| expect(applyDataMapToResultSet(resultSet, structure, {})).toEqual( | ||
| applyDataMap(serializeSql(resultSet), structure, {}), | ||
| ) | ||
| }) | ||
|
|
||
| test('throws DataMapperError when a mapped column is missing from the result set', () => { | ||
| const resultSet = { | ||
| columnTypes: [ColumnTypeEnum.Int32], | ||
| columnNames: ['id'], | ||
| rows: [[1]], | ||
| } | ||
| const structure = { | ||
| type: 'object', | ||
| serializedName: null, | ||
| skipNulls: false, | ||
| fields: { | ||
| name: { type: 'field', dbName: 'name', fieldType: { type: 'string', arity: 'scalar' } }, | ||
| }, | ||
| } satisfies ResultNode | ||
|
|
||
| expect(() => applyDataMapToResultSet(resultSet, structure, {})).toThrowError(DataMapperError) | ||
| }) | ||
|
|
||
| test('direct result-set mapping caches independently for different column orders', () => { | ||
| const structure = { | ||
| type: 'object', | ||
| serializedName: null, | ||
| skipNulls: false, | ||
| fields: { | ||
| id: { type: 'field', dbName: 'id', fieldType: { type: 'int', arity: 'scalar' } }, | ||
| name: { type: 'field', dbName: 'name', fieldType: { type: 'string', arity: 'scalar' } }, | ||
| }, | ||
| } satisfies ResultNode | ||
|
|
||
| expect( | ||
| applyDataMapToResultSet( | ||
| { | ||
| columnTypes: [ColumnTypeEnum.Int32, ColumnTypeEnum.Text], | ||
| columnNames: ['id', 'name'], | ||
| rows: [[1, 'Alice']], | ||
| }, | ||
| structure, | ||
| {}, | ||
| ), | ||
| ).toEqual([{ id: 1, name: 'Alice' }]) | ||
|
|
||
| expect( | ||
| applyDataMapToResultSet( | ||
| { | ||
| columnTypes: [ColumnTypeEnum.Text, ColumnTypeEnum.Int32], | ||
| columnNames: ['name', 'id'], | ||
| rows: [['Bob', 2]], | ||
| }, | ||
| structure, | ||
| {}, | ||
| ), | ||
| ).toEqual([{ id: 2, name: 'Bob' }]) | ||
| }) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.