Giter Site home page Giter Site logo

impala-frontend's Introduction

impala-frontend

这个库是Impala前端库,增加语法块位置信息的功能

impala版本:cdh5.10.0-release

主要功能

  1. 通过xx.startPositionxx.endPosition得语法块的开始位置和结束位置
  2. 通过xx.subBlocks去递归遍历子语法块

安装方法

把fe文件夹替换到Impala-cdhx.x.x-release目录中,运行./buildall.sh -fe_only,编译完成后复制fe/target/impala-frontend-0.1-SNAPSHOT.jar到工程中使用

Demo:

import java_cup.runtime.ExtendSymbolFactory;
import org.apache.impala.analysis.*;

import java.io.StringReader;

public class Test {
    public static void main(String[] args) throws Exception {
        String sql = "SELECT concat(o.order_id, '2') " +
            "FROM fact_order o " +
            "LEFT JOIN dim_business d " +
            "ON o.shop_id = d.shop_id " +
            "WHERE o.order_day_key=20170415";

        SqlScanner scanner = new SqlScanner(new StringReader(sql));
        SqlParser parser = new SqlParser(scanner, new ExtendSymbolFactory(sql));
        SelectStmt selectStmt = (SelectStmt) parser.parse().value;
        SelectList selectList = selectStmt.getSelectList();
        SelectListItem selectListItem = selectList.getItems().get(0);
        // expr相当于concat(o.order_id, '2')
        Expr expr = selectListItem.getExpr();

        // 输出结果:start: 7, end: 30
        System.out.println("start: " + expr.startPosition + ", end: " + expr.endPosition);

        // 0:"concat"
        // 1: "("
        // 2: o.order_id, '2'
        // 3: ")"
        FunctionParams functionParams = (FunctionParams) expr.subBlocks.get(2);
        // 输出结果:start: 14, end: 29
        System.out.println("start: " + functionParams.startPosition + ", end: " + functionParams.endPosition);
    }
}

maven依赖:

<dependency>
    <groupId>org.apache.hive</groupId>
    <artifactId>hive-exec</artifactId>
    <version>0.14.0</version>
</dependency>

<dependency>
    <groupId>org.apache.sentry</groupId>
    <artifactId>sentry-core-model-db</artifactId>
    <version>1.5.1-cdh5.10.0</version>
    <exclusions>
        <exclusion>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>org.apache.impala</groupId>
    <artifactId>impala-frontend</artifactId>
    <version>cdh5.10.0-release</version>
    <scope>system</scope>
    <!-- 这里改成你的jar包存放的位置 -->
    <systemPath>${project.basedir}/src/main/lib/impala-frontend-0.1-SNAPSHOT.jar</systemPath>
</dependency>

impala-frontend's People

Contributors

924060929 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

xiashuijun bharos

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.