You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Juan Rodríguez Hortalá <ju...@gmail.com> on 2016/06/02 19:39:48 UTC
Checking compliance to a schema with Calcite
Hi,
I have to check that some JSON objects have a certain shape. The idea is
defining a method that given a RelDataType and a String for a JSON object,
returns a boolean saying whether the JSON is complaint with the schema or
not. Can that be easily implemented with Calcite?
Thanks in advance.
Greetings,
Juan
Re: Checking compliance to a schema with Calcite
Posted by Juan Rodríguez Hortalá <ju...@gmail.com>.
Hi Jacques, you are right in that JSON schema is the most natural solution
for JSON. But I was looking to have a single SQL view of all the system.
Maybe defining a conversion between SQL schemas and JSON schemas could be
an approach that makes sense. I'll tell you guys if I'm able to make some
progress with this.
Thanks a lot for your help.
Greetings,
Juan
On Thu, Jun 2, 2016 at 1:21 PM, Jacques Nadeau <ja...@apache.org> wrote:
> I think you could do this with Calcite but I wonder if something like
> Jackson's json schema module [1] might be a better fit?
>
>
> [1] https://github.com/FasterXML/jackson-module-jsonSchema
>
> On Thu, Jun 2, 2016 at 1:17 PM, Julian Hyde <jh...@apache.org> wrote:
>
> > Would this be just a method, or would this be a user-defined function
> > that can be called from SQL?
> >
> > Writing it as a method would be straightforward, although it would
> > have to make certain assumptions about the mapping between JSON types
> > and SQL types. Writing it as a UDF is a bit harder, because we don't
> > have a way of representing types as values in SQL.
> >
> > One way to package it, that I think would be useful to other people,
> > would be a method in RexBuilder:
> >
> > RexLiteral makeLiteralFromJson(
> > Object o,
> > RelDataType type,
> > boolean ignoreUnknownFields)
> >
> > The input object, o, would be made up of Number, String, Boolean,
> > List, Map in the usual way, and would throw if the object does not
> > match the given type.
> >
> > Julian
> >
> >
> >
> > On Thu, Jun 2, 2016 at 12:39 PM, Juan Rodríguez Hortalá
> > <ju...@gmail.com> wrote:
> > > Hi,
> > >
> > > I have to check that some JSON objects have a certain shape. The idea
> is
> > > defining a method that given a RelDataType and a String for a JSON
> > object,
> > > returns a boolean saying whether the JSON is complaint with the schema
> or
> > > not. Can that be easily implemented with Calcite?
> > >
> > > Thanks in advance.
> > >
> > > Greetings,
> > >
> > > Juan
> >
>
Re: Checking compliance to a schema with Calcite
Posted by Jacques Nadeau <ja...@apache.org>.
I think you could do this with Calcite but I wonder if something like
Jackson's json schema module [1] might be a better fit?
[1] https://github.com/FasterXML/jackson-module-jsonSchema
On Thu, Jun 2, 2016 at 1:17 PM, Julian Hyde <jh...@apache.org> wrote:
> Would this be just a method, or would this be a user-defined function
> that can be called from SQL?
>
> Writing it as a method would be straightforward, although it would
> have to make certain assumptions about the mapping between JSON types
> and SQL types. Writing it as a UDF is a bit harder, because we don't
> have a way of representing types as values in SQL.
>
> One way to package it, that I think would be useful to other people,
> would be a method in RexBuilder:
>
> RexLiteral makeLiteralFromJson(
> Object o,
> RelDataType type,
> boolean ignoreUnknownFields)
>
> The input object, o, would be made up of Number, String, Boolean,
> List, Map in the usual way, and would throw if the object does not
> match the given type.
>
> Julian
>
>
>
> On Thu, Jun 2, 2016 at 12:39 PM, Juan Rodríguez Hortalá
> <ju...@gmail.com> wrote:
> > Hi,
> >
> > I have to check that some JSON objects have a certain shape. The idea is
> > defining a method that given a RelDataType and a String for a JSON
> object,
> > returns a boolean saying whether the JSON is complaint with the schema or
> > not. Can that be easily implemented with Calcite?
> >
> > Thanks in advance.
> >
> > Greetings,
> >
> > Juan
>
Re: Checking compliance to a schema with Calcite
Posted by Juan Rodríguez Hortalá <ju...@gmail.com>.
Hi Julian, thanks for your answer.
I was thinking on a method. I will tell you if I make progress in this
line, first I have to get familiar with the Calcite API.
Thanks again for your help.
Greetings,
Juan
On Thu, Jun 2, 2016 at 1:17 PM, Julian Hyde <jh...@apache.org> wrote:
> Would this be just a method, or would this be a user-defined function
> that can be called from SQL?
>
> Writing it as a method would be straightforward, although it would
> have to make certain assumptions about the mapping between JSON types
> and SQL types. Writing it as a UDF is a bit harder, because we don't
> have a way of representing types as values in SQL.
>
> One way to package it, that I think would be useful to other people,
> would be a method in RexBuilder:
>
> RexLiteral makeLiteralFromJson(
> Object o,
> RelDataType type,
> boolean ignoreUnknownFields)
>
> The input object, o, would be made up of Number, String, Boolean,
> List, Map in the usual way, and would throw if the object does not
> match the given type.
>
> Julian
>
>
>
> On Thu, Jun 2, 2016 at 12:39 PM, Juan Rodríguez Hortalá
> <ju...@gmail.com> wrote:
> > Hi,
> >
> > I have to check that some JSON objects have a certain shape. The idea is
> > defining a method that given a RelDataType and a String for a JSON
> object,
> > returns a boolean saying whether the JSON is complaint with the schema or
> > not. Can that be easily implemented with Calcite?
> >
> > Thanks in advance.
> >
> > Greetings,
> >
> > Juan
>
Re: Checking compliance to a schema with Calcite
Posted by Julian Hyde <jh...@apache.org>.
Would this be just a method, or would this be a user-defined function
that can be called from SQL?
Writing it as a method would be straightforward, although it would
have to make certain assumptions about the mapping between JSON types
and SQL types. Writing it as a UDF is a bit harder, because we don't
have a way of representing types as values in SQL.
One way to package it, that I think would be useful to other people,
would be a method in RexBuilder:
RexLiteral makeLiteralFromJson(
Object o,
RelDataType type,
boolean ignoreUnknownFields)
The input object, o, would be made up of Number, String, Boolean,
List, Map in the usual way, and would throw if the object does not
match the given type.
Julian
On Thu, Jun 2, 2016 at 12:39 PM, Juan Rodríguez Hortalá
<ju...@gmail.com> wrote:
> Hi,
>
> I have to check that some JSON objects have a certain shape. The idea is
> defining a method that given a RelDataType and a String for a JSON object,
> returns a boolean saying whether the JSON is complaint with the schema or
> not. Can that be easily implemented with Calcite?
>
> Thanks in advance.
>
> Greetings,
>
> Juan