From a4957fe19fce70fc16453be6af4dd578cd5051d2 Mon Sep 17 00:00:00 2001 From: Rafael Bey <24432403+rafaelbey@users.noreply.github.com> Date: Tue, 16 Apr 2024 16:57:38 -0400 Subject: [PATCH] Support from() without mapping on ES queries (#2786) --- .../core/pure/router/store/cluster.pure | 39 +++++++++++++------ .../core/pure/router/store/metamodel.pure | 2 +- .../extensions/store_contract.pure | 7 +++- .../elasticsearch_plan_test.pure | 2 +- .../engineGrammar_7._pure_ | 8 +--- 5 files changed, 35 insertions(+), 23 deletions(-) diff --git a/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/router/store/cluster.pure b/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/router/store/cluster.pure index 38398a86bfa..0bd8fa9cc7c 100644 --- a/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/router/store/cluster.pure +++ b/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/router/store/cluster.pure @@ -434,18 +434,33 @@ function meta::pure::router::clustering::cluster(v:ValueSpecification[1], mappin v:VariableExpression[1]|print(if($debug.debug,|$v->asString()->debug($debug.space+'Var: '),|'')); ^ClusterResponse(cluster=$v);, c:StoreMappingClusteredValueSpecification[1] | ^ClusterResponse(cluster = $c), - t:TDSRoutedValueSpecification[1] | ^ClusterResponse(cluster = ^StoreMappingClusteredValueSpecification( - genericType = $t.genericType, - multiplicity = $t.multiplicity, - s = $extensions->meta::pure::extension::storeContractFromStore($t.store), - store = $t.store, - mapping = $t.mapping, - runtime = $t.runtime, - openVars = $openVariables, - val = $t, - exeCtx = $t.executionContext, - executable = true - )), + t:TDSRoutedValueSpecification[1] | + let cluster = if ($t.mapping->isEmpty(), + | ^StoreClusteredValueSpecification( + genericType = $t.genericType, + multiplicity = $t.multiplicity, + s = $extensions->meta::pure::extension::storeContractFromStore($t.store), + store = $t.store, + runtime = $t.runtime, + openVars = $openVariables, + val = $t, + exeCtx = $t.executionContext, + executable = true + ), + | ^StoreMappingClusteredValueSpecification( + genericType = $t.genericType, + multiplicity = $t.multiplicity, + s = $extensions->meta::pure::extension::storeContractFromStore($t.store), + store = $t.store, + mapping = $t.mapping->toOne(), + runtime = $t.runtime, + openVars = $openVariables, + val = $t, + exeCtx = $t.executionContext, + executable = true + ) + ); + ^ClusterResponse(cluster = $cluster);, s:StoreRoutedValueSpecification[1]| let processed = $s.value->cluster([], $openVariables, $s.executionContext, ^$debug(space = $debug.space+' '), $analyticsDecision, $extensions); if ($processed.cluster->instanceOf(StoreClusteredValueSpecification), diff --git a/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/router/store/metamodel.pure b/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/router/store/metamodel.pure index 37552d67c02..7e392867bae 100644 --- a/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/router/store/metamodel.pure +++ b/legend-engine-core/legend-engine-core-pure/legend-engine-pure-code-compiled-core/src/main/resources/core/pure/router/store/metamodel.pure @@ -83,7 +83,7 @@ Class meta::pure::router::TDSRoutedValueSpecification extends RoutedValueSpecifi { id:String[1]; runtime:Runtime[1]; - mapping:Mapping[1]; + mapping:Mapping[0..1]; store:meta::pure::store::Store[1]; executionContext:meta::pure::runtime::ExecutionContext[1]; } diff --git a/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-V7-pure-metamodel/src/main/resources/core_elasticsearch_seven_metamodel/extensions/store_contract.pure b/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-V7-pure-metamodel/src/main/resources/core_elasticsearch_seven_metamodel/extensions/store_contract.pure index eca73b10b74..d10b97a0330 100644 --- a/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-V7-pure-metamodel/src/main/resources/core_elasticsearch_seven_metamodel/extensions/store_contract.pure +++ b/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-V7-pure-metamodel/src/main/resources/core_elasticsearch_seven_metamodel/extensions/store_contract.pure @@ -110,8 +110,11 @@ function meta::external::store::elasticsearch::v7::contract::routeFunctionExpres fe:FunctionExpression[1] | $fe.func == meta::external::store::elasticsearch::v7::tds::indexToTDS_Elasticsearch7Store_1__String_1__TabularDataSet_1_, {function: Function[1], fe: FunctionExpression[1], state: RoutingState[1], executionContext: meta::pure::runtime::ExecutionContext[1], vars: Map[1], inScopeVars: Map>[1], extensions: meta::pure::extension::Extension[*], debug: DebugContext[1] | let store = $fe->instanceValuesAtParameter(0, $vars, $inScopeVars)->toOne()->cast(@Elasticsearch7Store); - let mapping = $state.routingStrategy->cast(@meta::pure::router::store::metamodel::StoreMappingRoutingStrategy).mapping; - let runtime = $state.routingStrategy->cast(@meta::pure::router::store::metamodel::StoreMappingRoutingStrategy).runtime; + let mapping = if($state.routingStrategy->instanceOf(meta::pure::router::store::metamodel::StoreMappingRoutingStrategy), + |$state.routingStrategy->cast(@meta::pure::router::store::metamodel::StoreMappingRoutingStrategy).mapping, + |[] + ); + let runtime = $state.routingStrategy->cast(@meta::pure::router::store::metamodel::StoreRoutingStrategy).runtime; ^$state(value = ^TDSRoutedValueSpecification( genericType = $fe.genericType, multiplicity = $fe.multiplicity, diff --git a/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-executionPlan-test/src/main/resources/core_elasticsearch_execution_test/elasticsearch_plan_test.pure b/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-executionPlan-test/src/main/resources/core_elasticsearch_execution_test/elasticsearch_plan_test.pure index c5400ca29ea..a27bff5c473 100644 --- a/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-executionPlan-test/src/main/resources/core_elasticsearch_execution_test/elasticsearch_plan_test.pure +++ b/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-executionPlan-test/src/main/resources/core_elasticsearch_execution_test/elasticsearch_plan_test.pure @@ -230,7 +230,7 @@ function meta::external::store::elasticsearch::executionTest::testCase::tds::run let toCompile = $config.model->replace('%_url_%', 'http://%s:%d'->format([$url.host, $url.port])) + '\n\n' + '###Pure \n\n ' + 'function test::test(' + $varDefinitions + '): TabularDataSet[1] {\n' + - ' indexToTDS(test::Store, \'omdb-common\')->from(test::EmptyMapping, test::Runtime)->' + $toTest + ';' + + ' indexToTDS(test::Store, \'omdb-common\')->from(test::Runtime)->' + $toTest + ';' + '}'; // $toCompile->println(); diff --git a/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-executionPlan-test/src/main/resources/core_elasticsearch_execution_test/engineGrammar_7._pure_ b/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-executionPlan-test/src/main/resources/core_elasticsearch_execution_test/engineGrammar_7._pure_ index 29b203f6b60..babfa105e7b 100644 --- a/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-executionPlan-test/src/main/resources/core_elasticsearch_execution_test/engineGrammar_7._pure_ +++ b/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-executionPlan-test/src/main/resources/core_elasticsearch_execution_test/engineGrammar_7._pure_ @@ -52,10 +52,4 @@ Runtime test::Runtime connection: test::Connection ] ]; -} - -###Mapping -Mapping test::EmptyMapping -( - -) \ No newline at end of file +} \ No newline at end of file