how to fetch the objects in dm_acl who grants the same sets of permission at the same time - dql

I am doing a JavaFx project connected to Documentum data source . lets say I have a set of groups : group1 , group2 , group3
How can I query all the acl_names from dm_acl who has only and exactly these groups as their r_acceesor_name . For example using the following query I can get the r_accessor_name of a specific acl:
select r_acceessor_name from dm_acl where object_name = 'My_acl_name' enable (row_based)
and the output is :
group1
group2
group3
But what I want to do is the reverse of this .I've tried the following query :
select object_name from dm_acl where r_accessor_name = 'group1' or r_accessor_name = 'group2' or r_accessor_name = 'group3' enable (row_based)
But the problem with the output is that it's too general which makes sense because of keyword OR
then I tried this :
select object_name from dm_acl where r_accessor_name = 'group1' and r_accessor_name = 'group2' and r_accessor_name = 'group3' enable (row_based)
which is too specific ==> zero output

You confused yourself more than you can think of.
Every ACL object has at least two entries: dm_owner and dm_world where first represents repository owner and the last represents every user in repository.
Because of it your objective
... all the acl_names from dm_acl who has only and exactly these groups ...
cannot be achieved.
However, beside this, your query
SELECT object_name FROM dm_acl
WHERE r_accessor_name = 'group1'
AND r_accessor_name = 'group2'
AND r_accessor_name = 'group3'
ENABLE (ROW_BASED)
is the best you can get. Your problem is that you really don't have ACL in your repository that contains at least these 3 groups. This leads you to the your initial question: either you made wrong presumption either you tried to too much to generalize your question that you've omitted the important part of it. ;)

I think I read your mind and came to what you really need:
SELECT object_name FROM dm_acl
WHERE r_accessor_name IN ('group_A', 'group_B', 'group_C')
GROUP BY object_name
HAVING COUNT(DISTINCT r_accessor_name) = 2
ENABLE (row_based)
Try it and see if it'll work.

Related

Want to use multiple conditions on same field to count the events in Data Studio

Want to use multiple conditions on event_params.value.string with different event_param.key:
I have synced my firebase data to bigQuery and trying to visualize on Data studio.Data looks like this:
Now I have event_params.value.string field which has all the values as "app" ,"4G", "App_Open","DashboardOnionActivity" and
Event Param Name field has values like : ....,Action,Label
I want to count only those App_Open which has label as DashboardOnionActivity
I was using CASE with when and Then construct as :
CASE
WHEN REGEXP_MATCH(event_params.value.string, "(?i) App_Open") THEN "1-App_Open"
WHEN REGEXP_MATCH(event_params.value.string, "(?i)selfie_capture") THEN "2-selfie_capture"
ELSE "0"
END
This gives me the count of App_Open and selfie_capture but I am not sure how to apply 2 conditions as Param Name is different for both one is Action and other is Label
One workaround can be to have separate events as DashboardOnionActivity_App_Open and Others but looking for some efficient usage if any possible
Solved it by custom query option when adding data from BigQuery(bq) connector to Data Studio:
So as data obtained in bq from firebase is nested.
Need to use unnest() in subqueries to get the values out of it.
So used query in this format in a custom query :
SELECT
event_date,event_name,event_params,
CASE
WHEN (SELECT count(*) FROM UNNEST(event_params) i where i.value.string_value='App_Open') = 1 AND (SELECT count(*) FROM UNNEST(event_params) i where i.value.string_value='DashboardOnionActivity' ) =1 THEN "1-App_Open"
ELSE "other"
END App_status
From <table_name>
​where event_params is the struct field.
Let me break down the query and explain :
SELECT count(*) FROM UNNEST(event_params) i where i.value.string_value='App_Open' :
This counts the number of 'App_Open' happen in event_params.value.string_value for one event. As there is no duplicate event_params so it is [0,1]
Similarly for DashboardOnionActivity which is 0 when it doesn't occur 1 otherwise.
Once this is added as a data source in Data Studio count can be visualized by several charts like bar, inverted bar, scorecard, etc

