Skip to content

Commit

Permalink
Connection equality added for relational database connections - legen…
Browse files Browse the repository at this point in the history
…d using equality key based checks (#2418)

Tests added for athena, databricks, snowflake, bigquery and generic

(cherry picked from commit 1039d48)

Post processor comparison changed to look at sequence and type only. A future release will look to introduce an equality check function into a post processor which can be explicitly coded and used as it is impractical to add equality keys to all possible post processor hierarchies
  • Loading branch information
kkns-gs authored Oct 31, 2023
1 parent 34189f4 commit 1b75767
Show file tree
Hide file tree
Showing 25 changed files with 587 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "core_relational_athena",
"pattern": "(meta::relational::functions::sqlQueryToString::athena|meta::relational::tests::sqlQueryToString::athena|meta::pure::alloy::connections|meta::external::store::relational::runtime|meta::protocols::pure)(::.*)?",
"pattern": "(meta::relational::functions::sqlQueryToString::athena|meta::relational::tests::sqlQueryToString::athena|meta::pure::alloy::connections|meta::external::store::relational::runtime|meta::protocols::pure|meta::relational::tests::connEquality)(::.*)?",
"dependencies": [
"platform",
"platform_functions",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2021 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 meta::relational::metamodel::execute::tests::*;
import meta::external::store::relational::runtime::*;
import meta::pure::runtime::*;
import meta::relational::translation::*;
import meta::pure::extension::*;
import meta::relational::extension::*;
import meta::relational::runtime::*;
import meta::relational::tests::csv::*;
import meta::relational::metamodel::execute::*;
import meta::relational::metamodel::*;
import meta::pure::mapping::*;

function <<test.Test>> meta::relational::tests::connEquality::testConnectionEqualityAllSameAthena() : Boolean[1]
{
let c1 = ^RelationalDatabaseConnection(

type = DatabaseType.Athena,
datasourceSpecification = ^meta::pure::alloy::connections::alloy::specification::AthenaDatasourceSpecification(awsRegion='awsR', s3OutputLocation='s3OL', databaseName='db'),
authenticationStrategy = ^meta::pure::alloy::connections::alloy::authentication::ApiTokenAuthenticationStrategy(apiToken='token')
);

let c2 = ^RelationalDatabaseConnection(

type = DatabaseType.Athena,
datasourceSpecification = ^meta::pure::alloy::connections::alloy::specification::AthenaDatasourceSpecification(awsRegion='awsR', s3OutputLocation='s3OL', databaseName='db'),
authenticationStrategy = ^meta::pure::alloy::connections::alloy::authentication::ApiTokenAuthenticationStrategy(apiToken='token')
);

assert(runRelationalRouterExtensionConnectionEquality($c1, $c2));

}

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

Class meta::pure::alloy::connections::alloy::specification::AthenaDatasourceSpecification extends meta::pure::alloy::connections::alloy::specification::DatasourceSpecification
{
awsRegion: String[1];
s3OutputLocation: String[1];
databaseName: String[1];
<<equality.Key>> awsRegion: String[1];
<<equality.Key>> s3OutputLocation: String[1];
<<equality.Key>> databaseName: String[1];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2022 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.

package org.finos.legend.pure.code.core;

import junit.framework.TestSuite;
import org.finos.legend.pure.m3.execution.test.PureTestBuilder;
import org.finos.legend.pure.m3.execution.test.TestCollection;
import org.finos.legend.pure.runtime.java.compiled.execution.CompiledExecutionSupport;
import org.finos.legend.pure.runtime.java.compiled.testHelper.PureTestBuilderCompiled;

public class Test_Pure_Relational_ConnectionEquality
{
public static TestSuite suite()
{
String testPackage = "meta::relational::tests::connEquality";
CompiledExecutionSupport executionSupport = PureTestBuilderCompiled.getClassLoaderExecutionSupport();
return PureTestBuilderCompiled.buildSuite(TestCollection.collectTests(testPackage, executionSupport.getProcessorSupport(), ci -> PureTestBuilder.satisfiesConditions(ci, executionSupport.getProcessorSupport())), executionSupport);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "core_relational_bigquery",
"pattern": "(meta::relational::functions::sqlQueryToString::bigQuery|meta::relational::tests::sqlQueryToString::bigQuery|meta::relational::bigQuery::tests|meta::pure::alloy::connections|meta::external::store::relational::runtime|meta::protocols::pure)(::.*)?",
"pattern": "(meta::relational::functions::sqlQueryToString::bigQuery|meta::relational::tests::sqlQueryToString::bigQuery|meta::relational::bigQuery::tests|meta::pure::alloy::connections|meta::external::store::relational::runtime|meta::protocols::pure|meta::relational::tests::connEquality)(::.*)?",
"dependencies": [
"platform",
"platform_functions",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

Class meta::pure::alloy::connections::alloy::specification::BigQueryDatasourceSpecification extends meta::pure::alloy::connections::alloy::specification::DatasourceSpecification
{
projectId:String[1];
defaultDataset:String[1];
proxyHost: String[0..1];
proxyPort: String[0..1];
<<equality.Key>> projectId:String[1];
<<equality.Key>> defaultDataset:String[1];
<<equality.Key>> proxyHost: String[0..1];
<<equality.Key>> proxyPort: String[0..1];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2021 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 meta::relational::metamodel::execute::tests::*;
import meta::external::store::relational::runtime::*;
import meta::pure::runtime::*;
import meta::relational::translation::*;
import meta::pure::extension::*;
import meta::relational::extension::*;
import meta::relational::runtime::*;
import meta::relational::tests::csv::*;
import meta::relational::metamodel::execute::*;
import meta::relational::metamodel::*;
import meta::pure::mapping::*;

function <<test.Test>> meta::relational::tests::connEquality::testConnectionEqualityAllSameBigQuery() : Boolean[1]
{
let c1 = ^RelationalDatabaseConnection(

type = DatabaseType.Snowflake,
datasourceSpecification = ^meta::pure::alloy::connections::alloy::specification::BigQueryDatasourceSpecification(projectId='project', defaultDataset='defDs', proxyHost='ph', proxyPort='8080'),
authenticationStrategy = ^meta::pure::alloy::connections::alloy::authentication::ApiTokenAuthenticationStrategy(apiToken='token')
);

let c2 = ^RelationalDatabaseConnection(

type = DatabaseType.Snowflake,
datasourceSpecification = ^meta::pure::alloy::connections::alloy::specification::BigQueryDatasourceSpecification(projectId='project', defaultDataset='defDs', proxyHost='ph', proxyPort='8080'),
authenticationStrategy = ^meta::pure::alloy::connections::alloy::authentication::ApiTokenAuthenticationStrategy(apiToken='token')
);

assert(runRelationalRouterExtensionConnectionEquality($c1, $c2));

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2022 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.

package org.finos.legend.pure.code.core;

import junit.framework.TestSuite;
import org.finos.legend.pure.m3.execution.test.PureTestBuilder;
import org.finos.legend.pure.m3.execution.test.TestCollection;
import org.finos.legend.pure.runtime.java.compiled.execution.CompiledExecutionSupport;
import org.finos.legend.pure.runtime.java.compiled.testHelper.PureTestBuilderCompiled;

public class Test_Pure_Relational_ConnectionEquality
{
public static TestSuite suite()
{
String testPackage = "meta::relational::tests::connEquality";
CompiledExecutionSupport executionSupport = PureTestBuilderCompiled.getClassLoaderExecutionSupport();
return PureTestBuilderCompiled.buildSuite(TestCollection.collectTests(testPackage, executionSupport.getProcessorSupport(), ci -> PureTestBuilder.satisfiesConditions(ci, executionSupport.getProcessorSupport())), executionSupport);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name" : "core_relational_databricks",
"pattern" : "(meta::relational::functions::sqlQueryToString::databricks|meta::relational::tests::sqlQueryToString::databricks|meta::relational::databricks::tests|meta::relational::tests::functions::sqlstring::databricks|meta::pure::alloy::connections|meta::protocols::pure)(::.*)?",
"pattern" : "(meta::relational::functions::sqlQueryToString::databricks|meta::relational::tests::sqlQueryToString::databricks|meta::relational::tests::connEquality|meta::relational::databricks::tests|meta::relational::tests::functions::sqlstring::databricks|meta::pure::alloy::connections|meta::protocols::pure)(::.*)?",
"dependencies" : ["platform", "platform_functions", "platform_store_relational", "platform_dsl_mapping", "core_functions", "core", "core_relational"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2021 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 meta::relational::metamodel::execute::tests::*;
import meta::external::store::relational::runtime::*;
import meta::pure::runtime::*;
import meta::relational::translation::*;
import meta::pure::extension::*;
import meta::relational::extension::*;
import meta::relational::runtime::*;
import meta::relational::tests::csv::*;
import meta::relational::metamodel::execute::*;
import meta::relational::metamodel::*;
import meta::pure::mapping::*;

function <<test.Test>> meta::relational::tests::connEquality::testConnectionEqualityAllSameDataBricks() : Boolean[1]
{
let c1 = ^RelationalDatabaseConnection(

type = DatabaseType.Databricks,
datasourceSpecification = ^meta::pure::alloy::connections::alloy::specification::DatabricksDatasourceSpecification(hostname='host', port='8080', protocol='http', httpPath='http://path'),
authenticationStrategy = ^meta::pure::alloy::connections::alloy::authentication::ApiTokenAuthenticationStrategy(apiToken='token')
);

let c2 = ^RelationalDatabaseConnection(

type = DatabaseType.Databricks,
datasourceSpecification = ^meta::pure::alloy::connections::alloy::specification::DatabricksDatasourceSpecification(hostname='host', port='8080', protocol='http', httpPath='http://path'),
authenticationStrategy = ^meta::pure::alloy::connections::alloy::authentication::ApiTokenAuthenticationStrategy(apiToken='token')
);

assert(runRelationalRouterExtensionConnectionEquality($c1, $c2));

}


Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

Class meta::pure::alloy::connections::alloy::specification::DatabricksDatasourceSpecification extends meta::pure::alloy::connections::alloy::specification::DatasourceSpecification
{
hostname:String[1];
port:String[1];
protocol:String[1];
httpPath:String[1];
<<equality.Key>> hostname:String[1];
<<equality.Key>> port:String[1];
<<equality.Key>> protocol:String[1];
<<equality.Key>> httpPath:String[1];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2022 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.

package org.finos.legend.pure.code.core;

import junit.framework.TestSuite;
import org.finos.legend.pure.m3.execution.test.PureTestBuilder;
import org.finos.legend.pure.m3.execution.test.TestCollection;
import org.finos.legend.pure.runtime.java.compiled.execution.CompiledExecutionSupport;
import org.finos.legend.pure.runtime.java.compiled.testHelper.PureTestBuilderCompiled;

public class Test_Pure_Relational_ConnectionEquality
{
public static TestSuite suite()
{
String testPackage = "meta::relational::tests::connEquality";
CompiledExecutionSupport executionSupport = PureTestBuilderCompiled.getClassLoaderExecutionSupport();
return PureTestBuilderCompiled.buildSuite(TestCollection.collectTests(testPackage, executionSupport.getProcessorSupport(), ci -> PureTestBuilder.satisfiesConditions(ci, executionSupport.getProcessorSupport())), executionSupport);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name" : "core_relational_${dbtype}",
"pattern" : "(meta::relational::functions::sqlQueryToString::${dbType}|meta::relational::tests::sqlQueryToString::${dbType}|meta::pure::alloy::connections|meta::external::store::relational::runtime|meta::protocols::pure)(::.*)?",
"pattern" : "(meta::relational::functions::sqlQueryToString::${dbType}|meta::relational::tests::sqlQueryToString::${dbType}|meta::pure::alloy::connections|meta::external::store::relational::runtime|meta::protocols::pure|meta::relational::tests::connEquality)(::.*)?",
"dependencies" : ["platform", "platform_functions", "platform_store_relational", "core", "core_relational"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2021 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 meta::relational::metamodel::execute::tests::*;
import meta::external::store::relational::runtime::*;
import meta::pure::runtime::*;
import meta::relational::translation::*;
import meta::pure::extension::*;
import meta::relational::extension::*;
import meta::relational::runtime::*;
import meta::relational::tests::csv::*;
import meta::relational::metamodel::execute::*;
import meta::relational::metamodel::*;
import meta::pure::mapping::*;


function <<test.Test>> meta::relational::tests::connEquality::testConnectionEqualityAllSame__dbtype__() : Boolean[1]
{
let c1 = ^RelationalDatabaseConnection(

type = DatabaseType.__dbtype__,
datasourceSpecification = ^meta::pure::alloy::connections::alloy::specification::__dbtype__DatasourceSpecification(),
authenticationStrategy = ^meta::pure::alloy::connections::alloy::authentication::ApiTokenAuthenticationStrategy(apiToken='token')
);

let c2 = ^RelationalDatabaseConnection(

type = DatabaseType.Snowflake,
datasourceSpecification = ^meta::pure::alloy::connections::alloy::specification::BigQueryDatasourceSpecification(projectId='project', defaultDataset='defDs', proxyHost='ph', proxyPort='8080'),
authenticationStrategy = ^meta::pure::alloy::connections::alloy::authentication::ApiTokenAuthenticationStrategy(apiToken='token')
);

assert(runRelationalRouterExtensionConnectionEquality($c1, $c2));

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2022 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.

package org.finos.legend.pure.code.core;

import junit.framework.TestSuite;
import org.finos.legend.pure.m3.execution.test.PureTestBuilder;
import org.finos.legend.pure.m3.execution.test.TestCollection;
import org.finos.legend.pure.runtime.java.compiled.execution.CompiledExecutionSupport;
import org.finos.legend.pure.runtime.java.compiled.testHelper.PureTestBuilderCompiled;

public class Test_Pure_Relational_ConnectionEquality
{
public static TestSuite suite()
{
String testPackage = "meta::relational::tests::connEquality";
CompiledExecutionSupport executionSupport = PureTestBuilderCompiled.getClassLoaderExecutionSupport();
return PureTestBuilderCompiled.buildSuite(TestCollection.collectTests(testPackage, executionSupport.getProcessorSupport(), ci -> PureTestBuilder.satisfiesConditions(ci, executionSupport.getProcessorSupport())), executionSupport);
}
}
Loading

0 comments on commit 1b75767

Please sign in to comment.