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
1 change: 1 addition & 0 deletions sqlglot/expressions/dml.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ class LoadData(Expression):
"this": True,
"local": False,
"overwrite": False,
"temp": False,
"inpath": False,
"files": False,
"partition": False,
Expand Down
7 changes: 6 additions & 1 deletion sqlglot/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2896,7 +2896,12 @@ def loaddata_sql(self, expression: exp.LoadData) -> str:
if files:
files_sql = self.expressions(files, flat=True)
files_sql = f"FILES{self.wrap(files_sql)}"
this = f" {this}" if is_overwrite else f" INTO TABLE {this}"
if is_overwrite:
this = f" {this}"
elif expression.args.get("temp"):
this = f" INTO TEMP TABLE {this}"
else:
this = f" INTO TABLE {this}"
return f"LOAD DATA{overwrite}{this} FROM {files_sql}"

local = " LOCAL" if expression.args.get("local") else ""
Expand Down
6 changes: 5 additions & 1 deletion sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3592,13 +3592,17 @@ def _parse_load(self) -> exp.LoadData | exp.Command:
self._match_text_seq("INPATH")
inpath = self._parse_string()
overwrite = self._match(TokenType.OVERWRITE)
self._match_pair(TokenType.INTO, TokenType.TABLE)
temp: t.Optional[bool] = None
if self._match(TokenType.INTO):
temp = self._match(TokenType.TEMPORARY)
self._match(TokenType.TABLE)

return self.expression(
exp.LoadData(
this=self._parse_table(schema=True),
local=local,
overwrite=overwrite,
temp=temp,
inpath=inpath,
files=self._match_text_seq("FROM", "FILES")
and exp.Properties(expressions=self._parse_wrapped_properties()),
Expand Down
1 change: 1 addition & 0 deletions tests/dialects/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ def test_bigquery(self):
for load_data_sql in (
"LOAD DATA OVERWRITE mydataset.table1 FROM FILES(FORMAT='AVRO', uris=['gs://bucket/path/file.avro'])",
"LOAD DATA INTO TABLE mydataset.table1 FROM FILES(FORMAT='AVRO', uris=['gs://bucket/path/file.avro'])",
"LOAD DATA INTO TEMP TABLE mydataset.table1 FROM FILES(FORMAT='AVRO', uris=['gs://bucket/path/file.avro'])",
):
with self.subTest(load_data_sql=load_data_sql):
self.validate_identity(load_data_sql).assert_is(exp.LoadData)
Expand Down
Loading