Cosmos db Order by on 'computed field'

I am trying to select data based on a status which is a string. What I want is that status 'draft' comes first, so I tried this:
SELECT *
FROM c
ORDER BY c.status = "draft" ? 0:1
I get an error:
Unsupported ORDER BY clause. ORDER BY item expression could not be mapped to a document path
I checked Microsoft site and I see this:
The ORDER BY clause requires that the indexing policy include an index for the fields being sorted. The Azure Cosmos DB query runtime supports sorting against a property name and not against computed properties.
Which I guess makes what I want to do impossible with queries... How could I achieve this? Using a stored procedure?
Edit:
About stored procedure: actually, I am just thinking about this, that would mean, I need to retrieve all data before ordering, that would be bad as I take max 100 value from my database... IS there any way I can do it so I don t have to retrieve all data first? Thanks
Thanks!
ORDER BY item expression could not be mapped to a document path.
Basically, we are told we can only sort with properties of document, not derived values. c.status = "draft" ? 0:1 is derived value.
My idea:
Two parts of query sql: The first one select c.* from c where c.status ='draft',second one select c.* from c where c.status <> 'draft' order by c.status. Finally, combine them.
Or you could try to use stored procedure you mentioned in your question to process the data from the result of select * from c order by c.status. Put draft data in front of others by if-else condition.

How to delete an acl from dm_acl object table

I am using documentum and I want to remove few acls from my dm_acl object table . first I made sure that the acl exists :
select * from dm_acl where object_name = 'myAclName'
then I made sure that no other object is using that acl
select * from dm_folder where acl_name = 'myAclName'
and then I used the following to delete that acl :
delete dm_acl objects where object_name = 'myAclName'
But then I receive an error saying that you have specified a none updatable type (dm_acl). Is there any way that I can delete an acl using either DQL or DFC
You can't delete ACL objects using DQL. However you can delete it using API with syntax
destroy,c,<acl_object_id>
One more thing, check you mentioned
select * from dm_folder where acl_name = 'myAclName'
is not enough. ACL object can be found on every sysobject so basically you need to widen your check to dm_sysobject type
select * from dm_sysobject where acl_name = 'myAclName'
Deleting ACL through DFC is possible since there is destroyACL() method on IDfAcl interface.

how to fetch the records having highest level in connect by oracle?? or the record having longest hierarchical path

I would like to fetch the record having highest level in a table in oracle database using pl/sql.
for some keys it could be level 2 for some it could be level 6... I want to get the records with their highest level path.
can some one help or guide ?
Not sure even if the question is related to oracle but in oracle you can achieve this by doing something similar to your query.
select level
from dual
connect by level < 11
order by level desc
I got the answer I was trying to do something like this... here I can't post the table or example as it is very difficult to format the question... or data in table.. here goes my query :)
CREATE TABLE TEMP
AS
SELECT Fncnl_Lctn_Key,
LEVEL AS Lev,
Src_Parnt_Fncnl_Lctn_Code,
SYS_CONNECT_BY_PATH (Src_Fncnl_Lctn_Unqid, '/') PATH,
Parnt_Fncnl_Lctn_Key,
Src_Fncnl_Lctn_Unqid,
Src_Fncnl_Lctn_Name
FROM Fncnl_Lctn_Dim
CONNECT BY ( PRIOR Fncnl_Lctn_Key = Parnt_Fncnl_Lctn_Key
AND PRIOR Src_Fncnl_Lctn_Name = Src_Parnt_Fncnl_Lctn_Code)
ORDER BY Fncnl_Lctn_Key, LEVEL DESC;
And then further selecting
SELECT *
FROM Temp
WHERE (Fncnl_Lctn_Key, Lev) IN ( SELECT fncnl_Lctn_Key, MAX (lev) AS LEV
FROM Temp
GROUP BY Fncnl_Lctn_Key)
ORDER BY Fncnl_Lctn_Key;
Your Question is not very detailed, but I guess you mean the level in a hierarchical query with CONNECT BY?!
If so, you could just add the pseudo-column LEVEL to your query. Do
ORDER BY LEVEL DESC
and just focus on the first few, which have your highest level with a
rownum<10
(or ofc, something higher than 10, if you have multiple Leafs on the same level) in your WHERE-Clause.
For Example something like this should work:
SELECT some_id, parent_id, foo, bar, level FROM tableX CONNECT BY PRIOR some_id = parent_id WHERE rownum<10 ORDER BY level;

