All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alibaba.druid.sql.dialect.blink.parser.BlinkExprParser Maven / Gradle / Ivy

There is a newer version: 1.2.23
Show newest version
package com.alibaba.druid.sql.dialect.blink.parser;

import com.alibaba.druid.sql.parser.Lexer;
import com.alibaba.druid.sql.parser.SQLExprParser;
import com.alibaba.druid.sql.parser.SQLParserFeature;
import com.alibaba.druid.util.FnvHash;

import java.util.Arrays;

public class BlinkExprParser extends SQLExprParser {
    private static final String[] AGGREGATE_FUNCTIONS;
    private static final long[] AGGREGATE_FUNCTIONS_CODES;

    static {
        String[] strings = {"AVG", "COUNT", "MAX", "MIN", "STDDEV", "SUM", "ROW_NUMBER",
                "ROWNUMBER"};
        AGGREGATE_FUNCTIONS_CODES = FnvHash.fnv1a_64_lower(strings, true);
        AGGREGATE_FUNCTIONS = new String[AGGREGATE_FUNCTIONS_CODES.length];
        for (String str : strings) {
            long hash = FnvHash.fnv1a_64_lower(str);
            int index = Arrays.binarySearch(AGGREGATE_FUNCTIONS_CODES, hash);
            AGGREGATE_FUNCTIONS[index] = str;
        }
    }

    public BlinkExprParser(String sql) {
        this(new BlinkLexer(sql));
        this.lexer.nextToken();
    }

    public BlinkExprParser(String sql, SQLParserFeature... features) {
        this(new BlinkLexer(sql, features));
        this.lexer.nextToken();
    }

    public BlinkExprParser(Lexer lexer) {
        super(lexer);
        this.aggregateFunctions = AGGREGATE_FUNCTIONS;
        this.aggregateFunctionHashCodes = AGGREGATE_FUNCTIONS_CODES;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy