You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@trafodion.apache.org by xi...@esgyn.cn on 2018/03/10 14:35:05 UTC

答复: how to get original text for value_expression in the parser

I think you need to modify lex, the suffix is .ll file in EsgynDB.
Zhenxin.He and Wenjun.Zhu did the similar thing as you want.
You can ask them.

发送自 Windows 10 版邮件应用

发件人: Liu, Ming (Ming)
发送时间: 2018年3月10日 22:24
收件人: dev@trafodion.apache.org
主题: how to get original text for value_expression in the parser

Hi, all,

I am trying to get the text string in the parser for product 'value_experssion', but I cannot find a good way to do it for a long time without success.
Does anyone know how to do that?

Example, here is a production for function firstdayofyear:

     | TOK_FIRSTDAYOFYEAR '(' value_expression ')'
        {
                  $$ = new (PARSERHEAP()) ZZZBinderFunction(ITM_FIRSTDAYOFYEAR, $3);
                }

if the user input string for this production is "firstdayofyear ( tbl1.col1 )"
I want to get the full string as "firstdayofyear (tbl1.col1)"

So here is the code I tried but failed:
     | TOK_FIRSTDAYOFYEAR '(' value_expression ')'
        {
                                 NAString *utf8Str3 = unicodeToChar
                                   (ToTokvalPlusYYText(&$3)->yytext,
                                    ToTokvalPlusYYText(&$3)->yyleng,
                                    (CharInfo::CharSet) (
                                      ComGetNameInterfaceCharSet() // CharInfo::UTF8
                                    ),
                                    PARSERHEAP());
                NAString fullstr = "firstdayofyear ( " + *utf8Str3 + ")";
                  $$ = new (PARSERHEAP()) ZZZBinderFunction(ITM_FIRSTDAYOFYEAR, $3);
                }

utf8Str3 is a NULL pointer for "firstdayofyear (tbl1.col1) ", because a column will be parsed as an ItemExpr pointer, and ToTokvalPlusYYText failed to convert it and get correct yytext. I cannot find an example in the sqlparser.y for this, so ask help in the mail list.

The alternative way I now use is checking if utf8Str3 is NULL, if yes, then this is not what I need, since luckily in my case, the value_expression must be a function name which can always get the correct yytext. But I hope there is a better way to do this.

thanks,
Ming



Re: RE: how to get original text for value_expression in the parser

Posted by Ming Liu <li...@apache.org>.
unparse work perfectly ^_^
thanks Anoop!

RE: how to get original text for value_expression in the parser

Posted by "Liu, Ming (Ming)" <mi...@esgyn.cn>.
thanks Anoop and XiaoZhong, I will try the unparse

The purpose is: save the text string in MD tables as column's default value. When later do INSERT, parse this string to generate the runtime structure. 
To support some user required default value in table definition. For example
col1 char(10) default to_char(sysdate, 'YYYYMMDD')

So I want to save string "to_char(sysdate, 'YYYYMMDD') " in the metadata table.

Thanks,
Ming

-----Original Message-----
From: Anoop Sharma <an...@esgyn.com> 
Sent: Sunday, March 11, 2018 1:08 AM
To: dev@trafodion.apache.org
Subject: RE: how to get original text for value_expression in the parser

Is this string representation needed for display purpose or something else?

There is a virtual 'unparse' method defined on ItemExpr class which is the
base class for value_expression.
Calling that method will return the string representation by traversing over
the tree.
This method is used for creating text representation when needed.

One thing to be careful is to not overload parser step with functionality
that should preferable be done after bind step. It is also not a good idea
to refer to generated structures like yytext, yyleng etc in parser.

        // produce an ascii-version of the object (for display or saving into a file)
        virtual void unparse(NAString &result,
                       PhaseEnum phase = DEFAULT_PHASE,
                       UnparseFormatEnum form = USER_FORMAT,
                       TableDesc * tabId = NULL) const;

anoop


-----Original Message-----
From: xiaozhong.wang@esgyn.cn <xi...@esgyn.cn>
Sent: Saturday, March 10, 2018 6:35 AM
To: dev@trafodion.apache.org
Subject: 答复: how to get original text for value_expression in the parser

I think you need to modify lex, the suffix is .ll file in EsgynDB.
Zhenxin.He and Wenjun.Zhu did the similar thing as you want.
You can ask them.

发送自 Windows 10 版邮件应用

发件人: Liu, Ming (Ming)
发送时间: 2018年3月10日 22:24
收件人: dev@trafodion.apache.org<ma...@trafodion.apache.org>
主题: how to get original text for value_expression in the parser

Hi, all,

I am trying to get the text string in the parser for product 'value_experssion', but I cannot find a good way to do it for a long time without success.
Does anyone know how to do that?

