gocql SELECT *不返回所有列 [英] gocql SELECT * doesn't return all columns

查看:332
本文介绍了gocql SELECT *不返回所有列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为我的应用程序实现一些计数器时遇到这种奇怪的行为。
基本上,我做了一个计数器表,像这样:

  CREATE TABLE stats_dev.log_counters PRIMARY KEY,
所有计数器
);

然后我有一些特定类型的消息我想计数,我ALTER的表添加我以前没有的列。



我的应用程式不断增加,我开始有超过30列(不应超过50列),当我要检索所有计数器时,

  query:= s.Query(`SELECT * FROM`+ _apiCountersTable +`WHERE date IN? ,date)
res,err:= query.Iter()。SliceMap()

这返回我在34列34像30。虽然,当我做CQLSH的请求:

  cqlsh:stats_dev> SELECT * FROM api_counters WHERE date ='total'; 

我得到正确的完整结果。所以:


  1. 这是否来自我的请求,应该有所不同?

  2. gocql 驱动程序?

  3. 这种模式是否完全愚蠢?

我的临时解决方案是从 system.schema_columns 表中选择列名称, strings.Join()所有对我的SELECT查询...



非常感谢您的帮助。



首先,我想,考虑到你告诉我的是什么,我宁愿做有时会在 system.schema_columns 上创建 SELCT column_name ,并在更改表时刷新。我只需要 strings.join()我的 SELECT FROM api_counters 中的列。它工作,但如果我有2个不同的实例,一个会更新架构,另一个会收到一个GET请求,这个人不会知道新的列。



然后我重新排列了我的想法,发现有明显的另一种方式这样做,我只是改变这个模式:

CREATE TABLE stats_dev.api_counters(
日期文本,
描述文本,
所有计数器,
PRIMARY KEY(日期,描述)
);

,我根据我的期望更新字段。到目前为止很好。



我知道这绝对是选择3:我的模式不是最好的。


I came across this weird behaviour while trying to implement some counters for my application. Basically, I did a counter table like so :

CREATE TABLE stats_dev.log_counters (
  date text PRIMARY KEY,
  all counter
);

Then I have some specific types of message I want to count as well, so in my Go app, I ALTER the table to add the column I didn't have before.

My app is growing, and I start to have more than 30 columns (shouldn't be more than 50) and when I want to retrieve all those counters, some columns are missing in the result.

query := s.Query(`SELECT * FROM `+_apiCountersTable+` WHERE date IN ?`, dates)
res, err := query.Iter().SliceMap()

This returns me something like 30 over 34 columns. Although, when I do the request on CQLSH :

cqlsh:stats_dev> SELECT * FROM api_counters WHERE date = 'total';

I get the proper full result. So :

  1. Does that come from my request which should be different ?
  2. Could that come from gocql driver ?
  3. Is that pattern completely stupid ?

My temporary solution is to SELECT the column names from the system.schema_columns table and to strings.Join() all of that to my SELECT query ...

Thank you very much for your help.

解决方案

Thanks Andy for your help.

At first, I thought that considering what you told me, I would rather do a SELCT column_name on the system.schema_columns sometimes and refresh it when I alter my table. I would just then strings.join() the columns in my SELECT FROM api_counters. It worked but if I had 2 different instances, and one would update the schema and the other would receive a GET request, this one would not know the new column still.

And then I rearranged my ideas and found out that there was obviously an other way of doing that and I simply change for this schema : CREATE TABLE stats_dev.api_counters ( date text, description text, all counter, PRIMARY KEY (date, description) ); and I am updating the field based on the description I am expecting. So far so good.

I knew it was definitely Option 3 : my pattern was not the best one.

这篇关于gocql SELECT *不返回所有列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