Skip to content

Commit

Permalink
Legend Engine - Assortment of changes (#2349)
Browse files Browse the repository at this point in the history
1. refactor tests for simplified reading
2. autogenerate schema protocol models
3. grammar composer support tablesubquery
  • Loading branch information
gs-jp1 authored Oct 10, 2023
1 parent 59a7c9b commit cdda855
Show file tree
Hide file tree
Showing 14 changed files with 1,113 additions and 989 deletions.
16 changes: 16 additions & 0 deletions legend-engine-xts-sql/legend-engine-xt-sql-compiler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@
<classpathScope>test</classpathScope>
</configuration>
</execution>
<execution>
<id>Generate translator for protocol</id>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<includePluginDependencies>true</includePluginDependencies>
<mainClass>org.finos.legend.engine.protocol.generation.GenerateMetamodelToProtocolTranslator</mainClass>
<arguments>
<argument>core_external_query_sql_schema_metamodel.protocol.json</argument>
<argument>${project.build.directory}/generated-sources/</argument>
</arguments>
<classpathScope>test</classpathScope>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ public String visit(TableFunction val)
@Override
public String visit(TableSubquery val)
{
return null;
return "(" + visit(val.query) + ")";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ public void testWithinGroup()
check("SELECT percentile_cont(0.1) WITHIN GROUP (ORDER BY a ASC) FROM myTable");
}

@Test
public void testNested()
{
check("SELECT * from (select col from myTable)");
}

private void fail(String sql, int start, int end, String message)
{
try
Expand Down
16 changes: 16 additions & 0 deletions legend-engine-xts-sql/legend-engine-xt-sql-protocol/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@
<classpathScope>test</classpathScope>
</configuration>
</execution>
<execution>
<id>generate schema metamodel</id>
<phase>generate-sources</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<includePluginDependencies>true</includePluginDependencies>
<mainClass>org.finos.legend.engine.protocol.generation.GenerateMetaClasses</mainClass>
<arguments>
<argument>core_external_query_sql_schema_metamodel.protocol.json</argument>
<argument>${project.build.directory}/generated-sources/</argument>
</arguments>
<classpathScope>test</classpathScope>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"purePackage": "meta::external::query::sql::schema::metamodel",
"javaPackage": "org.finos.legend.engine.protocol.sql.schema.metamodel",
"elementsToBeExcluded": [
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Class meta::external::query::sql::schema::metamodel::SchemaColumn
{
<<equality.Key>> name: String[1];
}

Class meta::external::query::sql::schema::metamodel::PrimitiveSchemaColumn extends meta::external::query::sql::schema::metamodel::SchemaColumn
{
<<equality.Key>> type: meta::external::query::sql::schema::metamodel::PrimitiveType[1];
}

Class meta::external::query::sql::schema::metamodel::EnumSchemaColumn extends meta::external::query::sql::schema::metamodel::SchemaColumn
{
<<equality.Key>> type: String[1];
}


Class meta::external::query::sql::schema::metamodel::Schema
{
<<equality.Key>> columns: meta::external::query::sql::schema::metamodel::SchemaColumn[*];
<<equality.Key>> enums: meta::external::query::sql::schema::metamodel::Enum[*];
}

Enum meta::external::query::sql::schema::metamodel::PrimitiveType
{
Boolean,
StrictDate,
Number,
String,
LatestDate,
Float,
DateTime,
Date,
Integer,
Decimal
}

Class meta::external::query::sql::schema::metamodel::Enum
{
<<equality.Key>> type: String[1];
<<equality.Key>> values: String[*];
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ function meta::external::query::sql::transformation::queryToPure::getSchemaFromS
sources: SQLSource[*],
query: meta::external::query::sql::metamodel::Node[1],
extensions: meta::pure::extension::Extension[*]
): meta::external::query::sql::Schema[1]
): meta::external::query::sql::schema::metamodel::Schema[1]
{
let sqlTransformContext = processRootQuery($sources, $query, $extensions);
getSchema($sqlTransformContext);
}

function meta::external::query::sql::transformation::queryToPure::getSchema(context:SqlTransformContext[1]): meta::external::query::sql::Schema[1]
function meta::external::query::sql::transformation::queryToPure::getSchema(context:SqlTransformContext[1]): meta::external::query::sql::schema::metamodel::Schema[1]
{
$context.columns()->meta::external::query::sql::tdsColsToSchema();
}
Expand Down
Loading

0 comments on commit cdda855

Please sign in to comment.