def parse(input, &block)
columns, table, num = Hash.new { |h, k| h[k] = [] }, nil, 0
input.each { |line|
case line = line.chomp
when /\ACOPY\s+(\S+)\s+\((.+?)\)\s+FROM\s+stdin;\z/
columns[table = $1] = $2.split(/\s*,\s*/)
when /\A\\.\z/
table = nil
else
next unless table
cols = columns[table]
next if cols.empty?
Athena::Record.new(nil, block) { |record|
line.split(/\t/).each_with_index { |value, index|
column = cols[index] or next
if column == record_element
record.instance_variable_set(:@id, value)
end
record.update(column, value, config[column])
}
}
num += 1
end
}
num
end