Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: jayzhan211 <[email protected]>
  • Loading branch information
jayzhan211 committed Aug 4, 2024
1 parent a39212e commit 7384bb8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
8 changes: 2 additions & 6 deletions datafusion/optimizer/src/analyzer/type_coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,9 +1042,7 @@ mod test {
let expr = col("a").in_list(vec![lit(1_i32), lit(4_i8), lit(8_i64)], false);
let empty = empty_with_type(DataType::Int64);
let plan = LogicalPlan::Projection(Projection::try_new(vec![expr], empty)?);
let expected =
"Projection: a IN ([CAST(Int32(1) AS Int64), CAST(Int8(4) AS Int64), Int64(8)]) AS a IN (Map { iter: Iter([Literal(Int32(1)), Literal(Int8(4)), Literal(Int64(8))]) })\
\n EmptyRelation";
let expected = "Projection: a IN ([CAST(Int32(1) AS Int64), CAST(Int8(4) AS Int64), Int64(8)])\n EmptyRelation";
assert_analyzed_plan_eq(Arc::new(TypeCoercion::new()), plan, expected)?;

// a in (1,4,8), a is decimal
Expand All @@ -1057,9 +1055,7 @@ mod test {
)?),
}));
let plan = LogicalPlan::Projection(Projection::try_new(vec![expr], empty)?);
let expected =
"Projection: CAST(a AS Decimal128(24, 4)) IN ([CAST(Int32(1) AS Decimal128(24, 4)), CAST(Int8(4) AS Decimal128(24, 4)), CAST(Int64(8) AS Decimal128(24, 4))]) AS a IN (Map { iter: Iter([Literal(Int32(1)), Literal(Int8(4)), Literal(Int64(8))]) })\
\n EmptyRelation";
let expected = "Projection: CAST(a AS Decimal128(24, 4)) IN ([CAST(Int32(1) AS Decimal128(24, 4)), CAST(Int8(4) AS Decimal128(24, 4)), CAST(Int64(8) AS Decimal128(24, 4))])\n EmptyRelation";
assert_analyzed_plan_eq(Arc::new(TypeCoercion::new()), plan, expected)
}

Expand Down
22 changes: 11 additions & 11 deletions datafusion/sql/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,16 +469,16 @@ mod tests {
assert_eq!(
transformed_exprs,
vec![
col("unnest(struct_col).field1"),
col("unnest(struct_col).field2"),
col("UNNEST(struct_col).field1"),
col("UNNEST(struct_col).field2"),
]
);
assert_eq!(unnest_placeholder_columns, vec!["unnest(struct_col)"]);
assert_eq!(unnest_placeholder_columns, vec!["UNNEST(struct_col)"]);
// still reference struct_col in original schema but with alias,
// to avoid colliding with the projection on the column itself if any
assert_eq!(
inner_projection_exprs,
vec![col("struct_col").alias("unnest(struct_col)"),]
vec![col("struct_col").alias("UNNEST(struct_col)"),]
);

// unnest(array_col) + 1
Expand All @@ -491,12 +491,12 @@ mod tests {
)?;
assert_eq!(
unnest_placeholder_columns,
vec!["unnest(struct_col)", "unnest(array_col)"]
vec!["UNNEST(struct_col)", "UNNEST(array_col)"]
);
// only transform the unnest children
assert_eq!(
transformed_exprs,
vec![col("unnest(array_col)").add(lit(1i64))]
vec![col("UNNEST(array_col)").add(lit(1i64))]
);

// keep appending to the current vector
Expand All @@ -505,8 +505,8 @@ mod tests {
assert_eq!(
inner_projection_exprs,
vec![
col("struct_col").alias("unnest(struct_col)"),
col("array_col").alias("unnest(array_col)")
col("struct_col").alias("UNNEST(struct_col)"),
col("array_col").alias("UNNEST(array_col)")
]
);

Expand Down Expand Up @@ -553,17 +553,17 @@ mod tests {
// Only the inner most/ bottom most unnest is transformed
assert_eq!(
transformed_exprs,
vec![unnest(col("unnest(struct_col[matrix])"))]
vec![unnest(col("UNNEST(struct_col[matrix])"))]
);
assert_eq!(
unnest_placeholder_columns,
vec!["unnest(struct_col[matrix])"]
vec!["UNNEST(struct_col[matrix])"]
);
assert_eq!(
inner_projection_exprs,
vec![col("struct_col")
.field("matrix")
.alias("unnest(struct_col[matrix])"),]
.alias("UNNEST(struct_col[matrix])"),]
);

Ok(())
Expand Down
8 changes: 4 additions & 4 deletions datafusion/sql/tests/cases/plan_to_sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,10 @@ fn test_unnest_logical_plan() -> Result<()> {
let sql_to_rel = SqlToRel::new(&context);
let plan = sql_to_rel.sql_statement_to_plan(statement).unwrap();

let expected = "Projection: unnest(unnest_table.struct_col).field1, unnest(unnest_table.struct_col).field2, unnest(unnest_table.array_col), unnest_table.struct_col, unnest_table.array_col\
\n Unnest: lists[unnest(unnest_table.array_col)] structs[unnest(unnest_table.struct_col)]\
\n Projection: unnest_table.struct_col AS unnest(unnest_table.struct_col), unnest_table.array_col AS unnest(unnest_table.array_col), unnest_table.struct_col, unnest_table.array_col\
\n TableScan: unnest_table";
let expected = "Projection: UNNEST(unnest_table.struct_col).field1, UNNEST(unnest_table.struct_col).field2, UNNEST(unnest_table.array_col), unnest_table.struct_col, unnest_table.array_col\
\n Unnest: lists[UNNEST(unnest_table.array_col)] structs[UNNEST(unnest_table.struct_col)]\
\n Projection: unnest_table.struct_col AS UNNEST(unnest_table.struct_col), unnest_table.array_col AS UNNEST(unnest_table.array_col), unnest_table.struct_col, unnest_table.array_col\
\n TableScan: unnest_table";

assert_eq!(format!("{plan:?}"), expected);

Expand Down

0 comments on commit 7384bb8

Please sign in to comment.