Sessions by hits.page.pagePath in GA bigquery tables

I am new to bigquery, so sorry if this is a noob question! I am interested in breaking out sessions by page path or title. I understand one session can contain multiple paths/titles so the sum would be greater than total sessions. Essentially, I want to create a 'session id' and do a count distinct of sessionids where path like a or b.
It might actually be helpful to start at the very beginning and manually calculate total sessions. I tried to concatenate visit id and full visitor id to create a unique visit id, but apparently that is quite different from sessions. Can someone help enlighten me? Thanks!
I am working with our GA site data. Schema is the standard in GA exports.
DATA SAMPLE
Let's use an example out of the sample BigQuery (London Helmet) data:
There are 63 sessions in this day:
SELECT count(*) FROM [google.com:analytics-bigquery:LondonCycleHelmet.ga_sessions_20130910]
How many of those sessions are where hits.page.pagePath like /vests% or /helmets%? How many were vests only vs helmets only? Thanks!
Here is an example of how to calculate whether there were only helmets, or only vests or both helmets and vests or neither:
SELECT
visitID,
has_helmets AND has_vests AS both_helmets_and_vests,
has_helmets AND NOT has_vests AS helmets_only,
NOT has_helmets AND has_vests AS vests_only,
NOT has_helmets AND NOT has_vests AS neither_helmets_nor_vests
FROM (
SELECT
visitId,
SOME(hits.page.pagePath like '/helmets%') WITHIN RECORD AS has_helmets,
SOME(hits.page.pagePath like '/vests%') WITHIN RECORD AS has_vests,
FROM [google.com:analytics-bigquery:LondonCycleHelmet.ga_sessions_20130910]
)
Way 1, easier but you need to repeat on each field
Obviously you can do something like this :
SELECT count(*) FROM [google.com:analytics-bigquery:LondonCycleHelmet.ga_sessions_20130910] WHERE hits.page.pagePath like '/helmets%'
And then have multiple queries for your own substrings (one with '/vests%', one with 'helmets%', etc).
Way 2, works fine, but not with repeated fields
If you want ONE query that'll just group by on the first part of the string, you can do something like that :
Select a, Count(*) FROM (SELECT FIRST(SPLIT(hits.page.pagePath, '/')) as a FROM [google.com:analytics-bigquery:LondonCycleHelmet.ga_sessions_20130910] ) group by a
When I do this, it returns me the following the 63 sessions, with a total count of 63 :).
Way 3, using a FLATTEN on the table to get each hit individually
Since the "hits" field is repeatable, you would need a FLATTEN in your query :
Select a, Count(*) FROM (SELECT FIRST(SPLIT(hits.page.pagePath, '/')) as a FROM FLATTEN ([google.com:analytics-bigquery:LondonCycleHelmet.ga_sessions_20130910] , hits)) group by a
The reason why you need to FLATTEN here is that the "hits" field is repeatable. If you don't flatten, it won't look into ALL the "hits" in your response. Adding "FLATTEN" will make you work off a sub-table where each hit is in its own row, so you can query on all of them.
If you want it by sessions instead of hits, (it'll be both), do something like :
Select b, a Count(*) FROM (SELECT FIRST(SPLIT(hits.page.pagePath, '/')) as a, visitID as b, FROM FLATTEN ([google.com:analytics-bigquery:LondonCycleHelmet.ga_sessions_20130910] , hits)) group by b, a

Resources