1

I have two types of docs say obj_type_A and obj_type_B which may or may not be in a folder of type obj_type_fldr.

I need to get the count of both the docs present in the folder of type obj_type_fldr.

If it had an sql we can write sub-query in select clause. But DQL didn't support this function.

dnup1092
  • 375
  • 4
  • 15

1 Answers1

1

The trick here is to utilize the r_object_type attribute of dm_sysobject. So what you want is probably only achievable if both of your custom types are descendants of dm_sysobject. And in that case, this is how you do it.

Basic count

SELECT count(r_object_id), r_object_type 
FROM dm_sysobject
WHERE ANY i_folder_id IN (
    SELECT r_object_id 
    FROM obj_type_fldr
) 
AND r_object_type IN ('obj_type_A','obj_type_B') 
GROUP BY r_object_type

Example output:

dm_attr_0001  r_object_type
------------  --------------------------------
         271  obj_type_A
         195  obj_type_B
(2 rows affected)

Count per folder

Additionally, if you want to count how many documents are in each folder, just add i_folder_id to your query like this:

SELECT count(r_object_id), r_object_type, i_folder_id 
FROM dm_sysobject
WHERE ANY i_folder_id IN (
    SELECT r_object_id 
    FROM obj_type_fldr
) 
AND r_object_type IN ('obj_type_A','obj_type_B') 
GROUP BY r_object_type, i_folder_id

Example output:

dm_attr_0001  r_object_type     i_folder_id
------------  ----------------  ----------------
         271  obj_type_A        0b00000080000001
         100  obj_type_B        0b00000080000001
          95  obj_type_B        0b00000080000002
(3 rows affected)

You can of course extend this query with additional clauses, e.g. in order to count only documents that are within a specific path, but you get the general idea.

eivamu
  • 3,025
  • 1
  • 14
  • 20
  • i thought of the same but I need the output result like count(obj_type_A),count(obj_Type_B),i_folder_id. If i get the result in the above format then which will act like a flag in my code which will make the iteration over millions of data a bit fast. – dnup1092 Aug 30 '15 at 09:31
  • OK, I edited my answer. Please uprate it as helpful, and mark it as correct. – eivamu Aug 30 '15 at 09:41
  • the edited query will give me the result like `count,type,i_folder` if I'm not wrong.Lets say I only have two custom type type_A and type_B and I need to get the count of both the document type in a folder.Is it possible to get the count of both a object_type in a single row with there i_folder_id. So the schema what i want to be in result is `count(type_A),count(type_B),i_folder_id.` In raw sql this can be done by using subquery in select. Th – dnup1092 Aug 30 '15 at 09:47
  • That's one trickier. Let me think for a moment. And in the meantime, please read the introductory page for stackoverflow about how things work here. My answer is now _correct_ with regards to your question. Stackoverflow is not a discussion forum, it is a place for questions and answers :) – eivamu Aug 30 '15 at 09:52
  • 1
    Hmm new to the community :) . Will upvote the answer. and accept it. **I think EMC should have some thing to allow subquery in select clause.** – dnup1092 Aug 30 '15 at 10:00
  • Thanks :) I agree with you there. Well I have thought about your question and the only solution is to use a _registered view_ if you would like this as a "one-line answer", and then query this registered view from DQL. Your view needs to pick from both the dm_sysobject_s and dm_sysobject_r tables in your database. The first one contains only one row per ID, the second one (which holds i_folder_id) contains multiple rows per ID. More information here: https://community.emc.com/message/579811 – eivamu Aug 30 '15 at 10:05
  • But views are not updated regularly(only materialized view are updated that too over a period time configured by admin right? ) if i'm not wrong. So in that case there is some probability of getting obsolete data.Right? – dnup1092 Aug 30 '15 at 10:11
  • I think you are right. I myself would have used the query suggested in my original answer, and then used code (Java) to sort the output the way I want it. But I am fully aware that this is not always viable. – eivamu Aug 30 '15 at 10:17