SQL Query to fetch defects which is linked to Test Set , Test Case and Test Step from ALM - alm

I am using below query but it is not extracting defects which is linked to Test Steps of Test Cases.
So all the defects which are linked to test steps are not coming out.
SELECT Distinct BUG.BG_BUG_ID as "Defect ID", BUG.BG_DETECTED_BY as "Detected By", BUG.BG_SUMMARY as "Defect Name", BUG.BG_USER_03 as "Application", BUG.BG_USER_01 as "Category", LINK.LN_ENTITY_TYPE as "Type", TEST.TS_TEST_ID as "Test ID", TEST.TS_NAME as "Test Name", TEST.TS_USER_03 as "Test Category"
FROM LINK, BUG, TEST,STEP Where LINK.LN_BUG_ID = BUG.BG_BUG_ID AND LINK.LN_ENTITY_ID = TS_TEST_ID --AND BUG.BG_STATUS in ('Closed', 'Canceled', 'Duplicate') AND BUG.BG_DETECTED_IN_RCYC in (Select RELEASE_CYCLES.RCYC_ID from RELEASE_CYCLES where RELEASE_CYCLES.RCYC_NAME IN ('UAT - 3.1 MVA'))
Order by BUG.BG_BUG_ID

Related

Trying to find where NOT IN

