给出以下嵌套哈希文件:
SQL_LIST_ODS = {
foo_TableA: {
load_mode: "do_whatever1",
query: <<EOS,
select foo1, foo2, foo3 from foo_TableA
EOS
}
foo_TableB: {
load_mode: "do_whatever2",
query: <<EOS,
select foo1, foo2, foo3 from foo_TableB
EOS
}
}
需要根据#{load_mode}的值执行各种任务(例如&#34; do_whatever1&#34;或&#34; do_whatever2&#34;。这是我目前所拥有的片段。
require "./eas_etl_ods-oltp1_fulltbl_sql_ods.rb"
...
sql_list = SQL_LIST_ODS.dup # from separate sql file
sql_list.each_pair do # ***OR*** should this be sql_list.each do (vs each_pair)?
<<<insert logic here -- see notes below>>>
end
这是我们需要执行的基本逻辑(伪代码):
您可以帮助验证嵌套哈希文件并使用正确的语法完成代码段吗?
答案 0 :(得分:0)
你错过了foo_Tables之间的逗号。
然后尝试:
sql_list.each do |key, value|
if value[:load_mode] == "do_whatever1"
# do something with value[:query]
else
# do something else
end
end
如果您想与ruby 1.8兼容,请使用以下语法:
SQL_LIST_ODS = {
:foo_TableA => {
:load_mode => "do_whatever1",
:query => <<EOS,
select foo1, foo2, foo3 from foo_TableA
EOS
},
:foo_TableB => {
:load_mode => "do_whatever2",
:query => <<EOS,
select foo1, foo2, foo3 from foo_TableB
EOS
},
}