Skip to content
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
2 changes: 1 addition & 1 deletion lib/manifold/terraform/project_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Terraform
class ProjectConfiguration < Configuration
attr_reader :workspaces, :provider_version, :skip_provider_config

DEFAULT_TERRAFORM_GOOGLE_PROVIDER_VERSION = "6.18.1"
DEFAULT_TERRAFORM_GOOGLE_PROVIDER_VERSION = "6.24.0"

def initialize(workspaces, provider_version: DEFAULT_TERRAFORM_GOOGLE_PROVIDER_VERSION,
skip_provider_config: false)
Expand Down
66 changes: 26 additions & 40 deletions lib/manifold/terraform/workspace_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,11 @@

module Manifold
module Terraform
# Handles building metrics SQL for manifold routines
class MetricsSQLBuilder
def initialize(name, manifold_config)
@name = name
@manifold_config = manifold_config
end

def build_metrics_select
<<~SQL
SELECT
id,
timestamp,
#{build_metrics_struct}
FROM #{build_metric_joins}
SQL
end

private

def build_metrics_struct
metric_groups = @manifold_config["metrics"].keys
metric_groups.map { |group| "#{group}.metrics #{group}" }.join(",\n ")
end

def build_metric_joins
metric_groups = @manifold_config["metrics"]
joins = metric_groups.map { |group, config| "#{config["source"]} AS #{group}" }
first = joins.shift
return first if joins.empty?

"#{first}\n #{joins.map { |table| "FULL OUTER JOIN #{table} USING (id, timestamp)" }.join("\n ")}"
end

def timestamp_field
@manifold_config&.dig("timestamp", "field")
end
end

# Handles building SQL for manifold routines
class SQLBuilder
def initialize(name, manifold_config)
@name = name
@manifold_config = manifold_config
@metrics_builder = MetricsSQLBuilder.new(name, manifold_config)
end

def build_manifold_merge_sql
Expand Down Expand Up @@ -90,7 +51,7 @@ def timestamp_field
def build_source_query
<<~SQL
WITH Metrics AS (
#{@metrics_builder.build_metrics_select}
#{build_metrics_select}
)

SELECT
Expand All @@ -117,6 +78,31 @@ def build_merge_actions
INSERT ROW;
SQL
end

# Metrics SQL building methods
def build_metrics_select
<<~SQL
SELECT
id,
timestamp,
#{build_metrics_struct}
FROM #{build_metric_joins}
SQL
end

def build_metrics_struct
metric_groups = @manifold_config["metrics"].keys
metric_groups.map { |group| "#{group}.metrics #{group}" }.join(",\n ")
end

def build_metric_joins
metric_groups = @manifold_config["metrics"]
joins = metric_groups.map { |group, config| "#{config["source"]} AS #{group}" }
first = joins.shift
return first if joins.empty?

"#{first}\n #{joins.map { |table| "FULL OUTER JOIN #{table} USING (id, timestamp)" }.join("\n ")}"
end
end

# Handles building table configurations
Expand Down
Loading