Default

This application demonstrates how to use default function to process attributes with null values

Please see Values in Query guide for more information on format of the various data types.

define stream PatientRegistrationInputStream (
                 seqNo long, name string, age int,
                 height float, weight double, photo object,
                 isEmployee bool, wardNo object);

@info(name = 'SimpleIfElseQuery')
from PatientRegistrationInputStream
select 
    default(name, 'invalid') as name, 
    default(seqNo, 0l) as seqNo, 
    default(weight, 0d) as weight,

    default(age, 0) as age,   
    default(height, 0f) as height    
insert into PreprocessedPatientRegistrationInputStream;
define stream PatientRegistrationInputStream (
                 seqNo long, name string, age int,
                 height float, weight double, photo object,
                 isEmployee bool, wardNo object);

Defines PatientRegistrationInputStream having information in all primitive types.

@info(name = 'SimpleIfElseQuery')
from PatientRegistrationInputStream
select 
 default(name, 'invalid') as name, 

Default value of invalid to be used if name is null

 default(seqNo, 0l) as seqNo, 

Default value of 0l to be used if seqNo is null

 default(weight, 0d) as weight,
    

Default value of 0d to be used if weight is null

 default(age, 0) as age, 

Default value of 0 to be used if age is null

 default(height, 0f) as height   

Default value of 0f to be used if height is null

insert into PreprocessedPatientRegistrationInputStream;

Input

An event of all null attributes is sent to PatientRegistrationInputStream,

Output

After processing, the event arriving at PreprocessedPatientRegistrationInputStream will be as follows,

['invalid', 0 0.0, 0, 0.0]

with types,

[string, long, double, int, float]

Top