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

Add testing for building graph from mapping analytics result #3657

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions .changeset/slow-rats-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@finos/legend-graph': patch
---

Add testing for bulding graph from mapping analytics result
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ import type { V1_ExecutionResult } from '../protocol/pure/v1/engine/execution/V1
import { V1_ExecuteInput } from '../protocol/pure/v1/engine/execution/V1_ExecuteInput.js';
import type { V1_PureModelContext } from '../protocol/pure/v1/model/context/V1_PureModelContext.js';
import type { V1_ValueSpecification } from '../protocol/pure/v1/model/valueSpecification/V1_ValueSpecification.js';
import {
V1_MappingModelCoverageAnalysisInput,
type V1_MappingModelCoverageAnalysisResult,
} from '../protocol/pure/v1/engine/analytics/V1_MappingModelCoverageAnalysis.js';

export const ENGINE_TEST_SUPPORT_API_URL = 'http://localhost:6300/api';

Expand Down Expand Up @@ -151,3 +155,23 @@ export async function ENGINE_TEST_SUPPORT__compile(
modelDataContext,
);
}

export async function ENGINE_TEST_SUPPORT__mappingCoverage(
input: V1_MappingModelCoverageAnalysisInput,
): Promise<PlainObject<V1_MappingModelCoverageAnalysisResult>> {
return (
await axios.post<unknown, AxiosResponse<{ elements: object[] }>>(
`${ENGINE_TEST_SUPPORT_API_URL}/analytics/mapping/modelCoverage`,
V1_MappingModelCoverageAnalysisInput.serialization.toJson(input),
{
headers: {
[HttpHeader.CONTENT_TYPE]: ContentType.APPLICATION_JSON,
},
params: {
returnMappedEntityInfo: true,
returnMappedPropertyInfo: true,
},
},
)
).data;
}
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@
*/
throw error instanceof GraphBuilderError
? error
: new GraphBuilderError(error);

Check failure on line 918 in packages/legend-graph/src/graph-manager/protocol/pure/v1/V1_PureGraphManager.ts

View workflow job for this annotation

GitHub Actions / Run Test Group (engine-roundtrip)

Grammar roundtrip mismatch test › Relational operation element in relational property mapping

Graph Builder Error: Property 'type' field is missing or empty at V1_PureGraphManager.buildGraph (packages/legend-graph/src/graph-manager/protocol/pure/v1/V1_PureGraphManager.ts:918:11) Caused by: Assertion Error: Property 'type' field is missing or empty at assertNonNullable (packages/legend-shared/src/error/AssertionUtils.ts:35:11) at assertNonNullable (packages/legend-shared/src/error/AssertionUtils.ts:42:3) at guaranteeNonNullable (packages/legend-shared/src/error/AssertionUtils.ts:87:7) at V1_buildProperty (packages/legend-graph/src/graph-manager/protocol/pure/v1/transformation/pureGraph/to/helpers/V1_DomainBuilderHelper.ts:199:23) at packages/legend-graph/src/graph-manager/protocol/pure/v1/transformation/pureGraph/to/V1_ElementThirdPassBuilder.ts:174:46 at Array.forEach (<anonymous>) at V1_ElementThirdPassBuilder.forEach [as visit_Class] (packages/legend-graph/src/graph-manager/protocol/pure/v1/transformation/pureGraph/to/V1_ElementThirdPassBuilder.ts:160:24) at V1_Class.visit_Class [as accept_PackageableElementVisitor] (packages/legend-graph/src/graph-manager/protocol/pure/v1/model/packageableElements/domain/V1_Class.ts:53:20) at accept_PackageableElementVisitor (packages/legend-graph/src/graph-manager/protocol/pure/v1/V1_PureGraphManager.ts:1746:38) at func (packages/legend-shared/src/CommonUtils.ts:297:17) at Timeout.task [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:520:19)

