Exemplo n.º 1
0
 def run_idl(self, txn):
     self.result = [
         rowview.RowView(r) if self.row else
         {c: idlutils.get_column_value(r, c)
          for c in self.columns} for r in self.table.rows.values()
         if idlutils.row_match(r, self.conditions)
     ]
Exemplo n.º 2
0
    def run_idl(self, txn):
        table_schema = self.api._tables[self.table]
        idx = idlutils.get_index_column(table_schema)
        columns = self.columns or list(table_schema.columns.keys()) + ['_uuid']
        # If there's an index for this table, we'll fetch all columns and
        # remove the unwanted ones based on self.records. Otherwise, let's try
        # to get the uuid of the wanted ones which is an O(n^2) operation.
        if not idx and self.records:
            rows = []
            for record in self.records:
                try:
                    rows.append(self.api.idl.lookup(self.table, record))
                except idlutils.RowNotFound:
                    if self.if_exists:
                        continue
                    raise
        else:
            rows = table_schema.rows.values()

        def _match(row):
            elem = getattr(row, idx)
            return elem in self.records

        def _match_remove(row):
            elem = getattr(row, idx)
            found = elem in self.records
            if found:
                records_found.remove(elem)
            return found

        def _match_true(row):
            return True

        records_found = []
        if idx and self.records:
            if self.if_exists:
                match = _match
            else:
                # If we're using the approach of removing the unwanted
                # elements, we'll use a helper list to remove elements as we
                # find them in the DB contents. This will help us identify
                # quickly if there's some record missing to raise a RowNotFound
                # exception later.
                records_found = list(self.records)
                match = _match_remove
        else:
            match = _match_true

        self.result = [
            rowview.RowView(row) if self.row else {
                c: idlutils.get_column_value(row, c)
                for c in columns
            }
            for row in rows if match(row)
        ]

        if records_found:
            raise idlutils.RowNotFound(table=self.table, col=idx,
                                       match=records_found[0])
Exemplo n.º 3
0
 def run_idl(self, txn):
     # reduce search space if we have any indexed column and '=' match
     rows = (idlutils.index_condition_match(self.table, *self.conditions)
             or self.table.rows.values())
     self.result = [
         rowview.RowView(r) if self.row else
         {c: idlutils.get_column_value(r, c)
          for c in self.columns} for r in rows
         if idlutils.row_match(r, self.conditions)
     ]
Exemplo n.º 4
0
 def run_idl(self, txn):
     record = self.api.lookup(self.table, self.record)
     # TODO(twilson) This feels wrong, but ovs-vsctl returns single results
     # on set types without the list. The IDL is returning them as lists,
     # even if the set has the maximum number of items set to 1. Might be
     # able to inspect the Schema and just do this conversion for that case.
     result = idlutils.get_column_value(record, self.column)
     if isinstance(result, list) and len(result) == 1:
         self.result = result[0]
     else:
         self.result = result
Exemplo n.º 5
0
    def run_idl(self, txn):
        table_schema = self.api._tables[self.table]
        columns = self.columns or list(table_schema.columns.keys()) + ['_uuid']
        if self.records:
            rows = []
            for record in self.records:
                try:
                    rows.append(
                        idlutils.row_by_record(self.api.idl, self.table,
                                               record))

                except idlutils.RowNotFound:
                    if self.if_exists:
                        continue
                    raise
        else:
            rows = table_schema.rows.values()
        self.result = [
            rowview.RowView(row) if self.row else
            {c: idlutils.get_column_value(row, c)
             for c in columns} for row in rows
        ]