fenic.api.io.writer
Writer interface for saving DataFrames to external storage systems.
Classes:
-
DataFrameWriter
–Interface used to write a DataFrame to external storage systems.
DataFrameWriter
DataFrameWriter(dataframe: DataFrame)
Interface used to write a DataFrame to external storage systems.
Similar to PySpark's DataFrameWriter.
Supported External Storage Schemes: - Amazon S3 (s3://) - Format: s3://{bucket_name}/{path_to_file}
- Notes:
- Uses boto3 to aquire AWS credentials.
- Examples:
- s3://my-bucket/data.csv
- s3://my-bucket/data/*.parquet
-
Local Files (file:// or implicit)
-
Format: file://{absolute_or_relative_path}
-
Notes:
- Paths without a scheme (e.g., ./data.csv or /tmp/data.parquet) are treated as local files
- Examples:
- file:///home/user/data.csv
- ./data/*.parquet
-
Initialize a DataFrameWriter.
Parameters:
-
dataframe
(DataFrame
) –The DataFrame to write.
Methods:
-
csv
–Saves the content of the DataFrame as a single CSV file with comma as the delimiter and headers in the first row.
-
parquet
–Saves the content of the DataFrame as a single Parquet file.
-
save_as_table
–Saves the content of the DataFrame as the specified table.
-
save_as_view
–Saves the content of the DataFrame as a view.
Source code in src/fenic/api/io/writer.py
47 48 49 50 51 52 53 |
|
csv
csv(file_path: Union[str, Path], mode: Literal['error', 'overwrite', 'ignore'] = 'overwrite') -> QueryMetrics
Saves the content of the DataFrame as a single CSV file with comma as the delimiter and headers in the first row.
Parameters:
-
file_path
(Union[str, Path]
) –Path to save the CSV file to
-
mode
(Literal['error', 'overwrite', 'ignore']
, default:'overwrite'
) –Write mode. Default is "overwrite". - error: Raises an error if file exists - overwrite: Overwrites the file if it exists - ignore: Silently ignores operation if file exists
Returns:
-
QueryMetrics
(QueryMetrics
) –The query metrics
Save with overwrite mode (default)
df.write.csv("output.csv") # Overwrites if exists
Save with error mode
df.write.csv("output.csv", mode="error") # Raises error if exists
Save with ignore mode
df.write.csv("output.csv", mode="ignore") # Skips if exists
Source code in src/fenic/api/io/writer.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
|
parquet
parquet(file_path: Union[str, Path], mode: Literal['error', 'overwrite', 'ignore'] = 'overwrite') -> QueryMetrics
Saves the content of the DataFrame as a single Parquet file.
Parameters:
-
file_path
(Union[str, Path]
) –Path to save the Parquet file to
-
mode
(Literal['error', 'overwrite', 'ignore']
, default:'overwrite'
) –Write mode. Default is "overwrite". - error: Raises an error if file exists - overwrite: Overwrites the file if it exists - ignore: Silently ignores operation if file exists
Returns:
-
QueryMetrics
(QueryMetrics
) –The query metrics
Save with overwrite mode (default)
df.write.parquet("output.parquet") # Overwrites if exists
Save with error mode
df.write.parquet("output.parquet", mode="error") # Raises error if exists
Save with ignore mode
df.write.parquet("output.parquet", mode="ignore") # Skips if exists
Source code in src/fenic/api/io/writer.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
|
save_as_table
save_as_table(table_name: str, mode: Literal['error', 'append', 'overwrite', 'ignore'] = 'error') -> QueryMetrics
Saves the content of the DataFrame as the specified table.
Parameters:
-
table_name
(str
) –Name of the table to save to
-
mode
(Literal['error', 'append', 'overwrite', 'ignore']
, default:'error'
) –Write mode. Default is "error". - error: Raises an error if table exists - append: Appends data to table if it exists - overwrite: Overwrites existing table - ignore: Silently ignores operation if table exists
Returns:
-
QueryMetrics
(QueryMetrics
) –The query metrics
Save with error mode (default)
df.write.save_as_table("my_table") # Raises error if table exists
Save with append mode
df.write.save_as_table("my_table", mode="append") # Adds to existing table
Save with overwrite mode
df.write.save_as_table("my_table", mode="overwrite") # Replaces existing table
Source code in src/fenic/api/io/writer.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
save_as_view
save_as_view(view_name: str, description: str | None = None) -> None
Saves the content of the DataFrame as a view.
Parameters:
-
view_name
(str
) –Name of the view to save to
-
description
(str | None
, default:None
) –Optional human-readable view description to store in the catalog.
Returns:
-
None
–None.
Source code in src/fenic/api/io/writer.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|