
ps.odps-mapred-bridge.0.51.5-public.source-code.sql.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##
$!{ctx.functionCreateText}
@sub_query_mapper :=
#if(!${ctx.mapOnly()})
SELECT ${ctx.IntermediateColsJoined}
#else
SELECT ${ctx.PackagedColsJoined}
#end##
FROM
(
#foreach ($input_table_entry in ${ctx.mergeTableInfos().entrySet()})
#if(!${ctx.mapOnly()})
SELECT mr2sql_mapper_${ctx.Id}(#collist(${input_table_entry.Key})) as (${ctx.IntermediateColsJoinedMapOut})
#else
SELECT mr2sql_mapper_${ctx.Id}(#collist(${input_table_entry.Key})) as (${ctx.PackagedColsJoined})
#end##
FROM #tblname(${input_table_entry.Key})
#if (${input_table_entry.Value} && ${input_table_entry.Value.size()} > 0)
WHERE
#foreach($part in ${input_table_entry.Value})
($part) #if(${foreach.hasNext}) OR
#end
#end
#end##
#if(${foreach.hasNext})UNION ALL
#end##
#end##
#if(${ctx.isNoInputTableInfos()})
#if(!${ctx.mapOnly()})
SELECT mr2sql_mapper_${ctx.Id}() as (${ctx.IntermediateColsJoinedMapOut}) FROM values('') _t (_c) where false
#else
SELECT mr2sql_mapper_${ctx.Id}() as (${ctx.PackagedColsJoined}) FROM values('') _t (_c) where false
#end##
#end
) open_mr_alias1
#if (!${ctx.mapOnly()})
DISTRIBUTE BY ${ctx.PartitionColsJoined} SORT BY ${ctx.SortColsJoined}
#end
;
#if(!${ctx.mapOnly()})
@sub_query_reducer :=
SELECT mr2sql_reducer_${ctx.Id}(${ctx.IntermediateColsJoined}) as (${ctx.PackagedColsJoined})
FROM @sub_query_mapper;
FROM @sub_query_reducer
#else
FROM @sub_query_mapper
#end##
#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