mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 00:17:20 +02:00
Add Registrar Account Data view in BigQuery snapshot
This adds a new view table that contains the registrar id, the currency-specific billing account id and the corresponding currency in latest_billing dataset based on latest_snapshot dataset. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=151363209
This commit is contained in:
parent
190be064cb
commit
ff9c72097c
2 changed files with 75 additions and 0 deletions
|
@ -46,6 +46,8 @@ final class MakeBillingTablesCommand extends BigqueryCommand {
|
||||||
|
|
||||||
private static final SqlTemplate CURRENCY_TABLE_SQL = getSql("currency_table.sql");
|
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 REGISTRAR_DATA_SQL = getSql("registrar_data_view.sql");
|
||||||
|
private static final SqlTemplate REGISTRAR_ACCOUNT_DATA_SQL =
|
||||||
|
getSql("registrar_account_data_view.sql");
|
||||||
private static final SqlTemplate REGISTRY_DATA_SQL = getSql("registry_data_view.sql");
|
private static final SqlTemplate REGISTRY_DATA_SQL = getSql("registry_data_view.sql");
|
||||||
private static final SqlTemplate BILLING_DATA_SQL = getSql("billing_data_view.sql");
|
private static final SqlTemplate BILLING_DATA_SQL = getSql("billing_data_view.sql");
|
||||||
|
|
||||||
|
@ -59,6 +61,7 @@ final class MakeBillingTablesCommand extends BigqueryCommand {
|
||||||
try {
|
try {
|
||||||
makeCurrencyTable();
|
makeCurrencyTable();
|
||||||
makeRegistrarView();
|
makeRegistrarView();
|
||||||
|
makeRegistrarAccountView();
|
||||||
makeRegistryView();
|
makeRegistryView();
|
||||||
makeBillingView();
|
makeBillingView();
|
||||||
} catch (TableCreationException e) {
|
} catch (TableCreationException e) {
|
||||||
|
@ -99,6 +102,28 @@ final class MakeBillingTablesCommand extends BigqueryCommand {
|
||||||
.build()));
|
.build()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a view of registrar account data, which includes the billing account id and the
|
||||||
|
* currency used.
|
||||||
|
*
|
||||||
|
* <p>The generated view is similar to the one generated by {@link #makeRegistrarView()}, but it
|
||||||
|
* uses currency-specific billing account id and does not include allowed TLDs.
|
||||||
|
*/
|
||||||
|
private void makeRegistrarAccountView() throws Exception {
|
||||||
|
handleTableCreation(
|
||||||
|
"registrar account data view",
|
||||||
|
bigquery()
|
||||||
|
.query(
|
||||||
|
REGISTRAR_ACCOUNT_DATA_SQL.put("SOURCE_DATASET", sourceDatasetId).build(),
|
||||||
|
bigquery()
|
||||||
|
.buildDestinationTable("RegistrarAccountData")
|
||||||
|
.description(
|
||||||
|
"Synthetic view of registrar information "
|
||||||
|
+ "with currency-specific billing account id.")
|
||||||
|
.type(TableType.VIEW)
|
||||||
|
.build()));
|
||||||
|
}
|
||||||
|
|
||||||
/** Generates a view of registry data to feed into later views. */
|
/** Generates a view of registry data to feed into later views. */
|
||||||
private void makeRegistryView() throws Exception {
|
private void makeRegistryView() throws Exception {
|
||||||
handleTableCreation(
|
handleTableCreation(
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
-- 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([latest_snapshot.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
|
Loading…
Add table
Add a link
Reference in a new issue