douxing9567 2018-10-16 21:15
浏览 122
已采纳

使用gocql将用户定义类型的数组插入Cassandra

I have a UDT in Cassandra and I have a table that has an array of these UDTs in its schema. Here's a sample:

CREATE TYPE keyspace.test_type(
    x float, 
    y float)

In my schema I have

 CREATE TABLE test_table(
     key text,
     test_array list<FROZEN <test_type>>,
     PRIMARY KEY (key))

Inside my go package I built a struct:

type Test_type struct{
     x float32
     y float32
}

Then I have a function that essentially returns a list of this test_type: []test_type, let's call it my_array.

When I try to do the insert using gocql like such:

 err := gocql.Session.Query('INSERT into test_table (key,test_array)
                             VALUES (?,?)', 'key', my_array).Exec()

I get a bunch of null values instead of my array. Essentially the test_type does not correctly map to the UDT that I created is my assumption.

Essentially my question is how do you map a struct in go to a udt such that the type is recognized properly. .

  • 写回答

2条回答 默认 最新

  • douyu0725 2018-10-16 23:11
    关注

    Per: Converting Go struct to JSON

    The problem was resolved by renaming the fields so it exports. That way gocql can see the data type x & y.

    Simply renaming xto X and y to Y. Will do the trick

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助