Неверная ошибка сериализованного значения при чтении карты строговых объектов JSON из кассандры 1.2 с использованием DataStax 1.0.5 Java-драйвера и Cassaforte

StackOverflow https://stackoverflow.com//questions/23062125

Вопрос

Я использую Cassaforte 1.3.0-Beta9, Cassandra 1.2 (DataStax) и com.datastax.Cassandra / Cassandra-Driver-Core 1.0.5 (с 2,0 не работает с Cassandra 1.2).У меня есть стол со следующей схемой:

  CREATE TABLE entities (
  id text,
  address_country text,
  address_county text,
  address_region text,
  address_street_two text,
  csv_uploads list<text>,
  documents list<text>,
  name text,
  notes list<text>,
  photos list<text>,
  project_id text,
  property_code text,
  property_data text,
  retrofit_completion_date text,
  metering_point_ids text,
  devices map<text,text>,
  user_id text,
  PRIMARY KEY (id)
)
.

Это пример того, что хранится подряд:

7b237da126d39ccf98f80d78b6145a10828970f8 |
{'b9d88015c84312bf24cef0e7f1a0baf98dbc8d8d':
  '{"metadata":{"passivrole":"zone 1 temperature,zone 1 temperature"},
    "readings":
      [{"type":"temperature","resolution":"120","accuracy":"0.1","period":"INSTANT"},
       {"type":"interpolatedTemperatureAir","resolution":100,"accuracy":"0.1","period":"INSTANT"}],
   "description":"External air temperature sensor",
   "entity-id":"3e0730d4672538307056a30615aaaa333107d94e"}', 
'd2fe3dca47b760dd67759a56ee0ebbc2cb3395f4': 
  '{"metadata":{"passivrole":"zone 1 humidity"},
    "readings":[{"type":"blah","resolution":"120","accuracy":"0.1","period":"INSTANT"}],
  "description":" air humidity sensor",
  "entity-id":"3e0730d4672538307056a30615aaaa333107d94e"}'} |
alice
.

Когда я пытаюсь прочитать столбец devices, я получаю следующую ошибку:

