diff --git a/README.md b/README.md index 19ca310..c5e38e3 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ manifolds init 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 @@ -58,7 +58,7 @@ manifolds add 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 bq diff --git a/lib/manifolds/cli.rb b/lib/manifolds/cli.rb index adbbc59..d29cccd 100644 --- a/lib/manifolds/cli.rb +++ b/lib/manifolds/cli.rb @@ -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 diff --git a/lib/manifolds/services/big_query_service.rb b/lib/manifolds/services/big_query_service.rb index 9893f47..6faf3d7 100644 --- a/lib/manifolds/services/big_query_service.rb +++ b/lib/manifolds/services/big_query_service.rb @@ -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 @@ -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 diff --git a/spec/manifolds/cli_spec.rb b/spec/manifolds/cli_spec.rb index a194bbd..84afed8 100644 --- a/spec/manifolds/cli_spec.rb +++ b/spec/manifolds/cli_spec.rb @@ -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 diff --git a/spec/manifolds/services/big_query_service_spec.rb b/spec/manifolds/services/big_query_service_spec.rb index e1a5766..bf319b9 100644 --- a/spec/manifolds/services/big_query_service_spec.rb +++ b/spec/manifolds/services/big_query_service_spec.rb @@ -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