Cast null-able attribute to not null-able attribute


#1

Is there a way to cast a null-able attribute to not null-able attribute?

For example, this does not work:

AFL% cast(build(<x:int64>[i=0:9], i), <y:int64 not null>[i]);
Error description: Error during schema inferring. Attribute 'y' flags doesn't match.

I guess this is because SciDB does not know what value y should be if x is null.


#2

You have to use operator substitute()
https://paradigm4.atlassian.net/wiki/spaces/scidb/pages/241598546/substitute


#3

Oh, right, I forgot about it. Thanks!

Just for completeness of the example:

AFL% substitute(build(<x:int64>[i=0:9], i), 
                build(<s:int64 not null>[i=0:0], -1));
{i} x
...

AFL% show('substitute(build(<x:int64>[i=0:9], i), build(<s:int64 not null>[i=0:0], -1))', 'afl');
{i} schema
{0} 'build_subst<x:int64 NOT NULL> [i=0:9:0:1000000]'

#4

And for multiple attributes of different types, substitute needs to be called once for each type:

AFL% substitute(
       substitute(
         apply(build(<x:int64>[i=0:9], i), y, string(x)), 
         build(<s:int64 not null>[i=0:0], -1), x), 
       build(<s:string not null>[i=0:0], ''), y); 
{i} x,y
{0} 0,'0'
...

AFL% show('substitute(substitute(apply(build(<x:int64>[i=0:9], i), y, string(x)), build(<s:int64 not null>[i=0:0], -1), x), build(<s:string not null>[i=0:0], \'\'), y)', 'afl');
{i} schema
{0} 'build_subst_subst<x:int64 NOT NULL,y:string NOT NULL> [i=0:9:0:1000000]'