diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/legend-engine-xt-relationalStore-sqlDialectTranslation-pure/src/main/resources/core_external_store_relational_sql_dialect_translation/defaults/sqlDialectDefaults.pure b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/legend-engine-xt-relationalStore-sqlDialectTranslation-pure/src/main/resources/core_external_store_relational_sql_dialect_translation/defaults/sqlDialectDefaults.pure index bf6c5fa7714..c0ce0f4ee68 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/legend-engine-xt-relationalStore-sqlDialectTranslation-pure/src/main/resources/core_external_store_relational_sql_dialect_translation/defaults/sqlDialectDefaults.pure +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/legend-engine-xt-relationalStore-sqlDialectTranslation-pure/src/main/resources/core_external_store_relational_sql_dialect_translation/defaults/sqlDialectDefaults.pure @@ -554,9 +554,12 @@ function meta::external::store::relational::sqlDialectTranslation::defaults::fun let sep0 = $state.separatorIfPretty(0, $config); let sep1 = $state.separatorIfPretty(1, $config); - $sqlDialect->qualifiedName($f.name, $state, $config) + '(' + if($f.arguments->isEmpty(), | '', | $sep1) + - $f.arguments->map(a | $sqlDialect->executeNodeProcessor($a, [], $state->increaseLevel(), $config))->joinStrings(',' + $state.separator(1, $config)) + - + if($f.arguments->isEmpty(), | '', | $sep0) + ')' + + let args = $f.arguments->map(a | $sqlDialect->executeNodeProcessor($a, [], $state->increaseLevel(), $config)); + let noArgIsMultiLine = !($args->isNotEmpty() && $config.formatConfig.pretty && $args->map(a | $a->indexOf($config.formatConfig.lineSeparator) >= 0)->or()); + + $sqlDialect->qualifiedName($f.name, $state, $config) + '(' + if($noArgIsMultiLine, | '', | $sep1) + + $args->joinStrings(',' + if($noArgIsMultiLine, | ' ', | $state.separator(1, $config))) + + + if($noArgIsMultiLine, | '', | $sep0) + ')' + if ($f.window->isNotEmpty(), | ' ' + $sqlDialect->keyword('over', $state, $config) + ' (' + $sep1 + $sqlDialect->executeNodeProcessor($f.window->toOne(), [], $state->increaseLevel(), $config) + $sep0 + ')', | '' @@ -601,6 +604,7 @@ function meta::external::store::relational::sqlDialectTranslation::defaults::joi pair(|$j.type == JoinType.CROSS, | $sqlDialect->keyword('cross join', $state, $config)), pair(|$j.type == JoinType.LEFT, | $sqlDialect->keyword('left outer join', $state, $config)), pair(|$j.type == JoinType.RIGHT, | $sqlDialect->keyword('right outer join', $state, $config)), + pair(|$j.type == JoinType.FULL, | $sqlDialect->keyword('full outer join', $state, $config)), pair(|$j.type == JoinType.INNER, | $sqlDialect->keyword('inner join', $state, $config)) ], | failWithMessage('Unhandled join type: ' + $j.type->toString()) @@ -727,3 +731,15 @@ function meta::external::store::relational::sqlDialectTranslation::defaults::sub {n | true} ) } + +function meta::external::store::relational::sqlDialectTranslation::defaults::tableSubqueryProcessor_default(): NodeProcessor[1] +{ + nodeProcessor( + TableSubquery, + {sqlDialect, s, state, config | + let sep0 = $state.separatorIfPretty(0, $config); + let sep1 = $state.separatorIfPretty(1, $config); + '(' + $sep1 + $sqlDialect->executeNodeProcessor($s.query, $state->increaseLevel(), $config) + $sep0 + ')'; + } + ) +} diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/legend-engine-xt-relationalStore-sqlDialectTranslation-pure/src/main/resources/core_external_store_relational_sql_dialect_translation/defaults/sqlDialectDefaultsTests.pure b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/legend-engine-xt-relationalStore-sqlDialectTranslation-pure/src/main/resources/core_external_store_relational_sql_dialect_translation/defaults/sqlDialectDefaultsTests.pure index 72e33368a22..b7240d60d7d 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/legend-engine-xt-relationalStore-sqlDialectTranslation-pure/src/main/resources/core_external_store_relational_sql_dialect_translation/defaults/sqlDialectDefaultsTests.pure +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/legend-engine-xt-relationalStore-sqlDialectTranslation-pure/src/main/resources/core_external_store_relational_sql_dialect_translation/defaults/sqlDialectDefaultsTests.pure @@ -509,15 +509,9 @@ function <> meta::external::store::relational::sqlDialectTranslation: let c4 = ^QualifiedNameReference(name = ^QualifiedName(parts = ['db', 'schema', 'table', 'c4'])); assertEquals('db.func()', $dialect->executeNodeProcessor(^FunctionCall(name = $name), $state, $config)); + assertEquals('db.func(101)', $dialect->executeNodeProcessor(^FunctionCall(name = $name, arguments = literal(101)), $state, $config)); assertEquals( - 'db.func(\n' + - ' 101\n' + - ')', $dialect->executeNodeProcessor(^FunctionCall(name = $name, arguments = literal(101)), $state, $config)); - assertEquals( - 'db.func(\n' + - ' 101,\n' + - ' FALSE\n' + - ') OVER (\n' + + 'db.func(101, FALSE) OVER (\n' + ' PARTITION BY\n' + ' db.schema.table.c1,\n' + ' db.schema.table.c2\n' + @@ -540,6 +534,24 @@ function <> meta::external::store::relational::sqlDialectTranslation: $state, $config ) ); + + let caseExpression = ^SearchedCaseExpression(whenClauses = [^WhenClause(result = literal(101), operand = literal(false)), ^WhenClause(result = literal(102), operand = literal(true))]); + assertEquals( + 'db.func(\n' + + ' 101,\n' + + ' CASE\n' + + ' WHEN\n' + + ' FALSE\n' + + ' THEN\n' + + ' 101\n' + + ' WHEN\n' + + ' TRUE\n' + + ' THEN\n' + + ' 102\n' + + ' END\n' + + ')', + $dialect->executeNodeProcessor(^FunctionCall(name = $name, arguments = [literal(101), $caseExpression]), $state, $config) + ); } function <> meta::external::store::relational::sqlDialectTranslation::defaults::tests::testTableProcessing(): Boolean[1] @@ -574,6 +586,7 @@ function <> meta::external::store::relational::sqlDialectTranslation: assertEquals('db.schema.table_a CROSS JOIN db.schema.table_b', $dialect->executeNodeProcessor(^Join(left = $tblA, right = $tblB, type = JoinType.CROSS), $state, $config)); assertEquals('db.schema.table_a LEFT OUTER JOIN db.schema.table_b', $dialect->executeNodeProcessor(^Join(left = $tblA, right = $tblB, type = JoinType.LEFT), $state, $config)); assertEquals('db.schema.table_a RIGHT OUTER JOIN db.schema.table_b', $dialect->executeNodeProcessor(^Join(left = $tblA, right = $tblB, type = JoinType.RIGHT), $state, $config)); + assertEquals('db.schema.table_a FULL OUTER JOIN db.schema.table_b', $dialect->executeNodeProcessor(^Join(left = $tblA, right = $tblB, type = JoinType.FULL), $state, $config)); assertEquals('db.schema.table_a INNER JOIN db.schema.table_b', $dialect->executeNodeProcessor(^Join(left = $tblA, right = $tblB, type = JoinType.INNER), $state, $config)); assertEquals( @@ -1040,3 +1053,40 @@ function <> meta::external::store::relational::sqlDialectTranslation: ' 103 < 104\n' + ')', $dialect->executeNodeProcessor(^SubqueryExpression(query = ^Query(queryBody = $q1)), $state, $config)); } + + +function <> meta::external::store::relational::sqlDialectTranslation::defaults::tests::testTableSubqueryProcessing(): Boolean[1] +{ + let dialect = testDialect(); + let state = testSqlDialectTranslationState(); + let config = testSqlDialectTranslationConfig(false); + + let q1 = ^QuerySpecification( + select = ^Select(selectItems = [^SingleColumn(expression = ^ArithmeticExpression(left = literal(101), right = literal(102), type = ArithmeticType.ADD))]), + from = ^Table(name = ^QualifiedName(parts = ['t'])), + where = ^ComparisonExpression(left = literal(103), right = literal(104), operator = ComparisonOperator.LESS_THAN) + ); + assertEquals('(SELECT 101 + 102 FROM t WHERE 103 < 104)', $dialect->executeNodeProcessor(^TableSubquery(query = ^Query(queryBody = $q1)), $state, $config)); +} + +function <> meta::external::store::relational::sqlDialectTranslation::defaults::tests::testTableSubqueryPrettyFormatProcessing(): Boolean[1] +{ + let dialect = testDialect(); + let state = testSqlDialectTranslationState(); + let config = testSqlDialectTranslationConfig(true); + + let q1 = ^QuerySpecification( + select = ^Select(selectItems = [^SingleColumn(expression = ^ArithmeticExpression(left = literal(101), right = literal(102), type = ArithmeticType.ADD))]), + from = ^Table(name = ^QualifiedName(parts = ['t'])), + where = ^ComparisonExpression(left = literal(103), right = literal(104), operator = ComparisonOperator.LESS_THAN) + ); + assertEquals( + '(\n' + + ' SELECT\n' + + ' 101 + 102\n' + + ' FROM\n' + + ' t\n' + + ' WHERE\n' + + ' 103 < 104\n' + + ')', $dialect->executeNodeProcessor(^TableSubquery(query = ^Query(queryBody = $q1)), $state, $config)); +} \ No newline at end of file diff --git a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/legend-engine-xt-relationalStore-sqlDialectTranslation-pure/src/main/resources/core_external_store_relational_sql_dialect_translation/postgres/postgresSqlDialect.pure b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/legend-engine-xt-relationalStore-sqlDialectTranslation-pure/src/main/resources/core_external_store_relational_sql_dialect_translation/postgres/postgresSqlDialect.pure index a321ce319c8..764496e97bb 100644 --- a/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/legend-engine-xt-relationalStore-sqlDialectTranslation-pure/src/main/resources/core_external_store_relational_sql_dialect_translation/postgres/postgresSqlDialect.pure +++ b/legend-engine-xts-relationalStore/legend-engine-xt-relationalStore-generation/legend-engine-xt-relationalStore-pure/legend-engine-xt-relationalStore-sqlDialectTranslation-pure/src/main/resources/core_external_store_relational_sql_dialect_translation/postgres/postgresSqlDialect.pure @@ -96,7 +96,8 @@ function <> meta::external::store::relational::sqlDialectTransla aliasedRelationProcessor_default(), joinProcessor_default(), querySpecificationProcessor_default(), - unionProcessor_default() + unionProcessor_default(), + tableSubqueryProcessor_default() ] }