Skip to main content
Version: v1.15.0

fill

Function

fill add null values for missing record fields

Synopsis

fill(val: any, t: type) -> any

Description

The fill function adds to the input record val any fields that are present in the output type t but not in the input.

Filled fields are added with a null value. Filling is useful when you want to be sure that all fields in a schema are present in a record.

If val is not a record, it is returned unmodified.

Examples

Fill a record

echo '{a:1}' | zq -z 'fill(this, <{a:int64,b:string}>)' -

produces

{a:1,b:null(string)}

Fill an array of records

echo '[{a:1},{a:2}]' | zq -z 'fill(this, <[{a:int64,b:int64}]>)' -

produces

[{a:1,b:null(int64)},{a:2,b:null(int64)}]

Non-records are returned unmodified

echo '10.0.0.1 1 "foo"' | zq -z 'fill(this, <{a:int64,b:int64}>)' -

produces

10.0.0.1
1
"foo"