@@ -47,6 +47,120 @@ class DSSComputedColumn(object):
4747 def formula (name , formula , type = "double" ):
4848 return {"expr" : formula , "mode" : "GREL" , "name" : name , "type" : type }
4949
50+ from enum import Enum
51+ class DSSFilterOperator (Enum ):
52+ EMPTY_ARRAY = "empty array"
53+ NOT_EMPTY_ARRAY = "not empty array"
54+ CONTAINS_ARRAY = "array contains"
55+ NOT_EMPTY = "not empty"
56+ EMPTY = "is empty"
57+ NOT_EMPTY_STRING = "not empty string"
58+ EMPTY_STRING = "empty string"
59+ IS_TRUE = "true"
60+ IS_FALSE = "false"
61+ EQUALS_STRING = "== [string]"
62+ EQUALS_CASE_INSENSITIVE_STRING = "== [string]i"
63+ NOT_EQUALS_STRING = "!= [string]"
64+ SAME = "== [NaNcolumn]"
65+ DIFFERENT = "!= [NaNcolumn]"
66+ EQUALS_NUMBER = "== [number]"
67+ NOT_EQUALS_NUMBER = "!= [number]"
68+ GREATER_NUMBER = "> [number]"
69+ LESS_NUMBER = "< [number]"
70+ GREATER_OR_EQUAL_NUMBER = ">= [number]"
71+ LESS_OR_EQUAL_NUMBER = "<= [number]"
72+ EQUALS_DATE = "== [date]"
73+ GREATER_DATE = "> [date]"
74+ GREATER_OR_EQUAL_DATE = ">= [date]"
75+ LESS_DATE = "< [date]"
76+ LESS_OR_EQUAL_DATE = "<= [date]"
77+ BETWEEN_DATE = ">< [date]"
78+ EQUALS_COL = "== [column]"
79+ NOT_EQUALS_COL = "!= [column]"
80+ GREATER_COL = "> [column]"
81+ LESS_COL = "< [column]"
82+ GREATER_OR_EQUAL_COL = ">= [column]"
83+ LESS_OR_EQUAL_COL = "<= [column]"
84+ CONTAINS_STRING = "contains"
85+ REGEX = "regex"
86+
87+ class DSSFilter (object ):
88+ """Helper class to build filter objects for use in visual recipes"""
89+ @staticmethod
90+ def of_single_condition (column , operator , string = None , num = None , date = None , time = None , date2 = None , time2 = None , unit = None ):
91+ return {
92+ "enabled" : True ,
93+ "uiData" : {
94+ 'conditions' : [DSSFilter .condition (column , operator , string , num , date , time , date2 , time2 , unit )],
95+ "mode" : "&&"
96+ }
97+ }
98+
99+ @staticmethod
100+ def of_and_conditions (conditions ):
101+ return {
102+ "enabled" : True ,
103+ "uiData" : {
104+ 'conditions' : conditions ,
105+ "mode" : "&&"
106+ }
107+ }
108+
109+ @staticmethod
110+ def of_or_conditions (conditions ):
111+ return {
112+ "enabled" : True ,
113+ "uiData" : {
114+ 'conditions' : conditions ,
115+ "mode" : "||"
116+ }
117+ }
118+
119+ @staticmethod
120+ def of_formula (formula ):
121+ return {
122+ "enabled" : True ,
123+ "uiData" : {
124+ "mode" : "CUSTOM"
125+ },
126+ "expression" : formula
127+ }
128+
129+ @staticmethod
130+ def of_sql_expression (sql_expression ):
131+ return {
132+ "enabled" : True ,
133+ "uiData" : {
134+ "mode" : "SQL"
135+ },
136+ "expression" : sql_expression
137+ }
138+
139+ @staticmethod
140+ def condition (column , operator , string = None , num = None , date = None , time = None , date2 = None , time2 = None , unit = None ):
141+ if isinstance (operator , DSSFilterOperator ):
142+ operator = operator .value
143+ cond = {
144+ "input" : column ,
145+ "operator" : operator
146+ }
147+ if string is not None :
148+ cond ["string" ] = string
149+ if num is not None :
150+ cond ["num" ] = num
151+ if date is not None :
152+ cond ["date" ] = date
153+ if time is not None :
154+ cond ["time" ] = time
155+ if date2 is not None :
156+ cond ["date2" ] = date2
157+ if time2 is not None :
158+ cond ["time2" ] = time2
159+ if unit is not None :
160+ cond ["unit" ] = unit
161+
162+ return cond
163+
50164class DSSFilterBuilder (object ):
51165 """
52166 Builder for a "filter". In DSS, a filter is used to define a subset of rows for processing.
0 commit comments