handle missing fields in SQL as null - #7295
Conversation
|
A run of this branch at 7c021ad on the current sqllogic-ztests triggered 124 new similar failures in the "groupby" set, such as groupby/slt_good_0/q2177.yaml. Here's a simplified, self-contained repro: Whereas that works ok on current tip of I had Claude come up with the simplified repro, so it also gave its take on root cause and possible fixes, and that's available in a Gist if it helps at all. |
|
Another finding along the way that's mentioned in that Gist is that on this branch the Whereas they're maintained on tip of |
7c021ad to
bcba3db
Compare
|
I just pushed a fix for this...
|
Let's fix this in a subsequent PR. I think we can solve the more general problem of retaining typed NULLs throughout the runtime, which likely involves a small change to vector.Apply. |
This commit improves SQL semantics in the face of missing fields by turning them into nulls and adding a nullish coalescing variant of the . operator to propagate nulls in a path expression. This operator is inserted by the semantic pass and is not user visible. It is displayed in DAG output as "??.". To make this work, we fixed a problem in the optimizer where the flags in field.Chain weren't being propagated. This also fixed a problem in agg functions like count which are supposed to ignore nulls. The change to change-star.yaml reflects this, where this test is now has a SQL-compatible result. Closes #5984
915ded3 to
e29c4ce
Compare
|
rebased to new main |
| ``` | ||
|
|
||
| --- No newline at end of file | ||
| --- |
There was a problem hiding this comment.
Nit: Don't delete the newline here.
| // - It returns false when it cannot descend to a dag.RecordExpr.Elem. | ||
| func addPathToExpr(e dag.Expr, path []string) (dag.Expr, bool) { | ||
| if len(path) == 0 { | ||
| func addPathToExpr(e dag.Expr, chain field.Chain) (dag.Expr, bool) { |
There was a problem hiding this comment.
Nits: Rename this to addChainToExpr. And update the doc comment (s/path/chain/g more or less).
| super -f parquet -o integers.parquet integers.sup | ||
| super -f parquet -o integers2.parquet integers2.sup | ||
| super -s -c "SELECT * FROM integers.parquet LEFT OUTER JOIN integers2.parquet ON integers.i=integers2.k ORDER BY i;" |
There was a problem hiding this comment.
Nit: The issue described in #5984 isn't tied to Parquet specifically so there's no need to use it here.
| super -f parquet -o integers.parquet integers.sup | |
| super -f parquet -o integers2.parquet integers2.sup | |
| super -s -c "SELECT * FROM integers.parquet LEFT OUTER JOIN integers2.parquet ON integers.i=integers2.k ORDER BY i;" | |
| super -s -c "SELECT * FROM integers.sup LEFT OUTER JOIN integers2.sup ON integers.i=integers2.k ORDER BY i;" |
| } | ||
| return vector.NewWrappedError(d.sctx, fmt.Sprintf("'%s': applied to non-record", dot), innerVecs[0]) | ||
| } | ||
| dot := "." |
There was a problem hiding this comment.
Nit: I think op would be a better name for this.
This commit improves SQL semantics in the face of missing fields by turning them into nulls and adding a nullish coalescing variant of the . operator to propagate nulls in a path expression. This operator is inserted by the semantic pass and is not user visible. It is displayed in DAG output as "??.".
To make this work, we fixed a problem in the optimizer where the flags in field.Chain weren't being propagated.
This also fixed a problem in agg functions like count which are supposed to ignore nulls. The change to change-star.yaml reflects this, where this test is now has a SQL-compatible result.
Closes #5984