You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Enrico Olivelli <eo...@gmail.com> on 2017/11/14 12:59:28 UTC

Aliases for schemas

Hi,
(I am playing with the planner, you know)
I have several "schema" in my system, like "one", "two"
So my root schema is built this way:
final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
        for (String tableSpace : listTableSpaces()) {
            SchemaPlus schema = rootSchema.add(tableSpace, new
AbstractSchema());
}

Queries like
SELECT * from one.mytable
SELECT * from two.mytable

get parsed and validated.

But I would like to set a "default" schema to be used when the query does
not explicitly refer to a schema, like
default-schema='one'
SELECT * from mytable

which I would expect to be parsed as
SELECT * from one.mytable

Is it possible ?


Bonus question, separate from the former, it seems that the parser
complaints if I try to use a schema with name "default", using MYSQL5_5
compatinility for instance. Is there any tweak to make it work ?

Calcite is really great!
Enrico

Re: Aliases for schemas

Posted by Enrico Olivelli <eo...@gmail.com>.
It works very well !
Thank you

Enrico

2017-11-14 14:57 GMT+01:00 Enrico Olivelli <eo...@gmail.com>:

> ok so I can create the rootSchema, populate with all the schemas and then
> give to the config builder the "default schema"
> I will give it a try
> it sounds tricky to me, maybe I will file an issue
>
> Cheers
> Enrico
>
> 2017-11-14 14:55 GMT+01:00 Luis Fernando Kauer <
> lfkauer@yahoo.com.br.invalid>:
>
>>  When you set a defaultSchema in FrameworkConfig, internally Calcite uses
>> defaultSchema.getParentSchema() if not null as the root schema.
>> So if you set a default schema you don't need to set the root schema
>> elsewhere.
>> Did you try?    Em terça-feira, 14 de novembro de 2017 11:38:24 BRST,
>> Enrico Olivelli <eo...@gmail.com> escreveu:
>>
>>  But actually I am setting the "rootSchema" there.
>>
>> Unfortunately there is no notion of "root schema" in FrameworkConfig, can
>> you point me how to set this different "root schema" ?
>>
>> Enrico
>>
>> 2017-11-14 14:32 GMT+01:00 Luis Fernando Kauer
>> <lfkauer@yahoo.com.br.invalid
>> >:
>>
>> > Hi,
>> > FrameworkConfig has getDefaultSchema(), from javadoc "Returns the
>> default
>> > schema that should be checked before looking at the root schema.
>> Returns
>> > null to only consult the root schema".
>> > So, if you are using Frameworks.newConfigBuilder(), you can set it using
>> > ".defaultSchema( rootSchema.getSubSchema( "one" ))", for example.  Em
>> > terça-feira, 14 de novembro de 2017 10:59:33 BRST, Enrico Olivelli <
>> > eolivelli@gmail.com> escreveu:
>> >
>> >  Hi,
>> > (I am playing with the planner, you know)
>> > I have several "schema" in my system, like "one", "two"
>> > So my root schema is built this way:
>> > final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
>> >        for (String tableSpace : listTableSpaces()) {
>> >            SchemaPlus schema = rootSchema.add(tableSpace, new
>> > AbstractSchema());
>> > }
>> >
>> > Queries like
>> > SELECT * from one.mytable
>> > SELECT * from two.mytable
>> >
>> > get parsed and validated.
>> >
>> > But I would like to set a "default" schema to be used when the query
>> does
>> > not explicitly refer to a schema, like
>> > default-schema='one'
>> > SELECT * from mytable
>> >
>> > which I would expect to be parsed as
>> > SELECT * from one.mytable
>> >
>> > Is it possible ?
>> >
>> >
>> > Bonus question, separate from the former, it seems that the parser
>> > complaints if I try to use a schema with name "default", using MYSQL5_5
>> > compatinility for instance. Is there any tweak to make it work ?
>> >
>> > Calcite is really great!
>> > Enrico
>> >
>> >
>>
>
>

Re: Aliases for schemas

