Merged in feature/testquery (pull request #39)
Test Query * depstextandclean * startedcleaningresult * resulttidyup * roundone * cleaning * unsyncedquery * startedtestsandsimplification * api * querytests * resultprocessortests * unittests * cleanup
This commit is contained in:
@@ -11,29 +11,118 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const listResultValuesByID = `-- name: ListResultValuesByID :many
|
||||
SELECT id, queryId, value FROM results where id = ANY($1)
|
||||
const getResultValueWithVersion = `-- name: GetResultValueWithVersion :one
|
||||
SELECT id, value FROM results WHERE queryId = $1 and queryVersion = $2 and documentId = $3 and cleanVersion >= $4 and textVersion >= $5
|
||||
`
|
||||
|
||||
type ListResultValuesByIDRow struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Value string `db:"value"`
|
||||
type GetResultValueWithVersionParams struct {
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Queryversion int32 `db:"queryversion"`
|
||||
Documentid pgtype.UUID `db:"documentid"`
|
||||
Cleanversion int32 `db:"cleanversion"`
|
||||
Textversion int32 `db:"textversion"`
|
||||
}
|
||||
|
||||
// ListResultValuesByID
|
||||
type GetResultValueWithVersionRow struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Value string `db:"value"`
|
||||
}
|
||||
|
||||
// GetResultValueWithVersion
|
||||
//
|
||||
// SELECT id, queryId, value FROM results where id = ANY($1)
|
||||
func (q *Queries) ListResultValuesByID(ctx context.Context, id []pgtype.UUID) ([]*ListResultValuesByIDRow, error) {
|
||||
rows, err := q.db.Query(ctx, listResultValuesByID, id)
|
||||
// SELECT id, value FROM results WHERE queryId = $1 and queryVersion = $2 and documentId = $3 and cleanVersion >= $4 and textVersion >= $5
|
||||
func (q *Queries) GetResultValueWithVersion(ctx context.Context, arg *GetResultValueWithVersionParams) (*GetResultValueWithVersionRow, error) {
|
||||
row := q.db.QueryRow(ctx, getResultValueWithVersion,
|
||||
arg.Queryid,
|
||||
arg.Queryversion,
|
||||
arg.Documentid,
|
||||
arg.Cleanversion,
|
||||
arg.Textversion,
|
||||
)
|
||||
var i GetResultValueWithVersionRow
|
||||
err := row.Scan(&i.ID, &i.Value)
|
||||
return &i, err
|
||||
}
|
||||
|
||||
const listQueryRequirementValues = `-- name: ListQueryRequirementValues :many
|
||||
WITH latest_versions AS (
|
||||
SELECT
|
||||
r.queryId,
|
||||
MAX(r.cleanVersion) as max_clean_version,
|
||||
MAX(r.textVersion) as max_text_version
|
||||
FROM results r
|
||||
WHERE r.documentId = $3
|
||||
AND r.queryVersion = $2
|
||||
GROUP BY r.queryId
|
||||
)
|
||||
SELECT rq.requiredQueryId as queryId, r.value, q.type
|
||||
FROM requiredQueries as rq
|
||||
JOIN results as r on r.queryId = rq.requiredQueryId
|
||||
JOIN queries as q on q.id = rq.requiredQueryId
|
||||
JOIN latest_versions lv ON lv.queryId = r.queryId
|
||||
WHERE rq.queryId = $1 and r.documentId = $3
|
||||
and $2 >= rq.addedVersion
|
||||
and $2 < COALESCE(rq.removedVersion, $2 + 1)
|
||||
and r.queryVersion = $2
|
||||
and r.cleanVersion >= $4 and r.textVersion >= $5
|
||||
AND r.cleanVersion = lv.max_clean_version
|
||||
AND r.textVersion = lv.max_text_version
|
||||
`
|
||||
|
||||
type ListQueryRequirementValuesParams struct {
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Addedversion int32 `db:"addedversion"`
|
||||
Documentid pgtype.UUID `db:"documentid"`
|
||||
Cleanversion int32 `db:"cleanversion"`
|
||||
Textversion int32 `db:"textversion"`
|
||||
}
|
||||
|
||||
type ListQueryRequirementValuesRow struct {
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Value string `db:"value"`
|
||||
Type Querytype `db:"type"`
|
||||
}
|
||||
|
||||
// ListQueryRequirementValues
|
||||
//
|
||||
// WITH latest_versions AS (
|
||||
// SELECT
|
||||
// r.queryId,
|
||||
// MAX(r.cleanVersion) as max_clean_version,
|
||||
// MAX(r.textVersion) as max_text_version
|
||||
// FROM results r
|
||||
// WHERE r.documentId = $3
|
||||
// AND r.queryVersion = $2
|
||||
// GROUP BY r.queryId
|
||||
// )
|
||||
// SELECT rq.requiredQueryId as queryId, r.value, q.type
|
||||
// FROM requiredQueries as rq
|
||||
// JOIN results as r on r.queryId = rq.requiredQueryId
|
||||
// JOIN queries as q on q.id = rq.requiredQueryId
|
||||
// JOIN latest_versions lv ON lv.queryId = r.queryId
|
||||
// WHERE rq.queryId = $1 and r.documentId = $3
|
||||
// and $2 >= rq.addedVersion
|
||||
// and $2 < COALESCE(rq.removedVersion, $2 + 1)
|
||||
// and r.queryVersion = $2
|
||||
// and r.cleanVersion >= $4 and r.textVersion >= $5
|
||||
// AND r.cleanVersion = lv.max_clean_version
|
||||
// AND r.textVersion = lv.max_text_version
|
||||
func (q *Queries) ListQueryRequirementValues(ctx context.Context, arg *ListQueryRequirementValuesParams) ([]*ListQueryRequirementValuesRow, error) {
|
||||
rows, err := q.db.Query(ctx, listQueryRequirementValues,
|
||||
arg.Queryid,
|
||||
arg.Addedversion,
|
||||
arg.Documentid,
|
||||
arg.Cleanversion,
|
||||
arg.Textversion,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []*ListResultValuesByIDRow{}
|
||||
items := []*ListQueryRequirementValuesRow{}
|
||||
for rows.Next() {
|
||||
var i ListResultValuesByIDRow
|
||||
if err := rows.Scan(&i.ID, &i.Queryid, &i.Value); err != nil {
|
||||
var i ListQueryRequirementValuesRow
|
||||
if err := rows.Scan(&i.Queryid, &i.Value, &i.Type); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, &i)
|
||||
@@ -44,37 +133,64 @@ func (q *Queries) ListResultValuesByID(ctx context.Context, id []pgtype.UUID) ([
|
||||
return items, nil
|
||||
}
|
||||
|
||||
const listResultsByDocumentID = `-- name: ListResultsByDocumentID :many
|
||||
SELECT id, queryId, queryVersion FROM results
|
||||
where documentId = $1 and cleanVersion >= $2 and textVersion >= $3
|
||||
const listUnsyncedQueriesByDocId = `-- name: ListUnsyncedQueriesByDocId :many
|
||||
WITH RECURSIVE unsyncedQueries AS (
|
||||
SELECT dt.queryId, dt.requiredIds
|
||||
from documents as d
|
||||
JOIN fullActiveCollectors as c on d.jobId = c.jobId
|
||||
JOIN collectorQueryDependencyTree as dt on c.id = dt.collectorId
|
||||
LEFT JOIN results as r on r.queryId = dt.queryId
|
||||
and r.queryVersion = dt.queryVersion
|
||||
and r.cleanVersion >= c.minCleanVersion and r.textVersion >= c.minTextVersion
|
||||
where d.id = $1 and r.value is null
|
||||
|
||||
UNION
|
||||
|
||||
SELECT DISTINCT dt.queryId, dt.requiredIds
|
||||
FROM unsyncedQueries as u
|
||||
JOIN collectorQueryDependencyTree as dt ON u.queryId = any(dt.requiredIds)
|
||||
)
|
||||
SELECT id, type, activeversion, latestversion, config, requiredids FROM fullActiveQueries
|
||||
WHERE id in (SELECT queryId FROM unsyncedQueries)
|
||||
`
|
||||
|
||||
type ListResultsByDocumentIDParams struct {
|
||||
Documentid pgtype.UUID `db:"documentid"`
|
||||
Cleanversion int32 `db:"cleanversion"`
|
||||
Textversion int32 `db:"textversion"`
|
||||
}
|
||||
|
||||
type ListResultsByDocumentIDRow struct {
|
||||
ID pgtype.UUID `db:"id"`
|
||||
Queryid pgtype.UUID `db:"queryid"`
|
||||
Queryversion int32 `db:"queryversion"`
|
||||
}
|
||||
|
||||
// ListResultsByDocumentID
|
||||
// ListUnsyncedQueriesByDocId
|
||||
//
|
||||
// SELECT id, queryId, queryVersion FROM results
|
||||
// where documentId = $1 and cleanVersion >= $2 and textVersion >= $3
|
||||
func (q *Queries) ListResultsByDocumentID(ctx context.Context, arg *ListResultsByDocumentIDParams) ([]*ListResultsByDocumentIDRow, error) {
|
||||
rows, err := q.db.Query(ctx, listResultsByDocumentID, arg.Documentid, arg.Cleanversion, arg.Textversion)
|
||||
// WITH RECURSIVE unsyncedQueries AS (
|
||||
// SELECT dt.queryId, dt.requiredIds
|
||||
// from documents as d
|
||||
// JOIN fullActiveCollectors as c on d.jobId = c.jobId
|
||||
// JOIN collectorQueryDependencyTree as dt on c.id = dt.collectorId
|
||||
// LEFT JOIN results as r on r.queryId = dt.queryId
|
||||
// and r.queryVersion = dt.queryVersion
|
||||
// and r.cleanVersion >= c.minCleanVersion and r.textVersion >= c.minTextVersion
|
||||
// where d.id = $1 and r.value is null
|
||||
//
|
||||
// UNION
|
||||
//
|
||||
// SELECT DISTINCT dt.queryId, dt.requiredIds
|
||||
// FROM unsyncedQueries as u
|
||||
// JOIN collectorQueryDependencyTree as dt ON u.queryId = any(dt.requiredIds)
|
||||
// )
|
||||
// SELECT id, type, activeversion, latestversion, config, requiredids FROM fullActiveQueries
|
||||
// WHERE id in (SELECT queryId FROM unsyncedQueries)
|
||||
func (q *Queries) ListUnsyncedQueriesByDocId(ctx context.Context, id pgtype.UUID) ([]*Fullactivequery, error) {
|
||||
rows, err := q.db.Query(ctx, listUnsyncedQueriesByDocId, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := []*ListResultsByDocumentIDRow{}
|
||||
items := []*Fullactivequery{}
|
||||
for rows.Next() {
|
||||
var i ListResultsByDocumentIDRow
|
||||
if err := rows.Scan(&i.ID, &i.Queryid, &i.Queryversion); err != nil {
|
||||
var i Fullactivequery
|
||||
if err := rows.Scan(
|
||||
&i.ID,
|
||||
&i.Type,
|
||||
&i.Activeversion,
|
||||
&i.Latestversion,
|
||||
&i.Config,
|
||||
&i.Requiredids,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, &i)
|
||||
|
||||
Reference in New Issue
Block a user