<commit_before>{-# LANGUAGE FlexibleInstances     #-}
{-# LANGUAGE GADTs                 #-}
{-# LANGUAGE MonadComprehensions   #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE RebindableSyntax      #-}
{-# LANGUAGE TemplateHaskell       #-}
{-# LANGUAGE TypeFamilies          #-}
{-# LANGUAGE UndecidableInstances  #-}
{-# LANGUAGE ViewPatterns          #-}

-- | TPC-H Q16
module Queries.TPCH.Standard.Q16
    ( q16
    ) where

import Database.DSH
import Schema.TPCH

-- | TPC-H Query Q16
q16 :: Q [((Text, Text, Integer), Integer)]
q16 = groupAggr fst snd (length . nub)
      [ tup2 (tup3 (p_brandQ p) (p_typeQ p) (p_sizeQ p)) (ps_suppkeyQ ps)
      | ps <- partsupps
      , p  <- parts<commit_msg>TPC-H Q16: DSH query conforms to spec (result order)<commit_after>{-# LANGUAGE FlexibleInstances     #-}
{-# LANGUAGE GADTs                 #-}
{-# LANGUAGE MonadComprehensions   #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE RebindableSyntax      #-}
{-# LANGUAGE TemplateHaskell       #-}
{-# LANGUAGE TypeFamilies          #-}
{-# LANGUAGE UndecidableInstances  #-}
{-# LANGUAGE ViewPatterns          #-}

-- | TPC-H Q16
module Queries.TPCH.Standard.Q16
    ( q16
    ) where

import Database.DSH
import Schema.TPCH

byDescCount :: Q ((Text, Text, Integer), Integer) -> Q (Integer, Text, Text, Integer)
byDescCount (view -> (g, c)) = case view g of
    (b, t, s) -> tup4 (-1 * c) b t s

-- | TPC-H Query Q16
q16 :: Q [((Text, Text, Integer), Integer)]
q16 = sortWith byDescCount
      $ groupAggr fst snd (length . nub)
      [ tup2 (tup3 (p_brandQ p) (p_typeQ p) (p_sizeQ p)) (ps_suppkeyQ ps)
      | ps <- partsupps
      , p  <- parts
{'fraction_non_alphanumeric': 0.14902186421173763, 'fraction_numerical': 0.018411967779056387, 'mean_word_length': 2.578189300411523, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2733210', 'n_tokens_mistral': 706, 'n_tokens_neox': 675, 'n_words': 157}