Delete obsolete billing code

Now that we've verified the new Beam billing pipeline works, we can delete the
old manual commands we used to use.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=184707182
This commit is contained in:
larryruili 2018-02-06 11:01:32 -08:00 committed by jianglai
parent 2e62ad2658
commit 5f218b4a8b
10 changed files with 0 additions and 701 deletions

View file

@ -1,156 +0,0 @@
-- Copyright 2017 The Nomulus Authors. All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-- Billing Data View SQL
--
-- This query post-processes the OneTime billing events and then annotates
-- the resulting data with additional information from the Registrar,
-- DomainBase, Currency, and Cancellation tables.
SELECT
id,
BillingEvent.billingTime AS billingTime,
BillingEvent.eventTime AS eventTime,
BillingEvent.clientId AS registrarId,
Registrar.billingIdentifier AS billingId,
RegistrarAccount.billingAccountId AS billingAccountId,
BillingEvent.tld AS tld,
IF(
CONCAT(',', BillingEvent.flags, ',') CONTAINS (',ALLOCATION,'),
'ALLOCATE',
BillingEvent.reason) AS action,
BillingEvent.targetId AS domain,
BillingEvent.domainRepoId AS repositoryId,
periodYears AS years,
BillingEvent.currency AS currency,
amountMinor,
REGEXP_EXTRACT(cost, ' (.+)') AS amountString,
ROUND(amountMinor * Currency.conversionToUsd, 2) AS estimatedUsd,
flags,
Cancellation.cancellationId IS NOT NULL AS cancelled,
Cancellation.cancellationTime AS cancellationTime,
FROM (
SELECT
__key__.id AS id,
billingTime,
eventTime,
clientId,
tld,
reason,
targetId,
REGEXP_EXTRACT(__key__.path, '"DomainBase", "([^"]+)"') AS domainRepoId,
periodYears,
cost,
-- TODO(b/19031545): Find cleaner way to parse out currency and amount.
-- Parse out the currency code as the substring of 'cost' up to the space.
REGEXP_EXTRACT(cost, '(.+) ') AS currency,
-- Parse out the amount of minor units by stripping out non-digit chars
-- (i.e. currency, space, and period) and then converting to integer.
INTEGER(REGEXP_REPLACE(cost, r'\D+', '')) AS amountMinor,
-- Convert repeated flags field into flat comma-delimited string field,
-- excluding the internal-only flag 'SYNTHETIC'.
GROUP_CONCAT(IF(flags != 'SYNTHETIC', flags, NULL)) WITHIN RECORD AS flags,
-- Cancellations for recurring events will point to the recurring event's
-- key, which is stored in cancellationMatchingBillingEvent. The path
-- contains kind, id, and domainRepoId, all of which must match, so just
-- use the path.
COALESCE(cancellationMatchingBillingEvent.path, __key__.path)
AS cancellationMatchingPath,
FROM (
SELECT
*,
-- Count everything after first dot as TLD (to support multi-part TLDs).
REGEXP_EXTRACT(targetId, r'[.](.+)') AS tld,
FROM [%SOURCE_DATASET%.OneTime])
WHERE
-- Filter out prober data.
tld IN
(SELECT tld FROM [%DEST_DATASET%.RegistryData] WHERE type = 'REAL')
) AS BillingEvent
-- Join to pick up billing ID from registrar table.
LEFT JOIN EACH (
SELECT
__key__.name AS clientId,
billingIdentifier,
FROM
[%SOURCE_DATASET%.Registrar]
) AS Registrar
ON
BillingEvent.clientId = Registrar.clientId
-- Join to pick up currency specific registrar account id from registrar
-- account view.
LEFT JOIN EACH (
SELECT
registrarId,
billingAccountId,
currency
FROM
[%DEST_DATASET%.RegistrarAccountData]) AS RegistrarAccount
ON
BillingEvent.clientId = RegistrarAccount.registrarId
AND BillingEvent.currency = RegistrarAccount.currency
-- Join to pick up cancellations for billing events.
LEFT JOIN EACH (
SELECT
__key__.id AS cancellationId,
-- Coalesce matching fields from refOneTime and refRecurring (only one or
-- the other will ever be populated) for joining against referenced event.
COALESCE(refOneTime.path, refRecurring.path) AS cancelledEventPath,
eventTime AS cancellationTime,
billingTime AS cancellationBillingTime,
FROM (
SELECT
*,
-- Count everything after first dot as TLD (to support multi-part TLDs).
REGEXP_EXTRACT(targetId, r'[.](.+)') AS tld,
FROM
[%SOURCE_DATASET%.Cancellation])
WHERE
-- Filter out prober data.
tld IN
(SELECT tld FROM [%DEST_DATASET%.RegistryData] WHERE type = 'REAL')
) AS Cancellation
ON
BillingEvent.cancellationMatchingPath = Cancellation.cancelledEventPath
-- Require billing times to match so that cancellations for Recurring events
-- only apply to the specific recurrence being cancelled.
AND BillingEvent.billingTime = Cancellation.cancellationBillingTime
-- Join to pick up currency conversion factor.
LEFT JOIN EACH (
SELECT
currency,
conversionToUsd,
FROM
[%DEST_DATASET%.Currency]
) AS Currency
ON
BillingEvent.currency = Currency.currency
WHERE
-- Filter down to whitelisted TLDs that are "billable".
-- TODO(b/18092292): determine this automatically.
BillingEvent.tld IN
(SELECT tld FROM FLATTEN((
-- %TLDS% is passed in as a comma-delimited string of TLDs.
SELECT SPLIT('%TLDS%') AS tld FROM (SELECT 1 as unused)), tld))
-- Sort rows to show the latest billed items first.
ORDER BY
billingTime DESC,
-- Break ties in billing time using ID then TLD, to be deterministic.
id,
tld

