MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / CreateView

Class CreateView

misc/python/materialize/zippy/view_actions.py:91–137  ·  view source on GitHub ↗

Creates a view that is a join over one or more sources or tables

Source from the content-addressed store, hash-verified

89
90
91class CreateView(Action):
92 """Creates a view that is a join over one or more sources or tables"""
93
94 def __init__(self, capabilities: Capabilities, view: ViewExists) -> None:
95 self.view = view
96 super().__init__(capabilities)
97
98 def run(self, c: Composition, state: State) -> None:
99 first_input = self.view.inputs[0]
100 outer_join = " ".join(
101 f"JOIN {f.get_name_for_query()} USING (f1)" for f in self.view.inputs[1:]
102 )
103
104 index = (
105 f"> CREATE DEFAULT INDEX ON {self.view.name}" if self.view.has_index else ""
106 )
107
108 aggregates = [f"COUNT({first_input.get_name_for_query()}.f1) AS count_all"]
109
110 if self.view.expensive_aggregates:
111 aggregates.extend(
112 [
113 f"COUNT(DISTINCT {first_input.get_name_for_query()}.f1) AS count_distinct",
114 f"MIN({first_input.get_name_for_query()}.f1) AS min_value",
115 f"MAX({first_input.get_name_for_query()}.f1) AS max_value",
116 ]
117 )
118
119 aggregates = ", ".join(aggregates)
120
121 refresh = random.choice(
122 ["ON COMMIT", f"EVERY '{random.randint(1, 5)} seconds'"]
123 )
124
125 c.testdrive(
126 dedent(f"""
127 > CREATE MATERIALIZED VIEW {self.view.name}
128 WITH (REFRESH {refresh}) AS
129 SELECT {aggregates}
130 FROM {first_input.get_name_for_query()}
131 {outer_join}
132 """) + index,
133 mz_service=state.mz_service,
134 )
135
136 def provides(self) -> list[Capability]:
137 return [self.view]
138
139
140class ValidateView(Action):

Callers 15

plan_viewFunction · 0.85
plan_create_viewFunction · 0.85
generate_view_sqlFunction · 0.85
parse_create_viewMethod · 0.85
parse_explaineeMethod · 0.85
parse_main_statementFunction · 0.85
into_parser_statementMethod · 0.85
validate_single_variantFunction · 0.85
parse_stmtFunction · 0.85
normalize_name_withMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected