Enhance transfer logic for transaction reporting

Explicit transfer acks/nacks reverse the roles for transaction reporting
tabulation- this adds a quick check to account for this going forward.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=199474444
This commit is contained in:
larryruili 2018-06-06 09:07:21 -07:00 committed by Ben McIlwain
parent 5c7a20797e
commit 7487639e62
4 changed files with 33 additions and 3 deletions

View file

@ -113,6 +113,7 @@ public final class TransactionsReportingQueryBuilder implements QueryBuilder {
.put("EARLIEST_REPORT_TIME", timestampFormatter.print(earliestReportTime))
.put("LATEST_REPORT_TIME", timestampFormatter.print(latestReportTime))
.put("CLIENT_ID", "clientId")
.put("OTHER_CLIENT_ID", "otherClientId")
.put("TRANSFER_SUCCESS_FIELD", "TRANSFER_GAINING_SUCCESSFUL")
.put("TRANSFER_NACKED_FIELD", "TRANSFER_GAINING_NACKED")
.put("DEFAULT_FIELD", "field")
@ -127,7 +128,9 @@ public final class TransactionsReportingQueryBuilder implements QueryBuilder {
.put("HISTORYENTRY_TABLE", "HistoryEntry")
.put("EARLIEST_REPORT_TIME", timestampFormatter.print(earliestReportTime))
.put("LATEST_REPORT_TIME", timestampFormatter.print(latestReportTime))
// Roles are reversed for losing queries
.put("CLIENT_ID", "otherClientId")
.put("OTHER_CLIENT_ID", "clientId")
.put("TRANSFER_SUCCESS_FIELD", "TRANSFER_LOSING_SUCCESSFUL")
.put("TRANSFER_NACKED_FIELD", "TRANSFER_LOSING_NACKED")
.put("DEFAULT_FIELD", "NULL")

View file

@ -45,7 +45,16 @@ FROM (
SUM(amount) AS metricValue
FROM (
SELECT
entries.%CLIENT_ID% AS clientId,
CASE
-- Explicit transfer acks (approve) and nacks (reject) are done
-- by the opposing registrar. Thus, for these specific actions,
-- we swap the 'otherClientId' with the 'clientId' to properly
-- account for this reversal.
WHEN (entries.type = 'DOMAIN_TRANSFER_APPROVE'
OR entries.type = 'DOMAIN_TRANSFER_REJECT')
THEN entries.%OTHER_CLIENT_ID%
ELSE entries.%CLIENT_ID%
END AS clientId,
entries.domainTransactionRecords.tld[SAFE_OFFSET(index)] AS tld,
entries.domainTransactionRecords.reportingTime[SAFE_OFFSET(index)]
AS reportingTime,