Skip to content

Commit 2a7267e

Browse files
authored
Merge pull request #2259 from basho/aortile-riak-ts-examples
Updated the example table and sample codes
2 parents a2a98d4 + e7a6dc5 commit 2a7267e

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

content/riak/ts/1.4.0/using/writingdata.md

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ Riak TS allows you to write multiple rows of data at a time. To demonstrate, we'
3737
```sql
3838
CREATE TABLE GeoCheckin
3939
(
40+
id SINT64 NOT NULL,
4041
region VARCHAR NOT NULL,
4142
state VARCHAR NOT NULL,
4243
time TIMESTAMP NOT NULL,
4344
weather VARCHAR NOT NULL,
4445
temperature DOUBLE,
4546
PRIMARY KEY (
46-
(region, state, QUANTUM(time, 15, 'm')),
47-
region, state, time
47+
(id, QUANTUM(time, 15, 'm')),
48+
id, time
4849
)
4950
)
5051
```
@@ -67,16 +68,18 @@ public class RiakTSInsert {
6768
RiakClient client = RiakClient.newClient(8087, "myriakdb.host");
6869
List<Row> rows = Arrays.asList(
6970
new Row(
71+
new Cell(1),
7072
new Cell("South Atlantic"),
71-
new Cell("South Carolina"),
72-
Cell.newTimestamp(1234567),
73+
new Cell("Florida"),
74+
Cell.newTimestamp(1451606401),
7375
new Cell("hot"),
7476
new Cell(23.5)
7577
),
7678
new Row(
77-
new Cell("Mid-Atlantic"),
78-
new Cell("New York"),
79-
Cell.newTimestamp(1234567),
79+
new Cell(2),
80+
new Cell("East North Central"),
81+
new Cell("Illinois"),
82+
Cell.newTimestamp(1451606402),
8083
new Cell("windy"),
8184
new Cell(19.8)
8285
)
@@ -90,9 +93,13 @@ public class RiakTSInsert {
9093
```
9194

9295
```ruby
93-
client = Riak::Client.new 'myriakdb.host', pb_port: 8087
96+
require 'riak'
97+
98+
client = Riak::Client.new(:nodes => [
99+
{:host => 'myriakdb.host', :pb_port => 8087},
100+
])
94101
submission = Riak::TimeSeries::Submission.new client, "GeoCheckin"
95-
submission.measurements = [["South Atlantic", "South Carolina", 1234567, "hot", 23.5], ["Mid-Atlantic", "New York", 1234567, "windy", 19.8]]
102+
submission.measurements = [[1, "South Atlantic", "Florida", 1451606401, "hot", 23.5], [2, "East North Central", "Illinois", 1451606402, "windy", 19.8]]
96103
submission.write!
97104
```
98105

@@ -103,14 +110,10 @@ from riak.client import RiakClient
103110
# NB: modify 'host' and 'pb_port' to match your installation
104111
client = RiakClient(host='myriakdb.host', pb_port=8087)
105112

106-
fiveMins = datetime.timedelta(0, 300)
107-
ts0 = datetime.datetime(2015, 1, 1, 12, 0, 0)
108-
ts1 = ts0 + fiveMins
109-
110113
table = client.table('GeoCheckin')
111114
rows = [
112-
['South Atlantic', 'South Carolina', ts0, 'hot', 23.5],
113-
['Mid-Atlantic', 'New York', ts1, 'windy', 19.8]
115+
[1, 'South Atlantic', 'Florida', 1451606401, 'hot', 23.5],
116+
[2, 'East North Central', 'Illinois', 1451606402, 'windy', 19.8]
114117
]
115118
ts_obj = table.new(rows)
116119
print "Store result:", ts_obj.store()
@@ -162,10 +165,11 @@ RiakResult rslt = client.Execute(cmd);
162165
```javascript
163166
var Riak = require('basho-riak-client');
164167

165-
var hosts = [ 'riak-1:8087', 'riak-2:8087' ];
168+
var hosts = [ 'myriakdb.host:8087' ];
166169
var client = new Riak.Client(hosts);
167170

168-
var columns = [
171+
var columns = [
172+
{ name: 'id', type: Riak.Commands.TS.ColumnType.Int64 },
169173
{ name: 'region', type: Riak.Commands.TS.ColumnType.Varchar },
170174
{ name: 'state', type: Riak.Commands.TS.ColumnType.Varchar },
171175
{ name: 'time', type: Riak.Commands.TS.ColumnType.Timestamp },
@@ -174,8 +178,8 @@ var columns = [
174178
];
175179

176180
var rows = [
177-
[ 'South Atlantic', 'South Carolina', 1234567, 'hot', 23.5 ],
178-
[ 'Mid-Atlantic', 'New York', 1234567, 'windy', 19.8 ]
181+
[ 1, 'South Atlantic', 'Florida', 1451606401, 'hot', 23.5 ],
182+
[ 2, 'East North Central', 'Illinois', 1451606402, 'windy', 19.8 ]
179183
];
180184

181185
var cb = function (err, response) {
@@ -195,9 +199,9 @@ client.execute(store);
195199
```
196200

197201
```erlang
198-
%% TS 1.3 or newer. Records are represented as tuples.
199-
{ok, Pid} = riakc_pb_socket:start_link("myriakdb.host", 8087).
200-
riakc_ts:put(Pid, "GeoCheckin", [{<<"South Atlantic">>, <<"South Carolina">>, 1234567, <<"hot">>, 23.5}, {<<"Mid-Atlantic">>, <<"New York">>, 1234567, <<"windy">>, 19.8}]).
202+
%% TS 1.3 or newer. Records are represented as tuples.
203+
{ok, Pid} = riakc_pb_socket:start_link("localhost", 8087).
204+
riakc_ts:put(Pid, "GeoCheckin", [{1, <<"South Atlantic">>, <<"Florida">>, 1451606401, <<"hot">>, 23.5}, {2, <<"East North Central">>, <<"Illinois">>, 1451606402, <<"windy">>, 19.8}]).
201205
```
202206

203207
```php

0 commit comments

Comments
 (0)