-
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.
OAM-240 Added price_changes resource (#13)
- Loading branch information
1 parent
3bb8171
commit e5ebfcd
Showing
4 changed files
with
55 additions
and
1 deletion.
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
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
38 changes: 38 additions & 0 deletions
38
sigeca_data_export_microservice/app/domain/resources/price_changes_data.py
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 datetime import datetime | ||
from uuid import uuid4 | ||
|
||
from .abstract import ResourceReader | ||
from .util import schema_map, table_map, map_data | ||
from ...infrastructure import ChangeLogOperation | ||
|
||
|
||
class PriceChangesResourceReader(ResourceReader): | ||
@classmethod | ||
def read_table_name(cls): | ||
return "price_changes" | ||
|
||
@classmethod | ||
def read_schema_name(cls): | ||
return "referencedata" | ||
|
||
def transform_data(self, df): | ||
df = df.withColumn("occurreddate", df["occurreddate"].cast('string')) \ | ||
.withColumn("price", df["price"].cast("string")) | ||
|
||
schema_name = self.read_schema_name() | ||
table_name = self.read_table_name() | ||
|
||
return df.rdd.map(self._to_payload(table_name, schema_name)).collect() | ||
|
||
def _to_payload(self, table_name, schema_name): | ||
def map_schema(row): | ||
return { | ||
"id": str(uuid4()), | ||
"schema_name": schema_map[(schema_name, table_name)], | ||
"table_name": table_map[(schema_name, table_name)], | ||
"operation": ChangeLogOperation.SYNC.value, | ||
"change_time": datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ"), | ||
"row_data": map_data(row.asDict(), schema_name, table_name), | ||
} | ||
|
||
return map_schema |
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