Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use @timestamp instead of plain timestamp and prebuild the log
insert template.
  • Loading branch information
Derek Greentree committed Aug 9, 2012
1 parent 609d980 commit 4f0994e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/logstash/outputs/cassandra.rb
Expand Up @@ -52,6 +52,7 @@ def register
@columns_cql_clause = @columns.join(',')
@column_mappings = @columns.map { |c| @event_schema[c] }.map { |c| "%{#{c}}" }
@column_mappings_placeholder = (["?"]*@columns.size).join(',')
@log_insert_query = "INSERT INTO #{@table} (id,#{@columns_cql_clause}) VALUES (?,#{@column_mappings_placeholder})"

@logger.debug("Will map #{@columns_cql_clause} to #{@column_mappings_cql_clause}")
end # def register
Expand All @@ -73,16 +74,15 @@ def receive(event)
event_uuid = CassandraCQL::UUID.new(self.timestamp_as_uuid(event))

# Write the event itself. Unfortunately, maintaining the event and index tables don't happen as one atomic transaction; every update is separate.
log_insert_query = "INSERT INTO #{@table} (id,#{@columns_cql_clause}) VALUES (?,#{@column_mappings_placeholder})"
column_values = @column_mappings.map do |i|
if i.eql?('%{timestamp}')
if i.eql?('%{@timestamp}')
self.timestamp_as_uuid(event)
else
event.sprintf(i)
end
end
# @logger.info(log_insert_query)
@client.execute(log_insert_query, event_uuid, *column_values)
@client.execute(@log_insert_query, event_uuid, *column_values)

# Write index maintenance wide columns.
@index_tables.each do |tbl, id_key|
Expand Down

0 comments on commit 4f0994e

Please sign in to comment.