Skip to content

Commit 032081f

Browse files
committed
Changes to File Formats
1 parent df75e37 commit 032081f

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

databend_sqlalchemy/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
NDJSONFormat,
2020
ParquetFormat,
2121
ORCFormat,
22+
AVROFormat,
2223
AmazonS3,
2324
AzureBlobStorage,
2425
GoogleCloudStorage,

databend_sqlalchemy/dml.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ class Compression(Enum):
250250
DEFLATE = "DEFLATE"
251251
RAW_DEFLATE = "RAW_DEFLATE"
252252
XZ = "XZ"
253+
SNAPPY = "SNAPPY"
253254

254255

255256
class CopyFormat(ClauseElement):
@@ -401,6 +402,30 @@ def __init__(
401402
class ParquetFormat(CopyFormat):
402403
format_type = "PARQUET"
403404

405+
def __init__(
406+
self,
407+
*,
408+
missing_field_as: str = None,
409+
compression: Compression = None,
410+
):
411+
super().__init__()
412+
if missing_field_as:
413+
if missing_field_as not in ["ERROR", "FIELD_DEFAULT"]:
414+
raise TypeError(
415+
'Missing Field As should be "ERROR" or "FIELD_DEFAULT".'
416+
)
417+
self.options["MISSING_FIELD_AS"] = f"{missing_field_as}"
418+
if compression:
419+
if compression not in [Compression.ZSTD, Compression.SNAPPY]:
420+
raise TypeError(
421+
'Compression should be None, ZStd, or Snappy.'
422+
)
423+
self.options["COMPRESSION"] = compression.value
424+
425+
426+
class AVROFormat(CopyFormat):
427+
format_type = "AVRO"
428+
404429
def __init__(
405430
self,
406431
*,
@@ -418,6 +443,19 @@ def __init__(
418443
class ORCFormat(CopyFormat):
419444
format_type = "ORC"
420445

446+
def __init__(
447+
self,
448+
*,
449+
missing_field_as: str = None,
450+
):
451+
super().__init__()
452+
if missing_field_as:
453+
if missing_field_as not in ["ERROR", "FIELD_DEFAULT"]:
454+
raise TypeError(
455+
'Missing Field As should be "ERROR" or "FIELD_DEFAULT".'
456+
)
457+
self.options["MISSING_FIELD_AS"] = f"{missing_field_as}"
458+
421459

422460
class StageClause(ClauseElement, FromClauseRole):
423461
"""Stage Clause"""

0 commit comments

Comments
 (0)