You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Arash Bizhan zadeh <ar...@gmail.com> on 2021/12/16 19:11:24 UTC

Creating a parser for Big query

Hi,
I am trying to create a parser to parse big query statements like this -
this is kotlin btw:

val sqlParserConfig = BigQuerySqlDialect(
BigQuerySqlDialect.DEFAULT_CONTEXT.withDatabaseProduct(SqlDialect.DatabaseProduct.BIG_QUERY)).configureParser(SqlParser.config()
      .withParserFactory(SqlBabelParserImpl.FACTORY)

      .withConformance(SqlConformanceEnum.BIG_QUERY))
    val parser = SqlParser.create(str, sqlParserConfig)

but the resulting parser seems not to understand BQ specific things like
the `IF` function.

How can I properly construct a SqlParser?

Re: Creating a parser for Big query

Posted by Arash Bizhan zadeh <ar...@gmail.com>.
In the documentation section -
https://calcite.apache.org/docs/reference.html - in "Dialect Specific
Operator" I can see that "IF" is listed for Big-Query.  Based on this I
assumed that it should be supported out of the box without extentind the
parser.
It says that I need to specify a "fun" variable in the connection string.
As I am not really using a connection string, I am not sure how to create a
proper parser

On Fri, Dec 17, 2021 at 12:35 PM Maxim Gramin <mg...@querifylabs.com>
wrote:

> It looks like the parser needs to be extended
> https://calcite.apache.org/docs/adapter.html#extending-the-parser
>
> On Fri, Dec 17, 2021 at 5:34 PM Arash Bizhan zadeh <ar...@gmail.com>
> wrote:
>
> > This is my test query
> >
> > SELECT  IF(CAST(age as numeric) < 0.5, name, last_name) as customer_name
> > FROM 307320.test_dataset.customers
> >
> >
> >
> > On Fri, Dec 17, 2021 at 5:47 AM Maxim Gramin <mg...@querifylabs.com>
> > wrote:
> >
> > > Can you show the query? I don't see this one.
> > >
> > > On Thu, Dec 16, 2021 at 10:12 PM Arash Bizhan zadeh <arashbi@gmail.com
> >
> > > wrote:
> > >
> > > > Hi,
> > > > I am trying to create a parser to parse big query statements like
> this
> > -
> > > > this is kotlin btw:
> > > >
> > > > val sqlParserConfig = BigQuerySqlDialect(
> > > >
> > > >
> > >
> >
> BigQuerySqlDialect.DEFAULT_CONTEXT.withDatabaseProduct(SqlDialect.DatabaseProduct.BIG_QUERY)).configureParser(SqlParser.config()
> > > >       .withParserFactory(SqlBabelParserImpl.FACTORY)
> > > >
> > > >       .withConformance(SqlConformanceEnum.BIG_QUERY))
> > > >     val parser = SqlParser.create(str, sqlParserConfig)
> > > >
> > > > but the resulting parser seems not to understand BQ specific things
> > like
> > > > the `IF` function.
> > > >
> > > > How can I properly construct a SqlParser?
> > > >
> > >
> >
>

Re: Creating a parser for Big query

Posted by Arash Bizhan zadeh <ar...@gmail.com>.
I thought I was already using Babel parser
-  .withParserFactory(SqlBabelParserImpl.FACTORY) . Care to give me a code
snippet?

On Fri, Dec 17, 2021 at 2:45 PM Julian Hyde <jh...@gmail.com> wrote:

> Or use Babel parser.
>
> > On Dec 17, 2021, at 9:35 AM, Maxim Gramin <mg...@querifylabs.com>
> wrote:
> >
> > It looks like the parser needs to be extended
> > https://calcite.apache.org/docs/adapter.html#extending-the-parser
> >
> > On Fri, Dec 17, 2021 at 5:34 PM Arash Bizhan zadeh <ar...@gmail.com>
> > wrote:
> >
> >> This is my test query
> >>
> >> SELECT  IF(CAST(age as numeric) < 0.5, name, last_name) as customer_name
> >> FROM 307320.test_dataset.customers
> >>
> >>
> >>
> >> On Fri, Dec 17, 2021 at 5:47 AM Maxim Gramin <mg...@querifylabs.com>
> >> wrote:
> >>
> >>> Can you show the query? I don't see this one.
> >>>
> >>> On Thu, Dec 16, 2021 at 10:12 PM Arash Bizhan zadeh <arashbi@gmail.com
> >
> >>> wrote:
> >>>
> >>>> Hi,
> >>>> I am trying to create a parser to parse big query statements like this
> >> -
> >>>> this is kotlin btw:
> >>>>
> >>>> val sqlParserConfig = BigQuerySqlDialect(
> >>>>
> >>>>
> >>>
> >>
> BigQuerySqlDialect.DEFAULT_CONTEXT.withDatabaseProduct(SqlDialect.DatabaseProduct.BIG_QUERY)).configureParser(SqlParser.config()
> >>>>      .withParserFactory(SqlBabelParserImpl.FACTORY)
> >>>>
> >>>>      .withConformance(SqlConformanceEnum.BIG_QUERY))
> >>>>    val parser = SqlParser.create(str, sqlParserConfig)
> >>>>
> >>>> but the resulting parser seems not to understand BQ specific things
> >> like
> >>>> the `IF` function.
> >>>>
> >>>> How can I properly construct a SqlParser?
> >>>>
> >>>
> >>
>
>

Re: Creating a parser for Big query

Posted by Julian Hyde <jh...@gmail.com>.
Or use Babel parser.

