You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by Nagarajan Chinnasamy <na...@gmail.com> on 2017/01/14 13:52:50 UTC
Re: Invoking UDF that doesn't have parameters without paranthesis [Resolved]
Success :) I could invoke SESSION_ID without parenthesis. Following did the
trick:
1. In DrillSqlOperator, overriding getSyntax method to return
SqlSyntax.FUNCTION_ID
2. In DrillOperatorTable, adding operator when SqlSyntax is (FUNCTION ||
FUNCTION_ID)
Thanks for your inputs.
Best Regards,
Nagu.
On Fri, Jan 13, 2017 at 1:30 AM, Nagarajan Chinnasamy <
nagarajanchinnasamy@gmail.com> wrote:
> The CURRENT_DATE is constructed using the SqlFunction constructor:
>
> public SqlFunction(String name,
> SqlKind kind,
> SqlReturnTypeInference returnTypeInference,
> SqlOperandTypeInference operandTypeInference,
> SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory
> category)
>
> Whereas the DrillSqlOperator (derived from SqlFunction) is using the
> following constructor variation:
>
> super(new SqlIdentifier(name, SqlParserPos.ZERO),
> sqlReturnTypeInference,
> null,
> Checker.getChecker(argCountMin, argCountMax), //
> SqlOperandTypeChecker
> null,
> SqlFunctionCategory.USER_DEFINED_FUNCTION);
>
> In DrillSqlOperator (derived from SqlFunction), I tried:
>
> 1. setting OperandTypeChecker value to OperandTypes.NILADIC
> 2. Overriding getSyntax method to return SqlSyntax.FUNCTION_ID
>
> Both of the above did not help.
>
> When invoked without parenthesis, I get the following exception:
>
> 0: jdbc:drill:zk=local> select session_id from (values(1));
> Jan 13, 2017 12:58:00 AM org.apache.calcite.sql.validate.SqlValidatorException
> <init>
> SEVERE: org.apache.calcite.sql.validate.SqlValidatorException: Column
> 'session_id' not found in any table
> Jan 13, 2017 12:58:00 AM org.apache.calcite.runtime.CalciteException
> <init>
> SEVERE: org.apache.calcite.runtime.CalciteContextException: From line 1,
> column 8 to line 1, column 17: Column 'session_id' not found in any table
> Error: VALIDATION ERROR: From line 1, column 8 to line 1, column 17:
> Column 'session_id' not found in any table
>
> Looking for your inputs to resolve this issue...
>
> Best Regards,
> Nagu.
>
> On Wed, Dec 21, 2016 at 1:20 AM, Jinfeng Ni <jn...@apache.org> wrote:
>
>> For function without parentheses, Calcite validator checks a
>> SqlIdentifier against validator's operatorTable. If such identifier
>> appears in the operatorTable, the SqlIdentifier is converted to a
>> SqlCall. For your use case, you probably need add such function into
>> operatorTable. You may follow Julian's suggestion of looking at
>> CURRENT_DATE function.
>>
>> 1. https://github.com/apache/calcite/blob/master/core/src/main/
>> java/org/apache/calcite/sql/SqlIdentifier.java#L302-L308
>>
>> On Tue, Dec 20, 2016 at 11:19 AM, Julian Hyde <jh...@apache.org> wrote:
>> > I don’t think you need to change the parser, just the validator (the
>> changes to SqlOperator.getSyntax I described already). The parser will
>> parse an identifier, and the validator will recognize that it is a call to
>> a function with no arguments.
>> >
>> > Unless Drill has diverged further from Calcite than I imagine it has.
>> >
>> > Julian
>> >
>> >
>> >> On Dec 20, 2016, at 10:51 AM, Sudheesh Katkam <sk...@maprtech.com>
>> wrote:
>> >>
>> >> I do not know the exact answer.
>> >>
>> >> Quite likely the Calcite parser needs to be changed, this blob:
>> >>
>> >> https://github.com/apache/calcite/blob/master/core/src/main/
>> codegen/templates/Parser.jj#L4765 <https://github.com/apache/cal
>> cite/blob/master/core/src/main/codegen/templates/Parser.jj#L4765>
>> >>
>> >> Drill extends the Calcite parser, not sure if the change can be made
>> here:
>> >>
>> >> https://github.com/apache/drill/blob/master/exec/java-exec/
>> src/main/codegen/includes/parserImpls.ftl <https://github.com/apache/dri
>> ll/blob/master/exec/java-exec/src/main/codegen/includes/parserImpls.ftl>
>> >>
>> >> Thank you,
>> >> Sudheesh
>> >>
>> >>> On Dec 19, 2016, at 3:00 PM, Nagarajan Chinnasamy <
>> nagarajanchinnasamy@gmail.com> wrote:
>> >>>
>> >>> Hi Julian Hyde,
>> >>>
>> >>> Thanks for your response. I am looking for the Drill way of doing it.
>> >>>
>> >>> In fact I have coded session_id function exactly as one of other
>> >>> ContextFunctions of Drill. I seem to be missing something :(
>> >>>
>> >>>
>> >>>
>> >>>
>> >>> Best Regards,
>> >>> Nagu.
>> >>>
>> >>> On Mon, Dec 19, 2016 at 1:30 PM, Nagarajan Chinnasamy <
>> >>> nagarajanchinnasamy@gmail.com> wrote:
>> >>>
>> >>>> Hi,
>> >>>>
>> >>>> Am developing a UDF called SESSION_ID as detailed in issue:
>> >>>>
>> >>>> https://issues.apache.org/jira/browse/DRILL-5043
>> >>>>
>> >>>> It does not take any input parameters. Now, I can only invoke it
>> using
>> >>>> parenthesis as in:
>> >>>>
>> >>>> SELECT SESSION_ID() FROM (Values(1));
>> >>>>
>> >>>> I would like to know what do I need to do if I need to invoke it
>> without
>> >>>> paranthesis like:
>> >>>>
>> >>>> SELECT SESSION_ID FROM (Values(1));
>> >>>>
>> >>>> Appreciate your input.
>> >>>>
>> >>>> Best Regards,
>> >>>> Nagu.
>> >>>>
>> >>
>> >
>>
>
>
Re: Invoking UDF that doesn't have parameters without paranthesis
[Resolved]
Posted by Paul Rogers <pr...@mapr.com>.
Congrats! Nice job!
- Paul
> On Jan 14, 2017, at 5:52 AM, Nagarajan Chinnasamy <na...@gmail.com> wrote:
>
> Success :) I could invoke SESSION_ID without parenthesis. Following did the
> trick:
>
> 1. In DrillSqlOperator, overriding getSyntax method to return
> SqlSyntax.FUNCTION_ID
> 2. In DrillOperatorTable, adding operator when SqlSyntax is (FUNCTION ||
> FUNCTION_ID)
>
> Thanks for your inputs.
>
> Best Regards,
> Nagu.
>
> On Fri, Jan 13, 2017 at 1:30 AM, Nagarajan Chinnasamy <
> nagarajanchinnasamy@gmail.com> wrote:
>
>> The CURRENT_DATE is constructed using the SqlFunction constructor:
>>
>> public SqlFunction(String name,
>> SqlKind kind,
>> SqlReturnTypeInference returnTypeInference,
>> SqlOperandTypeInference operandTypeInference,
>> SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory
>> category)
>>
>> Whereas the DrillSqlOperator (derived from SqlFunction) is using the
>> following constructor variation:
>>
>> super(new SqlIdentifier(name, SqlParserPos.ZERO),
>> sqlReturnTypeInference,
>> null,
>> Checker.getChecker(argCountMin, argCountMax), //
>> SqlOperandTypeChecker
>> null,
>> SqlFunctionCategory.USER_DEFINED_FUNCTION);
>>
>> In DrillSqlOperator (derived from SqlFunction), I tried:
>>
>> 1. setting OperandTypeChecker value to OperandTypes.NILADIC
>> 2. Overriding getSyntax method to return SqlSyntax.FUNCTION_ID
>>
>> Both of the above did not help.
>>
>> When invoked without parenthesis, I get the following exception:
>>
>> 0: jdbc:drill:zk=local> select session_id from (values(1));
>> Jan 13, 2017 12:58:00 AM org.apache.calcite.sql.validate.SqlValidatorException
>> <init>
>> SEVERE: org.apache.calcite.sql.validate.SqlValidatorException: Column
>> 'session_id' not found in any table
>> Jan 13, 2017 12:58:00 AM org.apache.calcite.runtime.CalciteException
>> <init>
>> SEVERE: org.apache.calcite.runtime.CalciteContextException: From line 1,
>> column 8 to line 1, column 17: Column 'session_id' not found in any table
>> Error: VALIDATION ERROR: From line 1, column 8 to line 1, column 17:
>> Column 'session_id' not found in any table
>>
>> Looking for your inputs to resolve this issue...
>>
>> Best Regards,
>> Nagu.
>>
>> On Wed, Dec 21, 2016 at 1:20 AM, Jinfeng Ni <jn...@apache.org> wrote:
>>
>>> For function without parentheses, Calcite validator checks a
>>> SqlIdentifier against validator's operatorTable. If such identifier
>>> appears in the operatorTable, the SqlIdentifier is converted to a
>>> SqlCall. For your use case, you probably need add such function into
>>> operatorTable. You may follow Julian's suggestion of looking at
>>> CURRENT_DATE function.
>>>
>>> 1. https://github.com/apache/calcite/blob/master/core/src/main/
>>> java/org/apache/calcite/sql/SqlIdentifier.java#L302-L308
>>>
>>> On Tue, Dec 20, 2016 at 11:19 AM, Julian Hyde <jh...@apache.org> wrote:
>>>> I don’t think you need to change the parser, just the validator (the
>>> changes to SqlOperator.getSyntax I described already). The parser will
>>> parse an identifier, and the validator will recognize that it is a call to
>>> a function with no arguments.
>>>>
>>>> Unless Drill has diverged further from Calcite than I imagine it has.
>>>>
>>>> Julian
>>>>
>>>>
>>>>> On Dec 20, 2016, at 10:51 AM, Sudheesh Katkam <sk...@maprtech.com>
>>> wrote:
>>>>>
>>>>> I do not know the exact answer.
>>>>>
>>>>> Quite likely the Calcite parser needs to be changed, this blob:
>>>>>
>>>>> https://github.com/apache/calcite/blob/master/core/src/main/
>>> codegen/templates/Parser.jj#L4765 <https://github.com/apache/cal
>>> cite/blob/master/core/src/main/codegen/templates/Parser.jj#L4765>
>>>>>
>>>>> Drill extends the Calcite parser, not sure if the change can be made
>>> here:
>>>>>
>>>>> https://github.com/apache/drill/blob/master/exec/java-exec/
>>> src/main/codegen/includes/parserImpls.ftl <https://github.com/apache/dri
>>> ll/blob/master/exec/java-exec/src/main/codegen/includes/parserImpls.ftl>
>>>>>
>>>>> Thank you,
>>>>> Sudheesh
>>>>>
>>>>>> On Dec 19, 2016, at 3:00 PM, Nagarajan Chinnasamy <
>>> nagarajanchinnasamy@gmail.com> wrote:
>>>>>>
>>>>>> Hi Julian Hyde,
>>>>>>
>>>>>> Thanks for your response. I am looking for the Drill way of doing it.
>>>>>>
>>>>>> In fact I have coded session_id function exactly as one of other
>>>>>> ContextFunctions of Drill. I seem to be missing something :(
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> Best Regards,
>>>>>> Nagu.
>>>>>>
>>>>>> On Mon, Dec 19, 2016 at 1:30 PM, Nagarajan Chinnasamy <
>>>>>> nagarajanchinnasamy@gmail.com> wrote:
>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> Am developing a UDF called SESSION_ID as detailed in issue:
>>>>>>>
>>>>>>> https://issues.apache.org/jira/browse/DRILL-5043
>>>>>>>
>>>>>>> It does not take any input parameters. Now, I can only invoke it
>>> using
>>>>>>> parenthesis as in:
>>>>>>>
>>>>>>> SELECT SESSION_ID() FROM (Values(1));
>>>>>>>
>>>>>>> I would like to know what do I need to do if I need to invoke it
>>> without
>>>>>>> paranthesis like:
>>>>>>>
>>>>>>> SELECT SESSION_ID FROM (Values(1));
>>>>>>>
>>>>>>> Appreciate your input.
>>>>>>>
>>>>>>> Best Regards,
>>>>>>> Nagu.
>>>>>>>
>>>>>
>>>>
>>>
>>
>>