calcite-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jiunn Jye Ng <jiunn...@gmail.com>
Subject Re: Parsing SQL
Date Mon, 23 Feb 2015 02:34:07 GMT
works for me. quick copy paste based on what you have provided.


import org.apache.calcite.avatica.util.Casing;
import org.apache.calcite.avatica.util.Quoting;
import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.parser.SqlParseException;
import org.apache.calcite.sql.parser.SqlParser;

public class TestSqlParser {

public static void main(String[] args) {

String sql =  "select *\n from \"foodmart\".\"sales_fact_1997\" as s\n join
\"hr\".\"emps\" as e\n on e.\"empid\" = s.\"cust_id\"";
Quoting quoting = Quoting.DOUBLE_QUOTE;
Casing unquotedCasing = Casing.TO_UPPER;
Casing quotedCasing = Casing.UNCHANGED;
SqlParser parser = SqlParser.create(sql,
SqlParser.configBuilder().setQuoting(quoting)
.setUnquotedCasing(unquotedCasing)
.setQuotedCasing(quotedCasing).build());

try {
System.out.println("Here goes");
SqlNode sqlNode = parser.parseQuery();
System.out.println ("Done Parsing:" + sqlNode);
} catch (SqlParseException e) {
e.printStackTrace();
}
}
}


On Mon, Feb 23, 2015 at 7:42 AM, Renato MarroquĂ­n Mogrovejo <
renatoj.marroquin@gmail.com> wrote:

> Hi there,
>
> I have an application that reads data from HDFS using Spark but I need to
> add specific relation filters programatically. I could do this by parsing
> the SQL string but I thought that Apache Calcite could help on this. I
> tried using this:
>
> <code>
>     private static SqlParser getSqlParser(String sql) {
>         Quoting quoting = Quoting.DOUBLE_QUOTE;
>         Casing unquotedCasing = Casing.TO_UPPER;
>         Casing quotedCasing = Casing.UNCHANGED;
>         return SqlParser.create(
>                 sql,
>                 SqlParser.configBuilder().setQuoting(quoting)
>                         .setUnquotedCasing(unquotedCasing)
>                         .setQuotedCasing(quotedCasing).build());
>
>     }
> </code>
>
> with a query like "select *\n from \"foodmart\".\"sales_fact_1997\" as s\n
> join \"hr\".\"emps\" as e\n on e.\"empid\" = s.\"cust_id\"" (borrowed from
> Calcite tests), but I get:
>
> org.apache.calcite.sql.parser.SqlParseException: Encountered "select" at
> line 1, column 1.
> Was expecting one of:
>     "+" ...
>
> Any help is highly appreciated! Thanks!
>
>
> Renato M.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message