lib/google/cloud/bigtable/chunk_processor.rb in google-cloud-bigtable-0.6.2 vs lib/google/cloud/bigtable/chunk_processor.rb in google-cloud-bigtable-0.7.0
- old
+ new
@@ -44,33 +44,31 @@
#
def initialize
reset_to_new_row
end
+ ##
# Process chunk and build full row with cells
#
# @param chunk [Google::Bigtable::V2::ReadRowsResponse::CellChunk]
#
def process chunk
self.chunk = chunk
- if chunk.commit_row
- raise_if(
- chunk.value_size > 0,
- "Commit rows cannot have a non-zero value_size."
- )
- end
+ raise_if chunk.value_size.positive?, "Commit rows cannot have a non-zero value_size." if chunk.commit_row
+
if state == NEW_ROW
process_new_row
elsif state == CELL_IN_PROGRESS
process_cell_in_progress
elsif state == ROW_IN_PROGRESS
process_row_in_progress
end
end
+ ##
# Validate row status commit or reset
#
# @raise [Google::Cloud::Bigtable::InvalidRowStateError]
# if chunk has data on reset row state
#
@@ -79,53 +77,47 @@
value = (!chunk.row_key.empty? ||
chunk.family_name ||
chunk.qualifier ||
!chunk.value.empty? ||
- chunk.timestamp_micros > 0)
+ chunk.timestamp_micros.positive?)
raise_if value, "A reset should have no data"
end
+ ##
# Validate chunk has new row state
#
# @raise [Google::Cloud::Bigtable::InvalidRowStateError]
# If row already has a set key, chunk has an empty row key, chunk
# state is reset, new row key is the same as the last-read key,
# or if family name or column qualifier are empty
#
def validate_new_row
- raise_if(row.key, "A new row cannot have existing state")
- raise_if(chunk.row_key.empty?, "A row key must be set")
- raise_if(chunk.reset_row, "A new row cannot be reset")
- raise_if(
- last_key == chunk.row_key,
- "A commit happened but the same key followed"
- )
- raise_if(chunk.family_name.nil?, "A family must be set")
- raise_if(chunk.qualifier.nil?, "A column qualifier must be set")
+ raise_if row.key, "A new row cannot have existing state"
+ raise_if chunk.row_key.empty?, "A row key must be set"
+ raise_if chunk.reset_row, "A new row cannot be reset"
+ raise_if last_key == chunk.row_key, "A commit happened but the same key followed"
+ raise_if chunk.family_name.nil?, "A family must be set"
+ raise_if chunk.qualifier.nil?, "A column qualifier must be set"
end
+ ##
# Validate chunk merge is in progress to build new row
#
# @raise [Google::Cloud::Bigtable::InvalidRowStateError]
# If row and chunk row key are not same or chunk row key is empty.
#
def validate_row_in_progress
- raise_if(
- !chunk.row_key.empty? && chunk.row_key != row.key,
- "A commit is required between row keys"
- )
+ raise_if !chunk.row_key.empty? && chunk.row_key != row.key, "A commit is required between row keys"
- raise_if(
- chunk.family_name && chunk.qualifier.nil?,
- "A qualifier must be specified"
- )
+ raise_if chunk.family_name && chunk.qualifier.nil?, "A qualifier must be specified"
validate_reset_row
end
+ ##
# Process new row by setting values from current chunk.
#
# @return [Google::Cloud::Bigtable::Row]
#
def process_new_row
@@ -140,10 +132,11 @@
self.cur_labels = chunk.labels
next_state!
end
+ ##
# Process chunk if row state is in progress
#
# @return [Google::Cloud::Bigtable::Row]
#
def process_row_in_progress
@@ -156,10 +149,11 @@
self.cur_ts = chunk.timestamp_micros
self.cur_labels = chunk.labels if chunk.labels
next_state!
end
+ ##
# Process chunk if row cell state is in progress
#
# @return [Google::Cloud::Bigtable::Row]
#
def process_cell_in_progress
@@ -168,10 +162,11 @@
return reset_to_new_row if chunk.reset_row
next_state!
end
+ ##
# Set next state of row.
#
# @return [Google::Cloud::Bigtable::Row]
#
def next_state!
@@ -196,17 +191,11 @@
completed_row
end
# Build cell and append to row.
def persist_cell
- cell = Row::Cell.new(
- cur_family,
- cur_qaul,
- cur_ts,
- cur_val,
- cur_labels
- )
+ cell = Row::Cell.new cur_family, cur_qaul, cur_ts, cur_val, cur_labels
row.cells[cur_family] << cell
# Clear cached cell values
self.cur_val = nil
self.cur_ts = nil
@@ -222,25 +211,24 @@
self.cur_ts = nil
self.cur_val = nil
self.cur_labels = nil
end
+ ##
# Validate last row is completed
#
# @raise [Google::Cloud::Bigtable::InvalidRowStateError]
# If read rows response end without last row completed
#
def validate_last_row_complete
return if row.key.nil?
- raise_if(
- !chunk.commit_row,
- "Response ended with pending row without commit"
- )
+ raise_if !chunk.commit_row, "Response ended with pending row without commit"
end
private
+ ##
# Raise error on condition failure
#
# @raise [Google::Cloud::Bigtable::InvalidRowStateError]
#
def raise_if condition, message