-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
189 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#:schema ./mapping_schema.json | ||
[[tables]] | ||
from = "object_parquet" | ||
to = "object" | ||
[[tables.columns]] | ||
from = "oid_parquet" | ||
to = "oid" | ||
[[tables.columns]] | ||
from = "firstmjd_parquet" | ||
to = "firstmjd" | ||
[[tables.columns]] | ||
from = "ndet_parquet" | ||
to = "ndet" | ||
|
||
[[tables]] | ||
from = "detections_parquet" | ||
to = "detections" | ||
[[tables.columns]] | ||
from = "candid_parquet" | ||
to = "candid" | ||
[[tables.columns]] | ||
from = "oid_parquet" | ||
to = "oid" | ||
[[tables.columns]] | ||
from = "mag_parquet" | ||
to = "mag" | ||
[[tables.columns]] | ||
from = "other_parquet" | ||
to = "blahblah" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
tables: | ||
- from: object_parquet | ||
to: object_parquet | ||
columns: | ||
- from: oid_parquet | ||
to: oid | ||
- from: firstmjd_parquet | ||
to: firstmjd | ||
- from: ndet_parquet | ||
to: ndet | ||
- from: detections_parquet | ||
to: detections | ||
columns: | ||
- from: candid_parquet | ||
to: candid | ||
- from: oid_parquet | ||
to: oid | ||
- from: mag_parquet | ||
to: mag | ||
- from: "other_parquet" | ||
to: "blahblah" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from enum import Enum | ||
|
||
|
||
class ValidFileTypes(Enum): | ||
TOML = "TOML" | ||
YAML = "YAML" | ||
|
||
@classmethod | ||
def possible_values(cls): | ||
return [variant.value for variant in cls.__members__.values()] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from pydantic import BaseModel, Field | ||
|
||
# Using `from_` because `from` is a reserved keyword | ||
|
||
|
||
class ColumnMapping(BaseModel): | ||
from_: str = Field(alias="from") | ||
to: str = Field() | ||
|
||
|
||
class TableMappings(BaseModel): | ||
from_: str = Field(alias="from") | ||
to: str = Field() | ||
columns: list[ColumnMapping] = [] | ||
|
||
|
||
class DBMappings(BaseModel): | ||
tables: list[TableMappings] = [] | ||
|
||
|
||
a = { | ||
"tables": [ | ||
{ | ||
"from": "parquet_obj", | ||
"to": "obj", | ||
"columns": [{"from": "col_tabla", "to": "col_db"}], | ||
}, | ||
{ | ||
"from": "parquet_det", | ||
"to": "det", | ||
"columns": [ | ||
{"from": "col_tabla", "to": "col_db"}, | ||
{"from": "col_tabla", "to": "col_db"}, | ||
{"from": "col_tabla", "to": "col_db"}, | ||
], | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import math | ||
from pathlib import Path | ||
|
||
import polars as pl | ||
from faker import Faker | ||
|
||
fake = Faker() | ||
|
||
parquets = { | ||
"object_parquet": [ | ||
"oid_parquet", | ||
"firstmjd_parquet", | ||
"lastmjd_parquet", | ||
"ndet_parquet", | ||
], | ||
"detections_parquet": [ | ||
"candid_parquet", | ||
"oid_parquet", | ||
"mag_parquet", | ||
"other_parquet", | ||
"another_parquet", | ||
], | ||
} | ||
|
||
|
||
def generate_dummy_parquets( | ||
folder: str = "parquets", | ||
n_parquets: int = 30, | ||
n_rows_per_parquet: int = 1000, | ||
) -> None: | ||
for table, columns in parquets.items(): | ||
table_folder = Path(folder) / table | ||
table_folder.mkdir(parents=True, exist_ok=True) | ||
for i in range(1, n_parquets + 1): | ||
dummy_data = { | ||
column: [f"{column}: {fake.md5()}" for _ in range(n_rows_per_parquet)] | ||
for column in columns | ||
} | ||
df = pl.DataFrame(dummy_data) | ||
df.write_parquet( | ||
f"{folder}/{table}/{str(i).zfill(math.ceil(math.log10(n_parquets)))}.parquet" | ||
) |