Check failure on line 918 in packages/legend-graph/src/graph-manager/protocol/pure/v1/V1_PureGraphManager.ts

View workflow job for this annotation

GitHub Actions / Run Test Group (engine-roundtrip)

[INTEGRATION] test query execution with parameters

Graph Builder Error: Property 'type' field is missing or empty at V1_PureGraphManager.buildGraph (packages/legend-graph/src/graph-manager/protocol/pure/v1/V1_PureGraphManager.ts:918:11) Caused by: Assertion Error: Property 'type' field is missing or empty at assertNonNullable (packages/legend-shared/src/error/AssertionUtils.ts:35:11) at assertNonNullable (packages/legend-shared/src/error/AssertionUtils.ts:42:3) at guaranteeNonNullable (packages/legend-shared/src/error/AssertionUtils.ts:87:7) at V1_buildProperty (packages/legend-graph/src/graph-manager/protocol/pure/v1/transformation/pureGraph/to/helpers/V1_DomainBuilderHelper.ts:199:23) at packages/legend-graph/src/graph-manager/protocol/pure/v1/transformation/pureGraph/to/V1_ElementThirdPassBuilder.ts:174:46 at Array.forEach (<anonymous>) at V1_ElementThirdPassBuilder.forEach [as visit_Class] (packages/legend-graph/src/graph-manager/protocol/pure/v1/transformation/pureGraph/to/V1_ElementThirdPassBuilder.ts:160:24) at V1_Class.visit_Class [as accept_PackageableElementVisitor] (packages/legend-graph/src/graph-manager/protocol/pure/v1/model/packageableElements/domain/V1_Class.ts:53:20) at accept_PackageableElementVisitor (packages/legend-graph/src/graph-manager/protocol/pure/v1/V1_PureGraphManager.ts:1746:38) at func (packages/legend-shared/src/CommonUtils.ts:297:17) at Timeout.task [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:520:19)

Check failure on line 918 in packages/legend-graph/src/graph-manager/protocol/pure/v1/V1_PureGraphManager.ts

View workflow job for this annotation

GitHub Actions / Run Test Group (engine-roundtrip)

[INTEGRATION] test preivew-data query execution

Graph Builder Error: Property 'type' field is missing or empty at V1_PureGraphManager.buildGraph (packages/legend-graph/src/graph-manager/protocol/pure/v1/V1_PureGraphManager.ts:918:11) Caused by: Assertion Error: Property 'type' field is missing or empty at assertNonNullable (packages/legend-shared/src/error/AssertionUtils.ts:35:11) at assertNonNullable (packages/legend-shared/src/error/AssertionUtils.ts:42:3) at guaranteeNonNullable (packages/legend-shared/src/error/AssertionUtils.ts:87:7) at V1_buildProperty (packages/legend-graph/src/graph-manager/protocol/pure/v1/transformation/pureGraph/to/helpers/V1_DomainBuilderHelper.ts:199:23) at packages/legend-graph/src/graph-manager/protocol/pure/v1/transformation/pureGraph/to/V1_ElementThirdPassBuilder.ts:174:46 at Array.forEach (<anonymous>) at V1_ElementThirdPassBuilder.forEach [as visit_Class] (packages/legend-graph/src/graph-manager/protocol/pure/v1/transformation/pureGraph/to/V1_ElementThirdPassBuilder.ts:160:24) at V1_Class.visit_Class [as accept_PackageableElementVisitor] (packages/legend-graph/src/graph-manager/protocol/pure/v1/model/packageableElements/domain/V1_Class.ts:53:20) at accept_PackageableElementVisitor (packages/legend-graph/src/graph-manager/protocol/pure/v1/V1_PureGraphManager.ts:1746:38) at func (packages/legend-shared/src/CommonUtils.ts:297:17) at Timeout.task [as _onTimeout] (node_modules/jsdom/lib/jsdom/browser/Window.js:520:19)
} finally {
buildState.setMessage(undefined);
}
Expand Down Expand Up @@ -3274,6 +3274,14 @@
);
}