com.datastax.driver.core.exceptions.InvalidTypeException: Invalid serialized value for type map<text, text> (String didn't validate.)
    at com.datastax.driver.core.DataType.deserialize(DataType.java:503)
.

Я могу читать столбец устройств без проблем с использованием CQLSH (который отображается выше).Значения, хранящиеся на карте, строганы объекты JSON.

Вот образец рабочего процесса:

(require '[clojurewerkz.cassaforte.client :as cassaclient]
         ' [clojurewerkz.cassaforte.query :as cassaquery]
         ' [clojurewerkz.cassaforte.cql :as cql])

;; SELECT on empty devices:
(binding [cassaclient/*default-session* session]
      (let [entity (cql/select :entities (cassaquery/where :id "3e0730d4672538307056a30615aaaa333107d94e"))]
        (prn "retrieved entity: " entity)))

;; Returns vector of results, no errors:
"retrieved entity: " [{:retrofit_completion_date nil, :notes nil, :property_code "3e49de0-12af-012e-4f3a-12313b0348f8", :devices nil, :name nil, :user_id "alice", :csv_uploads nil, :project_id "0b4f512fb7834a0878252ab144a525d424445ba2", :photos nil, :property_data nil, :metering_point_ids "[\"1\" \"2\"]", :address_street_two nil, :documents nil, :address_region nil, :address_country nil, :address_county nil, :id "3e0730d4672538307056a30615aaaa333107d94e"}]

;; UPDATE using cassaforte:
(binding [cassaclient/*default-session* session]
  (cql/update :entities {:devices  {"0edf9e09bce895caf0342ac6ae12511555930362" "{:metadata {\"passivrole\" \"zone 1 humidity\"}, :readings [{\"type\" \"tba\", \"resolution\" \"90\", \"accuracy\" \"0.2\", \"period\" \"INSTANT\"}], :description \"lalalala\", :entity-id \"3e0730d4672538307056a30615aaaa333107d94e\"}"}} (cassaquery/where :id "3e0730d4672538307056a30615aaaa333107d94e")))

;; update worked ok, cqlsh (select devices from entities where id = '3e0730d4672538307056a30615aaaa333107d94e';)
;; returns correct map: 
;; {'0edf9e09bce895caf0342ac6ae12511555930362': '{:metadata {"passivrole" "zone 1 humidity"}, :readings [{"type" "tba", "resolution" "90", "accuracy" "0.2", "period" "INSTANT"}], :description "lalalala", :entity-id "3e0730d4672538307056a30615aaaa333107d94e"}'}

;; SELECT using cassaforte
(binding [cassaclient/*default-session* session]
      (let [entity (cql/select :entities (cassaquery/where :id "3e0730d4672538307056a30615aaaa333107d94e"))]
        (prn "retrieved entity: " entity)))

;; Returns this error:
;; InvalidTypeException Invalid serialized value for type map<text, text> (String didn't validate.)  com.datastax.driver.core.DataType.deserialize (DataType.java:503)
.

Я пробовал тот же рабочий процесс, используя RAW CQL и Cassaforte, и результаты были точно такими же:

(require '[clojurewerkz.cassaforte.client :as cassaclient])

;; SELECT on empty devices:
(cassaclient/execute session "SELECT * FROM entities WHERE id = '3e0730d4672538307056a30615aaaa333107d94e';")

;; Returns vector of results, no errors:
[{:retrofit_completion_date nil, :notes nil, :property_code "3e49de0-12af-012e-4f3a-12313b0348f8", :devices nil, :name nil, :user_id "alice", :csv_uploads nil, :project_id "0b4f512fb7834a0878252ab144a525d424445ba2", :photos nil, :property_data nil, :metering_point_ids "[\"1\" \"2\"]", :address_street_two nil, :documents nil, :address_region nil, :address_country nil, :address_county nil, :id "3e0730d4672538307056a30615aaaa333107d94e"}]

;; UPDATE using cassaforte:
(cassaclient/execute session "UPDATE entities SET devices = {'0edf9e09bce895caf0342ac6ae12511555930362' : '{:metadata {\"passivrole\" \"zone 1 humidity\"}, :readings [{\"type\" \"tba\", \"resolution\" \"90\", \"accuracy\" \"0.2\", \"period\" \"INSTANT\"}], :description \"lalalala\", :entity-id \"3e0730d4672538307056a30615aaaa333107d94e\"}'} WHERE id = '3e0730d4672538307056a30615aaaa333107d94e';")

;; update worked ok, cqlsh (select devices from entities where id = '3e0730d4672538307056a30615aaaa333107d94e';)
;; returns correct map: 
;; {'0edf9e09bce895caf0342ac6ae12511555930362': '{:metadata {"passivrole" "zone 1 humidity"}, :readings [{"type" "tba", "resolution" "90", "accuracy" "0.2", "period" "INSTANT"}], :description "lalalala", :entity-id "3e0730d4672538307056a30615aaaa333107d94e"}'}

;; SELECT using cassaforte
(cassaclient/execute session "SELECT * FROM entities WHERE id = '3e0730d4672538307056a30615aaaa333107d94e';")

;; Returns this error:
;; InvalidTypeException Invalid serialized value for type map<text, text> (String didn't validate.)  com.datastax.driver.core.DataType.deserialize (DataType.java:503)
.

Любая помощь и / или предложения о том, как объекты JSON должны храниться в коллекции карты Кассандры, будет очень оценена.

Это было полезно?

Решение

(Cassaforte сопровождающий здесь)

Не видел этот вопрос до сих пор,

Это была проблема с 1.0.5 версией драйвера DataStax. CassaForte в настоящее время находится в 2.0.0, выпуск закрыта с любой версией выше бета12. Более подробная информация: https://github.com/Clojurewerkz/cassaforte/issues/41

Используйте последнюю версию Cassaforte и попробуйте придерживаться версии Java-драйвера, которая приходит в комплекте с Cassaforte, и это будет все отлично.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top