Let physical-plan producers reuse a CASE's first-WHEN operand as its ELSE value

Aberta
#27,280 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

  • #27281 de @Weijun-H — fechado sem integrar

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
42/100
Tipo de issue
Funcionalidade
Clareza
Claramente especificada
Status de atividade
Estagnada
Stack de tecnologia
rust

Direção de pesquisa

Start with CaseExpr and the physical expression evaluation path; the issue does not name specific files or tests, so first locate CaseExpr and its existing tests. Check how the first WHEN operand is evaluated and how an opt-in can preserve caller-specified evaluation order. Done means ELSE reuses that operand’s evaluated array for ELSE rows while retaining the original evaluation order; add coverage for reuse and ordering.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

Is your feature request related to a problem or challenge?

CASE WHEN f(x) = 'a' THEN 'b' ELSE f(x) END evaluates f(x) for every row in the first WHEN, then again for the ELSE rows. For an expensive f the second call can dominate.

For plans that go through the logical optimizer, CommonSubexprEliminate can remove the duplicate by moving f(x) into a lower projection: with an immutable UDF f, EXPLAIN SELECT CASE WHEN f(value) = 1 THEN 100 ELSE f(value) END FROM t shows Projection: f(t.value) AS __common_expr_1 below the CASE (not extracted when f is volatile). An engine that builds physical plans directly never runs that rule. It also may not be able to use a lower projection: that evaluates f(x) before the columns preceding the CASE, so when those columns and f fail on different rows, a different error surfaces first. Spark-compatible engines need to keep the original order.

Describe the solution you'd like

An opt-in on CaseExpr: the caller states that ELSE is the same call as the operand evaluated first inside the first WHEN, and CaseExpr evaluates it once, at that position, and reuses the array for the ELSE rows. The caller supplies the evaluation-order rules, since which child a PhysicalExpr evaluates first is not part of the trait contract.

Describe alternatives you've considered
  • A lower ProjectionExec in the producer: changes which error surfaces first, as above.
  • Automatic detection inside CaseExpr: needs DataFusion to know evaluation order for every expression on the path. A built-in policy for BinaryExpr/NotExpr/CastExpr could be a follow-up.
Linguagem predominante
Rust
Estrelas
9.6k
Forks
2.6k
Merge médio
3d 4h
PRs com merge (30d)
345

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de apache/datafusion

Todas as issues de apache/datafusion

Issues semelhantes

Mais issues de Rust

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.