calcite icon indicating copy to clipboard operation
calcite copied to clipboard

[CALCITE-6259] The implementation of the Log library operator does not match the actual dialect behavior

Open caicancai opened this issue 11 months ago • 8 comments

https://issues.apache.org/jira/browse/CALCITE-6259

caicancai avatar Mar 01 '24 14:03 caicancai

It looks like there is a class loading conflict. Can anyone help me answer this question, I would be very grateful

caicancai avatar Mar 03 '24 03:03 caicancai

@tanclary It seems like I don't have a good way to solve this problem. Can you give me some advice?

caicancai avatar Mar 08 '24 16:03 caicancai

@tanclary It seems like I don't have a good way to solve this problem. Can you give me some advice?

Can you be more specific? What problem?

tanclary avatar Mar 08 '24 17:03 tanclary

Can you be more specific? What problem?

Thank you for your reply. You can find that I defined ReturnTypes.DOUBLE_FORCE_NULLABLE in LOG10_MS. The purpose is to make LOG10_MS return null when log10(0). However, during my debugging process, I found that the ReturnTypes.DOUBLE_FORCE_NULLABLE I defined did not take effect.

@LibraryOperator(libraries = {MYSQL, SPARK})
  public static final SqlFunction LOG10_MS =
      ((SqlBasicFunction) LOG10).withKind(SqlKind.LOG10_MS)
          .withReturnTypeInference(ReturnTypes.DOUBLE_FORCE_NULLABLE);

Regarding the ReturnType processing of LOG10_MS, it still follows the ReturnType logic of LOG10 in SqlStdOperatorTable

public static final SqlFunction LOG10 =
      SqlBasicFunction.create("LOG10",
          ReturnTypes.DOUBLE_NULLABLE,
          OperandTypes.NUMERIC,
          SqlFunctionCategory.NUMERIC);

Can you understand what I mean?

I feel that the ReturnTypes.DOUBLE_FORCE_NULLABLE of LOG10_MS I defined must be overwritten. Yes, I must have overlooked something

caicancai avatar Mar 09 '24 01:03 caicancai

@tanclary I feel that I cannot change SqlStdOperatorTable, which will affect some other tests (I tried)

caicancai avatar Mar 10 '24 13:03 caicancai

@tanclary I feel that I cannot change SqlStdOperatorTable, which will affect some other tests (I tried)

I raised a similar question on the mailing list and didn't hear back. See: https://lists.apache.org/thread/dloo5q43k6b739gqmg1qf2hht3wzvt0t

I think we need to edit the parser so that when it encounters the LOG function, we call a method to look up the SqlOperator based on the SqlConformance. Similar to what looks to have been suggested for Floor/Ceil. @tanclary @julianhyde perhaps you know?

jduo avatar Mar 11 '24 23:03 jduo

No, the parser should not be making decisions about semantics. The validator (assisted by the operator table) should be doing that.

julianhyde avatar Mar 12 '24 00:03 julianhyde

No, the parser should not be making decisions about semantics. The validator (assisted by the operator table) should be doing that.

Hi,thank you for your reply. I would like to ask if there are any previous cases similar to Jira that I can learn from. I don’t have a good idea at the moment. I should try Benchao’s idea https://lists.apache.org/[email protected] , but I’m not sure if I can complete it.

caicancai avatar Mar 12 '24 01:03 caicancai

@tanclary In addition, I have to explain that currently calcite's log10(0) returns -Infinity, but many databases I tested returned NULL or errors. I am not sure whether I should modify the underlying implementation of the log function (Sqlfunctions.log) , or create a new function

caicancai avatar Mar 12 '24 01:03 caicancai

I created two corresponding subtasks because the PR code changes may be large, and I am not sure about the ln and log10 functions, so I will adapt the log function first. Thank you for your reviews and suggestions.

I'm sorry about that

caicancai avatar Mar 13 '24 02:03 caicancai