async buildEntityFromMappingAnalyticsResult(
analyticsResult: V1_MappingModelCoverageAnalysisResult,
graph: PureModel,
buildActionState: ActionState,
): Promise<Entity[]> {
return [];
}

buildMappingModelCoverageAnalysisResult(
input: RawMappingModelCoverageAnalysisResult,
mapping: Mapping,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/**
* Copyright (c) 2020-present, Goldman Sachs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { describe, expect, test } from '@jest/globals';
import { resolve } from 'path';
import {
integrationTest,
type TEMPORARY__JestMatcher,
} from '@finos/legend-shared/test';
import {
V1_MappingModelCoverageAnalysisInput,
V1_MappingModelCoverageAnalysisResult,
V1_PureGraphManager,
} from '@finos/legend-graph';
import { ActionState } from '@finos/legend-shared';
import {
createGraphManagerStateFromGrammar,
generateModelEntitesFromModelGrammar,
} from '../utils/testUtils.js';
import {
ENGINE_TEST_SUPPORT__mappingCoverage,
TEST__excludeSectionIndex,
} from '@finos/legend-graph/test';

type ModelCoverageTestCase = [
string,
{
mappingPath: string;
inputFileDir: string;
inputFilePath: string;
expectedFileDir: string;
expectedFilePath: string;
},
];

const MODEL_COVERAGE_CASES: ModelCoverageTestCase[] = [
[
'simple relational model',
{
mappingPath: 'my::map',
inputFileDir: 'model',
inputFilePath: 'TEST_DATA_Model-coverage',
expectedFileDir: 'model',
expectedFilePath: 'TEST_DATA_Model-coverage',
},
],
];

describe(
integrationTest('Build Graph From Mapping Analytics Coverage and round trip'),
() => {
test.each(MODEL_COVERAGE_CASES)(
'%s',
async (
testName: ModelCoverageTestCase[0],
testCase: ModelCoverageTestCase[1],
) => {
const {
mappingPath,
inputFileDir,
inputFilePath,
expectedFileDir,
expectedFilePath,
} = testCase;
const graphManagerState = await createGraphManagerStateFromGrammar(
resolve(__dirname, inputFileDir),
inputFilePath,
);
const pureGraphManager =
graphManagerState.graphManager as V1_PureGraphManager;
const mappingModelCoverageInput =
new V1_MappingModelCoverageAnalysisInput();
mappingModelCoverageInput.clientVersion =
V1_PureGraphManager.DEV_PROTOCOL_VERSION;
mappingModelCoverageInput.mapping = mappingPath;
mappingModelCoverageInput.model =
pureGraphManager.getFullGraphModelData(graphManagerState.graph);
const mappingModelCoverageAnalysisResult =
(await ENGINE_TEST_SUPPORT__mappingCoverage(
mappingModelCoverageInput,
)) as unknown as V1_MappingModelCoverageAnalysisResult;

const minalGraphEntities =
await pureGraphManager.buildEntityFromMappingAnalyticsResult(
mappingModelCoverageAnalysisResult,
graphManagerState.graph,
ActionState.create(),
);
const expectedEntities = await generateModelEntitesFromModelGrammar(
resolve(__dirname, expectedFileDir),
expectedFilePath,
undefined,
);
(
expect(expectedEntities) as TEMPORARY__JestMatcher
).toIncludeSameMembers(TEST__excludeSectionIndex(expectedEntities));
},
);
},
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
###Relational
Database meta::analytics::mapping::modelCoverage::test::sampleDB
(
Table FirmTable
(
id INTEGER PRIMARY KEY,
legalName VARCHAR(200)
)
Table PersonTable
(
id INTEGER PRIMARY KEY,
firmID INTEGER,
firstName VARCHAR(200),
lastName VARCHAR(200)
)
Table AddressTable
(
id INTEGER PRIMARY KEY,
firmID INTEGER,
name VARCHAR(200)
)

Join firm_person(PersonTable.firmID = FirmTable.id)
Join firm_address(AddressTable.firmID = FirmTable.id)
)


###Pure
Enum meta::analytics::mapping::modelCoverage::test::IncType
{
Corp,
LLC
}

Class meta::analytics::mapping::modelCoverage::test::LegalEntity
{
legalName: String[1];
address: meta::analytics::mapping::modelCoverage::test::Address[1];
}

Class meta::analytics::mapping::modelCoverage::test::Firm extends meta::analytics::mapping::modelCoverage::test::LegalEntity
{
id: Decimal[1];
employees: meta::analytics::mapping::modelCoverage::test::Person[1..*];
incType: meta::analytics::mapping::modelCoverage::test::IncType[1];
employeeSize() {$this.employees->count()}: Number[1];
}

Class meta::analytics::mapping::modelCoverage::test::Person
{
firstName: String[1];
lastName: String[1];
}

Class meta::analytics::mapping::modelCoverage::test::Address
{
zipcode: Integer[1];
}

Class meta::analytics::mapping::modelCoverage::test::Street extends meta::analytics::mapping::modelCoverage::test::Address
{
streetName: String[1];
}

###Mapping
Mapping meta::analytics::mapping::modelCoverage::test::sampleRelationalMapping
(
*meta::analytics::mapping::modelCoverage::test::Firm: Relational
{
~primaryKey
(
[meta::analytics::mapping::modelCoverage::test::sampleDB]FirmTable.id
)
~mainTable [meta::analytics::mapping::modelCoverage::test::sampleDB]FirmTable
id: [meta::analytics::mapping::modelCoverage::test::sampleDB]FirmTable.id,
employees
(
firstName: [meta::analytics::mapping::modelCoverage::test::sampleDB]PersonTable.firstName
),
address: [meta::analytics::mapping::modelCoverage::test::sampleDB]@firm_address
}
*meta::analytics::mapping::modelCoverage::test::Person: Relational
{
~primaryKey
(
[meta::analytics::mapping::modelCoverage::test::sampleDB]PersonTable.id
)
~mainTable [meta::analytics::mapping::modelCoverage::test::sampleDB]PersonTable
firstName: [meta::analytics::mapping::modelCoverage::test::sampleDB]PersonTable.firstName,
lastName: [meta::analytics::mapping::modelCoverage::test::sampleDB]PersonTable.lastName
}
*meta::analytics::mapping::modelCoverage::test::LegalEntity: Operation
{
meta::pure::router::operations::inheritance_OperationSetImplementation_1__SetImplementation_MANY_()
}
*meta::analytics::mapping::modelCoverage::test::Address: Operation
{
meta::pure::router::operations::inheritance_OperationSetImplementation_1__SetImplementation_MANY_()
}
*meta::analytics::mapping::modelCoverage::test::Street: Operation
{
meta::pure::router::operations::union_OperationSetImplementation_1__SetImplementation_MANY_(s1,s2)
}
meta::analytics::mapping::modelCoverage::test::Street[s2]: Relational
{
~primaryKey
(
[meta::analytics::mapping::modelCoverage::test::sampleDB]AddressTable.id
)
~mainTable [meta::analytics::mapping::modelCoverage::test::sampleDB]AddressTable
zipcode: [meta::analytics::mapping::modelCoverage::test::sampleDB]AddressTable.id
}
meta::analytics::mapping::modelCoverage::test::Street[s1]: Relational
{
~primaryKey
(
[meta::analytics::mapping::modelCoverage::test::sampleDB]AddressTable.id
)
~mainTable [meta::analytics::mapping::modelCoverage::test::sampleDB]AddressTable
zipcode: [meta::analytics::mapping::modelCoverage::test::sampleDB]AddressTable.id
}
)
Loading