-
Notifications
You must be signed in to change notification settings - Fork 3
Array resolution #163
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
Merged
Merged
Array resolution #163
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
ced5484
phase 1 changes
senthilb-devrev d065d22
phase 2 changes
senthilb-devrev c1f0d40
phase 3 complete and working
senthilb-devrev 0396184
working with array + scalar resolution
senthilb-devrev 11f30ec
working with only a scalar resolution field
senthilb-devrev c24c8a1
updating in meerkat browser
senthilb-devrev 13b7f72
re-using dimensions instead of re-creating it
senthilb-devrev 32f0d90
minor refactoring
senthilb-devrev c00155e
minor update
senthilb-devrev 7600c52
unnest working as expected
senthilb-devrev 75889b0
working properly
senthilb-devrev dffc096
working properly
senthilb-devrev 4f063ff
working again
senthilb-devrev 94a1e10
moving everything to browser too
senthilb-devrev 2f077b1
mionr refactoring working
senthilb-devrev c273540
final changes after testing and copy pasting same code from browser i…
senthilb-devrev 06662f5
minor refactoring
senthilb-devrev 9bb01ad
udpated tests for resolution.ts
senthilb-devrev 2b7a570
adding a test
senthilb-devrev d2c4fba
Merge remote-tracking branch 'refs/remotes/origin/main'
senthilb-devrev 95beab1
ensuring we are having the same order by using row_id
senthilb-devrev 4ae0e4e
final ordering changes for row number
senthilb-devrev 086736b
minor
senthilb-devrev 2f27183
final tests
senthilb-devrev 6f27e74
fixed final tests
senthilb-devrev 804383c
fixing test
senthilb-devrev 61d6bde
cr comments
senthilb-devrev 34ae940
moving code into dependent files for better readability
senthilb-devrev b72c658
moving to use a merged flow
senthilb-devrev 30f63dc
changes after testing
senthilb-devrev 1cb3e1b
fixing lint error
senthilb-devrev c8c7f61
cr comments
senthilb-devrev b236c78
changing type of resolutionConfig isArrayType
senthilb-devrev 2f350b7
minor updates
senthilb-devrev 46d4884
splitting resolution file into multiple generators
senthilb-devrev 4a32ce4
minor update
senthilb-devrev aca247b
cr comments
senthilb-devrev 5b33f51
updating package version for meerkat-core
senthilb-devrev a6351cc
added a todo
senthilb-devrev 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
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
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
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 @@ | ||
| export const ROW_ID_DIMENSION_NAME = '__row_id'; | ||
152 changes: 82 additions & 70 deletions
152
...ore/src/get-wrapped-base-query-with-projections/__tests__/sql-expression-modifier.spec.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 |
|---|---|---|
| @@ -1,130 +1,142 @@ | ||
| import { Dimension } from '../../types/cube-types/table'; | ||
| import { isArrayTypeMember } from '../../utils/is-array-member-type'; | ||
| import { arrayFieldUnNestModifier, DimensionModifier, getModifiedSqlExpression, MODIFIERS, shouldUnnest } from "../sql-expression-modifiers"; | ||
| import { | ||
| arrayFieldUnNestModifier, | ||
| shouldUnnest, | ||
| } from '../modifiers/array-unnest-modifier'; | ||
| import { | ||
| getModifiedSqlExpression, | ||
| MODIFIERS, | ||
| } from '../sql-expression-modifiers'; | ||
| import { DimensionModifier } from '../types'; | ||
|
|
||
| jest.mock("../../utils/is-array-member-type", () => { | ||
| jest.mock('../../utils/is-array-member-type', () => { | ||
| return { | ||
| isArrayTypeMember: jest.fn() | ||
| } | ||
| isArrayTypeMember: jest.fn(), | ||
| }; | ||
| }); | ||
|
|
||
| const QUERY = { | ||
| measures: ["test_measure"], | ||
| dimensions: ["test_dimension"] | ||
| } | ||
| measures: ['test_measure'], | ||
| dimensions: ['test_dimension'], | ||
| }; | ||
|
|
||
| describe("Dimension Modifier", () => { | ||
| describe("arrayFieldUnNestModifier", () => { | ||
| it("should return the correct unnested SQL expression", () => { | ||
| describe('Dimension Modifier', () => { | ||
| describe('arrayFieldUnNestModifier', () => { | ||
| it('should return the correct unnested SQL expression', () => { | ||
| const modifier: DimensionModifier = { | ||
| sqlExpression: "some_array_field", | ||
| sqlExpression: 'some_array_field', | ||
| dimension: {} as Dimension, | ||
| key: "test_key", | ||
| query: QUERY | ||
| key: 'test_key', | ||
| query: QUERY, | ||
| }; | ||
| expect(arrayFieldUnNestModifier(modifier)).toBe("array[unnest(some_array_field)]"); | ||
| expect(arrayFieldUnNestModifier(modifier)).toBe( | ||
| 'array[unnest(some_array_field)]' | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe("shouldUnnest", () => { | ||
| it("should return true when dimension is array type and has shouldUnnestGroupBy modifier", () => { | ||
| describe('shouldUnnest', () => { | ||
| it('should return true when dimension is array type and has shouldUnnestGroupBy modifier', () => { | ||
| (isArrayTypeMember as jest.Mock).mockReturnValue(true); | ||
| const modifier: DimensionModifier = { | ||
| sqlExpression: "some_expression", | ||
| dimension: { | ||
| type: "array", | ||
| modifier: { shouldUnnestGroupBy: true } | ||
| sqlExpression: 'some_expression', | ||
| dimension: { | ||
| type: 'array', | ||
| modifier: { shouldUnnestGroupBy: true }, | ||
| } as Dimension, | ||
| key: "test_key", | ||
| query: QUERY | ||
| key: 'test_key', | ||
| query: QUERY, | ||
| }; | ||
| expect(shouldUnnest(modifier)).toBe(true); | ||
| }); | ||
|
|
||
| it("should return false when dimension is not array type", () => { | ||
| it('should return false when dimension is not array type', () => { | ||
| (isArrayTypeMember as jest.Mock).mockReturnValue(false); | ||
| const modifier: DimensionModifier = { | ||
| sqlExpression: "some_expression", | ||
| dimension: { | ||
| type: "string", | ||
| modifier: { shouldUnnestGroupBy: true } | ||
| sqlExpression: 'some_expression', | ||
| dimension: { | ||
| type: 'string', | ||
| modifier: { shouldUnnestGroupBy: true }, | ||
| } as Dimension, | ||
| key: "test_key", | ||
| query: QUERY | ||
| key: 'test_key', | ||
| query: QUERY, | ||
| }; | ||
| expect(shouldUnnest(modifier)).toBe(false); | ||
| }); | ||
|
|
||
| it("should return false when dimension doesn't have shouldUnnestGroupBy modifier", () => { | ||
| (isArrayTypeMember as jest.Mock).mockReturnValue(true); | ||
| const modifier: DimensionModifier = { | ||
| sqlExpression: "some_expression", | ||
| dimension: { | ||
| type: "array", | ||
| modifier: {} | ||
| sqlExpression: 'some_expression', | ||
| dimension: { | ||
| type: 'array', | ||
| modifier: {}, | ||
| } as Dimension, | ||
| key: 'test_key', | ||
| query: QUERY, | ||
| }; | ||
| expect(shouldUnnest(modifier)).toBe(false); | ||
| }); | ||
| it('should return false when dimension when modifier undefined', () => { | ||
| (isArrayTypeMember as jest.Mock).mockReturnValue(true); | ||
| const modifier: DimensionModifier = { | ||
| sqlExpression: 'some_expression', | ||
| dimension: { | ||
| type: 'array', | ||
| } as Dimension, | ||
| key: "test_key", | ||
| query: QUERY | ||
| key: 'test_key', | ||
| query: QUERY, | ||
| }; | ||
| expect(shouldUnnest(modifier)).toBe(false); | ||
| }); | ||
| it("should return false when dimension when modifier undefined", () => { | ||
| (isArrayTypeMember as jest.Mock).mockReturnValue(true); | ||
| const modifier: DimensionModifier = { | ||
| sqlExpression: "some_expression", | ||
| dimension: { | ||
| type: "array", | ||
| } as Dimension, | ||
| key: "test_key", | ||
| query: QUERY | ||
| }; | ||
| expect(shouldUnnest(modifier)).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("getModifiedSqlExpression", () => { | ||
| it("should not modify if no modifiers passed", () => { | ||
| describe('getModifiedSqlExpression', () => { | ||
| it('should not modify if no modifiers passed', () => { | ||
| (isArrayTypeMember as jest.Mock).mockReturnValue(true); | ||
| const input = { | ||
| sqlExpression: "array_field", | ||
| sqlExpression: 'array_field', | ||
| dimension: { | ||
| type: "array", | ||
| modifier: { shouldUnnestGroupBy: true } | ||
| type: 'array', | ||
| modifier: { shouldUnnestGroupBy: true }, | ||
| } as Dimension, | ||
| query: QUERY, | ||
| key: "test_key", | ||
| modifiers: [] | ||
| key: 'test_key', | ||
| modifiers: [], | ||
| }; | ||
| expect(getModifiedSqlExpression(input)).toBe("array_field"); | ||
| expect(getModifiedSqlExpression(input)).toBe('array_field'); | ||
| }); | ||
| it("should apply the modifier when conditions are met", () => { | ||
| it('should apply the modifier when conditions are met', () => { | ||
| (isArrayTypeMember as jest.Mock).mockReturnValue(true); | ||
| const input = { | ||
| sqlExpression: "array_field", | ||
| sqlExpression: 'array_field', | ||
| dimension: { | ||
| type: "array", | ||
| modifier: { shouldUnnestGroupBy: true } | ||
| type: 'array', | ||
| modifier: { shouldUnnestGroupBy: true }, | ||
| } as Dimension, | ||
| query: QUERY, | ||
| key: "test_key", | ||
| modifiers: MODIFIERS | ||
| key: 'test_key', | ||
| modifiers: MODIFIERS, | ||
| }; | ||
| expect(getModifiedSqlExpression(input)).toBe("array[unnest(array_field)]"); | ||
| expect(getModifiedSqlExpression(input)).toBe( | ||
| 'array[unnest(array_field)]' | ||
| ); | ||
| }); | ||
|
|
||
| it("should not apply the modifier when conditions are not met", () => { | ||
| it('should not apply the modifier when conditions are not met', () => { | ||
| (isArrayTypeMember as jest.Mock).mockReturnValue(false); | ||
| const input = { | ||
| sqlExpression: "non_array_field", | ||
| sqlExpression: 'non_array_field', | ||
| dimension: { | ||
| type: "string", | ||
| modifier: {} | ||
| type: 'string', | ||
| modifier: {}, | ||
| } as Dimension, | ||
| query: QUERY, | ||
| key: "test_key", | ||
| modifiers: MODIFIERS | ||
| key: 'test_key', | ||
| modifiers: MODIFIERS, | ||
| }; | ||
| expect(getModifiedSqlExpression(input)).toBe("non_array_field"); | ||
| expect(getModifiedSqlExpression(input)).toBe('non_array_field'); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
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
6 changes: 6 additions & 0 deletions
6
meerkat-core/src/get-wrapped-base-query-with-projections/index.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,6 @@ | ||
| export { getWrappedBaseQueryWithProjections } from './get-wrapped-base-query-with-projections'; | ||
| export { | ||
| getModifiedSqlExpression, | ||
| MODIFIERS, | ||
| } from './sql-expression-modifiers'; | ||
| export type { DimensionModifier, Modifier } from './types'; |
25 changes: 25 additions & 0 deletions
25
meerkat-core/src/get-wrapped-base-query-with-projections/modifiers/array-flatten-modifier.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,25 @@ | ||
| import { isArrayTypeMember } from '../../utils/is-array-member-type'; | ||
| import { DimensionModifier, Modifier } from '../types'; | ||
|
|
||
| export const arrayFlattenModifier = ({ | ||
| sqlExpression, | ||
| }: DimensionModifier): string => { | ||
| // Ensure NULL or empty arrays produce at least one row with NULL value | ||
| // This prevents rows from being dropped when arrays are NULL or empty | ||
| // COALESCE handles NULL, and len() = 0 check handles empty arrays [] | ||
| return `unnest(CASE WHEN ${sqlExpression} IS NULL OR len(COALESCE(${sqlExpression}, [])) = 0 THEN [NULL] ELSE ${sqlExpression} END)`; | ||
| }; | ||
|
|
||
| export const shouldFlattenArray = ({ | ||
| dimension, | ||
| }: DimensionModifier): boolean => { | ||
| const isArrayType = isArrayTypeMember(dimension.type); | ||
| const shouldFlattenArray = dimension.modifier?.shouldFlattenArray; | ||
| return !!(isArrayType && shouldFlattenArray); | ||
| }; | ||
|
|
||
| export const arrayFlattenModifierConfig: Modifier = { | ||
| name: 'shouldFlattenArray', | ||
| matcher: shouldFlattenArray, | ||
| modifier: arrayFlattenModifier, | ||
| }; |
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.