Example, here is a production for function firstdayofyear:

     | TOK_FIRSTDAYOFYEAR '(' value_expression ')'
        {
                  $$ = new (PARSERHEAP()) ZZZBinderFunction(ITM_FIRSTDAYOFYEAR, $3);
                }

if the user input string for this production is "firstdayofyear ( tbl1.col1 )"
I want to get the full string as "firstdayofyear (tbl1.col1)"

So here is the code I tried but failed:
     | TOK_FIRSTDAYOFYEAR '(' value_expression ')'
        {
                                 NAString *utf8Str3 = unicodeToChar
                                   (ToTokvalPlusYYText(&$3)->yytext,
                                    ToTokvalPlusYYText(&$3)->yyleng,
                                    (CharInfo::CharSet) (
                                      ComGetNameInterfaceCharSet() // CharInfo::UTF8
                                    ),
                                    PARSERHEAP());
                NAString fullstr = "firstdayofyear ( " + *utf8Str3 + ")";
                  $$ = new (PARSERHEAP()) ZZZBinderFunction(ITM_FIRSTDAYOFYEAR, $3);
                }

utf8Str3 is a NULL pointer for "firstdayofyear (tbl1.col1) ", because a column will be parsed as an ItemExpr pointer, and ToTokvalPlusYYText failed to convert it and get correct yytext. I cannot find an example in the sqlparser.y for this, so ask help in the mail list.

The alternative way I now use is checking if utf8Str3 is NULL, if yes, then this is not what I need, since luckily in my case, the value_expression must be a function name which can always get the correct yytext. But I hope there is a better way to do this.

thanks,
Ming




RE: how to get original text for value_expression in the parser

Posted by Anoop Sharma <an...@esgyn.com>.
Is this string representation needed for display purpose or something else?

There is a virtual 'unparse' method defined on ItemExpr class which is the
base class for value_expression.
Calling that method will return the string representation by traversing over
the tree.
This method is used for creating text representation when needed.

One thing to be careful is to not overload parser step with functionality
that should preferable be done after bind step. It is also not a good idea
to refer to generated structures like yytext, yyleng etc in parser.

        // produce an ascii-version of the object (for display or saving into a file)
        virtual void unparse(NAString &result,
                       PhaseEnum phase = DEFAULT_PHASE,
                       UnparseFormatEnum form = USER_FORMAT,
                       TableDesc * tabId = NULL) const;

anoop


-----Original Message-----
From: xiaozhong.wang@esgyn.cn <xi...@esgyn.cn>
Sent: Saturday, March 10, 2018 6:35 AM
To: dev@trafodion.apache.org
Subject: 答复: how to get original text for value_expression in the parser

I think you need to modify lex, the suffix is .ll file in EsgynDB.
Zhenxin.He and Wenjun.Zhu did the similar thing as you want.
You can ask them.

发送自 Windows 10 版邮件应用

发件人: Liu, Ming (Ming)
发送时间: 2018年3月10日 22:24
收件人: dev@trafodion.apache.org<ma...@trafodion.apache.org>
主题: how to get original text for value_expression in the parser

Hi, all,

I am trying to get the text string in the parser for product 'value_experssion', but I cannot find a good way to do it for a long time without success.
Does anyone know how to do that?

Example, here is a production for function firstdayofyear:

     | TOK_FIRSTDAYOFYEAR '(' value_expression ')'
        {
                  $$ = new (PARSERHEAP()) ZZZBinderFunction(ITM_FIRSTDAYOFYEAR, $3);
                }

if the user input string for this production is "firstdayofyear ( tbl1.col1 )"
I want to get the full string as "firstdayofyear (tbl1.col1)"

So here is the code I tried but failed:
     | TOK_FIRSTDAYOFYEAR '(' value_expression ')'
        {
                                 NAString *utf8Str3 = unicodeToChar
                                   (ToTokvalPlusYYText(&$3)->yytext,
                                    ToTokvalPlusYYText(&$3)->yyleng,
                                    (CharInfo::CharSet) (
                                      ComGetNameInterfaceCharSet() // CharInfo::UTF8
                                    ),
                                    PARSERHEAP());
                NAString fullstr = "firstdayofyear ( " + *utf8Str3 + ")";
                  $$ = new (PARSERHEAP()) ZZZBinderFunction(ITM_FIRSTDAYOFYEAR, $3);
                }

utf8Str3 is a NULL pointer for "firstdayofyear (tbl1.col1) ", because a column will be parsed as an ItemExpr pointer, and ToTokvalPlusYYText failed to convert it and get correct yytext. I cannot find an example in the sqlparser.y for this, so ask help in the mail list.

The alternative way I now use is checking if utf8Str3 is NULL, if yes, then this is not what I need, since luckily in my case, the value_expression must be a function name which can always get the correct yytext. But I hope there is a better way to do this.

thanks,
Ming