Skip to content

Commit 730b233

Browse files
committed
add ods support 0.22 release
1 parent 5994f81 commit 730b233

File tree

8 files changed

+588
-35
lines changed

8 files changed

+588
-35
lines changed

Cargo.lock

Lines changed: 541 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "flatterer"
3-
version = "0.21.1"
3+
version = "0.22.0"
44
authors = ["David Raznick <[email protected]>"]
55
edition = "2021"
66
license = "MIT"
@@ -14,9 +14,9 @@ serde_json = { version = "1.0.83", features = ["preserve_order"] }
1414
pyo3 = { version = "0.18.3", features = ["extension-module", "eyre"] }
1515
eyre = "0.6.8"
1616
#libflatterer={path = "../libflatterer"}
17-
libflatterer = "0.21.1"
17+
libflatterer = "0.22.0"
1818

19-
flatterer-web = "0.21.2"
19+
flatterer-web = "0.22.0"
2020
#flatterer-web={path = "../flatterer-web"}
2121

2222
env_logger = "0.10.1"

docs/changelog.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ All notable changes to this project will be documented in this file.
44

55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7-
## [0.21.1] - 2024-04-5
7+
## [0.22.0] - 2024-04-10
8+
9+
### New
10+
- ODS output
11+
12+
13+
## [0.21.1] - 2024-04-05
814

915
### Changed
1016
- UI backend changed to actix-web

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
# -- Project information -----------------------------------------------------
1919

2020
project = 'flatterer'
21-
copyright = '2021-2022, David Raznick'
21+
copyright = '2021-2025, David Raznick'
2222
author = 'David Raznick'
2323

2424
# The full version, including alpha/beta/rc tags
25-
release = '0.19'
25+
release = '0.22.0'
2626

2727
myst_heading_anchors = 3
2828

docs/options.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Options:
1515
--web Load web based version
1616
--csv / --nocsv Output CSV files, default true
1717
--xlsx / --noxlsx Output XLSX file, default false
18+
--ods / --noods Output ODS file, default false
1819
--sqlite / --nosqlite Output sqlite.db file, default false
1920
--parquet / --noparquet Output directory of parquet files, default false
2021
--postgres TEXT Connection string to postgres. If supplied will
@@ -74,6 +75,8 @@ Options:
7475

7576
**XLSX:** Output xlsx file to `<OUTPUT_DIRECTORY>/output.xlsx`.
7677

78+
**ODS:** Output xlsx file to `<OUTPUT_DIRECTORY>/output.ods`.
79+
7780
**SQLITE:** Output sqlite file to `<OUTPUT_DIRECTORY>/sqlite.db`.
7881

