Skip to content

Commit

Permalink
fix(joining): id field in joining
Browse files Browse the repository at this point in the history
  • Loading branch information
thanh-nguyen-dang committed Jul 30, 2020
1 parent 34c37ff commit 1071126
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
22 changes: 21 additions & 1 deletion tube/etl/indexers/aggregation/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@
)
from tube.etl.indexers.base.prop import PropFactory
from tube.utils.dd import get_node_table_name
from tube.utils.general import get_node_id_name, PROJECT_ID, PROJECT_CODE, PROGRAM_NAME
from tube.utils.general import (
get_node_id_name,
get_node_id_name_without_prefix,
PROJECT_ID,
PROJECT_CODE,
PROGRAM_NAME,
)
from .parser import Parser
from ..base.lambdas import sort_by_field, swap_property_as_key, make_key_from_property
from .lambdas import sliding
Expand Down Expand Up @@ -193,6 +199,16 @@ def get_joining_props(self, translator, joining_index):
props_without_fn = []
for r in joining_index.getting_fields:
src_prop = translator.parser.get_prop_by_name(r.prop.src)
# field which is identity of a node is named as _{node}_id now
# before in etl-mapping for joining_props, we use {node}_id
# for backward compatibility, we check first with the value in mapping file.
# if there is not any Prop object like that, we check with new format _{node}_id
if src_prop is None and r.prop.src == get_node_id_name_without_prefix(
translator.parser.doc_type
):
src_prop = translator.parser.get_prop_by_name(
get_node_id_name(translator.parser.doc_type)
)
dst_prop = self.parser.get_prop_by_name(r.prop.name)
if r.fn is None:
props_without_fn.append({"src": src_prop, "dst": dst_prop})
Expand Down Expand Up @@ -243,6 +259,10 @@ def join_to_an_index(self, df, translator, joining_node):
id_field_in_joining_df = translator.parser.get_prop_by_name(
joining_node.joining_field
).id
# field which is identity of a node is named as _{node}_id now
# before in etl-mapping for joining_props, we use {node}_id
# for backward compatibility, we check first with the value in mapping file.
# if there is not any Prop object like that, we check with new format _{node}_id
id_field_in_df = self.parser.get_prop_by_name(joining_node.joining_field)
if id_field_in_df is None:
id_field_in_df = self.parser.get_prop_by_name(
Expand Down
1 change: 0 additions & 1 deletion tube/etl/indexers/base/lambdas.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ast
import json
import collections
import sys


def extract_metadata(str_value):
Expand Down
6 changes: 6 additions & 0 deletions tube/etl/indexers/base/prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,11 @@ def __str__(self):
def __repr__(self):
return self.__str__()

def __eq__(self, other):
return self.id == other.id

def __ne__(self, other):
return self.id != other.id

def update_type(self, prop_type):
self.type = prop_type
3 changes: 3 additions & 0 deletions tube/etl/indexers/injection/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def __repr__(self):
def __eq__(self, other):
return self.__key__() == other.__key__()

def __ne__(self, other):
return self.__key__() != other.__key__()


class NodePath(object):
def __init__(self, class_name, upper_path):
Expand Down
8 changes: 6 additions & 2 deletions tube/utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ def get_resource_path_from_json(results, json_data):
return results


def get_node_id_name(node_name):
return "_{}_id".format(node_name)
def get_node_id_name(name):
return "_{}_id".format(name)


def get_node_id_name_without_prefix(name):
return "{}_id".format(name)


PROGRAM_NAME = "program_name"
Expand Down

0 comments on commit 1071126

Please sign in to comment.