0

So I have a custom SqlFunction:

  public static final class SqlApproximatePercentileFunction extends SqlAggFunction {
    public SqlApproximatePercentileFunction() {
      super(
          "APPROX_PERCENTILE",
          null,
          SqlKind.OTHER_FUNCTION,
          ReturnTypes.DOUBLE,
          null,
          family(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
          SqlFunctionCategory.USER_DEFINED_FUNCTION,
          false,
          false);
    }
  }

The details of APPROX_PERCENTILE is not so relevant, just FYI: https://prestodb.io/docs/current/functions/aggregate.html#approximate-aggregate-functions

I want to detect there is an error when a user query swaps arguments

   sql = "select approx_percentile(l.price, 0.6) from lineitem l"; // correct inputs
   sql = "select approx_percentile(0.6, l.price) from lineitem l"; // incorrect inputs

The problem is that in my record type definition, column price from table l is of SqlTypeName.NUMERIC which is the same as the SqlTypeName for 0.6.

What can we do in calcite to differentiate a numerical column from a numerical literal?

cpchung
  • 774
  • 3
  • 8
  • 23
  • one way we might be able to detect this error is to add a custom function in the parser grammar so it becomes a syntax error if user accidentally swaps argument – cpchung Jun 02 '23 at 21:18
  • Another way to check it would be to inspect whether the name of the first argument is in the table schema. Clearly this is not a general approach applicable to all functions of different argument types – cpchung Jun 03 '23 at 20:57

0 Answers0