Skip to content

[CALCITE-1882] Can't obtain the user defined aggregate function such …#502

Closed
yuqi1129 wants to merge 1 commit intoapache:masterfrom
yuqi1129:#1882
Closed

[CALCITE-1882] Can't obtain the user defined aggregate function such …#502
yuqi1129 wants to merge 1 commit intoapache:masterfrom
yuqi1129:#1882

Conversation

@yuqi1129
Copy link

…as sum,avg by calcite

boolean requiresOrder, boolean requiresOver, RelDataTypeFactory typeFactory) {
super(Util.last(opName.names), opName, SqlKind.OTHER_FUNCTION,
super(Util.last(opName.names), opName, SqlKind.getSqlKindByName(opName.names.get(0)) != null
? SqlKind.valueOf(opName.names.get(0)) : SqlKind.OTHER_FUNCTION,
Copy link
Contributor

@vlsi vlsi Jul 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is the right approach. What you do is you make "user-defined SUM function" to be treated as standard SUM function without giving a single check on the actual implementation.

That might trigger some optimization rules that alter results. For instance, Calcite could replace user-defined AVG(...) with standard SUM(...)/COUNT(...).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just want to defined a user-defind agg function with the name SUM, for example, add a sum function of String type, however, the sql kind of this function is other function, which will be filtered when find the name of SUM, i can't find a better solution than this, if you have any idea about this, do not hesitate to help.
By the way, I am not very clear about your answer " without giving a single check on the actual implementation", could you explain it in detail ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @vlsi. It's OK to have a UDAF with the same name as a built-in, but it's not OK for it to impersonate it by taking on its SqlKind value.

What happens if you leave its SqlKind as OTHER_FUNCTION?

Copy link
Author

@yuqi1129 yuqi1129 Jul 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@julianhyde @vlsi .I see, if this is not OK, i can change another method. The reason that causes this problem is that in parser phase, the parser directly convert 'SUM' to SqlSumAggFunction not SqlUnresolvedFuntion by name and at this time user-defined aggregate function has not been registered. this should be done in the validate phase as at this time converting 'Sum' to SqlSumAggFunction will cause calcite filters all function that is not SqlKind.SUM like user-defined aggregate funcion. Converting in the early phase may accelerate the validate phase later, but it will omit the user-defined aggregate function, which will lead validator can't find function.
My resolution:
Method of createCall in SqlAbstractParserImpl.java directly returns SqlUnresolvedFunction not a clear specific function like SqlSumAggFunction. But if do like this, hundreds of test case fail as createCall has changed and sql changed greatly after parser. this is quite troublesome.
Is that OK? advice is appreciate, thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vlsi vlsi added help wanted returned-with-feedback There are review comments (in JIRA and/or in GitHub) to be implemented before merging the PR discussion-in-jira There's open discussion in JIRA to be resolved before proceeding with the PR labels Jan 8, 2019
@zabetak
Copy link
Member

zabetak commented Jul 23, 2019

I have the impression that after merging #1205 this PR is obsolete. If nobody objects I will close this PR and proceed on doing the same to the JIRA case.

@zabetak zabetak closed this Jul 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

discussion-in-jira There's open discussion in JIRA to be resolved before proceeding with the PR help wanted returned-with-feedback There are review comments (in JIRA and/or in GitHub) to be implemented before merging the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants