
ps.odps-mapred-bridge.0.51.5-public.source-code.pl.vm Maven / Gradle / Ivy
## Hate the indentation issue! http://wiki.apache.org/velocity/VelocityWhitespaceGobbling
## macro collist: generate comma seperated column list, with label prefix if $withLabel is true
#macro(collist $tableInfo $prefix)
#foreach($col in ${tableInfo.Cols})
#if(${prefix})${prefix}#end${col}#if(${foreach.hasNext}),#end
#end ## end foreach
#end ## collist macro
#macro(selist $tableInfo $aslist)
#foreach($col in ${tableInfo.Cols})
${col}#if(${aslist}) as ${aslist[${foreach.index}]}#end#if(${foreach.hasNext}),#end
#end ## end foreach
#end ## selist macro
#macro(tblname $tableInfo)
#if(${tableInfo.ProjectName})${tableInfo.ProjectName}.#end${tableInfo.TableName}
#end ## selist tblname
## macro outputColsJoined: joined output columns.
#macro(outputColsJoined)
#if(${ctx.isNilOutput()})nil#else
#foreach($output_table in ${ctx.OutputTableInfos})
#if(${ctx.multiInsert()})
#collist($output_table "${output_table.Label}_")
#else
#collist($output_table)
#end
#if(${foreach.hasNext}),#end
#end
#if(${ctx.multiInsert()}),${ctx.MultidestLabel}#end ##
#end
#end ## outputColsJoined macro
## macro: inputColsJoined
#macro(inputColsJoined)
#foreach($input_table in ${ctx.InputTableInfos})
#collist($input_table)#break
#end
#end ## inputColsJoined macro
## macro partfilter
#macro(partfilter $tableInfo)
#foreach ($entry in ${tableInfo.PartSpec.entrySet()})
${entry.Key} = "${entry.Value}" #if(${foreach.hasNext}) AND #end
#end##
#end##
#set($nodeLast=$!{pipes.size()} - 1)
#set($nodePre = 0)
#foreach ($node in $pipes)
#set($nodeId=${velocityCount} - 1)
#set($nodeIdPre=${nodeId} - 1)
#if (${nodeId} == 0)
$!{ctx.FunctionCreateText}
@sub_query_${nodeId} :=
#if(!${ctx.mapOnly()})
SELECT ${node.IntermediateColsJoined}
#else
SELECT ${ctx.PackagedColsJoined}
#end##
FROM
(
#foreach ( $input_table in ${ctx.InputTableInfos} )
#if(!${ctx.mapOnly()})
SELECT mr2sql_mapper_${ctx.Id}_${nodeId}(#collist($input_table)) as (${node.IntermediateColsJoinedMapOut})
#else
SELECT mr2sql_mapper_${ctx.Id}_${nodeId}(#collist($input_table)) as (${ctx.PackagedColsJoined})
#end##
FROM #tblname($input_table)
#if (${input_table.PartSpec} && ${input_table.PartSpec.size()} > 0)
WHERE #partfilter($input_table)
#end
#if(${foreach.hasNext})UNION ALL#end##
#end
#if(${ctx.isNoInputTableInfos()})
#if(!${ctx.mapOnly()})
SELECT mr2sql_mapper_${ctx.Id}_${nodeId}() as (${node.IntermediateColsJoinedMapOut}) FROM values('') _t (_c) where false
#else
SELECT mr2sql_mapper_${ctx.Id}_${nodeId}() as (${ctx.PackagedColsJoined}) FROM values('') _t (_c) where false
#end##
#end
) open_mr_alias_${nodeId}_1
#if (!${ctx.mapOnly()})
DISTRIBUTE BY ${node.PartitionColsJoined} SORT BY ${node.SortColsJoined}
#end
;
#elseif (${nodeId} == ${nodeLast})
@sub_query_${nodeId} :=
SELECT mr2sql_reducer_${ctx.Id}_${nodeId}(${nodePre.IntermediateColsJoined}) as (${ctx.PackagedColsJoined})
from @sub_query_${nodeIdPre};
#else
@sub_query_${nodeId} :=
SELECT ${node.IntermediateColsJoined}
FROM
(
SELECT mr2sql_reducer_${ctx.Id}_${nodeId}(${nodePre.IntermediateColsJoined}) as (${node.IntermediateColsJoinedMapOut})
from @sub_query_${nodeIdPre}
) open_mr_alias_${nodeId}_2
DISTRIBUTE BY ${node.PartitionColsJoined} SORT BY ${node.SortColsJoined};
#end
#set($nodePre = $node)
#end
FROM @sub_query_${nodeLast}
#if(!${ctx.isNilOutput()})
#foreach($output_table in ${ctx.MultiOutputTableInfos})
INSERT#if(${ctx.isOutputOverwrite()}) OVERWRITE#else INTO#end TABLE #tblname($output_table)
#if (${output_table.PartSpec} && ${output_table.PartSpec.size()} > 0)
PARTITION(#foreach ($entry in ${output_table.PartSpec.entrySet()}) ${entry.Key} = "${entry.Value}" #if(${foreach.hasNext}),#end#end)
#end
#if(${ctx.multiInsert()})
SELECT #collist($output_table "")
WHERE ${ctx.MultidestLabel} = "${output_table.Label}"
#else
SELECT #collist($output_table)
#end
#end
#else
SELECT *
#end
;
© 2015 - 2025 Weber Informatics LLC | Privacy Policy