Skip to content

Commit

Permalink
Handle null on painless script
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelbey committed Nov 30, 2023
1 parent 57ea344 commit 9965a74
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,10 @@ else if (aggregationContainer.multi_terms != null)
}
else
{
if (!this.activities.isEmpty())
{
return false;
}
processor = ExecutionRequestVisitor.this::processNotAggregateResponse;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1389,12 +1389,16 @@ function meta::external::store::elasticsearch::v7::pureToEs::processPainlessIsNo
let field = $fieldPair.first.values->cast(@TDSESDetail)->toOne('isNotEmpty only works on tds columns for now');
let req = $fieldPair.second;

let script = $field.resultPath.property->match([
pair(^InlineScript(source = $field->painlessIsNotEmpty()->literal(), params = newMap([])), $req);
}


function meta::external::store::elasticsearch::v7::pureToEs::painlessIsNotEmpty(field: TDSESDetail[1]): String[1]
{
$field.resultPath.property->match([
text: TextProperty[1] | 'params[\'_source\'][\'%s\'] != null',
any: Any[1] | 'doc[\'%s\'].size() != 0';
])->format($field.path());

pair(^InlineScript(source = $script->literal(), params = newMap([])), $req);
}

function meta::external::store::elasticsearch::v7::pureToEs::processPainlessBooleanComparison(fe: FunctionExpression[1], initReq: State[1]): Pair<InlineScript, State>[1]
Expand Down Expand Up @@ -1459,12 +1463,12 @@ function meta::external::store::elasticsearch::v7::pureToEs::processPainlessBool
any: Any[*] | 'params[\'%s\']'
])->format($param.first);

let script = '%s.toInstant().toEpochMilli() %s %s'->format([painlessExtractField($tdsESDetail), $operation, $paramScript]);
let script = '(%s && %s.toInstant().toEpochMilli() %s %s)'->format([painlessIsNotEmpty($tdsESDetail), painlessExtractField($tdsESDetail), $operation, $paramScript]);
let literalOrExpression = $newValue->literalOrExpression(true)->toOne();
pair(^InlineScript(source = $script->literal(), params = newMap(pair($param.first, $literalOrExpression))), $param.second);
},
{|
let script = '%s %s params[\'%s\']'->format([painlessExtractField($tdsESDetail), $operation, $param.first]);
let script = '(%s && %s %s params[\'%s\'])'->format([painlessIsNotEmpty($tdsESDetail), painlessExtractField($tdsESDetail), $operation, $param.first]);
let literalOrExpression = $value->literalOrExpression(true)->toOne();
pair(^InlineScript(source = $script->literal(), params = newMap(pair($param.first, $literalOrExpression))), $param.second);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ meta::external::store::elasticsearch::executionTest::testCase::tds::project::mis
$config->testTdsExpression(x|$x->extend([col(x: TDSRow[1] | if($x.getDate('ReleaseDate') >= %1990-01-01, |'90s and newer', |'Older than 90s'), 'Bucket')]));
}

function
<<paramTest.Test>>
{doc.doc = 'Test projection on Elasticsearch with pure if expressions on nullable field'}
meta::external::store::elasticsearch::executionTest::testCase::tds::project::misc::testProjectExpressionOnNullable(config:TestConfig[1]):Boolean[1]
{
$config->testTdsExpression(x|$x->extend([col(x: TDSRow[1] | $x.getNullableString('MPAA') == 'PG-13', 'Bucket')]));
}

function
<<paramTest.Test>>
{doc.doc = 'Test projection on Elasticsearch with pure if expressions'}
Expand Down

0 comments on commit 9965a74

Please sign in to comment.