Skip to content

Commit

Permalink
Merge pull request #151 from m-lab/sandbox-fix-detail-query
Browse files Browse the repository at this point in the history
fix table detail query
  • Loading branch information
gfr10598 authored May 1, 2019
2 parents f77f498 + 0fc1ea2 commit 7e4973a
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions cloud/bq/sanity.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ func (at *AnnotatedTable) CachedDetail(ctx context.Context) (*Detail, error) {
if ctx == nil {
return nil, ErrNilContext
}
// TODO - use context
// TODO - maybe just embed code here.
at.detail, at.err = GetTableDetail(ctx, at.dataset, at.Table)
if at.err != nil {
log.Println(at.FullyQualifiedName(), at.TableID())
Expand All @@ -130,8 +128,6 @@ func (at *AnnotatedTable) CachedPartitionInfo(ctx context.Context) (*dataset.Par
if ctx == nil {
return nil, ErrNilContext
}
// TODO - use context
// TODO - maybe just embed code here.
at.pInfo, at.err = at.GetPartitionInfo(ctx)
return at.pInfo, at.err
}
Expand Down Expand Up @@ -168,18 +164,11 @@ func GetTableDetail(ctx context.Context, dsExt *dataset.Dataset, table bqiface.T
detail := Detail{}
queryString := fmt.Sprintf(`
#standardSQL
SELECT SUM(tests) AS TestCount, COUNT(DISTINCT task)-1 AS TaskFileCount
FROM (
-- This avoids null counts when the partition doesn't exist or is empty.
SELECT 0 AS tests, "fake-task" AS task
UNION ALL
SELECT COUNT(DISTINCT test_id) AS tests, task_filename AS task
FROM `+"`%s.%s`"+`
%s -- where clause
GROUP BY task
)`, dataset, tableName, where)

// TODO - this should take a context?
SELECT COUNT(DISTINCT test_id) AS TestCount, COUNT(DISTINCT task_filename) AS TaskFileCount
FROM `+"`%s.%s`"+`
%s -- where clause`,
dataset, tableName, where)

err := dsExt.QueryAndParse(ctx, queryString, &detail)
if err != nil {
log.Println(err)
Expand Down

0 comments on commit 7e4973a

Please sign in to comment.