Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Dimensions #5

Merged
merged 5 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ manifolds init <project_name>

2. **Add a New Data Project**

Add a new data project under the umbrella. This setup includes creating a directory for the data project and initializing with a template `config.yml` file.
Add a new data project under the umbrella. This setup includes creating a directory for the data project and initializing with a template `manifold.yml` file.

```bash
cd <project_name>
Expand All @@ -58,7 +58,7 @@ manifolds add <data_project_name>

3. **Generate BigQuery Resource Definitions**

After you fill out the config.yml file, this command generates the necessary BigQuery schema files based on the specified dimensions and metrics.
After you fill out the manifold.yml file, this command generates the necessary BigQuery schema files based on the specified dimensions and metrics.

```bash
manifolds generate <data_project_name> bq
Expand Down
2 changes: 1 addition & 1 deletion lib/manifolds/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def generate(project_name, service)

def copy_config_template(project_path)
template_path = File.join(File.dirname(__FILE__), "templates", "config_template.yml")
FileUtils.cp(template_path, "#{project_path}/config.yml")
FileUtils.cp(template_path, "#{project_path}/manifold.yml")
end
end
end
20 changes: 15 additions & 5 deletions lib/manifolds/services/big_query_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ def initialize(logger)
end

def generate_dimensions_schema(project_name)
config_path = "./projects/#{project_name}/config.yml"
config_path = "./projects/#{project_name}/manifold.yml"
return unless validate_config_exists(config_path, project_name)

config = YAML.load_file(config_path)
dimensions = extract_dimensions(config)
dimensions = extract_dimensions(config["dimensions"])
create_dimensions_file(project_name, dimensions)
end

Expand All @@ -30,9 +30,19 @@ def validate_config_exists(config_path, project_name)
true
end

def extract_dimensions(config)
config["dimensions"].map do |dim|
{ "type" => dim.values.first.upcase, "name" => dim.keys.first, "mode" => "NULLABLE" }
def extract_dimensions(dimensions_hash)
dimensions_hash.map do |dimension|
extract_fields(dimension)
end
end

def extract_fields(fields_hash, mode = "NULLABLE")
fields_hash.map do |name, type|
if type.is_a?(Hash)
{ "type" => "RECORD", "name" => name, "fields" => extract_fields(type) }
elsif type
{ "type" => type.upcase, "name" => name, "mode" => mode }
end
end
end

Expand Down
12 changes: 6 additions & 6 deletions spec/manifolds/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@
expect(Dir.exist?("./projects/#{sub_project_name}/routines")).to be true
end

it "creates a config.yml file" do
expect(File.exist?("./projects/#{sub_project_name}/config.yml")).to be true
it "creates a manifold.yml file" do
expect(File.exist?("./projects/#{sub_project_name}/manifold.yml")).to be true
end

it "writes the config.yml file with dimensions" do
expect(File.read("./projects/#{sub_project_name}/config.yml")).to include("dimensions")
it "writes the manifold.yml file with dimensions" do
expect(File.read("./projects/#{sub_project_name}/manifold.yml")).to include("dimensions")
end

it "writes the config.yml file with metrics" do
config = File.read("./projects/#{sub_project_name}/config.yml")
it "writes the manifold.yml file with metrics" do
config = File.read("./projects/#{sub_project_name}/manifold.yml")
expect(config).to include("metrics")
end
end
Expand Down
17 changes: 12 additions & 5 deletions spec/manifolds/services/big_query_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@
let(:logger) { instance_double("Logger") }
let(:service) { described_class.new(logger) }
let(:project_name) { "test_project" }
let(:config_path) { "./projects/#{project_name}/config.yml" }
let(:config_path) { "./projects/#{project_name}/manifold.yml" }
let(:config) do
{
"dimensions" => [
{ "name" => "STRING" },
{ "flag" => "BOOLEAN" }
]
"dimensions" => {
"context" => {
"site" => "STRING",
"user" => {
"id" => "INTEGER",
"preferences" => {
"notifications" => "BOOLEAN"
}
}
}
}
}
end

Expand Down