Skip to content

Commit

Permalink
feat: Add new topic_group and post_downvotes attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Sieboldianus committed May 15, 2023
1 parent 7bf1d55 commit 12c6bbb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/lbsntransform/input/mappings/field_mapping_lbsn.py
Expand Up @@ -284,6 +284,8 @@ def extract_post(cls, record, origin):
# get enum value
post.post_geoaccuracy = lbsn.Post.PostGeoaccuracy.Value(geo_acc.upper())
set_lbsn_attr(post, "hashtags", record)
set_lbsn_attr(post, "topic_group", record)
set_lbsn_attr(post, "post_downvotes", record)
set_lbsn_attr(post, "emoji", record)
set_lbsn_attr(post, "post_like_count", record)
set_lbsn_attr(post, "post_comment_count", record)
Expand Down
Expand Up @@ -37,7 +37,7 @@ def get_header_for_type(desc_name):
"hashtags, emoji, post_like_count, post_comment_count, "
"post_views_count, post_title, post_thumbnail_url, post_url, "
"post_type, post_filter, post_quote_count, post_share_count, "
"input_source, post_content_license",
"input_source, post_content_license, topic_group, post_downvotes",
lbsn.PostReaction.DESCRIPTOR.name: "origin_id, reaction_guid, reaction_latlng, user_guid, "
"referencedPost_guid, referencedPostreaction_guid, "
"reaction_type, reaction_date, reaction_content, "
Expand Down Expand Up @@ -237,6 +237,8 @@ def prepare_lbsn_post(cls, record):
post_record.post_share_count,
post_record.input_source,
post_record.post_content_license,
post_record.topic_group,
post_record.post_downvotes,
)
return prepared_record

Expand Down Expand Up @@ -418,6 +420,8 @@ def __init__(self, record=None):
self.post_share_count = HF.null_check(record.post_share_count)
self.input_source = HF.null_check(record.input_source)
self.post_content_license = HF.null_check(record.post_content_license)
self.topic_group = list(set(record.topic_group))
self.post_downvotes = HF.null_check(record.post_downvotes)
# optional:
self.latitude = 0
self.longitude = 0
Expand Down
7 changes: 6 additions & 1 deletion src/lbsntransform/output/lbsn/sql_lbsn.py
Expand Up @@ -154,7 +154,12 @@ def post_insertsql(values_str: str, record_type):
topical."post".input_source),
post_content_license = COALESCE(
EXCLUDED.post_content_license,
topical."post".post_content_license);
topical."post".post_content_license),
topic_group = COALESCE(
extensions.mergeArrays(EXCLUDED.topic_group,
topical."post".topic_group), ARRAY[]::text[]),
post_downvotes = COALESCE(EXCLUDED.post_downvotes,
topical."post".post_downvotes);
"""
return insert_sql

Expand Down

0 comments on commit 12c6bbb

Please sign in to comment.