Code Monkey home page Code Monkey logo

sql-parser's Introduction

FoundationDB SQL Parser

Overview

The FoundationDB SQL Parser is a complete, production-quality Java parser for the SQL language. It defines the SQL grammar as implemented by the FoundationDB SQL Layer but can be used independently. It is derived from the Apache Derby parser.

Building From Source

Maven is used to build, test and deploy.

Run tests and build jars:

$ mvn package

The resulting jar files are in target/.

Generate the documentation:

$ mvn javadoc:javadoc

The resulting HTML files are in target/site/apidocs/.

Using From Maven

The SQL Parser is in the standard Maven Central repository. Any Maven based project can use it directly by adding the appropriate entries to the dependencies section of its pom.xml file:

<dependencies>
  <dependency>
    <groupId>com.foundationdb</groupId>
    <artifactId>fdb-sql-parser</artifactId>
    <version>1.3.0</version>
  </dependency>
</dependencies>

Using From Binaries

Packaged jars can be downloaded directly from the Releases page and extracted using tar or unzip.

Working With The SQL Parser

A simple example:

import com.foundationdb.sql.parser.SQLParser;
import com.foundationdb.sql.parser.StatementNode;

public class ParserHello {
    public static void main(String[] args) throws Exception {
        SQLParser parser = new SQLParser();
        for(String s : args) {
            StatementNode stmt = parser.parseStatement(s);
            stmt.treePrint();
        }
    }
}

A new SQLParser is instantiated and each command line argument is parsed and printed to standard output. The result is a debug dump of all nodes in the underlying Abstract Syntax Tree. More advanced usages will generally parse a statement and then pass a custom Visitor to the accept() method.

To try the example from the command line, copy the code into a file named ParserHello.java. Then compile and run it, making sure to include the parser in the classpath.

Compile:

$ javac -cp fdb-sql-parser-1.3.0.jar ParserHello.java

Run (output trimmed):

$ javac -cp fdb-sql-parser-1.3.0.jar:. ParserHello "SELECT a FROM b"
com.foundationdb.sql.parser.CursorNode@5889dee2
statementType: SELECT
resultSet:
    com.foundationdb.sql.parser.SelectNode@4387f4d7
    resultColumns:
        [0]:
        com.foundationdb.sql.parser.ResultColumn@5123968
        name: a
        expression:
            com.foundationdb.sql.parser.ColumnReference@6f76dd71
            columnName: a
    fromList:
        [0]:
        com.foundationdb.sql.parser.FromBaseTable@18317b1d
        tableName: b

Contributing

  1. Fork
  2. Branch
  3. Commit
  4. Pull Request

Thanks! Please make sure any changes come with new tests.

Contact

License

Apache License, Version 2.0 Copyright (c) 2012-2014 FoundationDB, LLC It is free software and may be redistributed under the terms specified in the LICENSE.xt and NOTICE files.

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.