第二组关于数据误差的观点

时间:2013-09-02 02:28:44

标签: database clojure datomic

这是Datomic Mailing列表中的 duplicate post 。我想知道我是否可以要求第二组眼睛。

我尝试了 A) ,它运行时没有错误。但是我后来在查询时得到一个空洞的结果。所以我尝试了硬编码,如 B) 。但是,这个错误,说日期不是属性uuid的有效:tags/name ...但在该交易中没有任何地方,我是否尝试设置:tags/name属性。我正在设置:posts/created-date:posts/modified-date的日期。我在这里完全不知所措。

如果我检查数据库,如 C) ,我可以看到我的架构确实存在。我的架构位于底部。任何见解都表示赞赏。

谢谢

A)

(def mapped-fn 'datomic.api/transact)

(def adatom {:idx -1000006, :part :db.part/user, :posts/modified-date #inst "2013-01-01T08:00:00.000-00:00", :posts/created-date #inst "2013-01-01T08:00:00.000-00:00", :posts/content-type "c/t", :posts/content "c", :posts/title "t"})

(mapped-fn conn [adatom])

...

(datomic/q '[:find ?e :where [?e :posts/content-type "c/t"]] (datomic/db conn)) 
=> #<HashSet []>

B)

(datomic.api/transact conn [{:db/id #db/id [:db.part/db] :posts/modified-date #inst "2013-01-01T08:00:00.000-00:00", :posts/created-date #inst "2013-01-01T08:00:00.000-00:00", :posts/content-type "c/t", :posts/content "c", :posts/title "t"}])

     :transact/bad-data Value Tue Jan 01 00:00:00 PST 2013 is not a valid :uuid for attribute :tags/name
     clojure.lang.ExceptionInfo: :transact/bad-data Value Tue Jan 01 00:00:00 PST 2013 is not a valid :uuid for attribute :tags/name {:db/error :transact/bad-data}
        ... 1 stack levels elided ...
        at datomic.error$raise.invoke(error.clj:20)
        at datomic.error$raise.invoke(error.clj:16)
        at datomic.db.ProcessInpoint.inject(db.clj:1079)
        at datomic.db.ProcessInpoint.inject(db.clj:1056)
        at datomic.db$with_tx$inject_all__1619$fn__1620.invoke(db.clj:1197)
        ... 7 stack levels elided ...
        at datomic.db$with_tx$inject_all__1619.invoke(db.clj:1197)
        at datomic.db$with_tx.invoke(db.clj:1201)
        at datomic.peer.LocalConnection.transactAsync(peer.clj:260)
        at datomic.peer.LocalConnection.transact(peer.clj:252)
        at datomic.api$transact.invoke(api.clj:54)
        at stefon_datomic.crud$create.invoke(crud.clj:61)

C)

(datomic/db conn)
=> #datomic.db.Db{:id datomic:mem://stefon, [...] , #datomic.db.Attribute{:id 62, :kw :tags/name, :vtypeid 55, :cardinality 35, :isComponent nil, :unique nil, :index false, :noHistory nil, :fulltext nil}], :keys {0 :db.part/db, 1 :db/add, 2 :db/retract, 3 :db.part/tx, 35 :db.cardinality/one, 4 :db.part/user, 36 :db.cardinality/many, 37 :db.unique/value, 38 :db.unique/identity, 39 :fressian/tag, 40 :db/valueType, 41 :db/cardinality, 10 :db/ident, 42 :db/unique, 11 :db.install/partition, 43 :db/isComponent, 12 :db.install/valueType, 44 :db/index, 13 :db.install/attribute, 45 :db/noHistory, 14 :db.install/function, 46 :db/lang, 47 :db/code, 48 :db.lang/clojure, 49 :db.lang/java, 50 :db/txInstant, 51 :db/fulltext, 20 :db.type/ref, 52 :db/fn, 21 :db.type/keyword, 53 :db.fn/retractEntity, 22 :db.type/long, 54 :db.fn/cas, 23 :db.type/string, 55 :db.type/uuid, 24 :db.type/boolean, 56 :db.type/double, 25 :db.type/instant, 57 :db.type/float, 26 :db.type/fn, 58 :db.type/uri, 27 :db.type/bytes, 59 :db.type/bigint, 60 :db.type/bigdec, 61 :db/doc, 62 :tags/name}, :ids {:db.unique/value 37, :db/noHistory 45, :assets/asset 62, :posts/id 62, :posts/modified-date 62, :db.type/uuid 55, :assets/type 62, :db.type/bigint 59, :db.cardinality/many 36, :db.type/uri 58, :posts/content 62, :db.fn/cas 54, :db.type/ref 20, :db.type/keyword 21, :db.install/partition 11, :db/cardinality 41, :db.lang/clojure 48, :assets/name 62, :db.type/bytes 27, :db.cardinality/one 35, :db.type/string 23, :db/retract 2, :db.unique/identity 38, :db.install/attribute 13, :assets/id 62, :db.part/tx 3, :db/index 44, :posts/title 62, :db/unique 42, :db/fulltext 51, :db.type/instant 25, :posts/created-date 62, :db/txInstant 50, :db/lang 46, :db.lang/java 49, :db/doc 61, :db.type/fn 26, :db.install/valueType 12, :db.type/long 22, :db/add 1, :db/code 47, :tags/name 62, :db/isComponent 43, :db/fn 52, :posts/content-type 62, :db.type/bigdec 60, :db.install/function 14, :db/valueType 40, :tags/id 62, :db/ident 10, :db.part/db 0, :db.part/user 4, :db.type/boolean 24, :db.fn/retractEntity 53, :db.type/double 56, :fressian/tag 39, :db.type/float 57}, :index-root
-id nil, :index-rev 0, :asOfT nil, :sinceT nil}

模式

{:db/id {:part :db.part/db, :idx -1000139},
  :db/ident :posts/id,
  :db/valueType :db.type/uuid,
  :db/cardinality :db.cardinality/one,
  :db.install/_attribute :db.part/db}
 {:db/id {:part :db.part/db, :idx -1000139},
  :db/ident :posts/title,
  :db/valueType :db.type/string,
  :db/cardinality :db.cardinality/one,
  :db.install/_attribute :db.part/db}
 {:db/id {:part :db.part/db, :idx -1000139},
  :db/ident :posts/content,
  :db/valueType :db.type/string,
  :db/cardinality :db.cardinality/one,
  :db.install/_attribute :db.part/db}
 {:db/id {:part :db.part/db, :idx -1000139},
  :db/ident :posts/content-type,
  :db/valueType :db.type/string,
  :db/cardinality :db.cardinality/one,
  :db.install/_attribute :db.part/db}
 {:db/id {:part :db.part/db, :idx -1000139},
  :db/ident :posts/created-date,
  :db/valueType :db.type/instant,
  :db/cardinality :db.cardinality/one,
  :db.install/_attribute :db.part/db}
 {:db/id {:part :db.part/db, :idx -1000139},
  :db/ident :posts/modified-date,
  :db/valueType :db.type/instant,
  :db/cardinality :db.cardinality/one,
  :db.install/_attribute :db.part/db}
 {:db/id {:part :db.part/db, :idx -1000139},
  :db/ident :assets/id,
  :db/valueType :db.type/uuid,
  :db/cardinality :db.cardinality/one,
  :db.install/_attribute :db.part/db}
 {:db/id {:part :db.part/db, :idx -1000139},
  :db/ident :assets/name,
  :db/valueType :db.type/string,
  :db/cardinality :db.cardinality/one,
  :db.install/_attribute :db.part/db}
 {:db/id {:part :db.part/db, :idx -1000139},
  :db/ident :assets/type,
  :db/valueType :db.type/string,
  :db/cardinality :db.cardinality/one,
  :db.install/_attribute :db.part/db}
 {:db/id {:part :db.part/db, :idx -1000139},
  :db/ident :assets/asset,
  :db/valueType :db.type/string,
  :db/cardinality :db.cardinality/one,
  :db.install/_attribute :db.part/db}
 {:db/id {:part :db.part/db, :idx -1000139},
  :db/ident :tags/id,
  :db/valueType :db.type/uuid,
  :db/cardinality :db.cardinality/one,
  :db.install/_attribute :db.part/db}
 {:db/id {:part :db.part/db, :idx -1000139},
  :db/ident :tags/name,
  :db/valueType :db.type/string,
  :db/cardinality :db.cardinality/one,
  :db.install/_attribute :db.part/db}]

1 个答案:

答案 0 :(得分:1)

查看您的架构,似乎所有架构/属性定义都具有相同的ID:-1000139。当你改变tags\name的值时,我猜这是posts\modified-date上出现神秘错误的原因。

我不确定这是怎么发生的 - 也许检查一下你用来创建架构的代码。示例如下:

(require '[datomic.api :as d])

;; Create an in-memory database, with two attributes from the seattle example
(def uri "datomic:mem://seattle")
(d/create-database  uri)
(d/transact (d/connect uri)
  [{:db/id #db/id[:db.part/db]
    :db/ident :community/name
    :db/valueType :db.type/string
    :db/cardinality :db.cardinality/one
    :db/fulltext true
    :db/doc "A community's name" 
    :db.install/_attribute :db.part/db}

   {:db/id #db/id[:db.part/db]
    :db/ident :community/url
    :db/valueType :db.type/string
    :db/cardinality :db.cardinality/one
    :db/doc "A community's url"
    :db.install/_attribute :db.part/db}])

  ;; Create a function to get the id of an ident
  (defn id-of-ident [ident]
     (d/q '[:find ?e 
            :in $ ?ident
            :where [?e :db/ident ?ident]]
           (d/db (d/connect uri)) ident))

  ;; Prove the two idents have different ids
  (assert (not= (id-of-ident "community/url") (id-of-ident "community/name")))
  ;; => nil