I need to find my contacts that have a specific committee assignment or belong to a specific membership group that are not registered for a specific event. I tested each select separately, however it is definitely my NOT IN which is incorrect.. I keep getting an error.. The c.id (contact ID ) would be not in if the A.EventApi__Contact__c is not in the subquery ..
SELECT
DISTINCT (c.id) "ID",
c.Hidden_VIS__c "VIS Number",
c.FirstName "First Name",
c.LastName "Last Name",
CN.Name "Committee Name",
M.MEMBERSHIP_GROUP_NAME__C "Membership Name"
FROM CONTACT C
LEFT JOIN COMMITTEE_ASSIGNMENT__C CA
ON c.id=CA.CONTACT__C
LEFT JOIN COMMITTEE__C CN
ON CN.ID=CA.COMMITTEE__C
LEFT JOIN MEMBERSHIP__C M
ON M.DONOR__C=C.id
WHERE (CN.NAME='Boston Board of Directors' OR CN.NAME='Boston Board of Trustees' OR
CN.NAME='Capital Region Board of Directors')
OR (M.Status__c='Active' OR M.Status__c='Grace') AND (M.MEMBERSHIP_GROUP_NAME__C='CHAI
Society' OR M.MEMBERSHIP_GROUP_NAME__C='Sapphire')
AND c.id NOT IN (
SELECT
A.EventApi__Contact__c "Contact",
c.id
FROM EventApi__Attendee__c A
LEFT JOIN EventApi__Event__c E
ON E.ID=a.EventApi__Attendee_Event__c
Left Join CONTACT C
ON c.id=A.EventApi__Contact__c
WHERE E.Appeal_Code__c='1093' AND A.EventApi__Status__c='Registered');

Why does this Cosmos SQL query require a subquery?

I'm trying to understand why my query below will only work when using a subquery.
Sample document structure:
{
"id": "78832-fsdfdf-3242",
"type": "Specific",
"title": "JavaScript vs TypeScript",
"summary": "Explain the differences between JavaScript and TypeScript.",
"products": [
"javascript v6",
"typescript v1",
"node.js"
]
}
Query requirements:
Find the id of all documents where the terms 'javascript' or 'csharp' or 'coding' are contained in either the title, summary or in one of the listed products.
To solve this, I'm using CONTAINS(). To avoid repeating the CONTAINS() for each combination of field and search term, I create a concatenation of the fields in question and name it searchField.
Working query
This is the query I came up with. It's using a subquery sub to add the concatenated fields and products to the result set. Then, I can use CONTAINS() on sub.searchField.
SELECT sub.id
FROM
(
SELECT
o.id,
o.type,
CONCAT(o.title, " ", o.summary, " ", p) as searchField
FROM o
JOIN p in o.products
) sub
WHERE
sub.type = "Specific"
AND
(
CONTAINS(sub.searchField, "javascript", true)
OR CONTAINS(sub.searchField, "csharp", true)
OR CONTAINS(sub.searchField, "coding", true)
)
Non-working query
Originally, I had the query written as seen below. I expected it to work as in other SQL dialects, but I cannot access searchField in the WHERE clause.
"Error: Identifier 'searchField' could not be resolved."
SELECT o.id, CONCAT(o.title, " ", o.summary, " ", p) as searchField
FROM o
WHERE
o.type = "Specific"
AND
(
CONTAINS(searchField, "javascript", true)
OR CONTAINS(searchField, "csharp", true)
OR CONTAINS(searchField, "coding", true)
)
Questions
Is there a better way to achieve the result needed? (Although, surprisingly, the query consumes only 230 RUs)
Why is the subquery needed? I really want to understand this so I can learn when the use subqueries and potentially write queries that would otherwise not be possible.

Cosmos db null value

I have two kind of record mention below in my table staudentdetail of cosmosDb.In below example previousSchooldetail is nullable filed and it can be present for student or not.
sample record below :-
{
"empid": "1234",
"empname": "ram",
"schoolname": "high school ,bankur",
"class": "10",
"previousSchooldetail": {
"prevSchoolName": "1763440",
"YearLeft": "2001"
} --(Nullable)
}
{
"empid": "12345",
"empname": "shyam",
"schoolname": "high school",
"class": "10"
}
I am trying to access the above record from azure databricks using pyspark or scala code .But when we are building the dataframe reading it from cosmos db it does not bring previousSchooldetail detail in the data frame.But when we change the query including id for which the previousSchooldetail show in the data frame .
Case 1:-
val Query = "SELECT * FROM c "
Result when query fired directly
empid
empname
schoolname
class
Case2:-
val Query = "SELECT * FROM c where c.empid=1234"
Result when query fired with where clause.
empid
empname
school name
class
previousSchooldetail
prevSchoolName
YearLeft
Could you please tell me why i am not able to get previousSchooldetail in case 1 and how should i proceed.
As #Jayendran, mentioned in the comments, the first query will give you the previouschooldetail document wherever they are available. Else, the column would not be present.
You can have this column present for all the scenarios by using the IS_DEFINED function. Try tweaking your query as below:
SELECT c.empid,
c.empname,
IS_DEFINED(c.previousSchooldetail) ? c.previousSchooldetail : null
as previousSchooldetail,
c.schoolname,
c.class
FROM c
If you are looking to get the result as a flat structure, it can be tricky and would need to use two separate queries such as:
Query 1
SELECT c.empid,
c.empname,
c.schoolname,
c.class,
p.prevSchoolName,
p.YearLeft
FROM c JOIN c.previousSchooldetail p
Query 2
SELECT c.empid,
c.empname,
c.schoolname,
c.class,
null as prevSchoolName,
null as YearLeft
FROM c
WHERE not IS_DEFINED (c.previousSchooldetail) or
c.previousSchooldetail = null
Unfortunately, Cosmos DB does not support LEFT JOIN or UNION. Hence, I'm not sure if you can achieve this in a single query.
Alternatively, you can create a stored procedure to return the desired result.

Why the generated Queries by ormLite to load related references using IN do not use parameterized queries?

I have an issue related to loading reference/child tables when loading the parent table records from the database. My DB engine is MS SQL Server. I'm using ServiceStack.OrmLite v5.8.0. My application is written in C# .NET v4.6.2.
I have three entities, 1 parent and 2 children. They are marked properly using the required annotations by OrmLite. I noticed when running a query from C# to fetch the parent table including the children in one shot using an IN Condition, the queries that get generated to load the children records are not parameterized. Please have a look at the queries I got from SQL Profiler below:
This is the first query that fetches the records from the parent table. Notice the usage of the parameterized query:
exec sp_executesql N'SELECT "Id", "MeetingDateAndTime", "Location", "IsHeld", "ScheduledForDate", "ContactMeBy", "IsCanceled", "IncidentId", "IncidentNumber", "IncidentDateTime"
FROM "HomePageSearch_ResolutionMeetings"
WHERE "Id" IN (#0,#1,#2,#3,#4,#5,#6,#7,#8,#9,#10)
ORDER BY "IncidentDateTime" DESC',N'#0 int,#1 int,#2 int,#3 int,#4 int,#5 int,#6 int,#7 int,#8 int,#9 int,#10 int',#0=16,#1=15,#2=13,#3=14,#4=12,#5=8,#6=5,#7=6,#8=4,#9=1,#10=2
This is the second query that fetches the records from the first child table. Notice the usage of the hard-coded values while the parameters are being generated:
exec sp_executesql N'SELECT "Id", "ResolutionSessionIdFk", "Type", "RespondentId", "FirstName", "LastName" FROM "HomePageSearch_ResolutionMeetingsInvitees" WHERE "ResolutionSessionIdFk" IN (SELECT "HomePageSearch_ResolutionMeetings"."Id"
FROM "HomePageSearch_ResolutionMeetings"
WHERE "Id" IN (16,15,13,14,12,8,5,6,4,1,2))',N'#0 int,#1 int,#2 int,#3 int,#4 int,#5 int,#6 int,#7 int,#8 int,#9 int,#10 int',#0=16,#1=15,#2=13,#3=14,#4=12,#5=8,#6=5,#7=6,#8=4,#9=1,#10=2
This is the third query that fetches the records from the second child table. Notice the usage of the hard-coded values while the parameters are being generated:
exec sp_executesql N'SELECT "Id", "ResolutionMeetingIdFk", "Type", "FirstName", "LastName" FROM "HomePageSearch_ResolutionMeetingsOfficers" WHERE "ResolutionMeetingIdFk" IN (SELECT "HomePageSearch_ResolutionMeetings"."Id"
FROM "HomePageSearch_ResolutionMeetings"
WHERE "Id" IN (16,15,13,14,12,8,5,6,4,1,2))',N'#0 int,#1 int,#2 int,#3 int,#4 int,#5 int,#6 int,#7 int,#8 int,#9 int,#10 int',#0=16,#1=15,#2=13,#3=14,#4=12,#5=8,#6=5,#7=6,#8=4,#9=1,#10=2
Any idea why?

