You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hive.apache.org by liuyehan <ly...@163.com> on 2022/09/21 03:06:18 UTC

How to add some children to the abstract syntax tree AST to implement UDF encryption function

Hi,everyone 


Problem :  How to add some children to the abstract syntax tree AST to implement UDF encryption function



I want to implement a function like this, pass SQL as insert into B select ID from a --&gt; Run the insert into b select UDF (ID) from A command At present, my idea is to implement HiveSemanticAnalyzerHook preAnalyze method, now I add child nodes in this way will report an error, see the source code did not find the example, so would like to ask you, how to change the AST add child nodes?

ASTNode outerAST = new ASTNode(new CommonToken(hiveParser.tok_function, "(TOK_FUNCTION MD5 (tok_table_or_col name))");

Ast. GetChild (0). The getChild (1). The getChild (1). The getChild (0). SetChild (0, outerAST);

Thank you.



Best regards,
Liuyehan 

| |
liuyehan
|
|
lyh1067341434@163.com
|

Re: How to add some children to the abstract syntax tree AST to implement UDF encryption function

Posted by liuyehan <ly...@163.com>.
Hi,Jan Fili



Thank you for your reply. Since it is to cooperate with the customer, it must be changed in this way. The child nodes of the abstract syntax tree are added. You can't just add children through code like I did. To change the execution plan of the entire SQL?

The idea is to use the preAnalyze method to analyze the AST and change the AST to encrypt some fields.



Best regards,
Liuyehan 



| |
liuyehan
|
|
lyh1067341434@163.com
|
---- Replied Message ----
| From | Jan Fili<ja...@gmail.com> |
| Date | 9/21/2022 14:02 |
| To | <us...@hive.apache.org> |
| Subject | Re: How to add some children to the abstract syntax tree AST to implement UDF encryption function |
Just run the command internally to the UDF? Or use Map directly? 


Just as some quicker means. 


Otherwise you would need to adjust the Grammar file, rebuild and the new child will be recognized 


liuyehan <ly...@163.com> schrieb am Mi., 21. Sept. 2022, 05:06:

Hi,everyone 


Problem :  How to add some children to the abstract syntax tree AST to implement UDF encryption function



I want to implement a function like this, pass SQL as insert into B select ID from a --&gt; Run the insert into b select UDF (ID) from A command At present, my idea is to implement HiveSemanticAnalyzerHook preAnalyze method, now I add child nodes in this way will report an error, see the source code did not find the example, so would like to ask you, how to change the AST add child nodes?

ASTNode outerAST = new ASTNode(new CommonToken(hiveParser.tok_function, "(TOK_FUNCTION MD5 (tok_table_or_col name))");

Ast. GetChild (0). The getChild (1). The getChild (1). The getChild (0). SetChild (0, outerAST);

Thank you.



Best regards,
Liuyehan 

| |
liuyehan
|
|
lyh1067341434@163.com
|

Re: How to add some children to the abstract syntax tree AST to implement UDF encryption function

Posted by Jan Fili <ja...@gmail.com>.
Just run the command internally to the UDF? Or use Map directly?

Just as some quicker means.

Otherwise you would need to adjust the Grammar file, rebuild and the new
child will be recognized

liuyehan <ly...@163.com> schrieb am Mi., 21. Sept. 2022, 05:06:

> Hi,everyone
>
> Problem :  How to add some children to the abstract syntax tree AST to
> implement UDF encryption function
>
> I want to implement a function like this, pass SQL as insert into B select
> ID from a --&gt; Run the insert into b select UDF (ID) from A command At
> present, my idea is to implement HiveSemanticAnalyzerHook preAnalyze
> method, now I add child nodes in this way will report an error, see the
> source code did not find the example, so would like to ask you, how to
> change the AST add child nodes?
>
> ASTNode outerAST = new ASTNode(new CommonToken(hiveParser.tok_function,
> "(TOK_FUNCTION MD5 (tok_table_or_col name))");
>
> Ast. GetChild (0). The getChild (1). The getChild (1). The getChild (0).
> SetChild (0, outerAST);
> Thank you.
>
>
> Best regards,
> Liuyehan
> liuyehan
> lyh1067341434@163.com
>
> <https://maas.mail.163.com/dashi-web-extend/html/proSignature.html?ftlId=1&name=liuyehan&uid=lyh1067341434%40163.com&iconUrl=https%3A%2F%2Fmail-online.nosdn.127.net%2Fsma957d454002c351ecf6ffb4bd3c71fdc.jpg&items=%5B%22lyh1067341434%40163.com%22%5D>
>