#3973 Add DISTINCT to QueryProcessor
Closed a year ago by jcupova. Opened a year ago by jcupova.
jcupova/koji issue-3972  into  master

Add DISTINCT to QueryProcessor
Jana Cupova • a year ago  
file modified
+7 -1
@@ -665,7 +665,7 @@ 

      def __str__(self):

          query = \

              """

- SELECT %(col_str)s

+ SELECT %(distinct)s%(col_str)s

    FROM %(table_str)s

  %(join_str)s

  %(clause_str)s
@@ -688,6 +688,12 @@ 

                  col_str = 'count(*)'

          else:

              col_str = self._seqtostr(self.columns)

+         if self.opts.get('distinct') and not self.opts.get('countOnly'):

+             distinct = 'DISTINCT '

+         elif self.opts.get('distinct') and self.opts.get('countOnly'):

+             koji.GenericError('DISTINCT cannot be used with countOnly.')

+         else:

+             distinct = ''

          table_str = self._seqtostr(self.tables, sort=True)

          join_str = self._joinstr()

          clause_str = self._seqtostr(self.clauses, sep=')\n   AND (')

@@ -139,3 +139,13 @@ 

          results = proc.execute()

          self.assertEqual(

              results, [['result_1_col_1', 'result_1_col_2'], ['result_2_col_1', 'result_2_col_2']])

+ 

+     def test_distinct_and_count(self):

+         proc = kojihub.QueryProcessor(

+             columns=['something'],

+             tables=['awesome'],

+             opts={'distinct': True}

+         )

+         actual = " ".join([token for token in str(proc).split() if token])

+         expected = "SELECT DISTINCT something FROM awesome"

+         self.assertEqual(actual, expected)

rebased onto b2f2df5

a year ago

Do we have a use case for this?

Metadata Update from @tkopecek:
- Pull-request tagged with: no_qe

a year ago

PR #3970 would like to use it. Idea is to collect all (also inherited) permissions in one query.

I'm not in a hurry to add this feature to QueryProcessor. We might not need this for #3970 (see my comments there). If we were to add this, it should likely not be exposed in queryOpts.

Pull-Request has been closed by jcupova

a year ago