You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Jose Antonio Illescas del Olmo <jo...@gmail.com> on 2016/02/13 21:11:12 UTC

Mongo ObjectId to VARCHAR

How can define a mongo json model to convert ObjectId to VARCHAR?

      cast(_MAP[\'_id\'] AS varchar(24)) AS id

throws error:

> select id from countries;
+--------------------------+
|            ID            |
+--------------------------+
java.lang.ClassCastException: org.bson.types.ObjectId cannot be cast to
java.lang.String
at
org.apache.calcite.avatica.util.AbstractCursor$StringAccessor.getString(AbstractCursor.java:727)
at
org.apache.calcite.avatica.AvaticaResultSet.getString(AvaticaResultSet.java:236)
at sqlline.Rows$Row.<init>(Rows.java:183)
at sqlline.IncrementalRows.hasNext(IncrementalRows.java:63)
at sqlline.TableOutputFormat.print(TableOutputFormat.java:33)
at sqlline.SqlLine.print(SqlLine.java:1652)
at sqlline.Commands.execute(Commands.java:833)
at sqlline.Commands.sql(Commands.java:732)
at sqlline.SqlLine.dispatch(SqlLine.java:807)
at sqlline.SqlLine.begin(SqlLine.java:681)
at sqlline.SqlLine.start(SqlLine.java:398)
at sqlline.SqlLine.main(SqlLine.java:292)

Re: Mongo ObjectId to VARCHAR

Posted by Julian Hyde <jh...@apache.org>.
I don’t think there is a way to do this. We need to add a feature to Calcite.

I saw you logged https://issues.apache.org/jira/browse/CALCITE-1088 and https://issues.apache.org/jira/browse/CALCITE-1089.  Thanks for those. You set fixVersion = 1.7 but I’m going to clear that field.

Julian



> On Feb 13, 2016, at 12:11 PM, Jose Antonio Illescas del Olmo <jo...@gmail.com> wrote:
> 
> How can define a mongo json model to convert ObjectId to VARCHAR?
> 
>      cast(_MAP[\'_id\'] AS varchar(24)) AS id
> 
> throws error:
> 
>> select id from countries;
> +--------------------------+
> |            ID            |
> +--------------------------+
> java.lang.ClassCastException: org.bson.types.ObjectId cannot be cast to
> java.lang.String
> at
> org.apache.calcite.avatica.util.AbstractCursor$StringAccessor.getString(AbstractCursor.java:727)
> at
> org.apache.calcite.avatica.AvaticaResultSet.getString(AvaticaResultSet.java:236)
> at sqlline.Rows$Row.<init>(Rows.java:183)
> at sqlline.IncrementalRows.hasNext(IncrementalRows.java:63)
> at sqlline.TableOutputFormat.print(TableOutputFormat.java:33)
> at sqlline.SqlLine.print(SqlLine.java:1652)
> at sqlline.Commands.execute(Commands.java:833)
> at sqlline.Commands.sql(Commands.java:732)
> at sqlline.SqlLine.dispatch(SqlLine.java:807)
> at sqlline.SqlLine.begin(SqlLine.java:681)
> at sqlline.SqlLine.start(SqlLine.java:398)
> at sqlline.SqlLine.main(SqlLine.java:292)