UnionTransformer
Visão geral
Converte nós Union do Tableau em instruções SQL UNION ALL. Combina múltiplas entradas com preenchimento automático de NULL para campos divergentes.
Tipo de nó: .v1.SimpleUnion / .v2018_2_3.SuperUnion
Saída: SQL UNION ALL
Recursos
- Combinação de 2 ou mais conjuntos de dados de entrada
- UNION ALL (preserva duplicatas)
- Preenchimento automático de NULL para campos ausentes
- Tratamento de esquemas divergentes
Exemplo de nó Tableau
Entrada (formato Tableau)
{
"id": "a02f726a-5afb-4188-a02c-178d5555cc6a",
"name": "Union Sales Sources",
"node_type": ".v2018_2_3.SuperUnion",
"base_type": "superNode",
"actionNode": {
"nodeType": ".v1.SimpleUnion",
"namespaceFieldMappings": [
{
"fieldMappings": {},
"namespaceName": "Union-Namespace-1"
},
{
"fieldMappings": {},
"namespaceName": "Union-Namespace-2"
},
{
"fieldMappings": {},
"namespaceName": "Union-Namespace-3"
},
{
"fieldMappings": {},
"namespaceName": "Union-Namespace-4"
},
{
"fieldMappings": {},
"namespaceName": "Union-Namespace-5"
}
]
}
}
Esquemas de entrada
Entrada 1 - 16 campos:
[
{"name": "year", "type": "integer"},
{"name": "month", "type": "integer"},
{"name": "city", "type": "string"},
{"name": "customer_name", "type": "string"},
{"name": "sales_amount", "type": "real"}
]
Entrada 2 - 21 campos (tem campos adicionais):
[
{"name": "year", "type": "integer"},
{"name": "month", "type": "integer"},
{"name": "city", "type": "string"},
{"name": "customer_name", "type": "string"},
{"name": "sales_amount", "type": "real"},
{"name": "material_hier_4_name", "type": "string"},
{"name": "standard_cost", "type": "real"},
{"name": "units", "type": "integer"}
]
Entrada 3 - 18 campos (tem campos adicionais diferentes):
[
{"name": "year", "type": "integer"},
{"name": "month", "type": "integer"},
{"name": "city", "type": "string"},
{"name": "customer_name", "type": "string"},
{"name": "sales_amount", "type": "real"},
{"name": "number_of_rows_aggregated", "type": "integer"},
{"name": "adjustment_factor", "type": "real"}
]
SQL gerado
SELECT
year,
month,
city,
customer_name,
customer_number,
division,
invoice_date,
material_description,
material_number,
order_type_description,
region_manager_number,
sales_region_manager_name,
sales_rep_name,
sales_rep_number,
state_regioncode,
sales_amount,
NULL AS material_hier_4_name,
NULL AS material_hier_4_number,
NULL AS standard_cost,
NULL AS units,
NULL AS units_eaches,
NULL AS number_of_rows_aggregated,
NULL AS adjustment_factor
FROM cash_basis_V0S8
UNION ALL
SELECT
year,
month,
city,
customer_name,
customer_number,
division,
invoice_date,
material_description,
material_number,
order_type_description,
region_manager_number,
sales_region_manager_name,
sales_rep_name,
sales_rep_number,
state_regioncode,
sales_amount,
material_hier_4_name,
material_hier_4_number,
standard_cost,
units,
units_eaches,
NULL AS number_of_rows_aggregated,
NULL AS adjustment_factor
FROM cut_off_V0S12
UNION ALL
SELECT
year,
month,
city,
customer_name,
customer_number,
division,
invoice_date,
material_description,
material_number,
order_type_description,
region_manager_number,
sales_region_manager_name,
sales_rep_name,
sales_rep_number,
state_regioncode,
sales_amount,
NULL AS material_hier_4_name,
NULL AS material_hier_4_number,
NULL AS standard_cost,
NULL AS units,
NULL AS units_eaches,
number_of_rows_aggregated,
adjustment_factor
FROM adjustments_V0S15
UNION ALL
SELECT
year,
month,
city,
customer_name,
customer_number,
division,
invoice_date,
material_description,
material_number,
order_type_description,
NULL AS region_manager_number,
NULL AS sales_region_manager_name,
NULL AS sales_rep_name,
NULL AS sales_rep_number,
state_regioncode,
sales_amount,
NULL AS material_hier_4_name,
NULL AS material_hier_4_number,
NULL AS standard_cost,
NULL AS units,
NULL AS units_eaches,
NULL AS number_of_rows_aggregated,
adjustment_factor
FROM clean_4_V0S18
UNION ALL
SELECT
year,
month,
city,
customer_name,
customer_number,
division,
invoice_date,
material_description,
material_number,
order_type_description,
region_manager_number,
sales_region_manager_name,
sales_rep_name,
sales_rep_number,
state_regioncode,
sales_amount,
NULL AS material_hier_4_name,
NULL AS material_hier_4_number,
NULL AS standard_cost,
NULL AS units,
NULL AS units_eaches,
NULL AS number_of_rows_aggregated,
NULL AS adjustment_factor
FROM clean_5_V0S22
Como funciona
1. Coletar todos os campos únicos
Percorre todos os esquemas de entrada para construir a lista completa de campos.
2. Gerar preenchimento de NULL
Para cada entrada, adiciona NULL AS field_name para campos ausentes nessa entrada.
3. Combinar com UNION ALL
Empilha todas as instruções SELECT com UNION ALL (preserva todas as linhas, incluindo duplicatas).
Estratégia de união no Tableau Prep
⚠️ Importante: use união posicional (não por nome)
Ao configurar nós Union no Tableau Prep, prefira união posicional em vez de união por nome.
Motivo: A sintaxe UNION ALL BY NAME do Snowflake não funciona corretamente em determinados cenários:
- Consultas aninhadas complexas
- Grande quantidade de campos
- Incompatibilidades de tipos entre entradas
O conversor gera UNION ALL posicional padrão com preenchimento explícito de NULL, que é mais confiável.
Limitações
- ⚠️ Mínimo de 2 entradas - Union exige pelo menos 2 conjuntos de dados de entrada
- ⚠️ Compatibilidade de tipos obrigatória - Campos com nomes coincidentes devem ter tipos compatíveis
- ⚠️ Apenas UNION ALL - Não remove duplicatas
- ⚠️ Sem ORDER BY - A ordem de saída não é garantida
Transformadores relacionados
- AggregateTransformer - Para agrupar/agregar dados unidos
- ContainerTransformer - Para filtrar ou transformar antes/depois da união
- JoinTransformer - Para combinar conjuntos de dados horizontalmente (não verticalmente)