-
Notifications
You must be signed in to change notification settings - Fork 113
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
Snapshot building for filter operations (part of roundtrip) #3737
Conversation
🦋 Changeset detectedLatest commit: 8c41ad9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 28 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
...s/legend-data-cube/src/stores/core/__tests__/DataCubeQueryFilterSnapshotBuilder-repl.test.ts
Outdated
Show resolved
Hide resolved
...s/legend-data-cube/src/stores/core/__tests__/DataCubeQueryFilterSnapshotBuilder-repl.test.ts
Outdated
Show resolved
Hide resolved
packages/legend-data-cube/src/stores/core/filter/DataCubeQueryFilterOperation.ts
Outdated
Show resolved
Hide resolved
packages/legend-data-cube/src/stores/core/filter/DataCubeQueryFilterOperation.ts
Outdated
Show resolved
Hide resolved
packages/legend-data-cube/src/stores/core/DataCubeQueryEngine.ts
Outdated
Show resolved
Hide resolved
packages/legend-data-cube/src/stores/core/DataCubeQuerySnapshotBuilderUtils.ts
Outdated
Show resolved
Hide resolved
packages/legend-data-cube/src/stores/core/DataCubeQuerySnapshotBuilderUtils.ts
Outdated
Show resolved
Hide resolved
packages/legend-data-cube/src/stores/core/DataCubeQuerySnapshotBuilder.ts
Show resolved
Hide resolved
packages/legend-data-cube/src/stores/core/DataCubeQuerySnapshotBuilderUtils.ts
Outdated
Show resolved
Hide resolved
packages/legend-data-cube/src/stores/core/DataCubeQuerySnapshotBuilderUtils.ts
Outdated
Show resolved
Hide resolved
...s/legend-data-cube/src/stores/core/__tests__/DataCubeQueryFilterSnapshotBuilder-repl.test.ts
Outdated
Show resolved
Hide resolved
packages/legend-data-cube/src/stores/core/__tests__/DataCubeQuerySnapshotBuilder.repl-test.ts
Outdated
Show resolved
Hide resolved
packages/legend-data-cube/src/stores/core/__tests__/DataCubeQuerySnapshotBuilder.repl-test.ts
Outdated
Show resolved
Hide resolved
...s/legend-data-cube/src/stores/core/__tests__/DataCubeQueryFilterSnapshotBuilder.repl-test.ts
Outdated
Show resolved
Hide resolved
...s/legend-data-cube/src/stores/core/__tests__/DataCubeQueryFilterSnapshotBuilder.repl-test.ts
Outdated
Show resolved
Hide resolved
efc0e74
to
5887c4e
Compare
packages/legend-data-cube/src/stores/core/DataCubeQueryEngine.ts
Outdated
Show resolved
Hide resolved
return undefined; | ||
} | ||
|
||
function _buildFilterConditionSnapshot( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as discussed, distribute this logic to each of the operator. For common logic that can be shared, we can leave them here, e.g. _not(), etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls check , if this looks better, thanks
packages/legend-data-cube/src/stores/core/__tests__/Test__DataCubeEngine.ts
Outdated
Show resolved
Hide resolved
...end-data-cube/src/stores/core/__tests__/DataCubeQueryFilterSnapshotBuilder.data-cube-test.ts
Outdated
Show resolved
Hide resolved
e17a1b3
to
c6f7e65
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments, this is good enough, let's merge this. We'll come back for some cleanups.
packages/legend-data-cube/src/stores/core/__tests__/Test__DataCubeEngine.ts
Show resolved
Hide resolved
...end-data-cube/src/stores/core/__tests__/DataCubeQueryFilterSnapshotBuilder.data-cube-test.ts
Show resolved
Hide resolved
packages/legend-data-cube/src/stores/core/DataCubeQuerySnapshotBuilderUtils.ts
Show resolved
Hide resolved
packages/legend-data-cube/src/stores/core/DataCubeQuerySnapshotBuilderUtils.ts
Show resolved
Hide resolved
return _buildFilterSnapshot(vs, filterOperations); | ||
} | ||
} | ||
return undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One key thing you miss is that what we're doing is not a high-tolerable read, the algo expects a very particular form of query, if deviated, we throw error.
| undefined { | ||
if (vs instanceof V1_AppliedFunction) { | ||
if ( | ||
Object.values(DataCubeFunction) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why we need this?
DataCubeFunction
does define all the functions DataCube
should understand but they are not pertained to functions used within a filter. The logic here should be really simple:
- Found an
V1_AppliedFunction
, run through the list of filter operations until we found a match - If no match found, try
NOT
flavor - If still not match found, throw error.
- If not found
V1_AppliedFunction
in step (1), throw error.
af.parameters[0] instanceof V1_AppliedFunction && | ||
af.parameters[0].function === _functionName(DataCubeFunction.TO_LOWERCASE) | ||
) { | ||
return _buildCaseInsensitiveFilterConditionSnapshot(af); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the above comment on the algo outline. I think you're making this a little too complicated. Each branch of this method in theory can be converted into a utility function, e.g. how to read the V1_AppliedProperty
and see if it fits what a particular operator supports and then to build the snapshot, an operator from the list of DataCubeQueryFilterOperator
has to be picked, nothing outside of that list hsould be
For example, in case of Contains
, the logic in the buildConditionSnapshot
method of DatacubeQueryFilterOperation__Contain
needs
// operatorFunctionFullPath, | ||
// )}() expects '1 argument'`, | ||
// ); | ||
// buildConditionSnapshot(expression: V1_AppliedFunction) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's remove all these stuffs
if (value instanceof V1_PrimitiveValueSpecification) { | ||
filterConditionSnapshot.value = _dataCubeOperationValue(value); | ||
} | ||
return filterConditionSnapshot satisfies DataCubeQuerySnapshotFilterCondition; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to do this, TS is smart enough to force this to be DataCubeQuerySnapshotFilterCondition
@@ -73,8 +80,15 @@ export class DataCubeQueryFilterOperation__Contain extends DataCubeQueryFilterOp | |||
} | |||
|
|||
buildConditionSnapshot(expression: V1_AppliedFunction) { | |||
/** TODO: @datacube roundtrip */ | |||
return undefined; | |||
const value = expression.parameters[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, the spirit here is to verify the expression follows a specific form, else, return undefined
.
if (funcMap.filter) { | ||
data.filter = _buildFilterSnapshot( | ||
_lambdaParam(funcMap.filter, 0).body[0]!, | ||
filterOperations!, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using the non-null assertion operator
like this, this is pretty much a typing hack, and we strive to be ax explicit as we could when giving out proper message
Summary
How did you test this change?