diff --git a/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-V7-executionPlan/src/main/java/org/finos/legend/engine/plan/execution/stores/elasticsearch/v7/result/ExecutionRequestVisitor.java b/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-V7-executionPlan/src/main/java/org/finos/legend/engine/plan/execution/stores/elasticsearch/v7/result/ExecutionRequestVisitor.java index 6387c5ca105..4c89bb358ca 100644 --- a/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-V7-executionPlan/src/main/java/org/finos/legend/engine/plan/execution/stores/elasticsearch/v7/result/ExecutionRequestVisitor.java +++ b/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-V7-executionPlan/src/main/java/org/finos/legend/engine/plan/execution/stores/elasticsearch/v7/result/ExecutionRequestVisitor.java @@ -273,12 +273,17 @@ private static Iterator processFiltersBucket(AggregateTDSResultVisit for (Map.Entry bucketEntry : buckets.keyed.entrySet()) { + FiltersBucket value = bucketEntry.getValue(); + + if (value.doc_count.getLiteral() == 0) + { + continue; + } + MutableMap result = Maps.mutable.empty(); result.put(key, bucketEntry.getKey()); - FiltersBucket value = bucketEntry.getValue(); - for (Map.Entry aggregateEntry : value.__additionalProperties.entrySet()) { result.put(aggregateEntry.getKey(), ((AggregateBase) aggregateEntry.getValue().unionValue()).accept(aggregateTDSResultVisitor)); diff --git a/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-V7-pure-metamodel/src/main/resources/core_elasticsearch_seven_metamodel/functions/pure_to_elasticsearch.pure b/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-V7-pure-metamodel/src/main/resources/core_elasticsearch_seven_metamodel/functions/pure_to_elasticsearch.pure index 4226f0162c5..efb89461fca 100644 --- a/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-V7-pure-metamodel/src/main/resources/core_elasticsearch_seven_metamodel/functions/pure_to_elasticsearch.pure +++ b/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-V7-pure-metamodel/src/main/resources/core_elasticsearch_seven_metamodel/functions/pure_to_elasticsearch.pure @@ -1535,16 +1535,11 @@ function meta::external::store::elasticsearch::v7::pureToEs::processPainlessBool ]); let paramScript = $newValue->match([ - pv: PlanVarPlaceHolder[1] | - if($pv.type == StrictDate, - |'LocalDate.parse(params[\'%s\']).atTime(0, 0).toInstant(ZoneOffset.UTC).toEpochMilli()', - | if($pv.type == DateTime, - |'ZonedDateTime.parse(params[\'%s\']).toInstant().toEpochMilli()', - | fail('Type not supported on variable - %s:%s'->format([$pv.name, $pv.type->elementToPath()]))->cast(@String) - ) - ), - any: Any[*] | 'params[\'%s\']' - ])->format($param.first); + pv: PlanVarPlaceHolder[1] | + '(params[\'%s\'].length() <= 10 ? LocalDate.parse(params[\'%s\']).atTime(0, 0) : LocalDateTime.parse(params[\'%s\'])).toInstant(ZoneOffset.UTC).toEpochMilli()' + ->format([$param.first, $param.first, $param.first]), + any: Any[*] | 'params[\'%s\']'->format($param.first) + ]); let script = '(%s && %s.toInstant().toEpochMilli() %s %s)'->format([painlessIsNotEmpty($tdsESDetail), painlessExtractField($tdsESDetail), $operation, $paramScript]); let literalOrExpression = $newValue->literalOrExpression(true)->toOne(); diff --git a/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-executionPlan-test/src/main/resources/core_elasticsearch_execution_test/elasticsearch_plan_test_aggregation.pure b/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-executionPlan-test/src/main/resources/core_elasticsearch_execution_test/elasticsearch_plan_test_aggregation.pure index c86cbd5e80d..ca101408ad1 100644 --- a/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-executionPlan-test/src/main/resources/core_elasticsearch_execution_test/elasticsearch_plan_test_aggregation.pure +++ b/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-executionPlan-test/src/main/resources/core_elasticsearch_execution_test/elasticsearch_plan_test_aggregation.pure @@ -135,3 +135,64 @@ meta::external::store::elasticsearch::executionTest::testCase::tds::groupBy::tes |'Newer', |'Newest'))), 'ReleaseDate'), col(x: TDSRow[1] | $x.getInteger('Budget'), 'Budget')])->groupBy('ReleaseDate', agg('sumBudget', r | $r.getInteger('Budget'), agg | $agg->sum()))); } + +function + <> + {doc.doc = 'Test projection on Elasticsearch with pure nested if expressions'} +meta::external::store::elasticsearch::executionTest::testCase::tds::groupBy::testGroupByIfExpressionOnAdjustTodayFunctions(config:TestConfig[1]):Boolean[1] +{ + $config->testTdsExpression(x|$x->extend([col(x: TDSRow[1] | + if($x.getDate('ReleaseDate') < today()->adjust(-15, DurationUnit.YEARS), + |'Oldest', + |if($x.getDate('ReleaseDate') < today()->adjust(-10, DurationUnit.YEARS), + |'Older', + |if($x.getDate('ReleaseDate') < today()->adjust(-5, DurationUnit.YEARS), + |'Newer', + |'Newest'))), 'Bucket')])->groupBy('Bucket', agg('sumBudget', r | $r.getInteger('Budget'), agg | $agg->sum()))); +} + +function + <> + {doc.doc = 'Test projection on Elasticsearch with pure nested if expressions'} +meta::external::store::elasticsearch::executionTest::testCase::tds::groupBy::testGroupByExpressionOnAdjustTodayFunctions(config:TestConfig[1]):Boolean[1] +{ + $config->testTdsExpression(x|$x->extend([col(x: TDSRow[1] | + $x.getDate('ReleaseDate') < today()->adjust(-15, DurationUnit.YEARS), + 'Is Old?')])->groupBy('Is Old?', agg('sumBudget', r | $r.getInteger('Budget'), agg | $agg->sum()))); +} + + +function + <> + {doc.doc = 'Test projection on Elasticsearch with pure nested if expressions'} +meta::external::store::elasticsearch::executionTest::testCase::tds::groupBy::testGroupByIfExpressionOnAdjustNowFunctions(config:TestConfig[1]):Boolean[1] +{ + $config->testTdsExpression(x|$x->extend([col(x: TDSRow[1] | + if($x.getDate('ReleaseDate') < now()->adjust(-15, DurationUnit.YEARS), + |'Oldest', + |if($x.getDate('ReleaseDate') < now()->adjust(-10, DurationUnit.YEARS), + |'Older', + |if($x.getDate('ReleaseDate') < now()->adjust(-5, DurationUnit.YEARS), + |'Newer', + |'Newest'))), 'Bucket')])->groupBy('Bucket', agg('sumBudget', r | $r.getInteger('Budget'), agg | $agg->sum()))); +} + +function + <> + {doc.doc = 'Test projection on Elasticsearch with pure nested if expressions'} +meta::external::store::elasticsearch::executionTest::testCase::tds::groupBy::testGroupByExpressionOnAdjustNowFunctions(config:TestConfig[1]):Boolean[1] +{ + $config->testTdsExpression(x|$x->extend([col(x: TDSRow[1] | + $x.getDate('ReleaseDate') < now()->adjust(-15, DurationUnit.YEARS), + 'Is Old?')])->groupBy('Is Old?', agg('sumBudget', r | $r.getInteger('Budget'), agg | $agg->sum()))); +} + +function + <> + {doc.doc = 'Test projection on Elasticsearch with pure nested if expressions'} +meta::external::store::elasticsearch::executionTest::testCase::tds::groupBy::testGroupByExpressionOnAdjustNowFunctions2(config:TestConfig[1]):Boolean[1] +{ + $config->testTdsExpression(x|$x->extend([col(x: TDSRow[1] | + $x.getDate('ReleaseDate') < now(), + 'Is Old?')])->groupBy('Is Old?', agg('sumBudget', r | $r.getInteger('Budget'), agg | $agg->sum()))); +} \ No newline at end of file diff --git a/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-executionPlan-test/src/main/resources/core_elasticsearch_execution_test/elasticsearch_plan_test_filter_date.pure b/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-executionPlan-test/src/main/resources/core_elasticsearch_execution_test/elasticsearch_plan_test_filter_date.pure index d69e338dd57..a4d90be8557 100644 --- a/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-executionPlan-test/src/main/resources/core_elasticsearch_execution_test/elasticsearch_plan_test_filter_date.pure +++ b/legend-engine-xts-elasticsearch/legend-engine-xt-elasticsearch-executionPlan-test/src/main/resources/core_elasticsearch_execution_test/elasticsearch_plan_test_filter_date.pure @@ -186,4 +186,20 @@ meta::external::store::elasticsearch::executionTest::testCase::tds::filter::date { let var = %2010-04-26T00:00:00.200+0000; $config->testTdsExpression(x | $x->filter(x | $var <= $x.getDate('ReleaseDate'))); +} + +function + <> + {doc.doc = 'Test less than equal filter on Elasticsearch Integer property mapping with variable'} +meta::external::store::elasticsearch::executionTest::testCase::tds::filter::date::testFilterUsingValueFromAdjustNowFunctions(config:TestConfig[1]):Boolean[1] +{ + $config->testTdsExpression(x | $x->filter(x | $x.getDate('ReleaseDate') >= now()->adjust(-15, DurationUnit.YEARS))); +} + +function + <> + {doc.doc = 'Test less than equal filter on Elasticsearch Integer property mapping with variable'} +meta::external::store::elasticsearch::executionTest::testCase::tds::filter::date::testFilterUsingValueFromAdjustTodayFunctions(config:TestConfig[1]):Boolean[1] +{ + $config->testTdsExpression(x | $x->filter(x | $x.getDate('ReleaseDate') >= today()->adjust(-15, DurationUnit.YEARS))); } \ No newline at end of file