خطأ غير صالح في القيمة التسلسلية عند قراءة خريطة كائنات json مقسمة من Cassandra 1.2 باستخدام برنامج تشغيل Java DataStax 1.0.5 و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)

لقد جربت نفس سير العمل باستخدام 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 في مجموعة خرائط Cassandra ستكون موضع تقدير كبير.

هل كانت مفيدة؟

المحلول

(مشرف Cassaforte هنا)

لم أرى هذا السؤال إلا الآن

كانت هذه مشكلة في الإصدار 1.0.5 من برنامج تشغيل DataStax.Cassaforte موجود حاليًا في الإصدار 2.0.0، ويتم إغلاق المشكلة مع أي إصدار أعلى من beta12.مزيد من المعلومات هنا: https://github.com/clojurewerkz/cassaforte/issues/41

استخدم أحدث إصدار من Cassaforte وحاول الالتزام بإصدار Java Driver الذي يأتي مرفقًا مع Cassaforte وسيكون كل شيء رائعًا.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top