From c18dfca8ca6de65d0a01dac08b256e4b80be5dd2 Mon Sep 17 00:00:00 2001 From: gs-ssh16 Date: Tue, 29 Oct 2024 10:33:57 +0000 Subject: [PATCH] Formatting update for subqueries/applied functions --- .../defaults/sqlDialectDefaults.pure | 16 ++++++++-------- .../defaults/sqlDialectDefaultsTests.pure | 10 +++++----- .../sqlDialectTranslator.pure | 9 +++++++++ 3 files changed, 22 insertions(+), 13 deletions(-) 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 36d4f06b74b..bf6c5fa7714 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 @@ -448,9 +448,9 @@ function meta::external::store::relational::sqlDialectTranslation::defaults::inL nodeProcessor( InListExpression, {sqlDialect, l, state, config | - let sep0 = $state.separator(0, $config); - let sep1 = $state.separator(1, $config); - let whenClauses = $l.values->map(v | $sqlDialect->executeNodeProcessor($v, [], $state->increaseLevel(), $config))->joinStrings(',' + $sep1); + let sep0 = $state.separatorIfPretty(0, $config); + let sep1 = $state.separatorIfPretty(1, $config); + let whenClauses = $l.values->map(v | $sqlDialect->executeNodeProcessor($v, [], $state->increaseLevel(), $config))->joinStrings(',' + $state.separator(1, $config)); '(' + $sep1 + $whenClauses + $sep0 + ')'; }, {n | true} @@ -551,11 +551,11 @@ function meta::external::store::relational::sqlDialectTranslation::defaults::fun assert($f.group->isEmpty(), | 'Grouped function call processing not implemented yet'); assert($f.orderBy->isEmpty(), | 'Sorted function call processing not implemented yet'); - let sep0 = $state.separator(0, $config); - let sep1 = $state.separator(1, $config); + 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(',' + $sep1) + + $f.arguments->map(a | $sqlDialect->executeNodeProcessor($a, [], $state->increaseLevel(), $config))->joinStrings(',' + $state.separator(1, $config)) + + if($f.arguments->isEmpty(), | '', | $sep0) + ')' + if ($f.window->isNotEmpty(), | ' ' + $sqlDialect->keyword('over', $state, $config) + ' (' + $sep1 + $sqlDialect->executeNodeProcessor($f.window->toOne(), [], $state->increaseLevel(), $config) + $sep0 + ')', @@ -720,8 +720,8 @@ function meta::external::store::relational::sqlDialectTranslation::defaults::sub nodeProcessor( SubqueryExpression, {sqlDialect, s, state, config | - let sep0 = $state.separator(0, $config); - let sep1 = $state.separator(1, $config); + let sep0 = $state.separatorIfPretty(0, $config); + let sep1 = $state.separatorIfPretty(1, $config); '(' + $sep1 + $sqlDialect->executeNodeProcessor($s.query, $state->increaseLevel(), $config) + $sep0 + ')'; }, {n | true} 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 48c4cc83de4..72e33368a22 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 @@ -345,7 +345,7 @@ function <> meta::external::store::relational::sqlDialectTranslation: let config = testSqlDialectTranslationConfig(false); let e = ^InListExpression(values = [literal(101), literal(102), literal(103)]); - assertEquals('( 101, 102, 103 )', $dialect->executeNodeProcessor($e, $state, $config)); + assertEquals('(101, 102, 103)', $dialect->executeNodeProcessor($e, $state, $config)); } function <> meta::external::store::relational::sqlDialectTranslation::defaults::tests::testInListExpressionPrettyFormatProcessing(): Boolean[1] @@ -372,7 +372,7 @@ function <> meta::external::store::relational::sqlDialectTranslation: let valueList = ^InListExpression(values = [literal(101), literal(102), literal(103)]); let e1 = ^InPredicate(valueList = $valueList, value = literal(101)); let e2 = ^InPredicate(valueList = $valueList, value = literal(101)); - assertEquals('101 IN ( 101, 102, 103 )', $dialect->executeNodeProcessor($e1, $state, $config)); + assertEquals('101 IN (101, 102, 103)', $dialect->executeNodeProcessor($e1, $state, $config)); } function <> meta::external::store::relational::sqlDialectTranslation::defaults::tests::testInPredicatePrettyFormatProcessing(): Boolean[1] @@ -476,9 +476,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(101)', $dialect->executeNodeProcessor(^FunctionCall(name = $name, arguments = literal(101)), $state, $config)); assertEquals( - 'db.func( 101, FALSE ) OVER ( PARTITION BY db.schema.table.c1, db.schema.table.c2 ORDER BY db.schema.table.c3 DESC NULLS FIRST, db.schema.table.c4 ASC NULLS LAST )', + 'db.func(101, FALSE) OVER (PARTITION BY db.schema.table.c1, db.schema.table.c2 ORDER BY db.schema.table.c3 DESC NULLS FIRST, db.schema.table.c4 ASC NULLS LAST)', $dialect->executeNodeProcessor( ^FunctionCall( name = $name, @@ -1016,7 +1016,7 @@ function <> meta::external::store::relational::sqlDialectTranslation: 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(^SubqueryExpression(query = ^Query(queryBody = $q1)), $state, $config)); + assertEquals('(SELECT 101 + 102 FROM t WHERE 103 < 104)', $dialect->executeNodeProcessor(^SubqueryExpression(query = ^Query(queryBody = $q1)), $state, $config)); } function <> meta::external::store::relational::sqlDialectTranslation::defaults::tests::testSubqueryExpressionPrettyFormatProcessing(): Boolean[1] 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/sqlDialectTranslator.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/sqlDialectTranslator.pure index d79f8e40fa3..159d6e367fd 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/sqlDialectTranslator.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/sqlDialectTranslator.pure @@ -80,12 +80,21 @@ Class meta::external::store::relational::sqlDialectTranslation::SqlDialectTransl { level: Integer[1] = 0; + {doc.doc = 'Returns right level indentation for next line if pretty format configured, else space'} separator(offsetIndex: Integer[1], config: SqlDialectTranslationConfig[1]) { if ($config.formatConfig.pretty, | $config.formatConfig.lineSeparator + repeat($config.formatConfig.indent, $this.level + $offsetIndex)->joinStrings(), | ' ' ) }: String[1]; + + {doc.doc = 'Returns right level indentation for next line if pretty format configured, else empty string'} + separatorIfPretty(offsetIndex: Integer[1], config: SqlDialectTranslationConfig[1]) { + if ($config.formatConfig.pretty, + | $config.formatConfig.lineSeparator + repeat($config.formatConfig.indent, $this.level + $offsetIndex)->joinStrings(), + | '' + ) + }: String[1]; } function meta::external::store::relational::sqlDialectTranslation::increaseLevel(state: SqlDialectTranslationState[1]): SqlDialectTranslationState[1]