Posted by Enrico Olivelli <eo...@gmail.com>.
ok so I can create the rootSchema, populate with all the schemas and then
give to the config builder the "default schema"
I will give it a try
it sounds tricky to me, maybe I will file an issue

Cheers
Enrico

2017-11-14 14:55 GMT+01:00 Luis Fernando Kauer <lfkauer@yahoo.com.br.invalid
>:

>  When you set a defaultSchema in FrameworkConfig, internally Calcite uses
> defaultSchema.getParentSchema() if not null as the root schema.
> So if you set a default schema you don't need to set the root schema
> elsewhere.
> Did you try?    Em terça-feira, 14 de novembro de 2017 11:38:24 BRST,
> Enrico Olivelli <eo...@gmail.com> escreveu:
>
>  But actually I am setting the "rootSchema" there.
>
> Unfortunately there is no notion of "root schema" in FrameworkConfig, can
> you point me how to set this different "root schema" ?
>
> Enrico
>
> 2017-11-14 14:32 GMT+01:00 Luis Fernando Kauer
> <lfkauer@yahoo.com.br.invalid
> >:
>
> > Hi,
> > FrameworkConfig has getDefaultSchema(), from javadoc "Returns the default
> > schema that should be checked before looking at the root schema.  Returns
> > null to only consult the root schema".
> > So, if you are using Frameworks.newConfigBuilder(), you can set it using
> > ".defaultSchema( rootSchema.getSubSchema( "one" ))", for example.  Em
> > terça-feira, 14 de novembro de 2017 10:59:33 BRST, Enrico Olivelli <
> > eolivelli@gmail.com> escreveu:
> >
> >  Hi,
> > (I am playing with the planner, you know)
> > I have several "schema" in my system, like "one", "two"
> > So my root schema is built this way:
> > final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
> >        for (String tableSpace : listTableSpaces()) {
> >            SchemaPlus schema = rootSchema.add(tableSpace, new
> > AbstractSchema());
> > }
> >
> > Queries like
> > SELECT * from one.mytable
> > SELECT * from two.mytable
> >
> > get parsed and validated.
> >
> > But I would like to set a "default" schema to be used when the query does
> > not explicitly refer to a schema, like
> > default-schema='one'
> > SELECT * from mytable
> >
> > which I would expect to be parsed as
> > SELECT * from one.mytable
> >
> > Is it possible ?
> >
> >
> > Bonus question, separate from the former, it seems that the parser
> > complaints if I try to use a schema with name "default", using MYSQL5_5
> > compatinility for instance. Is there any tweak to make it work ?
> >
> > Calcite is really great!
> > Enrico
> >
> >
>

Re: Aliases for schemas

Posted by Luis Fernando Kauer <lf...@yahoo.com.br.INVALID>.
 When you set a defaultSchema in FrameworkConfig, internally Calcite uses defaultSchema.getParentSchema() if not null as the root schema.
So if you set a default schema you don't need to set the root schema elsewhere.
Did you try?    Em terça-feira, 14 de novembro de 2017 11:38:24 BRST, Enrico Olivelli <eo...@gmail.com> escreveu:  
 
 But actually I am setting the "rootSchema" there.

Unfortunately there is no notion of "root schema" in FrameworkConfig, can
you point me how to set this different "root schema" ?

Enrico

2017-11-14 14:32 GMT+01:00 Luis Fernando Kauer <lfkauer@yahoo.com.br.invalid
>:

