MCPcopy
hub / github.com/apache/superset / as_create_table

Method as_create_table

superset/sql_parse.py:246–270  ·  view source on GitHub ↗

Reformats the query into the create table as query. Works only for the single select SQL statements, in all other cases the sql query is not modified. :param table_name: table that will contain the results of the query execution :param schema_name: schema name for th

(
        self,
        table_name: str,
        schema_name: Optional[str] = None,
        overwrite: bool = False,
        method: CtasMethod = CtasMethod.TABLE,
    )

Source from the content-addressed store, hash-verified

244 self._extract_from_token(token_list)
245
246 def as_create_table(
247 self,
248 table_name: str,
249 schema_name: Optional[str] = None,
250 overwrite: bool = False,
251 method: CtasMethod = CtasMethod.TABLE,
252 ) -> str:
253 """Reformats the query into the create table as query.
254
255 Works only for the single select SQL statements, in all other cases
256 the sql query is not modified.
257 :param table_name: table that will contain the results of the query execution
258 :param schema_name: schema name for the target table
259 :param overwrite: table_name will be dropped if true
260 :param method: method for the CTA query, currently view or table creation
261 :return: Create table as query
262 """
263 exec_sql = ""
264 sql = self.stripped()
265 # TODO(bkyryliuk): quote full_table_name
266 full_table_name = f"{schema_name}.{table_name}" if schema_name else table_name
267 if overwrite:
268 exec_sql = f"DROP {method} IF EXISTS {full_table_name};\n"
269 exec_sql += f"CREATE {method} {full_table_name} AS \n{sql}"
270 return exec_sql
271
272 def _extract_from_token(self, token: Token) -> None:
273 """

Callers 2

execute_sql_statementFunction · 0.95
test_create_table_asFunction · 0.95

Calls 1

strippedMethod · 0.95

Tested by 1

test_create_table_asFunction · 0.76