定义一张临时表,往里插数据,返回表名
temp_terms_table_name = insert_keywords_into_table(keywords, batch_id, audience_id)
sql_array << "SELECT 'opx:'||click_opxpid, 'aids', #{audience_id} FROM dw.clickdatas c INNER JOIN dw.searcher se ON c.searcher_id = se.id INNER JOIN #{temp_terms_table_name} t on position(t.term in c.leading_keyword) != 0 WHERE client_id = #{a.client_id} AND c_date >= #{int_date} GROUP BY 1"
def insert_keywords_into_table(arr_keywords, batch_id, audience_id)
str_table_name = "workspace.audience_terms_#{batch_id}_#{audience_id}"
Audience.connection.execute("create table #{str_table_name} (term text) with (appendonly = true, compresslevel = 6);") if @keywords_table_created == false
@keywords_table_created = true
keywords_string = arr_keywords.collect{|k| "(#{SearchenginePpc.connection.quote(k)})"}.join(",")
Audience.connection.execute("insert into #{str_table_name} values #{keywords_string};")
return str_table_name
end