|
23 | 23 | import org.apache.calcite.linq4j.tree.Expression; |
24 | 24 | import org.apache.calcite.rex.RexCall; |
25 | 25 | import org.apache.calcite.sql.SqlAggFunction; |
26 | | -import org.apache.calcite.sql.SqlCall; |
27 | | -import org.apache.calcite.sql.SqlFunction; |
28 | | -import org.apache.calcite.sql.SqlFunctionCategory; |
29 | 26 | import org.apache.calcite.sql.SqlKind; |
30 | | -import org.apache.calcite.sql.SqlLiteral; |
31 | | -import org.apache.calcite.sql.SqlNode; |
32 | 27 | import org.apache.calcite.sql.SqlOperator; |
33 | | -import org.apache.calcite.sql.fun.SqlLibraryOperators; |
34 | | -import org.apache.calcite.sql.fun.SqlStdOperatorTable; |
35 | | -import org.apache.calcite.sql.fun.SqlTrimFunction; |
36 | | -import org.apache.calcite.sql.type.OperandTypes; |
37 | 28 | import org.apache.calcite.sql.type.ReturnTypes; |
38 | 29 | import org.apache.calcite.sql.type.SqlTypeTransforms; |
39 | 30 | import org.apache.calcite.sql.util.ReflectiveSqlOperatorTable; |
40 | | -import org.apache.calcite.sql.validate.SqlValidator; |
41 | 31 | import org.apache.calcite.util.BuiltInMethod; |
42 | 32 | import org.opensearch.sql.calcite.udf.udaf.FirstAggFunction; |
43 | 33 | import org.opensearch.sql.calcite.udf.udaf.LastAggFunction; |
@@ -144,130 +134,6 @@ public class PPLBuiltinOperators extends ReflectiveSqlOperatorTable { |
144 | 134 | public static final SqlOperator SCALAR_MAX = new ScalarMaxFunction().toUDF("SCALAR_MAX"); |
145 | 135 | public static final SqlOperator SCALAR_MIN = new ScalarMinFunction().toUDF("SCALAR_MIN"); |
146 | 136 |
|
147 | | - // Math functions with rewrite rules for validation |
148 | | - public static final SqlOperator LOG_VALIDATOR = |
149 | | - new SqlFunction( |
150 | | - "LOG", |
151 | | - SqlKind.LOG, |
152 | | - ReturnTypes.DOUBLE_NULLABLE, |
153 | | - null, |
154 | | - OperandTypes.NUMERIC_OPTIONAL_NUMERIC, |
155 | | - SqlFunctionCategory.USER_DEFINED_FUNCTION) { |
156 | | - @Override |
157 | | - public SqlNode rewriteCall(SqlValidator validator, SqlCall call) { |
158 | | - // Rewrite LOG(x, b) to LOG(b, x) - swap arguments for Calcite compatibility |
159 | | - if (call.operandCount() == 2) { |
160 | | - return SqlLibraryOperators.LOG.createCall( |
161 | | - call.getParserPosition(), call.operand(1), call.operand(0)); |
162 | | - } |
163 | | - return super.rewriteCall(validator, call); |
164 | | - } |
165 | | - }; |
166 | | - |
167 | | - public static final SqlFunction ATAN_VALIDATOR = |
168 | | - new SqlFunction( |
169 | | - "ATAN", |
170 | | - SqlKind.OTHER_FUNCTION, |
171 | | - ReturnTypes.DOUBLE_NULLABLE, |
172 | | - null, |
173 | | - OperandTypes.NUMERIC_OPTIONAL_NUMERIC, |
174 | | - SqlFunctionCategory.USER_DEFINED_FUNCTION) { |
175 | | - @Override |
176 | | - public SqlNode rewriteCall(SqlValidator validator, SqlCall call) { |
177 | | - // Rewrite ATAN(y, x) to ATAN2(y, x) |
178 | | - if (call.operandCount() == 2) { |
179 | | - return SqlStdOperatorTable.ATAN2.createCall( |
180 | | - call.getParserPosition(), call.operand(0), call.operand(1)); |
181 | | - } |
182 | | - return super.rewriteCall(validator, call); |
183 | | - } |
184 | | - }; |
185 | | - |
186 | | - public static final SqlFunction SQRT_VALIDATOR = |
187 | | - new SqlFunction( |
188 | | - "SQRT", |
189 | | - SqlKind.OTHER_FUNCTION, |
190 | | - ReturnTypes.DOUBLE_NULLABLE, |
191 | | - null, |
192 | | - OperandTypes.NUMERIC, |
193 | | - SqlFunctionCategory.USER_DEFINED_FUNCTION) { |
194 | | - @Override |
195 | | - public SqlNode rewriteCall(SqlValidator validator, SqlCall call) { |
196 | | - // Rewrite SQRT(x) to POWER(x, 0.5) |
197 | | - return SqlStdOperatorTable.POWER.createCall( |
198 | | - call.getParserPosition(), |
199 | | - call.operand(0), |
200 | | - SqlLiteral.createExactNumeric("0.5", call.getParserPosition())); |
201 | | - } |
202 | | - }; |
203 | | - |
204 | | - // String functions with rewrite rules for validation |
205 | | - public static final SqlFunction TRIM_VALIDATOR = |
206 | | - new SqlFunction( |
207 | | - "TRIM", |
208 | | - SqlKind.TRIM, |
209 | | - ReturnTypes.VARCHAR_NULLABLE, |
210 | | - null, |
211 | | - OperandTypes.CHARACTER, |
212 | | - SqlFunctionCategory.USER_DEFINED_FUNCTION) { |
213 | | - @Override |
214 | | - public SqlNode rewriteCall(SqlValidator validator, SqlCall call) { |
215 | | - // Rewrite TRIM(x) to TRIM(BOTH ' ' FROM x) |
216 | | - if (call.operandCount() == 1) { |
217 | | - return SqlStdOperatorTable.TRIM.createCall( |
218 | | - call.getParserPosition(), |
219 | | - SqlLiteral.createSymbol(SqlTrimFunction.Flag.BOTH, call.getParserPosition()), |
220 | | - SqlLiteral.createCharString(" ", call.getParserPosition()), |
221 | | - call.operand(0)); |
222 | | - } |
223 | | - return super.rewriteCall(validator, call); |
224 | | - } |
225 | | - }; |
226 | | - |
227 | | - public static final SqlFunction LTRIM_VALIDATOR = |
228 | | - new SqlFunction( |
229 | | - "LTRIM", |
230 | | - SqlKind.LTRIM, |
231 | | - ReturnTypes.VARCHAR_NULLABLE, |
232 | | - null, |
233 | | - OperandTypes.CHARACTER, |
234 | | - SqlFunctionCategory.USER_DEFINED_FUNCTION) { |
235 | | - @Override |
236 | | - public SqlNode rewriteCall(SqlValidator validator, SqlCall call) { |
237 | | - // Rewrite LTRIM(x) to TRIM(LEADING ' ' FROM x) |
238 | | - if (call.operandCount() == 1) { |
239 | | - return SqlStdOperatorTable.TRIM.createCall( |
240 | | - call.getParserPosition(), |
241 | | - SqlLiteral.createSymbol(SqlTrimFunction.Flag.LEADING, call.getParserPosition()), |
242 | | - SqlLiteral.createCharString(" ", call.getParserPosition()), |
243 | | - call.operand(0)); |
244 | | - } |
245 | | - return super.rewriteCall(validator, call); |
246 | | - } |
247 | | - }; |
248 | | - |
249 | | - public static final SqlFunction RTRIM_VALIDATOR = |
250 | | - new SqlFunction( |
251 | | - "RTRIM", |
252 | | - SqlKind.RTRIM, |
253 | | - ReturnTypes.VARCHAR_NULLABLE, |
254 | | - null, |
255 | | - OperandTypes.CHARACTER, |
256 | | - SqlFunctionCategory.USER_DEFINED_FUNCTION) { |
257 | | - @Override |
258 | | - public SqlNode rewriteCall(SqlValidator validator, SqlCall call) { |
259 | | - // Rewrite RTRIM(x) to TRIM(TRAILING ' ' FROM x) |
260 | | - if (call.operandCount() == 1) { |
261 | | - return SqlStdOperatorTable.TRIM.createCall( |
262 | | - call.getParserPosition(), |
263 | | - SqlLiteral.createSymbol(SqlTrimFunction.Flag.TRAILING, call.getParserPosition()), |
264 | | - SqlLiteral.createCharString(" ", call.getParserPosition()), |
265 | | - call.operand(0)); |
266 | | - } |
267 | | - return super.rewriteCall(validator, call); |
268 | | - } |
269 | | - }; |
270 | | - |
271 | 137 | public static final SqlOperator COSH = |
272 | 138 | adaptMathFunctionToUDF( |
273 | 139 | "cosh", ReturnTypes.DOUBLE_FORCE_NULLABLE, NullPolicy.ANY, PPLOperandTypes.NUMERIC) |
|
0 commit comments