Skip to content

Null handling in put, network_of, typename, nameof, and grep #6948

@philrz

Description

@philrz

In super, operations on null values with put, network_of, typename, and nameof currently produce non-null values. We could choose to do what SQL probably would do if these existed in SQL, which I suspect would be to propagate the null.

$ echo 'null' | super -c "put x:=1" -
error({message:"put: not a record",on:null})

$ echo 'null' | super -c "network_of(this)" -
error({message:"network_of: not an IP",on:null})

$ echo 'null' | super -c "network_of(10.1.2.3, this)" -
error({message:"network_of: bad arg for CIDR mask",on:null})

$ echo 'null' | super -c "typename(this)" -
error({message:"typename: argument must be a string",on:null})

$ echo 'null' | super -c "nameof(this)" -
error("missing")

$ echo 'null' | super -c "values grep('a', this)" -
false

$ echo 'null' | super -c "values grep(this, 'a')" -
error({message:"grep: pattern argument must be a string",on:null})

Details

Repro is with super commit 9ba80d7.

$ super -version
Version: v0.3.0-122-g9ba80d768

These are intentionally covered in this issue separate from #6947, as those all had direct equivalents in legacy SQL, whereas these are our own inventions so in theory we could make our own rules.

I believe it was @nwt who made a compelling argument that SuperSQL should typically propagate nulls even in non-SQL contexts: NULL values are primarily a concern because they come from outside systems or are produced by legacy SQL queries. In a world starting from zero based on super-structured data, rather than relying on NULL we'd probably advocate the use of first-class errors (e.g., error("missing"), structured errors, etc.) as these all convey more meaning than SQL's catch-all use of NULL for all things "unknown". But since nulls are often unavoidable, we could be consistent with SQL by treating it as a placeholder for "unknown" and propagating the null to the result when we encounter a null input to any SuperSQL function/operator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions