Skip to content

Commit 954cc4f

Browse files
committed
Fix copyInto files clause
1 parent 372ffab commit 954cc4f

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

databend_sqlalchemy/databend_dialect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ def visit_copy_into(self, copy_into, **kw):
10401040

10411041
result = f"COPY INTO {target}" f" FROM {source}"
10421042
if hasattr(copy_into, "files") and isinstance(copy_into.files, list):
1043-
result += f"FILES = {', '.join([f for f in copy_into.files])}"
1043+
result += f" FILES = ({', '.join(["'{0}'".format(f) for f in copy_into.files])})"
10441044
if hasattr(copy_into, "pattern") and copy_into.pattern:
10451045
result += f" PATTERN = '{copy_into.pattern}'"
10461046
if not isinstance(copy_into.file_format, NoneType):

tests/test_copy_into.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,38 @@ def test_copy_into_table_sub_select_column_clauses(self):
162162
checkparams={"1_1": "xyz", "IF_1": "NULL", "IF_2": "NOTNULL"},
163163
)
164164

165+
def test_copy_into_table_files(self):
166+
m = MetaData()
167+
tbl = Table(
168+
"atable",
169+
m,
170+
Column("id", Integer),
171+
schema="test_schema",
172+
)
173+
174+
copy_into = CopyIntoTable(
175+
target=tbl,
176+
from_=GoogleCloudStorage(
177+
uri="gcs://some-bucket/a/path/to/files",
178+
credentials="XYZ",
179+
),
180+
files=['one','two','three'],
181+
file_format=CSVFormat(),
182+
)
183+
184+
self.assert_compile(
185+
copy_into,
186+
(
187+
"COPY INTO test_schema.atable"
188+
" FROM 'gcs://some-bucket/a/path/to/files' "
189+
"CONNECTION = ("
190+
" ENDPOINT_URL = 'https://storage.googleapis.com' "
191+
" CREDENTIAL = 'XYZ' "
192+
") FILES = ('one', 'two', 'three')"
193+
" FILE_FORMAT = (TYPE = CSV)"
194+
),
195+
)
196+
165197

166198
class CopyIntoResultTest(fixtures.TablesTest):
167199
run_create_tables = "each"

0 commit comments

Comments
 (0)