[ 
https://issues.apache.org/jira/browse/HIVE-23182?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17081627#comment-17081627
 ] 

David Mollitor edited comment on HIVE-23182 at 4/12/20, 3:52 AM:
-----------------------------------------------------------------

I created this JIRA based on a support case in the Cloudera/Hortonworks 
community forums.

I just stumbled across the answer to this working on something seemingly 
unrelated.

The user is experiencing this issue because, for masking, the query is parsed 
by ANTLR, manipulated to mask the appropriate values, and then passed through 
the Hive ANTLR SQL parser to be processed again. However, it fails the second 
pass through the parser because there is a feature called 
{{hive.support.quoted.identifiers}}. This feature is enabled in HS2 by default 
and it tells Hive if it should accept (or reject) values wrapped in backticks 
(or quotes). When the query is parsed the first time, the flag is correctly 
passed from the user's session context, so table names with quotes are handled 
successfully. However, the session context (and therefore this flag) is not 
provided to the parser the second time around and therefore the parser rejects 
the quoted IDs. This is because, if no context is provided, the default 
behavior becomes "false".
{code:java|title=HiveLexer.g}
  public void setHiveConf(Configuration hiveConf) {
    this.hiveConf = hiveConf;
  }
  
  protected boolean allowQuotedId() {
    if(hiveConf == null){
      // This line here: No context provided? Feature is disable.
      return false;
    }
    String supportedQIds = HiveConf.getVar(hiveConf, 
HiveConf.ConfVars.HIVE_QUOTEDID_SUPPORT);
    return !"none".equals(supportedQIds);
  }
{code}


was (Author: belugabehr):
I created this JIRA based on a support case in the Cloudera/Hortonworks 
community forums.

I just stumbled across the answer to this.

The user is experiencing and issue because, for masking, the query is 
manipulated to mask the appropriate values and then passed through the Hive 
ANTLR SQL parser to be processed again.  However, it fails because there is a 
feature called {{hive.support.quoted.identifiers}}.  This feature is enabled by 
default, and it allows the original query to be parsed correctly.  However, 
this flag (via the session context) is not provided to the parser the second 
time around and therefore the parser mishandles the backticks.  If no context 
is provided, the default behavior becomes "false".

{code:java|title=HiveLexer.g}
  public void setHiveConf(Configuration hiveConf) {
    this.hiveConf = hiveConf;
  }
  
  protected boolean allowQuotedId() {
    if(hiveConf == null){
      return false;
    }
    String supportedQIds = HiveConf.getVar(hiveConf, 
HiveConf.ConfVars.HIVE_QUOTEDID_SUPPORT);
    return !"none".equals(supportedQIds);
  }
{code}

> Semantic Exception: rule Identifier failed predicate allowQuotedId
> ------------------------------------------------------------------
>
>                 Key: HIVE-23182
>                 URL: https://issues.apache.org/jira/browse/HIVE-23182
>             Project: Hive
>          Issue Type: Improvement
>            Reporter: David Mollitor
>            Priority: Major
>         Attachments: Querying a Hive Table (via Hiveserver2) with Colum... - 
> Cloudera Community.pdf
>
>
> Querying a Hive Table (via Hiveserver2) with Column Masking enabled via 
> Ranger Hive Plugin returns with an error.
> {code:none}
> [42000]: Error while compiling statement: FAILED: SemanticException 
> org.apache.hadoop.hive.ql.parse.ParseException: line 1:62 rule Identifier 
> failed predicate: {allowQuotedId()}? line 1:74 rule Identifier failed 
> predicate: {allowQuotedId()}? line 1:94 rule Identifier failed predicate: 
> {allowQuotedId()}? line 1:117 rule Identifier failed predicate: 
> {allowQuotedId()}?
> {code}
> https://community.cloudera.com/t5/Support-Questions/Querying-a-Hive-Table-via-Hiveserver2-with-Column-Masking/td-p/167260



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to