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

Download 2279.patch

Fixes: https://pagure.io/koji/issue/2270

                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 9f543862795e6c6cddd74e33dc93d30884f027d1

updated to sort it client-side

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

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

Commit 272a7184 fixes this pull-request

Pull-Request has been merged by tkopecek

Metadata