Skip to content

Primitive type foils fuse #4525

@philrz

Description

@philrz

Repro is with Zed commit 06f7936. This problem was spotted while researching zui/2751 and uses some of its test data to repro.

Consider these individual test data values in three separate files.

First we have a simple record in record.zson.

$ cat record.zson 
{
    name: "Allendale Elementary School",
    school_rating: 5.,
    size: 851.,
    reduced_lunch: 10.,
    state_percentile_16: 90.2,
    state_percentile_15: 95.8,
    stu_teach_ratio: 15.7,
    school_type: "Public",
    avg_score_15: 89.4,
    avg_score_16: 85.2,
    full_time_teachers: 54.,
    percent_black: 2.9,
    percent_white: 85.5,
    percent_asian: 1.6,
    percent_hispanic: 5.6
}

$ zq -Z 'typeof(this)' record.zson 
<{
    name: string,
    school_rating: float64,
    size: float64,
    reduced_lunch: float64,
    state_percentile_16: float64,
    state_percentile_15: float64,
    stu_teach_ratio: float64,
    school_type: string,
    avg_score_15: float64,
    avg_score_16: float64,
    full_time_teachers: float64,
    percent_black: float64,
    percent_white: float64,
    percent_asian: float64,
    percent_hispanic: float64
}>

Next is another record in has-nulls.zson that differs in its type becuase it has null values for two fields.

$ cat has-nulls.zson 
{
    name: "Carmel Elementary",
    school_rating: 5.,
    size: 583.,
    reduced_lunch: 21.,
    state_percentile_16: 93.7,
    state_percentile_15: null,
    stu_teach_ratio: 14.9,
    school_type: "Public",
    avg_score_15: null,
    avg_score_16: 89.,
    full_time_teachers: 39.,
    percent_black: 3.4,
    percent_white: 79.6,
    percent_asian: 1.9,
    percent_hispanic: 8.9
}

$ zq -Z 'typeof(this)' has-nulls.zson 
<{
    name: string,
    school_rating: float64,
    size: float64,
    reduced_lunch: float64,
    state_percentile_16: float64,
    state_percentile_15: null,
    stu_teach_ratio: float64,
    school_type: string,
    avg_score_15: null,
    avg_score_16: float64,
    full_time_teachers: float64,
    percent_black: float64,
    percent_white: float64,
    percent_asian: float64,
    percent_hispanic: float64
}>

Finally we have a string value in string.zson.

$ cat string.zson 
"15 avg_score_16 full_time_teachers percent_black percent_white percent_asian percent_hispanic"

$ zq -Z 'typeof(this)' string.zson 
<string>

I can successfully fuse any pairing of the three values to create a single unified type.

$ zq -Z 'fuse | count() by typeof(this)' record.zson has-nulls.zson 
{
    typeof: <{
        name: string,
        school_rating: float64,
        size: float64,
        reduced_lunch: float64,
        state_percentile_16: float64,
        state_percentile_15: float64,
        stu_teach_ratio: float64,
        school_type: string,
        avg_score_15: float64,
        avg_score_16: float64,
        full_time_teachers: float64,
        percent_black: float64,
        percent_white: float64,
        percent_asian: float64,
        percent_hispanic: float64
    }>,
    count: 2 (uint64)
}

$ zq -Z 'fuse | count() by typeof(this)' record.zson string.zson 
{
    typeof: <(
        string,
        {
            name: string,
            school_rating: float64,
            size: float64,
            reduced_lunch: float64,
            state_percentile_16: float64,
            state_percentile_15: float64,
            stu_teach_ratio: float64,
            school_type: string,
            avg_score_15: float64,
            avg_score_16: float64,
            full_time_teachers: float64,
            percent_black: float64,
            percent_white: float64,
            percent_asian: float64,
            percent_hispanic: float64
        }
    )>,
    count: 2 (uint64)
}

$ zq -Z 'fuse | count() by typeof(this)' has-nulls.zson string.zson 
{
    typeof: <(
        string,
        {
            name: string,
            school_rating: float64,
            size: float64,
            reduced_lunch: float64,
            state_percentile_16: float64,
            state_percentile_15: null,
            stu_teach_ratio: float64,
            school_type: string,
            avg_score_15: null,
            avg_score_16: float64,
            full_time_teachers: float64,
            percent_black: float64,
            percent_white: float64,
            percent_asian: float64,
            percent_hispanic: float64
        }
    )>,
    count: 2 (uint64)

However (here comes the bug) when I try to fuse all three values at once, I still end up with two types, one being a union that includes string and the other doesn't.

$ zq -Z 'fuse | count() by typeof(this)' record.zson has-nulls.zson string.zson 
{
    typeof: <(
        string,
        {
            name: string,
            school_rating: float64,
            size: float64,
            reduced_lunch: float64,
            state_percentile_16: float64,
            state_percentile_15: float64,
            stu_teach_ratio: float64,
            school_type: string,
            avg_score_15: float64,
            avg_score_16: float64,
            full_time_teachers: float64,
            percent_black: float64,
            percent_white: float64,
            percent_asian: float64,
            percent_hispanic: float64
        }
    )>,
    count: 2 (uint64)
}
{
    typeof: <{
        name: string,
        school_rating: float64,
        size: float64,
        reduced_lunch: float64,
        state_percentile_16: float64,
        state_percentile_15: null,
        stu_teach_ratio: float64,
        school_type: string,
        avg_score_15: null,
        avg_score_16: float64,
        full_time_teachers: float64,
        percent_black: float64,
        percent_white: float64,
        percent_asian: float64,
        percent_hispanic: float64
    }>,
    count: 1 (uint64)
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions