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

Lai Zhou commented on CALCITE-2282:
-----------------------------------

+1.[~julianhyde] , is there a good way to solve this ?

I use a customized parser to override the createCall method of 
SqlAbstractParserImpl to activate my OperatorTable.

I think it's a typical case that respond to the Calcite's  objective: One 
planner fits all.

 
{code:java}
public class ${parser.class} extends SqlAbstractParserImpl
{
    private static final Logger LOGGER = CalciteTrace.getParserTracer();

    // Can't use quoted literal because of a bug in how JavaCC translates
    // backslash-backslash.
    private static final char BACKSLASH = 0x5c;
    private static final char DOUBLE_QUOTE = 0x22;
    private static final String DQ = DOUBLE_QUOTE + "";
    private static final String DQDQ = DQ + DQ;

    private static Metadata metadata;

    private Casing unquotedCasing;
    private Casing quotedCasing;
    private int identifierMaxLength;
    private SqlConformance conformance;

    /**
     * {@link SqlParserImplFactory} implementation for creating parser.
     */
    public static final SqlParserImplFactory FACTORY = new 
SqlParserImplFactory() {
        public SqlAbstractParserImpl getParser(Reader stream) {
            return new ${parser.class}(stream);
        }
    };

      @Override
      public SqlCall createCall(
          SqlIdentifier funName,
          SqlParserPos pos,
          SqlFunctionCategory funcType,
          SqlLiteral functionQualifier,
          SqlNode[] operands) {
        SqlOperator fun = null;

        // First, try a half-hearted resolution as a builtin function.
        // If we find one, use it; this will guarantee that we
        // preserve the correct syntax (i.e. don't quote builtin function
        /// name when regenerating SQL).
        if (funName.isSimple()) {
          final List list = new ArrayList();
          HiveSqlOperatorTable.instance().lookupOperatorOverloads(funName, 
funcType, SqlSyntax.FUNCTION, list);
          if (list.size() > 0) {
            fun = (SqlOperator) list.get(0);
          }
        }

        // Otherwise, just create a placeholder function.  Later, during
        // validation, it will be resolved into a real function reference.
        if (fun == null) {
          fun = new SqlUnresolvedFunction(funName, null, null, null, null,
              funcType);
        }

        return fun.createCall(functionQualifier, pos, operands);
    }
{code}
 

> Allow OperatorTable to be pluggable in the parser
> -------------------------------------------------
>
>                 Key: CALCITE-2282
>                 URL: https://issues.apache.org/jira/browse/CALCITE-2282
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>            Reporter: Sudheesh Katkam
>            Priority: Major
>         Attachments: CALCITE-2282.patch.txt
>
>
> SqlAbstractParserImpl [hardcodes OperatorTable to 
> SqlStdOperatorTable|https://github.com/apache/calcite/blob/8327e674e7f0a768d124fa37fd75cda4b8a35bb6/core/src/main/java/org/apache/calcite/sql/parser/SqlAbstractParserImpl.java#L334|https://github.com/apache/calcite/blob/8327e674e7f0a768d124fa37fd75cda4b8a35bb6/core/src/main/java/org/apache/calcite/sql/parser/SqlAbstractParserImpl.java#L334].
>  Make this pluggable via a protected method.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to