lib/abank/bigquery.rb in abank-0.2.1 vs lib/abank/bigquery.rb in abank-0.2.2
- old
+ new
@@ -52,10 +52,23 @@
@job.wait_until_done!
puts @job.error['message'] if @job.failed?
@job.failed?
end
+ # executa Stored procedure (SP) job bigquery
+ #
+ # @param (see job_bigquery?)
+ # @return (see num_insert)
+ def esp(sql)
+ job_bigquery?(sql) ? 0 : num_insert(apibq.jobs(parent_job: job))
+ end
+
+ # @return [Integer] numero linhas inseridas
+ def num_insert(sps)
+ sps.find { |j| j.statement_type == 'INSERT' }.num_dml_affected_rows
+ end
+
# cria Data Manipulation Language (DML) job bigquery
#
# @param (see job_bigquery?)
# @return [Integer] numero linhas afetadas
def dml(sql)
@@ -86,9 +99,10 @@
puts 'LINHAS CLASSIFICADAS ' +
dml('update hernanilr.ab.mv set mv.ct=tt.nct' \
' from (select * from hernanilr.ab.cl) as tt' \
' where mv.dl=tt.dl and mv.dv=tt.dv' \
' and mv.ds=tt.ds and mv.vl=tt.vl').to_s
+ puts 'RENDAS INSERIDAS ' + esp('call hernanilr.ab.rendas()').to_s
end
# @return [Integer] numero linhas inseridas
def sql_insert
return 1 unless linha[:i]