示例#1
0
  def stream_update(self, position, timeout=3600.0):
    try:
      req = binlogdata_pb2.StreamUpdateRequest(position=position)

      it = self.stub.StreamUpdate(req, timeout)
      for response in it:
        stream_event = response.stream_event
        fields = []
        rows = []
        if stream_event.primary_key_fields:
          conversions = []
          for field in stream_event.primary_key_fields:
            fields.append(field.name)
            conversions.append(proto3_encoding.conversions.get(field.type))

          for r in stream_event.primary_key_values:
            row = tuple(proto3_encoding.make_row(r, conversions))
            rows.append(row)

        yield update_stream.StreamEvent(
            category=int(stream_event.category),
            table_name=stream_event.table_name,
            fields=fields,
            rows=rows,
            sql=stream_event.sql,
            timestamp=stream_event.timestamp,
            transaction_id=stream_event.transaction_id)
    except face.AbortionError as e:
      # FIXME(alainjobart) These exceptions don't print well, so raise
      # one that will.  The real fix is to define a set of exceptions
      # for this library and raise that, but it's more work.
      raise dbexceptions.OperationalError(e.details, e)
示例#2
0
    def stream_update(self, position, timeout=3600.0):
        try:
            req = binlogdata_pb2.StreamUpdateRequest(position=position)

            it = self.stub.StreamUpdate(req, timeout)
            for response in it:
                stream_event = response.stream_event
                fields = []
                rows = []
                if stream_event.primary_key_fields:
                    conversions = []
                    for field in stream_event.primary_key_fields:
                        fields.append(field.name)
                        conversions.append(
                            proto3_encoding.conversions.get(field.type))

                    for r in stream_event.primary_key_values:
                        row = tuple(proto3_encoding.make_row(r, conversions))
                        rows.append(row)

                yield update_stream.StreamEvent(
                    category=int(stream_event.category),
                    table_name=stream_event.table_name,
                    fields=fields,
                    rows=rows,
                    sql=stream_event.sql,
                    timestamp=stream_event.timestamp,
                    transaction_id=stream_event.transaction_id)
        except face.AbortionError as e:
            # FIXME(alainjobart) These exceptions don't print well, so raise
            # one that will.  The real fix is to define a set of exceptions
            # for this library and raise that, but it's more work.
            raise dbexceptions.OperationalError(e.details, e)
示例#3
0
 def row_generator():
   try:
     for response in it:
       for row in response.result.rows:
         yield tuple(proto3_encoding.make_row(row, convs))
   except Exception:
     logging.exception('gRPC low-level error')
     raise
示例#4
0
def convert_statement(statement):
  """Converts encoded rows inside a StreamEvent.Statement to native types.

  Args:
    statement: the StreamEvent.Statement object.

  Returns:
    fields: array of names for the primary key columns.
    rows: array of tuples for each primary key value.
  """
  fields = []
  rows = []
  if statement.primary_key_fields:
    conversions = []
    for field in statement.primary_key_fields:
      fields.append(field.name)
      conversions.append(proto3_encoding.conversions.get(field.type))

    for r in statement.primary_key_values:
      row = tuple(proto3_encoding.make_row(r, conversions))
      rows.append(row)

  return fields, rows
示例#5
0
def convert_statement(statement):
    """Converts encoded rows inside a StreamEvent.Statement to native types.

  Args:
    statement: the StreamEvent.Statement object.

  Returns:
    fields: array of names for the primary key columns.
    rows: array of tuples for each primary key value.
  """
    fields = []
    rows = []
    if statement.primary_key_fields:
        conversions = []
        for field in statement.primary_key_fields:
            fields.append(field.name)
            conversions.append(proto3_encoding.conversions.get(field.type))

        for r in statement.primary_key_values:
            row = tuple(proto3_encoding.make_row(r, conversions))
            rows.append(row)

    return fields, rows