在CQL中删除time数据类型的尾随零

时间:2018-03-22 05:37:35

标签: cassandra cql

尝试删除arrival_time的尾随零,列数据类型为时间

SELECT * FROM TABLE

我得到了这个:

station_name | arrival_time --------------+-------------------- Wellington | 06:05:00.000000000

我需要结果如下:

station_name | arrival_time --------------+-------------------- Wellington | 06:05:00

我是CQL的新手,提前谢谢。

3 个答案:

答案 0 :(得分:1)

因此,您无法使用time类型在Cassandra中实际执行此操作。但是,您可以使用timestamp

执行此操作
cassdba@cqlsh:stackoverflow> CREATE TABLE arrival_time2 (station_name TEXT PRIMARY KEY, 
    arrival_time time, arrival_timestamp timestamp);
cassdba@cqlsh:stackoverflow> INSERT INTO arrival_time2 (station_name , arrival_time , arrival_timestamp)
    VALUES ('Wellington','06:05:00','2018-03-22 06:05:00');
cassdba@cqlsh:stackoverflow> SELECT * FROM arrival_time2;

 station_name | arrival_time       | arrival_timestamp
--------------+--------------------+---------------------------------
   Wellington | 06:05:00.000000000 | 2018-03-22 11:05:00.000000+0000

(1 rows)

当然,这也不是你想要的,真的。接下来,您需要在time_format的{​​{1}}部分设置[ui]

~/.cassandra/cqlshrc

重启cqlsh,这应该有效:

[ui]
time_format = %Y-%m-%d %H:%M:%S

答案 1 :(得分:0)

select station_name, SUBSTRING( Convert(Varchar(20),arrival_time), 0, 9)  As arrival_time
from [Table]

使用以下表格和数据格式

CREATE TABLE [dbo].[ArrivalStation](
    [station_name] [varchar](500) NULL,
    [arrival_time] [Time](7) NULL
) ON [PRIMARY]


INSERT [dbo].[ArrivalStation] ([station_name], [arrival_time]) VALUES (N'Wellington ', N'06:05:00.0000000')
INSERT [dbo].[ArrivalStation] ([station_name], [arrival_time]) VALUES (N'Singapore', N'12:35:29.1234567')

答案 2 :(得分:-2)

class EncoderRNN(nn.Module):
    def __init__(self, dict_size, hidden_size):
        super(EncoderRNN, self).__init__()
        self.hidden_size = hidden_size
        self.embedding = nn.Embedding(dict_size, hidden_size)
        self.gru = nn.GRU(hidden_size, hidden_size, batch_first=True)

    def forward(self, input_batch, input_batch_length, hidden):
        embedded = self.embedding(input_batch)
        packed_input = nn.utils.rnn.pack_padded_sequence(embedded, input_batch_length.cpu().numpy(), batch_first=True)
        output, hidden = self.gru(packed_input, hidden)
        return output, hidden


class DecoderRNN(nn.Module):
    def __init__(self, hidden_size, dict_size):
        super(DecoderRNN, self).__init__()
        self.hidden_size = hidden_size
        self.embedding = nn.Embedding(dict_size, hidden_size)
        self.gru = nn.GRU(hidden_size, hidden_size, batch_first=True)
        self.out = nn.Linear(hidden_size, dict_size)
        self.softmax = nn.LogSoftmax(dim=1)

    def forward(self, target_batch, target_batch_length, hidden, train=False):
        embedded = self.embedding(target_batch)
        output = F.relu(embedded)

        if train:
            # minus 1 to eliminate <EOS>
            output = nn.utils.rnn.pack_padded_sequence(output, (target_batch_length - 1).cpu().numpy(),
                                                       batch_first=True)

        output, hidden = self.gru(output, hidden)
        output = self.softmax(self.out(output[0]))
        return output, hidden