#2279 koji-gc: fix query order
Merged 2 years ago by tkopecek. Opened 2 years ago by tkopecek.
tkopecek/koji issue2270  into  master

file modified
@@ -871,6 +871,7 @@ 

              print("Pruning tag: %s" % tagname)

          # get builds

          history = session.queryHistory(tag=tagname, active=True)['tag_listing']

+         history = sorted(history, key=lambda x: -x['create_ts'])

          if not history:

              if options.debug:

                  print("No history for %s" % tagname)

                orderCol = self.colsByAlias.get(order)
                if orderCol:
                    # use alias as order
                    orderCol = order
                elif order in self.columns:
                    # use column as order
                    orderCol = order

The problem with this is that we have two different forms of aliases here.

  • aliases in QueryProcessor which affect the names of the fields in the dictionary that is returned
  • aliases in SQL, which QueryProcessor itself does not set, but some of our invocations include in the fields value.

Consider the case with query_processor where we pass

  • field = 'EXTRACT(EPOCH FROM ev1.time) AS create_ts'
  • alias = 'create_ts'

Here the alias after the AS in the field definition matches the alias for the dict given to QueryProcessor, but:

  • they are not guaranteed to be the same
  • QueryProcessor does not add AS clauses for the alias values.

I think in most cases, this is going to work because we mostly use sane aliases, but we'd need to check to be sure.

I suppose we could have QueryProcessor add the AS clauses, but we'd also have to do a lot of checking there (and have the invocations stop including them in the field).

And if we do get to a point where we can always use the literal alias in the order, then the code should probably be something more like:

                # only allow sane order values
                if order not in self.columns and order not in self.aliases:
                    raise Exception('invalid order: ' + order)
                order_exprs.append(order + direction)

So, do you think, there is a sane way to order query_history by create_ts without touching QueryProcessor?

rebased onto 9f54386

2 years ago

updated to sort it client-side

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

2 years ago

Metadata Update from @jcupova:
- Pull-request untagged with: testing-ready
- Pull-request tagged with: no_qe

2 years ago

Commit 272a718 fixes this pull-request

Pull-Request has been merged by tkopecek

2 years ago