7982
**PARQUET:** Output parquet files in `<OUTPUT_DIRECTORY>/parquet/`.
@@ -92,6 +95,11 @@ flatterer --nocsv INPUT_FILE OUTPUT_DIRECTORY
9295
flatterer --xlsx INPUT_FILE OUTPUT_DIRECTORY
9396
```
9497

98+
**ods output:**
99+
```bash
100+
flatterer --ods INPUT_FILE OUTPUT_DIRECTORY
101+
```
102+
95103
**sqlite output:**
96104
```bash
97105
flatterer --sqlite INPUT_FILE OUTPUT_DIRECTORY
@@ -129,7 +137,7 @@ flatterer.flatten('inputfile.json', 'ouput_dir', csv=False, sqlite=True, xlsx=Tr
129137

130138
Name of the table that represents data at the root of the JSON object.
131139

132-
For CSV will create `<OUTPUT_DIRECTORY>/csv/<main_table_name>.csv` and for XLSX will be the first tab name.
140+
For CSV will create `<OUTPUT_DIRECTORY>/csv/<main_table_name>.csv` and for XLSX/ODS will be the first tab name.
133141

134142
For CLI defaults to name of input file without the file ending and for python defaults to `main`.
135143

@@ -567,8 +575,8 @@ flatterer.flatten('inputfile.jl', 'ouput_dir', fields='fields.csv', only_fields=
567575

568576
Path to tables CSV file. The file can be used for:
569577

570-
* Changing the sheet order in xlsx output.
571-
* Giving the tables (and xlsx sheets) a new name by using `table_title`
578+
* Changing the sheet order in xlsx/ods output.
579+
* Giving the tables (and xlsx/ods sheets) a new name by using `table_title`
572580
* Removing unwanted tables when using the [](#only-tables) option.
573581

574582
The CSV file needs the following headers:

docs/outputs.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Outputs
22

3-
All of CSV, XLSX, PARQUET and SQLITE data can be produced with the following.
3+
All of CSV, XLSX, ODS, PARQUET and SQLITE data can be produced with the following.
44

55
```bash
6-
flatterer games.json games_dir --xlsx --csv --sqlite --parquet
6+
flatterer games.json games_dir --xlsx --ods --csv --sqlite --parquet
77
```
88

99
This will create the directory structure:
@@ -21,6 +21,7 @@ games_dir/
2121
├── tables.csv
2222
├── sqlite.db
2323
├── output.xlsx
24+
├── output.ods
2425
├── postgresql
2526
│   ├── postgresql_load.sql
2627
│   └── postgresql_schema.sql
@@ -37,6 +38,10 @@ The `csv` directory contains a CSV file representing a relational table. A new
3738

3839
The XLSX output can be found in the output.xlsx file. It contains the same data as the CSV files with a sheet per table. Sheet names are truncated to not go over the allowed limit.
3940

41+
## ODS
42+
43+
The ODS output can be found in the output.ods file. File is loaded into memory, this could cause issues for large files. Sheet names are truncated to not go over the allowed limit.
44+
4045
## SQLITE
4146

4247
A `sqlite.db` is created in the output directory where each csv file is put in its own table.

flatterer/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def flatten(
6060
output_dir='',
6161
csv=True,
6262
xlsx=False,
63+
ods=False,
6364
sqlite=False,
6465
parquet=False,
6566
dataframe=False,
@@ -139,7 +140,7 @@ def flatten(
139140
s3 = True if output_dir.startswith("s3://") else False
140141

141142
if method == 'flatten':
142-
flatten_rs(input, output_dir, csv, xlsx, sqlite, parquet,
143+
flatten_rs(input, output_dir, csv, xlsx, ods, sqlite, parquet,
143144
main_table_name, tables_csv, only_tables, fields_csv, only_fields,
144145
inline_one_to_one, path_separator, preview,
145146
table_prefix, id_prefix, emit_obj, force,
@@ -153,7 +154,7 @@ def flatten(
153154
if s3:
154155
raise AttributeError("s3 output not available when supplying an iterator")
155156

156-
iterator_flatten_rs(bytes_generator(input), output_dir, csv, xlsx, sqlite, parquet,
157+
iterator_flatten_rs(bytes_generator(input), output_dir, csv, xlsx, ods, sqlite, parquet,
157158
main_table_name, tables_csv, only_tables, fields_csv, only_fields,
158159
inline_one_to_one, path_separator, preview,
159160
table_prefix, id_prefix, emit_obj, force,
@@ -191,6 +192,9 @@ def flatten(
191192
if xlsx:
192193
output['xlsx'] = os.path.join(output_dir, 'output.xlsx')
193194

195+
if ods:
196+
output['ods'] = os.path.join(output_dir, 'output.ods')
197+
194198
return output
195199

196200
finally:
@@ -207,6 +211,7 @@ def iterator_flatten(*args, **kw):
207211
@click.option('--web', default=False, is_flag=True ,help='Load web based version')
208212
@click.option('--csv/--nocsv', default=True, help='Output CSV files, default true')
209213
@click.option('--xlsx/--noxlsx', default=False, help='Output XLSX file, default false')
214+
@click.option('--ods/--noods', default=False, help='Output ODS file, default false')
210215
@click.option('--sqlite/--nosqlite', default=False, help='Output sqlite.db file, default false')
211216
@click.option('--parquet/--noparquet', default=False, help='Output directory of parquet files, default false')
212217
@click.option('--postgres', default="", help='Connection string to postgres. If supplied will load data into postgres')
@@ -258,6 +263,7 @@ def cli(
258263
web=False,
259264
csv=True,
260265
xlsx=False,
266+
ods=False,
261267
sqlite=False,
262268
sqlite_path='',
263269
parquet=False,
@@ -328,6 +334,7 @@ def cli(
328334
output_directory,
329335
csv=csv,
330336
xlsx=xlsx,
337+
ods=ods,
331338
sqlite=sqlite,
332339
parquet=parquet,
333340
postgres=postgres,

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ fn flatterer(_py: Python, m: &PyModule) -> PyResult<()> {
4343
output_dir: String,
4444
csv: bool,
4545
xlsx: bool,
46+
ods: bool,
4647
sqlite: bool,
4748
parquet: bool,
4849
main_table_name: String,
@@ -85,6 +86,7 @@ fn flatterer(_py: Python, m: &PyModule) -> PyResult<()> {
8586

8687
op.csv = csv;
8788
op.xlsx = xlsx;
89+
op.ods = ods;
8890
op.sqlite = sqlite;
8991
op.parquet = parquet;
9092
op.main_table_name = main_table_name;
@@ -140,6 +142,7 @@ fn flatterer(_py: Python, m: &PyModule) -> PyResult<()> {
140142
output_dir: String,
141143
csv: bool,
142144
xlsx: bool,
145+
ods: bool,
143146
sqlite: bool,
144147
parquet: bool,
145148
main_table_name: String,
@@ -178,6 +181,7 @@ fn flatterer(_py: Python, m: &PyModule) -> PyResult<()> {
178181

179182
options.csv = csv;
180183
options.xlsx = xlsx;
184+
options.ods = ods;
181185
options.sqlite = sqlite;
182186
options.parquet = parquet;
183187
options.main_table_name = main_table_name;
@@ -223,6 +227,10 @@ fn flatterer(_py: Python, m: &PyModule) -> PyResult<()> {
223227
log::warn!("XLSX output not supported in multi threaded mode");
224228
options.xlsx = false;
225229
}
230+
if options.ods {
231+
log::warn!("ODS output not supported in multi threaded mode");
232+
options.ods = false;
233+
}
226234
if final_output_path.is_dir() {
227235
if options.force {
228236
remove_dir_all(&final_output_path)?;

0 commit comments

Comments
 (0)