|
92 | 92 | ]
|
93 | 93 |
|
94 | 94 |
|
95 |
| -def contains_not_commented(sql_query, substr, lower=False): |
96 |
| - if lower: |
97 |
| - sql_query = sql_query.lower() |
98 |
| - count_substr = sql_query.count(substr) |
99 |
| - count_substr_commented = sql_query.count('--' + substr) + sql_query.count('-- ' + substr) |
100 |
| - return count_substr > count_substr_commented |
| 95 | +def contains_insert(sql_query): |
| 96 | + sql_query = sql_query.lower() |
| 97 | + return sql_query.count('insert into') > sql_query.count('--insert into') + sql_query.count('-- insert into') |
101 | 98 |
|
102 | 99 |
|
103 | 100 | def validate_sql(sql_query):
|
104 | 101 | # Unsupported constructions
|
105 |
| - if contains_not_commented(sql_query, 'define subquery', lower=True): |
| 102 | + if 'define subquery' in sql_query.lower(): |
106 | 103 | pytest.skip('SUBQUERY is not supported in KQP')
|
107 | 104 |
|
108 |
| - if contains_not_commented(sql_query, 'insert into', lower=True): |
| 105 | + if contains_insert(sql_query): |
109 | 106 | pytest.skip('INSERT is not supported in KQP')
|
110 | 107 |
|
111 |
| - if contains_not_commented(sql_query, 'discard', lower=True): |
| 108 | + if 'discard' in sql_query.lower(): |
112 | 109 | pytest.skip('DISCARD is not supported in KQP')
|
113 | 110 |
|
114 |
| - if contains_not_commented(sql_query, 'evaluate', lower=True): |
| 111 | + if 'evaluate' in sql_query.lower(): |
115 | 112 | pytest.skip('EVALUATE is not supported in KQP')
|
116 | 113 |
|
117 |
| - if contains_not_commented(sql_query, 'concat(', lower=True): |
| 114 | + if 'concat(' in sql_query.lower(): |
118 | 115 | pytest.skip('CONCAT is not supported in KQP')
|
119 | 116 |
|
120 |
| - if contains_not_commented(sql_query, '.range(', lower=True) or contains_not_commented(sql_query, ' range(', lower=True): |
| 117 | + if '.range(' in sql_query.lower() or ' range(' in sql_query.lower(): |
121 | 118 | pytest.skip('RANGE is not supported in KQP')
|
122 | 119 |
|
123 |
| - if contains_not_commented(sql_query, ' each(', lower=True): |
| 120 | + if ' each(' in sql_query.lower(): |
124 | 121 | pytest.skip('EACH is not supported in KQP')
|
125 | 122 |
|
126 |
| - if contains_not_commented(sql_query, 'drop table', lower=True): |
| 123 | + if 'drop table' in sql_query.lower(): |
127 | 124 | pytest.skip('DROP TABLE is not supported in KQP for extarnal entities')
|
128 | 125 |
|
129 |
| - if contains_not_commented(sql_query, 'sample ', lower=True) or contains_not_commented(sql_query, 'sample(', lower=True): |
| 126 | + if 'sample ' in sql_query.lower() or 'sample(' in sql_query.lower(): |
130 | 127 | pytest.skip('SAMPLE is not supported in KQP')
|
131 | 128 |
|
132 |
| - if contains_not_commented(sql_query, 'count(', lower=True): |
| 129 | + if 'count(' in sql_query.lower(): |
133 | 130 | pytest.skip('COUNT is not supported in KQP')
|
134 | 131 |
|
135 | 132 | # Unsupported functions
|
136 |
| - if contains_not_commented(sql_query, 'TableName('): |
| 133 | + if 'TableName(' in sql_query: |
137 | 134 | pytest.skip('TableName is not supported in KQP')
|
138 | 135 |
|
139 |
| - if contains_not_commented(sql_query, 'QuoteCode('): |
| 136 | + if 'QuoteCode(' in sql_query: |
140 | 137 | pytest.skip('QuoteCode is not supported in KQP')
|
141 | 138 |
|
142 |
| - if contains_not_commented(sql_query, 'RangeComputeFor('): |
| 139 | + if 'RangeComputeFor(' in sql_query: |
143 | 140 | pytest.skip('RangeComputeFor is not supported in KQP')
|
144 | 141 |
|
145 |
| - if contains_not_commented(sql_query, 'FromBytes('): |
| 142 | + if 'FromBytes(' in sql_query: |
146 | 143 | pytest.skip('FromBytes is not supported in KQP')
|
147 | 144 |
|
148 |
| - if contains_not_commented(sql_query, 'folder(', lower=True): |
| 145 | + if 'folder(' in sql_query.lower(): |
149 | 146 | pytest.skip('Folder is not supported in KQP')
|
150 | 147 |
|
151 |
| - if contains_not_commented(sql_query, 'file(', lower=True) or contains_not_commented(sql_query, 'FileContent('): |
| 148 | + if 'file(' in sql_query.lower() or 'FileContent(' in sql_query: |
152 | 149 | pytest.skip('Files is not supported in KQP')
|
153 | 150 |
|
154 | 151 | # Unsupported pragmas
|
155 |
| - if contains_not_commented(sql_query, 'library(', lower=True): |
| 152 | + if 'library(' in sql_query.lower(): |
156 | 153 | pytest.skip('Pragma Library is not supported in KQP')
|
157 | 154 |
|
158 |
| - if contains_not_commented(sql_query, 'refselect', lower=True): |
| 155 | + if 'refselect' in sql_query.lower(): |
159 | 156 | pytest.skip('Pragma RefSelect is not supported in KQP')
|
160 | 157 |
|
161 |
| - if contains_not_commented(sql_query, 'optimizerflags', lower=True): |
| 158 | + if 'optimizerflags' in sql_query.lower(): |
162 | 159 | pytest.skip('Pragma OptimizerFlags is not supported in KQP')
|
163 | 160 |
|
164 |
| - if contains_not_commented(sql_query, 'disablepullupflatmapoverjoin', lower=True): |
| 161 | + if 'disablepullupflatmapoverjoin' in sql_query.lower(): |
165 | 162 | pytest.skip('Pragma DisablePullUpFlatMapOverJoin is not supported in KQP')
|
166 | 163 |
|
167 |
| - if contains_not_commented(sql_query, 'costbasedoptimizer', lower=True): |
| 164 | + if 'costbasedoptimizer' in sql_query.lower(): |
168 | 165 | pytest.skip('Pragma CostBasedOptimizer is not supported in KQP')
|
169 | 166 |
|
170 | 167 | # Unsupported types
|
171 |
| - if contains_not_commented(sql_query, 'date32', lower=True): |
| 168 | + if 'date32' in sql_query.lower(): |
172 | 169 | pytest.skip('Type Date32 is not supported in KQP')
|
173 | 170 |
|
174 |
| - if contains_not_commented(sql_query, 'datetime64', lower=True): |
| 171 | + if 'datetime64' in sql_query.lower(): |
175 | 172 | pytest.skip('Type Datetime64 is not supported in KQP')
|
176 | 173 |
|
177 |
| - if contains_not_commented(sql_query, 'timestamp64', lower=True): |
| 174 | + if 'timestamp64' in sql_query.lower(): |
178 | 175 | pytest.skip('Type Timestamp64 is not supported in KQP')
|
179 | 176 |
|
180 |
| - if contains_not_commented(sql_query, 'interval64', lower=True): |
| 177 | + if 'interval64' in sql_query.lower(): |
181 | 178 | pytest.skip('Type Interval64 is not supported in KQP')
|
182 | 179 |
|
183 |
| - if contains_not_commented(sql_query, 'interval64', lower=True): |
| 180 | + if 'interval64' in sql_query.lower(): |
184 | 181 | pytest.skip('Type Interval64 is not supported in KQP')
|
185 | 182 |
|
186 |
| - if contains_not_commented(sql_query, 'void(', lower=True): |
| 183 | + if 'void(' in sql_query.lower(): |
187 | 184 | pytest.skip('Type Void is not supported in KQP')
|
188 | 185 |
|
189 |
| - if contains_not_commented(sql_query, 'variant(', lower=True): |
| 186 | + if 'variant(' in sql_query.lower(): |
190 | 187 | pytest.skip('Type Variant is not supported in KQP')
|
191 | 188 |
|
192 | 189 |
|
|
0 commit comments