Trying to leverage the WIQL Editor feature:
'ever contains tag'
Searching Syntax, Trial and Error
Select
[System.Id],
[System.Title],
[System.State],
[System.Tags]
From WorkItems
Where [System.WorkItemType] = 'Change Request'
AND [State] <> 'Closed'
AND [State] <> 'Cancelled'
AND EVER [Tags] CONTAINS 'My Tag'
order by [Microsoft.VSTS.Common.Priority] asc,
[System.CreatedDate] desc
Expect it to return all work items that ever had a specific tag.
No, it's not able to do this through work item query at present.
Even though TFS supports a “Was Ever” operator for work item queries. But this operator is not applicable to all fields. As you can see, unlike assign to filed, the tag field only have Contians and Does Not Contain two operators.
So according to your Syntax AND EVER [Tags] CONTAINS 'My Tag'. This will not return all work items that ever had a specific tag.
For your requirement, you need to use Rest API or Client API to fetch the history of a work item and filter the tag value you have ever added in the record of all history info. It's a little bit complicated.
Related
I'm trying to sort documents of type 'Case' by the 'Name' of the 'Contact' they belong to in Solr. But cases have no 'ContactName' field or similar, only 'ContactId'.
Only examples I could find are iterations of the example on this link: https://wiki.apache.org/solr/Join
But I couldn't apply it to my situation because of the sorting afterwards. The following gives me the cases I want but I can't sort it by the contact name afterwards because it only returns the fields of the cases.
{!join from=Id to=ContactId}*:*
SQL equivalent of what I want would be something like:
SELECT Case.Id, Contact.Name
FROM Case
LEFT JOIN Contact
ON Case.ContactId = Contact.Id
ORDER BY Contact.Name ASC;
So to answer my own question after some digging and a Solr training:
It is not best practice to use joins in a NoSql database like Solr. If you need joins, then your database is structured wrong. You should index everything you need, in the document itself, even if it is redundant. So in my case, I should index 'Contact.Name' field in my 'Case' documents.
Still, it is apparently possible to use SQL queries in Solr in case it is absolutely needed, if you're using SolrCloud but it doesn't support joins. However it is possible to work around that as follows:
SELECT s1.Id
FROM salesforce s1, salesforce s2
WHERE s1._type_ = 'Case' and s2._type_ = 'Contact' AND s1.ContactId = s2.Id
ORDER BY s2.Name ASC
It should be noted that the fields after '.' like the 'Id' in 's1.Id' must have 'docValues' activated in the schema. More info on docValues is here.
I try to create a WIQL query that compares field contents of a work item and its related (linked) work items, e.g. where the 'state' of the work item is different from the 'state' of the related work item.
SELECT [System.Id], ... FROM WorkItemLinks WHERE ...
[Source].[System.State] <> [Target].[System.State])
ORDER BY [System.CreatedDate] desc, [System.AssignedTo] mode(MayContain)
(The ... above only indicate the parts that I have ommitted here for clarity.)
When I try to apply the query, I get this error message from TFS:
The link query can not mix expression with different prefixes
Is there a way to compare source and target fields with WIQL?
No, just as the error message indicates, you cannot mix expression with different prefixes. So you cannot compare the field in Source and Target directly. Refer to this link from MSDN for details: http://blogs.msdn.com/b/team_foundation/archive/2010/07/02/wiql-syntax-for-link-query.aspx
However, for the fields with pre-defined list values, you can write the query like following to achieve the feature you want.
SELECT [System.Id] FROM WorkItemLinks WHERE
([Source].[System.State] = ‘New’ and [Target].[System.State] <> ‘New’)
OR ([Source].[System.State] = ‘Resolved’ and [Target].[System.State] <> ‘Resolved’)
OR ([Source].[System.State] = ‘Active’ and [Target].[System.State] <> ‘Active’)
OR ([Source].[System.State] = ‘Closed’ and [Target].[System.State] <> ‘Closed’)
ORDER BY [System.CreatedDate] desc, [System.AssignedTo] mode(MayContain)
I have the following query returning duplicate titles, but :id is nil:
Movie.select(:title).group(:title).having("count(*) > 1")
[#<Movie:0x007f81f7111c20 id: nil, title: "Fargo">,
#<Movie:0x007f81f7111ab8 id: nil, title: "Children of Men">,
#<Movie:0x007f81f7111950 id: nil, title: "The Martian">,
#<Movie:0x007f81f71117e8 id: nil, title: "Gravity">]
I tried adding :id to the select and group but it returns an empty array. How can I return the whole movie record, not just the titles?
A SQL-y Way
First, let's just solve the problem in SQL, so that the Rails-specific syntax doesn't trick us.
This SO question is a pretty clear parallel: Finding duplicate values in a SQL Table
The answer from KM (second from the top, non-checkmarked, at the moment) meets your criteria of returning all duplicated records along with their IDs. I've modified KM's SQL to match your table...
SELECT
m.id, m.title
FROM
movies m
INNER JOIN (
SELECT
title, COUNT(*) AS CountOf
FROM
movies
GROUP BY
title
HAVING COUNT(*)>1
) dupes
ON
m.title=dupes.title
The portion inside the INNER JOIN ( ) is essentially what you've generated already. A grouped table of duplicated titles and counts. The trick is JOINing it to the unmodified movies table, which will exclude any movies that don't have matches in the query of dupes.
Why is this so hard to generate in Rails? The trickiest part is that, because we're JOINing movies to movies, we have to create table aliases (m and dupes in my query above).
Sadly, it Rails doesn't provide any clean ways of declaring these aliases. Some references:
Rails GitHub issues mentioning "join" and "alias". Misery.
SO Question: ActiveRecord query with alias'd table names
Fortunately, since we've got the SQL in-hand, we can use the .find_by_sql method...
Movie.find_by_sql("SELECT m.id, m.title FROM movies m INNER JOIN (SELECT title, COUNT(*) FROM movies GROUP BY title HAVING COUNT(*)>1) dupes ON m.first=.first")
Because we're calling Movie.find_by_sql, ActiveRecord assumes our hand-written SQL can be bundled into Movie objects. It doesn't massage or generate anything, which lets us do our aliases.
This approach has its shortcomings. It returns an array and not an ActiveRecord Relation, which means it can't be chained with other scopes. And, in the documentation for the find_by_sql method, we get extra discouragement...
This should be a last resort because using, for example, MySQL specific terms will lock you to using that particular database engine or require you to change your call if you switch engines.
A Rails-y Way
Really, what is the SQL doing above? It's getting a list of names that appear more than once. Then, it's matching that list against the original table. So, let's just do that using Rails.
titles_with_multiple = Movie.group(:title).having("count(title) > 1").count.keys
Movie.where(title: titles_with_multiple)
We call .keys because the first query returns an hash. The keys are our titles. The where() method can take an array, and we've handed it an array of titles. Winner.
You could argue one line of Ruby is more elegant than two. And if that one line of Ruby has an ungodly string of SQL embedded within it, how elegant is it really?
Hope this helps!
You can try to add id in your select:
Movie.select([:id, :title]).group(:title).having("count(title) > 1")
I have a JIRA project AAA and lots of tickets like AAA1, AAA2, AAA3
I'd like to search the tickets ordered by the name and ticket number, so it shows like this:
AAA1
AAA2
AAA3
what key word I should use for the filter?
I tried using 'order by Created', most of the tickets are displayed in order, but the one moved from other project is not in order because in the other project, it was created earlier.
In a JQL query, end the query with :
ORDER BY key
We have a Team Project Collection Source Control Setting for Check-in Notes that requires each check-in to capture a "Tracking Number". This number is external to TFS. I need to search for all the changesets that have a specific Tracking number.
The resulting changeset list tells me what to get latest version on, for a monthly deployment.
We don't use Work Items.
Question 1) Where in tfs_default_collection are the notes stored? One way to easily look would be to query with .SQL. I don't see "Note" in any of the database schemas.
Question 2) If I can't use .SQL to search, what object reference in Microsoft.TeamFoundation.VersionControl.Client.dll will give me the details of the Check-in Notes?
If I know what the changeset number is, then I can do something like this to give me the list.
-- these are all the .slq objects checked in $Release on '2013-01-28'
SELECT
chg_set.CreationDate,
chg_set.ChangeSetId,
v.FullPath
FROM dbo.tbl_ChangeSet (nolock)AS chg_set
INNER JOIN dbo.tbl_Version (nolock)AS v ON chg_set.ChangeSetId = v.VersionFrom
LEFT OUTER JOIN dbo.tbl_File (nolock) AS f ON v.FileId = f.FileId
WHERE chg_set.CreationDate >= '2013-01-31'
and FullPath like '%Tracker\Releases\2013.02.31%'
and FullPath like '%.sql%'
ORDER BY chg_set.CreationDate, v.FullPath
After some more digging into TFS_DefaultCollection I found it.
I can join these results with the query above and see exactly what I am looking for.
SELECT ReleaseNoteId, FieldName, BaseValue
from Tfs_DefaultCollection.dbo.tbl_ReleaseNoteDetails
where ReleaseNoteId in (SELECT ReleaseNoteId
FROM Tfs_DefaultCollection.dbo.tbl_ReleaseNote
where DateCreated between '2013-01-18' and '2013-02-22')
and FieldName = 'Tracker #'
and BaseValue <> '0' -- base value of zero is a merge from $Main
Thank you, in advance.