View file

@ -1,22 +0,0 @@
-- Copyright 2017 The Nomulus Authors. All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-- Currency Table Creation SQL
--
-- This query generates a static table of currency information.
SELECT
currency, conversionToUsd, exponent
FROM
(SELECT 'JPY' AS currency, 0.0098 AS conversionToUsd, 0 AS exponent),
(SELECT 'USD' AS currency, 0.0100 AS conversionToUsd, 2 AS exponent)

View file

@ -1,50 +0,0 @@
-- Copyright 2017 The Nomulus Authors. All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-- Registrar Account Data View SQL
--
-- This query lists registrar IDs with billing account IDs and corresponding
-- currencies.
--
-- The table that contains both billing account IDs and currencies as repeated
-- fields are first flattened to two separate tables, with IDs and currencies
-- in each table, and the corresponding row numbers, partitioned over registrar.
-- The row numbers are used to join the two tables together, restoring the
-- original mapping between IDs and currencies.
SELECT
I.registrarId AS registrarId,
-- Apply no-op STRING() function to keep BigQuery schema transformation logic
-- from wanting different names in direct query vs save-as-view.
STRING(C.billingAccountMap.currency) AS currency,
STRING(I.billingAccountMap.accountId) AS billingAccountId,
FROM (
SELECT
__key__.name AS registrarId,
billingAccountMap.accountId,
ROW_NUMBER() OVER (PARTITION BY registrarId) AS pos
FROM
FLATTEN([%SOURCE_DATASET%.Registrar], billingAccountMap.accountId)) AS I
JOIN (
SELECT
__key__.name AS registrarId,
billingAccountMap.currency,
ROW_NUMBER() OVER (PARTITION BY registrarId) AS pos
FROM
FLATTEN([%SOURCE_DATASET%.Registrar], billingAccountMap.currency)) AS C
ON
I.registrarId == C.registrarId
AND I.pos == C.pos
ORDER BY
registrarId,
I.pos

View file

@ -1,30 +0,0 @@
-- Copyright 2017 The Nomulus Authors. All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-- Registrar Data View SQL
--
-- This query lists each registrar ID with type, billing ID, and allowed TLDs.
--
-- Note that there is one row per registrar (allowedTlds is repeated), versus
-- registrar_account_data_view.sql which has multiple rows per registrar.
SELECT
__key__.name AS registrarId,
type,
billingIdentifier AS billingId,
allowedTlds
FROM
[%SOURCE_DATASET%.Registrar]
-- Note: We can't ORDER BY registrarId here because ORDER/GROUP BY will
-- flatten results, and the allowedTlds field above is repeated.
-- TODO(b/19031339): Add "ORDER BY" if the BigQuery known issue is fixed.

View file

@ -1,27 +0,0 @@
-- Copyright 2017 The Nomulus Authors. All Rights Reserved.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
-- Registry Data View SQL
--
-- This query lists registry fields necessary for billing.
--
-- TODO(b/20764952): extend this view to support timed transition properties.
-- TODO(b/18092292): add a column for whether the TLD is "billable" or not.
SELECT
tldStr AS tld,
tldType AS type,
FROM
[%SOURCE_DATASET%.Registry]
ORDER BY
tld