Class: Fluent::BigObjectOutput::TableElement

Inherits:
Object
  • Object
show all
Includes:
Configurable
Defined in:
lib/fluent/plugin/out_bigobject.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log) ⇒ TableElement

Returns a new instance of TableElement.



28
29
30
31
# File 'lib/fluent/plugin/out_bigobject.rb', line 28

def initialize(log)
  super()
  @log = log
end

Instance Attribute Details

#mpatternObject (readonly)

Returns the value of attribute mpattern.



26
27
28
# File 'lib/fluent/plugin/out_bigobject.rb', line 26

def mpattern
  @mpattern
end

Instance Method Details

#configure(conf) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fluent/plugin/out_bigobject.rb', line 33

def configure(conf)
  super
  @mpattern = Fluent::MatchPattern.create(pattern)
  @mapping = parse_column_mapping(@column_mapping)
  @log.info("column mapping for #{table} - #{@mapping}")
  @format_proc = Proc.new { |record|
    new_record = {}
    @mapping.each { |k, c|
      new_record[c] = record[k]
    }
    new_record
  }
end

#send(bourl, chunk) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/fluent/plugin/out_bigobject.rb', line 47

def send(bourl, chunk)
  stmts = Array.new
  i=0
  columns = nil
  chunk.msgpack_each { |tag, time, data|
     keys = Array.new
     values = Array.new
     data = @format_proc.call(data)
     data.keys.sort.each do |key|
       keys << key
       values << data[key]
     end
     if columns.to_s.empty?
       columns = "(#{keys.join(",")})"
     end
     #single quote each column data
     stmts.push("('#{values.join("','")}')")
     i+=1
  }
  
  sendStmt = "INSERT INTO #{@table}  #{columns} VALUES" + stmts.join(",")
#      @log.debug("sendStmt=", sendStmt)
  @log.info("bigobject start insert #{i} rows")
  resp = sendBO(bourl, sendStmt)
  parsed = JSON.parse(resp)
  err = parsed['Err']
#      puts "Content=#{parsed['Content']}, Err=#{err}"
  if (err.to_s!='')
    @log.error("[BigObject] #{err}")
  end
  @log.info("bigobject end insert #{i} rows")
  
end

#to_sObject



81
82
83
# File 'lib/fluent/plugin/out_bigobject.rb', line 81

def to_s
  "table:#{table}, column_mapping:#{column_mapping}, pattern:#{pattern}"
end