Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1""" 

2List of cleansing styles for database sink 

3""" 

4import re 

5from enum import Enum 

6 

7 

8class RuleEnums(Enum): 

9 """ 

10 List of available rules for cleansing field names 

11 """ 

12 # Change # to NUM 

13 NUM_SIGN = lambda col: col.replace('#', 'NUM') 

14 # Remove non-alphanumeric chars 

15 REPLACE_SPEC_CHAR = lambda col: re.sub("[^A-Za-z0-9]", "_", col) 

16 # Make uppercase 

17 MAKE_UPPER = lambda col: col.upper() 

18 # Mimic current df column conversion 

19 STRIP = lambda col: col.rstrip().lstrip() 

20 # Remove trailing underscores 

21 REMOVE_TRAILING_UNDERSCORES = lambda col: col.rstrip("_") 

22 # Change any sequence of underscores to as single underscore 

23 MULTI_TO_SINGLE_UNDERSCORES = lambda col: re.sub("_{2,}", "_", col) 

24 # If column starts with a number, put an underscore in front of it 

25 LEADING_UNDERSCORE = lambda col: "_" + col if re.match(r'[0-9]', col 

26 ) else col 

27 # if column name consists only from "_" replace it with "UNDERSCORE" 

28 REPLACE_UNDERSCORE_IN_SINGLE_CHAR_NAME = lambda col: col.replace( 

29 "_", "UNDERSCORE") if len(col) == 1 else col 

30 

31 

32class StyleEnums(Enum): 

33 """ 

34 List of available styles with conforming rules 

35 """ 

36 SNOWFLAKE = [ 

37 RuleEnums.NUM_SIGN, RuleEnums.REPLACE_SPEC_CHAR, RuleEnums.MAKE_UPPER, 

38 RuleEnums.REMOVE_TRAILING_UNDERSCORES, 

39 RuleEnums.MULTI_TO_SINGLE_UNDERSCORES, RuleEnums.LEADING_UNDERSCORE 

40 ] 

41 POSTGRES = [ 

42 RuleEnums.NUM_SIGN, RuleEnums.REPLACE_SPEC_CHAR, RuleEnums.MAKE_UPPER, 

43 RuleEnums.REMOVE_TRAILING_UNDERSCORES, 

44 RuleEnums.MULTI_TO_SINGLE_UNDERSCORES, RuleEnums.LEADING_UNDERSCORE 

45 ] 

46 HEAP = [ 

47 RuleEnums.NUM_SIGN, RuleEnums.REPLACE_SPEC_CHAR, RuleEnums.MAKE_UPPER, 

48 RuleEnums.MULTI_TO_SINGLE_UNDERSCORES, 

49 RuleEnums.REPLACE_UNDERSCORE_IN_SINGLE_CHAR_NAME, 

50 RuleEnums.LEADING_UNDERSCORE 

51 ] 

52 DEFAULT_DF = [ 

53 RuleEnums.MAKE_UPPER, RuleEnums.STRIP 

54 ]