Remove MakeBillingTablesCommand credit data views

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=151130847
This commit is contained in:
nickfelt 2017-03-24 08:57:01 -07:00 committed by Ben McIlwain
parent c6a1c3d870
commit 0d32b6b7b2
3 changed files with 0 additions and 157 deletions

View file

@ -47,8 +47,6 @@ final class MakeBillingTablesCommand extends BigqueryCommand {
private static final SqlTemplate CURRENCY_TABLE_SQL = getSql("currency_table.sql");
private static final SqlTemplate REGISTRAR_DATA_SQL = getSql("registrar_data_view.sql");
private static final SqlTemplate REGISTRY_DATA_SQL = getSql("registry_data_view.sql");
private static final SqlTemplate CREDIT_DATA_SQL = getSql("credit_data_view.sql");
private static final SqlTemplate CREDIT_BALANCE_DATA_SQL = getSql("credit_balance_data_view.sql");
private static final SqlTemplate BILLING_DATA_SQL = getSql("billing_data_view.sql");
/** Runs the main billing table/view creation logic. */
@ -62,8 +60,6 @@ final class MakeBillingTablesCommand extends BigqueryCommand {
makeCurrencyTable();
makeRegistrarView();
makeRegistryView();
makeCreditView();
makeCreditBalanceView();
makeBillingView();
} catch (TableCreationException e) {
// Swallow since we already will have printed an error message.
@ -117,46 +113,6 @@ final class MakeBillingTablesCommand extends BigqueryCommand {
.build()));
}
/**
* Generates a view of registrar credit entities that links in information from the owning
* Registrar (e.g. billing ID).
*/
private void makeCreditView() throws Exception {
handleTableCreation(
"credit data view",
bigquery().query(
CREDIT_DATA_SQL
.put("SOURCE_DATASET", sourceDatasetId)
.put("DEST_DATASET", bigquery().getDatasetId())
.build(),
bigquery().buildDestinationTable("CreditData")
.description("Synthetic view of registrar credit information.")
.type(TableType.VIEW)
.build()));
}
/**
* Generates a view of registrar credit balance entities that collapses them down to the one
* 'true' credit balance for a given credit ID and effective time, eliminating any duplicates by
* choosing the most recently written balance entry of the set.
*
* <p>The result is a list of the historical balances of each credit (according to the most recent
* data written) that can be used to find the active balance of a credit at any point in time.
*/
private void makeCreditBalanceView() throws Exception {
handleTableCreation(
"credit balance data view",
bigquery().query(
CREDIT_BALANCE_DATA_SQL
.put("SOURCE_DATASET", sourceDatasetId)
.put("DEST_DATASET", bigquery().getDatasetId())
.build(),
bigquery().buildDestinationTable("CreditBalanceData")
.description("Synthetic view of registrar credit balance information.")
.type(TableType.VIEW)
.build()));
}
/**
* Generates a view of consolidated billing information that includes currency conversions,
* registrar details, and cancellation flags on top of the original BillingEvent.OneTime data.

View file

@ -1,61 +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.
-- Credit Balance Data View SQL
--
-- This query post-processes RegistrarCreditBalance entities to collapse them
-- down to one 'true' amount per credit ID and effective time, eliminating any
-- duplicates by choosing the most recently written balance entry of the set,
-- and then joins these 'real' balances to the CreditData view.
--
-- The result is a list showing how each credit's balance has developed over
-- time, which can be used to find the actual balance of a given credit at
-- any particular point in time (e.g. the time when invoices are run).
SELECT
CreditData.registrarId AS registrarId,
CreditData.creditId AS creditId,
effectiveTime,
REGEXP_EXTRACT(amount, '(.+) ') AS currency,
INTEGER(REGEXP_REPLACE(amount, r'\D+', '')) AS amountMinor
FROM (
SELECT
creditId,
effectiveTime,
amount,
ROW_NUMBER() OVER (
PARTITION BY
creditId,
effectiveTime
ORDER BY
writtenTime DESC
) AS recencyRank
FROM (
SELECT
INTEGER(REGEXP_EXTRACT(__key__.path, '"RegistrarCredit", (.+?),'))
AS creditId,
effectiveTime,
writtenTime,
amount
FROM [%SOURCE_DATASET%.RegistrarCreditBalance]
)
) AS BalanceData
LEFT JOIN EACH
[%DEST_DATASET%.CreditData] AS CreditData
ON
BalanceData.creditId = CreditData.creditId
WHERE
recencyRank = 1
ORDER BY
creditId,
effectiveTime

View file

@ -1,52 +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.
-- Credit Data View SQL
--
-- This query post-processes RegistrarCredit entities and joins them to the
-- corresponding owning Registrar entities. The join is mostly a no-op, but
-- it does ensure that if extracting the registrar parent from a credit fails
-- then this view will indicate that by showing the registrar ID as null.
-- TODO(b/19031915): add optional sanity-checking for that type of invariant.
SELECT
Registrar.registrarId AS registrarId,
RegistrarCredit.__key__.id AS creditId,
RegistrarCredit.type AS type,
CreditType.priority AS typePriority,
creationTime,
currency,
description,
tld,
FROM (
SELECT
*,
REGEXP_EXTRACT(__key__.path, '"Registrar", "(.+?)"') AS registrarId
FROM
[%SOURCE_DATASET%.RegistrarCredit]
) AS RegistrarCredit
LEFT JOIN
(SELECT registrarId FROM [%DEST_DATASET%.RegistrarData]) AS Registrar
ON
RegistrarCredit.registrarId = Registrar.registrarId
LEFT JOIN (
-- TODO(b/19031546): Generate this table from the CreditType enum.
SELECT * FROM
(SELECT 'AUCTION' AS type, 1 AS priority),
(SELECT 'PROMOTION' AS type, 2 AS priority),
) AS CreditType
ON
RegistrarCredit.type = CreditType.type
ORDER BY
creationTime,
creditId