为什么 cqlsh 右对齐字符串?

tbs*_*ing 4 cql cassandra cqlsh

我发现使用 cqlsh 显示的字符串值是右对齐的。是否有一个原因?有没有办法左对齐字符串?

cqlsh:test> create table test (id int, a ascii, t text, primary key(id));
cqlsh:test> insert into test (id, a, t) values (1, 'ascii', 'text');
cqlsh:test> insert into test (id, a, t) values (2, 'a', 't');       
cqlsh:test> select * from test;                              

 id | a     | t
----+-------+------
  1 | ascii | text
  2 |     a |    t

(2 rows)
Run Code Online (Sandbox Code Playgroud)

And*_*ert 5

我认为这主要是出于美学原因而完成的,但是您可以更改它!

cqlsh 只是一个使用 python 驱动程序的 python 文件。可以简单地在print_formatted_resultcqlsh的方法中修改如下代码:

    for row in formatted_values:                                                
        line = ' | '.join(col.rjust(w, color=self.color) for (col, w) in zip(row, widths))
        self.writeresult(' ' + line)
Run Code Online (Sandbox Code Playgroud)

您可以将 col.rjust 更改为 ljust、center 等,或者您可以简单地将其更改为 'col' 以按原样打印数据。

使用 ljust 的示例:

cqlsh:friends> select * from group_friends;

 groupid                              | friendid | time
--------------------------------------+----------+--------
 13814000-1dd2-11b2-8080-808080808080 | 1        | 123456
 13814000-1dd2-11b2-8080-808080808080 | 2        | 123456
 13814000-1dd2-11b2-8080-808080808080 | 4        | 123456
 13814000-1dd2-11b2-8080-808080808080 | 8        | 123456
 13814000-1dd2-11b2-8080-808080808080 | 22       | 123456
 13814000-1dd2-11b2-8080-808080808080 | 1002     | 123456
Run Code Online (Sandbox Code Playgroud)