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

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

package com.shulie.druid.sql.dialect.blink.parser;

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

import java.util.Arrays;

public class BlinkExprParser extends SQLExprParser {
    private final static String[] AGGREGATE_FUNCTIONS;
    private final static 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