> On Dec 17, 2021, at 9:35 AM, Maxim Gramin <mg...@querifylabs.com> wrote:
> 
> It looks like the parser needs to be extended
> https://calcite.apache.org/docs/adapter.html#extending-the-parser
> 
> On Fri, Dec 17, 2021 at 5:34 PM Arash Bizhan zadeh <ar...@gmail.com>
> wrote:
> 
>> This is my test query
>> 
>> SELECT  IF(CAST(age as numeric) < 0.5, name, last_name) as customer_name
>> FROM 307320.test_dataset.customers
>> 
>> 
>> 
>> On Fri, Dec 17, 2021 at 5:47 AM Maxim Gramin <mg...@querifylabs.com>
>> wrote:
>> 
>>> Can you show the query? I don't see this one.
>>> 
>>> On Thu, Dec 16, 2021 at 10:12 PM Arash Bizhan zadeh <ar...@gmail.com>
>>> wrote:
>>> 
>>>> Hi,
>>>> I am trying to create a parser to parse big query statements like this
>> -
>>>> this is kotlin btw:
>>>> 
>>>> val sqlParserConfig = BigQuerySqlDialect(
>>>> 
>>>> 
>>> 
>> BigQuerySqlDialect.DEFAULT_CONTEXT.withDatabaseProduct(SqlDialect.DatabaseProduct.BIG_QUERY)).configureParser(SqlParser.config()
>>>>      .withParserFactory(SqlBabelParserImpl.FACTORY)
>>>> 
>>>>      .withConformance(SqlConformanceEnum.BIG_QUERY))
>>>>    val parser = SqlParser.create(str, sqlParserConfig)
>>>> 
>>>> but the resulting parser seems not to understand BQ specific things
>> like
>>>> the `IF` function.
>>>> 
>>>> How can I properly construct a SqlParser?
>>>> 
>>> 
>> 


Re: Creating a parser for Big query

Posted by Maxim Gramin <mg...@querifylabs.com>.
It looks like the parser needs to be extended
https://calcite.apache.org/docs/adapter.html#extending-the-parser

On Fri, Dec 17, 2021 at 5:34 PM Arash Bizhan zadeh <ar...@gmail.com>
wrote:

> This is my test query
>
> SELECT  IF(CAST(age as numeric) < 0.5, name, last_name) as customer_name
> FROM 307320.test_dataset.customers
>
>
>
> On Fri, Dec 17, 2021 at 5:47 AM Maxim Gramin <mg...@querifylabs.com>
> wrote:
>
> > Can you show the query? I don't see this one.
> >
> > On Thu, Dec 16, 2021 at 10:12 PM Arash Bizhan zadeh <ar...@gmail.com>
> > wrote:
> >
> > > Hi,
> > > I am trying to create a parser to parse big query statements like this
> -
> > > this is kotlin btw:
> > >
> > > val sqlParserConfig = BigQuerySqlDialect(
> > >
> > >
> >
> BigQuerySqlDialect.DEFAULT_CONTEXT.withDatabaseProduct(SqlDialect.DatabaseProduct.BIG_QUERY)).configureParser(SqlParser.config()
> > >       .withParserFactory(SqlBabelParserImpl.FACTORY)
> > >
> > >       .withConformance(SqlConformanceEnum.BIG_QUERY))
> > >     val parser = SqlParser.create(str, sqlParserConfig)
> > >
> > > but the resulting parser seems not to understand BQ specific things
> like
> > > the `IF` function.
> > >
> > > How can I properly construct a SqlParser?
> > >
> >
>

Re: Creating a parser for Big query

Posted by Arash Bizhan zadeh <ar...@gmail.com>.
This is my test query

SELECT  IF(CAST(age as numeric) < 0.5, name, last_name) as customer_name
FROM 307320.test_dataset.customers



On Fri, Dec 17, 2021 at 5:47 AM Maxim Gramin <mg...@querifylabs.com>
wrote:

> Can you show the query? I don't see this one.
>
> On Thu, Dec 16, 2021 at 10:12 PM Arash Bizhan zadeh <ar...@gmail.com>
> wrote:
>
> > Hi,
> > I am trying to create a parser to parse big query statements like this -
> > this is kotlin btw:
> >
> > val sqlParserConfig = BigQuerySqlDialect(
> >
> >
> BigQuerySqlDialect.DEFAULT_CONTEXT.withDatabaseProduct(SqlDialect.DatabaseProduct.BIG_QUERY)).configureParser(SqlParser.config()
> >       .withParserFactory(SqlBabelParserImpl.FACTORY)
> >
> >       .withConformance(SqlConformanceEnum.BIG_QUERY))
> >     val parser = SqlParser.create(str, sqlParserConfig)
> >
> > but the resulting parser seems not to understand BQ specific things like
> > the `IF` function.
> >
> > How can I properly construct a SqlParser?
> >
>

Re: Creating a parser for Big query

Posted by Maxim Gramin <mg...@querifylabs.com>.
Can you show the query? I don't see this one.

On Thu, Dec 16, 2021 at 10:12 PM Arash Bizhan zadeh <ar...@gmail.com>
wrote:

> Hi,
> I am trying to create a parser to parse big query statements like this -
> this is kotlin btw:
>
> val sqlParserConfig = BigQuerySqlDialect(
>
> BigQuerySqlDialect.DEFAULT_CONTEXT.withDatabaseProduct(SqlDialect.DatabaseProduct.BIG_QUERY)).configureParser(SqlParser.config()
>       .withParserFactory(SqlBabelParserImpl.FACTORY)
>
>       .withConformance(SqlConformanceEnum.BIG_QUERY))
>     val parser = SqlParser.create(str, sqlParserConfig)
>
> but the resulting parser seems not to understand BQ specific things like
> the `IF` function.
>
> How can I properly construct a SqlParser?
>