neuecc / LINQ-to-BigQuery

LINQ to BigQuery is C# LINQ Provider for Google BigQuery. It also enables Desktop GUI Client with LINQPad and plug-in driver.
MIT License
85 stars 16 forks source link

fixed descending ordering for window functions when specifying multple columns #35

Closed kbremner closed 9 years ago

kbremner commented 9 years ago

Currently it only specifies the last key as DESC. Fixed so that all keys are specified as DESC when carrying out descending ordering for a window function.

neuecc commented 9 years ago

Thank you and sorry for delay response. I'll check it.

neuecc commented 9 years ago

Mreged but I'll try to add ThenBy for window function

neuecc commented 9 years ago

Thanks, I've modified following code finally.

context.From<Shakespeare>()
       .Where(x => x.corpus == "othello" && BqFunc.Length(x.word) > 10)
       .Select(x => new
       {
           x.word,
           x.word_count,
           row_num = BqFunc.RowNumber(x)
               .OrderByDescending(y => y.word)
               .ThenBy(y => y.word_count)
               .ThenByByDescending(y => y.corpus)
               .Value
       })
       .Limit(5);

as

SELECT
  [word],
  [word_count],
  ROW_NUMBER() OVER (ORDER BY [word] DESC, [word_count], [corpus] DESC) AS [row_num]
FROM
  [publicdata:samples.shakespeare]
WHERE
  (([corpus] = 'othello') AND (LENGTH([word]) > 10))
LIMIT 5