[Solved] ANTRL compiles the HiveLexer.g file and reports an error syntax error: antlr: NoViableAltException(@[])

Table of Contents

Project scene:

Problem Description

Cause Analysis:

solution:


Project Scenario:

The need to obtain data blood relationship by programming is not common for data warehouses. Only when the scale of data reaches a large level, or the number of reports with complex data production relationships increases to a large degree, separate data blood relationship work is necessary. .
Manual identification and management is more cost-effective until scale is reached.

antlr refers to an open-source parser that can automatically generate a syntax tree based on input and display it visually. ANTLR-Another Tool for Language Recognition, its predecessor is PCCTS, which provides a recognizer (recognizer), compiler (parser) for languages including Java, C++, C# to automatically construct custom languages through grammar descriptions ) and interpreter (translator) framework. There are multiple versions of antlr v2 v3 v4 coexisting, most Chinese documents are v2, hive 1.1.0 version mentions antlr 3.4 in the comments. ANTLR combines the above, which allows us to define lexical rules for identifying streams of characters and parsing rules for interpreting streams of tokens. ANTLR will then automatically generate the corresponding lexer/parser based on the user-supplied grammar file. Users can use them to compile the input text and convert it into other forms (such as AST-Abstract Syntax Tree, abstract syntax tree).

Use ANTLR3.5.2 to parse HiveLexer.g in the source code grammar file of Hivesql, put the code:

@lexer::header {
package org.apache.hadoop.hive.ql.parse

import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.hive.conf.HiveConf
}

@lexer::members {
  private Configuration hiveConf
  
  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)
  }
}

This paragraph needs to be commented so that JAVA compiled with ANTLR does not have this package.

Problem description

After commenting out this section with /** */, it is still compiled and an error is found:

[10:58:10] error(100): HiveLexer.g:42:1: syntax error: antlr: NoViableAltException(9@[])
[10:58:10] error(100): HiveLexer.g:42:2: syntax error: antlr: NoViableAltException(49@[])
[10:58:10] error(100): HiveLexer.g:42:7: syntax error: antlr: MissingTokenException(inserted [@-1,0:0='<missing ACTION>',<4>, 42:6] at :)
[10:58:10] error(100): HiveLexer.g:42:8: syntax error: antlr: NoViableAltException(22@[])
[10:58:10] error(100): HiveLexer.g:42:9: syntax error: antlr: NoViableAltException(80@[])
[10:58:10] error(100): HiveLexer.g:42:9: syntax error: antlr: NoViableAltException(80@[])
[10:58:10] error(100): HiveLexer.g:47:1: syntax error: antlr: MissingTokenException(inserted [@-1,0:0='<missing SEMI>',<82>, 47:0] at KW_TRUE)

Cause Analysis:

Query data discovery

The ‘;’ in the comment is used as a terminator, which produces an error

Stepping on the pit guide: Uncle’s experience sharing (78) hive query error NoViableAltException – Mr. Craftsman – Blog Park

Hive split semicolon problem

hive error NoViableAltException

Solution:

Delete all the original annotation documents or delete any of them.

problem solved.