generated from finos/software-project-blueprint
-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Native function to parse Postgres SQL statements
- Loading branch information
Showing
49 changed files
with
787 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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 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 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
79 changes: 79 additions & 0 deletions
79
...Store-postgresSql/legend-engine-pure-functions-relationalStore-postgresSql-parser/pom.xml
This file contains 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,79 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2024 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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<parent> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-xt-relationalStore-postgresSql</artifactId> | ||
<version>4.63.2-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>legend-engine-pure-functions-relationalStore-postgresSql-parser</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Legend Engine - Pure - Functions - Relational Store - Postgres SQL - Parser</name> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.finos.legend.pure</groupId> | ||
<artifactId>legend-pure-maven-generation-par</artifactId> | ||
<executions> | ||
<execution> | ||
<phase>generate-sources</phase> | ||
<goals> | ||
<goal>build-pure-jar</goal> | ||
</goals> | ||
<configuration> | ||
<sourceDirectory>src/main/resources</sourceDirectory> | ||
<purePlatformVersion>${legend.pure.version}</purePlatformVersion> | ||
<extraRepositories> | ||
<extraRepository> | ||
${project.basedir}/src/main/resources/core_external_store_relational_postgres_sql_parser.definition.json | ||
</extraRepository> | ||
</extraRepositories> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.finos.legend.pure</groupId> | ||
<artifactId>legend-pure-m2-dsl-diagram-grammar</artifactId> | ||
<version>${legend.pure.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-pure-code-compiled-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-xt-relationalStore-postgresSqlModel-pure</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.finos.legend.pure</groupId> | ||
<artifactId>legend-pure-m3-core</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
28 changes: 28 additions & 0 deletions
28
.../engine/code/core/CoreExternalStoreRelationalPostgresSqlParserCodeRepositoryProvider.java
This file contains 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,28 @@ | ||
// Copyright 2024 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.engine.code.core; | ||
|
||
import org.finos.legend.pure.m3.serialization.filesystem.repository.CodeRepository; | ||
import org.finos.legend.pure.m3.serialization.filesystem.repository.CodeRepositoryProvider; | ||
import org.finos.legend.pure.m3.serialization.filesystem.repository.GenericCodeRepository; | ||
|
||
public class CoreExternalStoreRelationalPostgresSqlParserCodeRepositoryProvider implements CodeRepositoryProvider | ||
{ | ||
@Override | ||
public CodeRepository repository() | ||
{ | ||
return GenericCodeRepository.build("core_external_store_relational_postgres_sql_parser.definition.json"); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...vices/org.finos.legend.pure.m3.serialization.filesystem.repository.CodeRepositoryProvider
This file contains 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 @@ | ||
org.finos.legend.engine.code.core.CoreExternalStoreRelationalPostgresSqlParserCodeRepositoryProvider |
18 changes: 18 additions & 0 deletions
18
...ser/src/main/resources/core_external_store_relational_postgres_sql_parser.definition.json
This file contains 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,18 @@ | ||
{ | ||
"name": "core_external_store_relational_postgres_sql_parser", | ||
"pattern": "(meta::external::store::relational::postgresSql::parser)(::.*)?", | ||
"dependencies": [ | ||
"platform", | ||
"platform_dsl_store", | ||
"platform_dsl_mapping", | ||
"platform_dsl_path", | ||
"platform_dsl_graph", | ||
"platform_dsl_diagram", | ||
"platform_store_relational", | ||
"core_functions_standard", | ||
"core_functions_unclassified", | ||
"core_functions_json", | ||
"core", | ||
"core_external_store_relational_postgres_sql_model" | ||
] | ||
} |
52 changes: 52 additions & 0 deletions
52
.../main/resources/core_external_store_relational_postgres_sql_parser/postgresSqlParser.pure
This file contains 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,52 @@ | ||
// Copyright 2024 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::external::query::sql::metamodel::*; | ||
import meta::external::store::relational::postgresSql::parser::*; | ||
import meta::pure::functions::meta::*; | ||
import meta::json::*; | ||
|
||
native function meta::external::store::relational::postgresSql::parser::parseSqlStatementToJson(sql: String[1]): String[1]; | ||
|
||
function meta::external::store::relational::postgresSql::parser::parseSqlStatement(sql: String[1]): Statement[1] | ||
{ | ||
let statementJson = $sql->parseSqlStatementToJson(); | ||
$statementJson->fromJSON( | ||
Statement, | ||
^JSONDeserializationConfig( | ||
typeKeyName = '_type', | ||
failOnUnknownProperties = true, | ||
typeLookup = typeLookupPairs() | ||
) | ||
); | ||
} | ||
|
||
function <<access.private>> meta::external::store::relational::postgresSql::parser::typeLookupPairs(): Pair<String, String>[*] | ||
{ | ||
getAllPackageElements(meta::external::query::sql::metamodel, false) | ||
->filter(x | $x->instanceOf(Class)) | ||
->cast(@Class<Any>) | ||
->map(x | pair($x.name->toLowerFirstCharacter()->toOne(), $x->elementToPath())) | ||
} | ||
|
||
function <<test.Test>> meta::external::store::relational::postgresSql::parser::testParseSqlStatement(): Boolean[1] | ||
{ | ||
let statement = parseSqlStatement('SELECT 1 + 2 as result'); | ||
assert($statement->instanceOf(Query)); | ||
assert($statement->cast(@Query).queryBody->instanceOf(QuerySpecification)); | ||
assert($statement->cast(@Query).queryBody->cast(@QuerySpecification).select.selectItems->size() == 1); | ||
assert($statement->cast(@Query).queryBody->cast(@QuerySpecification).select.selectItems->toOne()->instanceOf(SingleColumn)); | ||
assert($statement->cast(@Query).queryBody->cast(@QuerySpecification).select.selectItems->toOne()->cast(@SingleColumn).alias == 'result'); | ||
assert($statement->cast(@Query).queryBody->cast(@QuerySpecification).select.selectItems->toOne()->cast(@SingleColumn).expression->instanceOf(ArithmeticExpression)); | ||
} |
154 changes: 154 additions & 0 deletions
154
...pure-runtime-java-extension-compiled-functions-relationalStore-postgresSql-parser/pom.xml
This file contains 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,154 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2024 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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<parent> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-xt-relationalStore-postgresSql</artifactId> | ||
<version>4.63.2-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>legend-engine-pure-runtime-java-extension-compiled-functions-relationalStore-postgresSql-parser</artifactId> | ||
<packaging>jar</packaging> | ||
<name>Legend Engine - Pure - Runtime - Java Extension - Compiled - Functions - Relational Store - Postgres SQL - Parser</name> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.finos.legend.pure</groupId> | ||
<artifactId>legend-pure-maven-generation-java</artifactId> | ||
<executions> | ||
<execution> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>build-pure-compiled-jar</goal> | ||
</goals> | ||
<configuration> | ||
<generateSources>true</generateSources> | ||
<preventJavaCompilation>true</preventJavaCompilation> | ||
<generationType>modular</generationType> | ||
<useSingleDir>true</useSingleDir> | ||
<repositories> | ||
<repository>core_external_store_relational_postgres_sql_parser</repository> | ||
</repositories> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.finos.legend.pure</groupId> | ||
<artifactId>legend-pure-m2-dsl-diagram-grammar</artifactId> | ||
<version>${legend.pure.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-pure-code-compiled-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-xt-relationalStore-postgresSqlModel-pure</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-pure-functions-relationalStore-postgresSql-parser</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<!-- PURE --> | ||
<dependency> | ||
<groupId>org.finos.legend.pure</groupId> | ||
<artifactId>legend-pure-m4</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.pure</groupId> | ||
<artifactId>legend-pure-m3-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.pure</groupId> | ||
<artifactId>legend-pure-runtime-java-engine-compiled</artifactId> | ||
</dependency> | ||
<!-- PURE --> | ||
|
||
<!-- ENGINE --> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-pure-platform-java</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-pure-runtime-java-extension-compiled-functions-unclassified</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-pure-runtime-java-extension-compiled-functions-json</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-pure-code-compiled-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-xt-relationalStore-postgresSqlModel-pure</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-xt-relationalStore-postgresSql-protocol</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-xt-relationalStore-postgresSql-grammar</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.finos.legend.engine</groupId> | ||
<artifactId>legend-engine-pure-functions-relationalStore-postgresSql-parser</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<!-- ENGINE --> | ||
|
||
<dependency> | ||
<groupId>org.eclipse.collections</groupId> | ||
<artifactId>eclipse-collections</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.collections</groupId> | ||
<artifactId>eclipse-collections-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
</dependency> | ||
|
||
<!-- TEST --> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
</dependency> | ||
<!-- TEST --> | ||
</dependencies> | ||
</project> |
Oops, something went wrong.