Exemplo n.º 1
0
def unpivot(stream, common_fields, unpivot_name_field, unpivot_value_field):
	"""Unpivot a table. Keep fields lines, use other as values"""
	for row in stream:
		if isinstance(row, StreamHeader): 
			header = row.replace(fields=common_fields+[unpivot_name_field, unpivot_value_field])
			other_fields = [field for field in  row.fields if not field in common_fields]
			yield header
		elif isinstance(row, StreamMeta):
			yield row
		else:
			commons = [getattr(row, StreamHeader.keynormalize(f)) for f in common_fields]
			for field in other_fields:
				yield header.t._make(commons + [field, getattr(row, StreamHeader.keynormalize(field))])
Exemplo n.º 2
0
def unpivot(stream, common_fields,
    unpivot_name_field, unpivot_value_field):
    """Unpivot a table. Keep fields lines, use other as values"""
    for row in stream:
        if isinstance(row, StreamHeader):
            header = row.replace(
                fields=common_fields + [unpivot_name_field, unpivot_value_field])
            other_fields = [field for field in row.fields
                if not field in common_fields]
            yield header
        elif isinstance(row, StreamMeta):
            yield row
        else:
            commons = [getattr(row, StreamHeader.keynormalize(f)) for f in common_fields]
            for field in other_fields:
                yield header.t._make(commons + [field, getattr(row, StreamHeader.keynormalize(field))])
Exemplo n.º 3
0
 def test_keynormalize(self):
     self.assertEqual('Payant_Gratuit',
                      StreamHeader.keynormalize('Payant/Gratuit'))
Exemplo n.º 4
0
kt_msg = StreamHeader(
    typename='ktg',
    fields=[
        'date',
        'hour',
        'time',
        'name',
        # event  name.  VARCHAR(63)
        # Customer event or:
        # ucc_new_install, ucc_old_install,
        # or [event_type]
        # or gc1, gc2, gc3, gc4
        'uid',  # user id  that performs the action  BIGINT
        # also 'r' for  responses
        'st1',
        'st2',
        'st3',
        # event subtyping  VARCHAR(63)
        # for pgr :
        #   st1 = parsed referer
        #   st2 = source_ip_country
        #   st3 = http or https
        # for cpu
        # 	st1 = gender
        #   st2 = local country
        #   st3 = local state (us state)
        'channel_type',  # channel type or transaction type VARCHAR(63) 
        # for pgr : fxb_ref or fx_type
        'value',  # value associated to event (or revenue)  INTEGER
        # for cpu :
        # 	v = number of friends
        # for gc1, ...
        #  value for the goal
        'level',  # user level associated to event          INTEGER
        # for cpu
        # 	l = age
        'recipients',  # list of recipients uid, comma separated (ins,nes) VARCHAR(1023)
        'tracking_tag',  # unique tracking tag ( also match su : short tracking tag) VARCHAR(63)
        'data',  # JSON Payload + additional query parameters not processed VARCHAR(255)
    ])
Exemplo n.º 5
0
 def test_keynormalize(self):
     self.assertEqual('Payant_Gratuit', StreamHeader.keynormalize('Payant/Gratuit'))