OpenJPA/MySQL: modifying a table while the same table is used in the where clause

I want to execute a delete query via openJPA and mysql.
This mysql statement works fine:
delete from GENERIC
where PARENT_ID not in (select g2.ID from (select * from GENERIC) g2);
The basic element are a table GENERIC with columns ID and PARENT_ID
Mapping the GENERIC table to GenericEntity class, ID column to id member (of that class) and PARENT_ID column to parentId member, I tried this simple test:
entityManager.createQuery("delete from GenericEntity g1 where " +
"g1.parentId not in " +
"(select g2.id from (select * from GenericEntity) g2)"
).executeUpdate();
And I get this error:
org.apache.openjpa.persistence.ArgumentException: "Encountered "g1 .
parentId not in ( select g2 . id from (" at character 36, but
expected: ["(", "*", "+", ",", "-", ".", "/", ":", "<", "<=", "<>",
"=", ">", ">=", "?", "ABS", "ALL", "AND", "ANY", "AS", "ASC", "AVG",
"BETWEEN", "BOTH", "BY", "CASE", "CLASS", "COALESCE", "CONCAT",
"COUNT", "CURRENT_DATE", "CURRENT_TIME", "CURRENT_TIMESTAMP",
"DELETE", "DESC", "DISTINCT", "ELSE", "EMPTY", "END", "ENTRY",
"ESCAPE", "EXISTS", "FETCH", "FROM", "GROUP", "HAVING", "IN", "INDEX",
"INNER", "IS", "JOIN", "KEY", "LEADING", "LEFT", "LENGTH", "LIKE",
"LOCATE", "LOWER", "MAX", "MEMBER", "MIN", "MOD", "NEW", "NOT",
"NULL", "NULLIF", "OBJECT", "OF", "OR", "ORDER", "OUTER", "SELECT",
"SET", "SIZE", "SOME", "SQRT", "SUBSTRING", "SUM", "THEN", "TRAILING",
"TRIM", "TYPE", "UPDATE", "UPPER", "VALUE", "WHEN", "WHERE",
, , , ,
, , ,
, ]." while parsing JPQL "delete from
GenericEntity g1 where g1.parentId not in (select g2.id from (select *
from GenericEntity) g2)". See nested stack trace for original parse
error.
I tried different variants, also replaced the delete by an update (to set a 'deleted' flag instead), but it seems to be a general problem to modify a table when this very table is used in the where clause.
I'd appreciate very much a hint, how to continue or a link to any helpful material.
Thank you very much in advance!
After a lot of research, I have found a solution. It works fine to separate the select from the delete query and pass the list of IDs as a parameter to the delete statement:
List<Integer> idList = entityManager
.createQuery("select g.id from GenericEntity g",Integer.class)
.getResultList();
entityManager
.createQuery("delete from GenericEntity g where g.parentId not in (:idList)")
.setParameter("idList", idList)
.executeUpdate();

Resources