This commit is contained in:
lcaggio 2023-03-03 15:08:57 +01:00
parent 32808f93ea
commit 594a615e1e
8 changed files with 75 additions and 5 deletions

View File

@ -66,3 +66,18 @@ In the repository `demo` folder you can find an example on how to create a Verte
| [vpc](outputs.tf#L38) | VPC Network. | |
<!-- END TFDOC -->
## Test
```hcl
module "test" {
source = "./fabric/blueprints/data-solutions/bq-ml/"
project_create = {
billing_account_id = "123456-123456-123456"
parent = "folders/12345678"
}
project_id = "project-1"
prefix = "prefix"
}
# tftest modules=9 resources=46
```

View File

@ -1,3 +1,19 @@
/*
* Copyright 2023 Google LLC
*
* 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
*
* https://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.
*/
select *
from ML.EXPLAIN_PREDICT(MODEL `{project-id}.{dataset}.{model-name}`,
(select * except (session_id, session_starting_ts, user_id, has_purchased)
@ -5,4 +21,4 @@ from ML.EXPLAIN_PREDICT(MODEL `{project-id}.{dataset}.{model-name}`,
where extract(ISOYEAR from session_starting_ts) = 2023
),
STRUCT(5 AS top_k_features, 0.5 as threshold)
)
)

View File

@ -1,3 +1,19 @@
/*
* Copyright 2023 Google LLC
*
* 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
*
* https://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.
*/
CREATE view if not exists `{project_id}.{dataset}.ecommerce_abt` as
with abt as (
@ -18,4 +34,4 @@ select abt.*, case when extract(DAYOFWEEK from session_starting_ts) in (1,7) the
, (select count(distinct uo.order_id) from unnest(user_orders) uo where uo.order_creations_ts < session_starting_ts and status in ('Cancelled', 'Returned') ) as number_of_unsuccessful_orders
from abt
left join previous_orders pso
on abt.user_id = pso.user_id
on abt.user_id = pso.user_id

View File

@ -1,3 +1,19 @@
/*
* Copyright 2023 Google LLC
*
* 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
*
* https://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.
*/
create or replace model `{project_id}.{dataset}.{model_name}`
OPTIONS(model_type='{model_type}',
input_label_cols=['has_purchased'],
@ -8,4 +24,4 @@ OPTIONS(model_type='{model_type}',
) as
select * except (session_id, session_starting_ts, user_id)
from `{project_id}.{dataset}.ecommerce_abt_table`
where extract(ISOYEAR from session_starting_ts) = 2022
where extract(ISOYEAR from session_starting_ts) = 2022

View File

@ -12,9 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# tfdoc:file:description Core resources.
###############################################################################
# Project #
###############################################################################
locals {
service_encryption_keys = var.service_encryption_keys
shared_vpc_project = try(var.network_config.host_project, null)
@ -160,7 +163,7 @@ module "dataset" {
project_id = module.project.project_id
id = "${replace(var.prefix, "-", "_")}_data"
encryption_key = try(local.service_encryption_keys.bq, null) # Example assignment of an encryption key
location = "US"
location = "US"
}
###############################################################################
@ -239,7 +242,6 @@ resource "google_notebooks_instance" "playground" {
service_account = module.service-account-notebook.email
# Enable Secure Boot
shielded_instance_config {
enable_secure_boot = true
}

View File

@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# tfdoc:file:description Output variables.
output "bucket" {
description = "GCS Bucket URL."
value = module.bucket.url

View File

@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# tfdoc:file:description Terraform variables.
variable "location" {
description = "The location where resources will be deployed."

View File

@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# tfdoc:file:description Terraform version.
terraform {
required_version = ">= 1.3.1"
required_providers {