How to query datasets by group with CKAN API? - rest

I have managed to create a query to get datasets by tags. For reference I have the following query:
http://localhost/api/3/action/package_search?fq=tags:(my-first-tag%20AND%20my-second-tag)&rows=2
Now, I need to filter these results by the group also. I added a dataset to a group and can see the group as:
http://localhost/api/3/action/group_list
But how can I add the group to the previous query? I can't seem to find anything that works.

You can use the filter query (fq) to search using the group name. For e.g to search the datasets that are in the test group
https://demo.ckan.org/api/3/action/package_search?fq=groups:test-group
To include the two fq, we need to make the query like this:
http://localhost/api/3/action/package_search?fq=tags:(my-tag-1%20AND%20my-tag-2)+groups:my-group-1&rows=2

Related

How to create a parameter and use inside a custom sql query in Tableau

I have a list of countries.
I need to create a parameter that can be used inside a custom sql.
For Eg:
List of countries
Argentina,Brazil,Colombia,Ecuador...
The requirement is
User should be able to select multiple countries
Based on that selection, need to run a custom sql that uses SQL IN query or multiple OR.
If user select Argentina and Brazil
Custom sql will be like
select * from players where countries in ('Argentina','Brazil)'
I tried with Set and Filters. But how can I create a parameter based on the selection of filters/Sets?
Parameters are single select only. So in your scenario it is not possible. You could create multiple parameters but that would mean the user would need to pick a country for each otherwise your query would not work. Here are instructions for creating and using parameters in custom sql. https://help.tableau.com/current/pro/desktop/en-us/customsql.htm#use-parameters-in-a-custom-sql-query

How to define a tags / value query in Grafana 7.4?

I am having some trouble understanding the concept of Value groups/tags in Grafana 7.4.x with MySQL as a data source.
My main query gets the Countries
SELECT
NAME as __text,
id AS __value
from
countries
The tags query gets the Continents
SELECT
NAME as __text,
id AS __value
from
continents
That works so far, tags are shown in the list, but nothing happens once I click on them.
My tags query:
continents.$tag.*
The tags query seems to be the problem. Any help is greatly appreciated.
3 queries are involved:
The first one is under "Query Options" -> "Query": This one should list all the values (all the countries in your case).
The second query is the "Tags query" under "Value groups/tags": This query should list all the Tags you want (continents).
The third query is "Tag values query": This is where the magic happens, this query should return all the different values matching the selected tags, so, you must add a WHERE clause somewhere that Grafana will use to create a query to get the correct values, ...WHERE continent = '$tag'. <- $tag will automatically be replaced by a list of tags the user has chosen.
Be aware that the official documentation provides examples for InfluxDB datasource, since you are using MySQL, you must use SQL queries everywhere, so continents.$tag.* is invalid.

Sails 1.0 Group By

Now that groupBy is deprecated, how can I mimic a SQL command like SELECT COUNT(*) FROM table GROUP BY xxx using the Waterline ORM ?
This page recommends using .sum() and .avg() but these methods are for number-type columns. Here I want to be able to count the rows of grouped columns, whatever type it is.
I think for specific groupBy query, you've got two choices.
The first one is a 2 step action.
1) Select all the unique element "group by field" you've got in the database.
2) Then count the record for each unique group by field element.
The second one is to use .sendNativeQuery() wich allow you to send a native SQL query to the datastore (you can use this only if you use a real SQL server and not the embedded Sails.JS database)
sendNativeQuery() Documentation

SSRS subquery based on other query

I'd like to make an overview of projects.
This contains some fixed info; table projects joined with some other tables.
Now the report needs to have some subqueries: how many sales per salesman, how many is in transit, inventory, ... and so on.
I have a tablix with grouping on project (as to create an excel with one worksheet per projet).
How would I go about executing a new subquery per project (f.e. select owner, sum(totalprice) from opportunities where project=xxx group by owner)
I know I could achieve this with subreports; but as I will have about 10 subreports, I was hoping I could solve this with extra datasets and some filtering (and thus keep all logic in one file).
What's the best way to achieve this?
I would create a dataset with this query:
select owner, project, sum(totalprice) as totalprice from opportunities group by owner, project
Next, in your tablix where you want to display owner and totalprice info, you will have an expression like this:
=LOOKUP(Fields!<FirstDataSetProjectFieldName>.Value, Fields!project.Value, Fields!owner.Value, "<NewDatasetName>")
The above code will send the value of the project you are searching for, match it with a the same field in your new dataset, then return the requested value from the new dataset. You can obviously do this for totalprice as well.
Check out the documentation for LOOKUP to get a better handle on it but I think this is the solution you are looking for.

Query items user was mentioned in

Is there a way to query work items where a user was mentioned? I am able to receive 'hard-coded' results by querying for
"History"-"Contains word"-"\#Username",
but I want a generic version, which works for all users. (Opposed to writing one query for every user)
Use this predicate:
Field: "ID"
Operator: "In"
Value: "#RecentMentions"
This automatically filters for work items, where current user has been mentioned.
I found it in predefined filter "Mentioned" in "Work Items" section. If you click on "Open in Queries" button, you will get a query with above filter. (This section can even remove the need for that query...)
Note: at present time, works only in VSTS.
https://{org}.visualstudio.com/{project}/_workitems/mentioned/
This would achieve the same result.
There is no way to achieve this by work item query directly just as starain mentioned. You can create a custom hub or custom widget by using VSTS Extension to show these information in web portal.
You can’t achieve that through work item query directly, you could build a app to retrieve data through REST API (https://www.visualstudio.com/en-us/docs/integrate/api/wit/wiql), change query text according different conditions (e.g. users)
Your query should be something like this
Select Id,Title From WorkItems Where ID IN (#RecentMentions) order by [System.ChangedDate] desc
here is the reference for rest of the macro's available in ADO rest API.
https://learn.microsoft.com/en-us/azure/devops/boards/queries/query-operators-variables?view=azure-devops