Skip to content

Commit

Permalink
Legend SQL - Handle null valuespecifications correctly in cast (#2499)
Browse files Browse the repository at this point in the history
  • Loading branch information
gs-jp1 authored Dec 6, 2023
1 parent e035f85 commit 554665f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1585,9 +1585,10 @@ function <<access.private>> meta::external::query::sql::transformation::queryToP

let expression = processExpression($c.expression, $expContext, $context);

$c.expression->match([
n:NullLiteral[1] | processCastAsCast($c, $expression, $expContext, $context),
e:meta::external::query::sql::metamodel::Expression[1] |
if ($expression->evaluateAndDeactivate().multiplicity == PureZero,
|
processCastAsCast($c, $expression, $expContext, $context),
|
let type = $expression.genericType.rawType->toOne();
let castName = $c.type.name->toUpper();

Expand All @@ -1598,7 +1599,7 @@ function <<access.private>> meta::external::query::sql::transformation::queryToP
pair($type == String || $castName == 'TEXT', | processCastAsParse($c, $expression, $expContext, $context)),
pair(true, | processCastAsCast($c, $expression, $expContext, $context))
]->getValues(true)->first()->toOne()->eval()->evaluateAndDeactivate();
]);
);
}

function <<access.private>> meta::external::query::sql::transformation::queryToPure::processDoublePrecisionCast(c:Cast[1], v:ValueSpecification[1], expContext:SqlTransformExpressionContext[1], context:SqlTransformContext[1]):ValueSpecification[1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,9 @@ function <<test.Test>> meta::external::query::sql::transformation::queryToPure::
function <<test.Test>> meta::external::query::sql::transformation::queryToPure::tests::testNullCasts():Boolean[1]
{
test('SELECT CAST(NULL AS VARCHAR) AS "string", CAST(NULL AS TEXT) AS "text", CAST(NULL AS DATE) AS "date", ' +
'CAST(NULL AS INTEGER) AS "integer", CAST(NULL AS BOOLEAN) AS "boolean", CAST(NULL AS DOUBLE PRECISION) AS "double", CAST(NULL AS NUMERIC) AS "numeric", CAST(NULL AS TIMESTAMP) AS "timestamp" FROM service."/service/service1"',
'CAST(NULL AS INTEGER) AS "integer", CAST(NULL AS BOOLEAN) AS "boolean", CAST(NULL AS DOUBLE PRECISION) AS "double", ' +
'CAST(NULL AS NUMERIC) AS "numeric", CAST(NULL AS TIMESTAMP) AS "timestamp", CAST(floor(NULL) AS TEXT) AS "exp" ' +
'FROM service."/service/service1"',

{| FlatInput.all()->project(
[ x | $x.booleanIn, x | $x.integerIn, x | $x.floatIn, x | $x.decimalIn, x | $x.strictDateIn, x | $x.dateTimeIn, x | $x.stringIn ],
Expand All @@ -1064,7 +1066,8 @@ function <<test.Test>> meta::external::query::sql::transformation::queryToPure::
col(row:TDSRow[1] | cast([], @Boolean), 'boolean'),
col(row:TDSRow[1] | cast([], @Float), 'double'),
col(row:TDSRow[1] | cast([], @Decimal), 'numeric'),
col(row:TDSRow[1] | cast([], @DateTime), 'timestamp')
col(row:TDSRow[1] | cast([], @DateTime), 'timestamp'),
col(row:TDSRow[1] | cast([], @String), 'exp')
])
})
}
Expand Down

0 comments on commit 554665f

Please sign in to comment.