Kassandra time stamp

I prefer to use timestamp as one of the columns in Cassandra (which I decided to use as the Clustering Key). which is the right way to save a column as a timestamp in Kassandra?

( ie ) Is it good to use milliseconds (Example: 1513078338560) as shown below?

INSERT INTO testdata (nodeIp, totalCapacity, physicalUsage, readIOPS, readBW, writeIOPS, writeBW, writeLatency, flashMode, timestamp) VALUES('172.30.56.60',1, 1,1,1,1,1,1,'yes',1513078338560); 

or use the date (now ());

INSERT INTO testdata (nodeIp, totalCapacity, physicalUsage, readIOPS, readBW, writeIOPS, writeBW, writeLatency, flashMode, timestamp) VALUES('172.30.56.60',1, 1,1,1,1,1,1,'yes',dateof(now()));

which is a faster and recommended way to use timestamp based queries in Cassandra?

NOTE: I know that it is stored in milliseconds, I used 'SELECT timestamp, blobAsBigint(timestampAsBlob(timestamp)) FROM'

Thanks Harry

+4
source share
1 answer

dateof Cassandra >= 2.2... toTimestamp, : toTimestamp(now()). , toUnixTimestamp, :

cqlsh:test> CREATE TABLE test_times (a int, b timestamp, PRIMARY KEY (a,b));
cqlsh:test> INSERT INTO test_times (a,b) VALUES (1, toTimestamp(now()));
cqlsh:test> SELECT toUnixTimestamp(b) FROM test_times;

 system.tounixtimestamp(b)
---------------------------
         1513086032267

(1 rows)

cqlsh:test> SELECT b FROM test_times;

 b
---------------------------------
 2017-12-12 13:40:32.267000+0000

(1 rows)

- :

  • ,
  • " " - Cassandra , , .

(Java-like).

PreparedStatement prepared = session.prepare(
    "insert into your_table (field1, field2) values (?, ?)");
while(true) {
    session.execute(prepared.bind(value1, value2));
}
+3

Source: https://habr.com/ru/post/1690608/


All Articles