Skip to content
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

Merged
merged 5 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changeset/eighty-adults-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
'@finos/legend-data-cube': patch
---
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ import {
} from './DataCubeQueryEngine.js';
import { buildDefaultConfiguration } from './DataCubeConfigurationBuilder.js';
import {
_buildFilterSnapshot,
_colSpecArrayParam,
_colSpecParam,
_funcMatch,
_lambdaParam,
_param,
} from './DataCubeQuerySnapshotBuilderUtils.js';
import type { DataCubeSource } from './model/DataCubeSource.js';
import type { DataCubeQueryFilterOperation } from './filter/DataCubeQueryFilterOperation.js';

// --------------------------------- BUILDING BLOCKS ---------------------------------

Expand Down Expand Up @@ -99,6 +102,14 @@ enum _FUNCTION_SEQUENCE_COMPOSITION_PART {
LIMIT = 'limit',
}

function isFunctionInValidSequence(
value: string,
): value is _FUNCTION_SEQUENCE_COMPOSITION_PART {
return Object.values(_FUNCTION_SEQUENCE_COMPOSITION_PART).includes(
value as _FUNCTION_SEQUENCE_COMPOSITION_PART,
);
}

// This corresponds to the function sequence that we currently support:
//
// ->extend()*
Expand Down Expand Up @@ -223,14 +234,30 @@ function extractFunctionMap(
}
if (currentFunc.parameters.length > supportedFunc.parameters) {
const valueSpecification = currentFunc.parameters[0];
if (!(valueSpecification instanceof V1_AppliedFunction)) {
if (
!(
valueSpecification instanceof V1_AppliedFunction ||
isFunctionInValidSequence(currentFunc.function)
)
) {
throw new Error(
`Query must be a sequence of function calls (e.g. x()->y()->z())`,
);
} else if (
currentFunc.function === _FUNCTION_SEQUENCE_COMPOSITION_PART.FILTER
) {
currentFunc.parameters = currentFunc.parameters.slice(1);
sequence.unshift(currentFunc);
if (valueSpecification instanceof V1_AppliedFunction) {
currentFunc = valueSpecification;
} else {
break;
}
} else {
currentFunc.parameters = currentFunc.parameters.slice(1);
sequence.unshift(currentFunc);
currentFunc = valueSpecification as V1_AppliedFunction;
}
currentFunc.parameters = currentFunc.parameters.slice(1);
sequence.unshift(currentFunc);
currentFunc = valueSpecification;
} else {
sequence.unshift(currentFunc);
break;
Expand Down Expand Up @@ -290,6 +317,7 @@ export function validateAndBuildQuerySnapshot(
partialQuery: V1_ValueSpecification,
source: DataCubeSource,
baseQuery: DataCubeQuery,
filterOperations?: DataCubeQueryFilterOperation[],
) {
// --------------------------------- BASE ---------------------------------
// Build the function call sequence and the function map to make the
Expand All @@ -316,7 +344,12 @@ export function validateAndBuildQuerySnapshot(
/** TODO: @datacube roundtrip */

// --------------------------------- FILTER ---------------------------------
/** TODO: @datacube roundtrip */
if (funcMap.filter) {
gs-gunjan marked this conversation as resolved.
Show resolved Hide resolved
data.filter = _buildFilterSnapshot(
_lambdaParam(funcMap.filter, 0).body[0]!,
filterOperations!,
Copy link
Contributor

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

);
}

// --------------------------------- SELECT ---------------------------------

Expand Down
Loading
Loading