> Hi,
> FrameworkConfig has getDefaultSchema(), from javadoc "Returns the default
> schema that should be checked before looking at the root schema.  Returns
> null to only consult the root schema".
> So, if you are using Frameworks.newConfigBuilder(), you can set it using
> ".defaultSchema( rootSchema.getSubSchema( "one" ))", for example.  Em
> terça-feira, 14 de novembro de 2017 10:59:33 BRST, Enrico Olivelli <
> eolivelli@gmail.com> escreveu:
>
>  Hi,
> (I am playing with the planner, you know)
> I have several "schema" in my system, like "one", "two"
> So my root schema is built this way:
> final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
>        for (String tableSpace : listTableSpaces()) {
>            SchemaPlus schema = rootSchema.add(tableSpace, new
> AbstractSchema());
> }
>
> Queries like
> SELECT * from one.mytable
> SELECT * from two.mytable
>
> get parsed and validated.
>
> But I would like to set a "default" schema to be used when the query does
> not explicitly refer to a schema, like
> default-schema='one'
> SELECT * from mytable
>
> which I would expect to be parsed as
> SELECT * from one.mytable
>
> Is it possible ?
>
>
> Bonus question, separate from the former, it seems that the parser
> complaints if I try to use a schema with name "default", using MYSQL5_5
> compatinility for instance. Is there any tweak to make it work ?
>
> Calcite is really great!
> Enrico
>
>  

Re: Aliases for schemas

Posted by Enrico Olivelli <eo...@gmail.com>.
But actually I am setting the "rootSchema" there.

Unfortunately there is no notion of "root schema" in FrameworkConfig, can
you point me how to set this different "root schema" ?

Enrico

2017-11-14 14:32 GMT+01:00 Luis Fernando Kauer <lfkauer@yahoo.com.br.invalid
>:

> Hi,
> FrameworkConfig has getDefaultSchema(), from javadoc "Returns the default
> schema that should be checked before looking at the root schema.  Returns
> null to only consult the root schema".
> So, if you are using Frameworks.newConfigBuilder(), you can set it using
> ".defaultSchema( rootSchema.getSubSchema( "one" ))", for example.   Em
> terça-feira, 14 de novembro de 2017 10:59:33 BRST, Enrico Olivelli <
> eolivelli@gmail.com> escreveu:
>
>  Hi,
> (I am playing with the planner, you know)
> I have several "schema" in my system, like "one", "two"
> So my root schema is built this way:
> final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
>         for (String tableSpace : listTableSpaces()) {
>             SchemaPlus schema = rootSchema.add(tableSpace, new
> AbstractSchema());
> }
>
> Queries like
> SELECT * from one.mytable
> SELECT * from two.mytable
>
> get parsed and validated.
>
> But I would like to set a "default" schema to be used when the query does
> not explicitly refer to a schema, like
> default-schema='one'
> SELECT * from mytable
>
> which I would expect to be parsed as
> SELECT * from one.mytable
>
> Is it possible ?
>
>
> Bonus question, separate from the former, it seems that the parser
> complaints if I try to use a schema with name "default", using MYSQL5_5
> compatinility for instance. Is there any tweak to make it work ?
>
> Calcite is really great!
> Enrico
>
>

Re: Aliases for schemas

Posted by Luis Fernando Kauer <lf...@yahoo.com.br.INVALID>.
Hi,
FrameworkConfig has getDefaultSchema(), from javadoc "Returns the default schema that should be checked before looking at the root schema.  Returns null to only consult the root schema".
So, if you are using Frameworks.newConfigBuilder(), you can set it using ".defaultSchema( rootSchema.getSubSchema( "one" ))", for example.   Em terça-feira, 14 de novembro de 2017 10:59:33 BRST, Enrico Olivelli <eo...@gmail.com> escreveu:  
 
 Hi,
(I am playing with the planner, you know)
I have several "schema" in my system, like "one", "two"
So my root schema is built this way:
final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
        for (String tableSpace : listTableSpaces()) {
            SchemaPlus schema = rootSchema.add(tableSpace, new
AbstractSchema());
}

Queries like
SELECT * from one.mytable
SELECT * from two.mytable

get parsed and validated.

But I would like to set a "default" schema to be used when the query does
not explicitly refer to a schema, like
default-schema='one'
SELECT * from mytable

which I would expect to be parsed as
SELECT * from one.mytable

Is it possible ?


Bonus question, separate from the former, it seems that the parser
complaints if I try to use a schema with name "default", using MYSQL5_5
compatinility for instance. Is there any tweak to make it work ?

Calcite is really great!
Enrico