-1

I have a table in google app engine datastore as ItemData with columns as below.

-------------------------------
| letter | f_no | s_no | t_no |
-------------------------------
|  A     |  2   |  3   |  0   |
|  X     |  5   |  8   |  5   |
|  C     |  4   |  6   |  5   |
|  T     |  2   |  3   |  6   |
|  A     |  2   |  4   |  0   |
|  A     |  6   |  3   |  0   |
|  C     |  2   |  2   |  9   |
-------------------------------

I need to find most frequent value in each columns.

How can i achieve this using GQL?

Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
Bishan
  • 15,211
  • 52
  • 164
  • 258

1 Answers1

2

There is no single query that can do it. There is no datastore equivalent to the MySQL-ism select count(distinct column_id) from table.

It can actually be a quite complex problem to solve, given a big table and a lot of different distinct values. The naive way is to simply fetch all entities and do the counting in your code, but if your table has a lot of entities in it this will eventually exceed the query deadline.

In general when it comes to datastore querying problems, if a query seems annoying to implement and looks like it won't scale, and you need to be able to execute it relatively frequently, chances are you should be be preparing the information gathering on insert by using some kind of acceleration structure or counter. If you don't need to execute it frequently, MapReduce may be the answer.

kblomster
  • 91
  • 2