cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Harikrishnan Pillai <HPil...@walmartlabs.com>
Subject Re: Is it possible to have a column which can hold any data type (for inserting as json)
Date Thu, 02 Feb 2017 04:37:31 GMT
You can use text type in Cassandra and store the full Json  string .

Sent from my iPhone

On Feb 1, 2017, at 8:30 PM, Rajeswari Menon <rajeswari.m@thinkpalm.com<mailto:rajeswari.m@thinkpalm.com>>
wrote:

Yes. Is there any way to define value to accept any data type as the json value data may vary?
Or is there any way to do the same without defining a schema?

Regards,
Rajeswari

From: Benjamin Roth [mailto:benjamin.roth@jaumo.com]
Sent: 01 February 2017 15:36
To: user@cassandra.apache.org<mailto:user@cassandra.apache.org>
Subject: RE: Is it possible to have a column which can hold any data type (for inserting as
json)

Value is defined as text column and you try to insert a double. That's simply not allowed

Am 01.02.2017 09:02 schrieb "Rajeswari Menon" <rajeswari.m@thinkpalm.com<mailto:rajeswari.m@thinkpalm.com>>:
Given below is the sql query I executed.

insert into data JSON'{
      "id": 1,
   "address":"",
   "datatype":"DOUBLE",
   "name":"Longitude",
   "attributes":{
      "ID":"1"
   },
   "category":"REAL",
   "value":1.390692,
   "timestamp":1485923271718,
   "quality":"GOOD"
}';

Regards,
Rajeswari

From: Benjamin Roth [mailto:benjamin.roth@jaumo.com<mailto:benjamin.roth@jaumo.com>]
Sent: 01 February 2017 12:35
To: user@cassandra.apache.org<mailto:user@cassandra.apache.org>
Subject: Re: Is it possible to have a column which can hold any data type (for inserting as
json)

You should post the whole CQL query you try to execute! Why don't you use a native JSON type
for your JSON data?

2017-02-01 7:51 GMT+01:00 Rajeswari Menon <rajeswari.m@thinkpalm.com<mailto:rajeswari.m@thinkpalm.com>>:
Hi,

                I have a json data as shown below.

                {
                                "address":"127.0.0.1",
"datatype":"DOUBLE",
"name":"Longitude",
                                 "attributes":{
                                                "Id":"1"
                                },
                                "category":"REAL",
                                "value":1.390692,
                                "timestamp":1485923271718,
                                "quality":"GOOD"
}

To store the above json to Cassandra, I defined a table as shown below

create table data
(
      id int primary key,
      address text,
      datatype text,
      name text,
      attributes map < text, text >,
      category text,
      value text,
      "timestamp" timestamp,
      quality text
);

When I try to insert the data as JSON I got the error : Error decoding JSON value for value:
Expected a UTF-8 string, but got a Double: 1.390692. The message is clear that a double value
cannot be inserted to text column. The real issue is that the value can be of any data type,
so the schema cannot be predefined. Is there a way to create a column which can hold value
of any data type. (I don't want to hold the entire json as string. My preferred way is to
define a schema.)

Regards,
Rajeswari



--
Benjamin Roth
Prokurist

Jaumo GmbH * www.jaumo.com<http://www.jaumo.com>
Wehrstra?e 46 * 73035 G?ppingen * Germany
Phone +49 7161 304880-6<tel:07161%203048806> * Fax +49 7161 304880-1<tel:07161%203048801>
AG Ulm * HRB 731058 * Managing Director: Jens Kammerer

Mime
View raw message