Skip to content

Commit ee3d57b

Browse files
2 parents 3d95be1 + 6e46e39 commit ee3d57b

139 files changed

Lines changed: 1201 additions & 843 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

debian/cassandra-tools.install

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ tools/bin/sstablemetadata usr/bin
66
tools/bin/sstableofflinerelevel usr/bin
77
tools/bin/sstablerepairedset usr/bin
88
tools/bin/sstablesplit usr/bin
9-
tools/bin/addtocmstool usr/bin
9+
tools/bin/cmsofflinetool usr/bin
1010
tools/bin/offlineclustermetadatadump usr/bin

redhat/cassandra.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ This package contains extra tools for working with Cassandra clusters.
214214
%attr(755,root,root) %{_bindir}/fqltool
215215
%attr(755,root,root) %{_bindir}/generatetokens
216216
%attr(755,root,root) %{_bindir}/hash_password
217-
%attr(755,root,root) %{_bindir}/addtocmstool
217+
%attr(755,root,root) %{_bindir}/cmsofflinetool
218218
%attr(755,root,root) %{_bindir}/offlineclustermetadatadump
219219

220220

src/java/org/apache/cassandra/cql3/Attributes.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ public boolean isTimeToLiveSet()
8282
return timeToLive != null;
8383
}
8484

85-
public long getTimestamp(long now, QueryOptions options) throws InvalidRequestException
85+
public long getTimestamp(long now, FunctionContext context) throws InvalidRequestException
8686
{
8787
if (timestamp == null)
8888
return now;
8989

90-
ByteBuffer tval = timestamp.bindAndGet(options);
90+
ByteBuffer tval = timestamp.bindAndGet(context);
9191
if (tval == null)
9292
throw new InvalidRequestException("Invalid null value of timestamp");
9393

@@ -106,15 +106,15 @@ public long getTimestamp(long now, QueryOptions options) throws InvalidRequestEx
106106
return LongType.instance.compose(tval);
107107
}
108108

109-
public int getTimeToLive(QueryOptions options, TableMetadata metadata) throws InvalidRequestException
109+
public int getTimeToLive(FunctionContext context, TableMetadata metadata) throws InvalidRequestException
110110
{
111111
if (timeToLive == null)
112112
{
113113
ExpirationDateOverflowHandling.maybeApplyExpirationDateOverflowPolicy(metadata, metadata.params.defaultTimeToLive, true);
114114
return metadata.params.defaultTimeToLive;
115115
}
116116

117-
ByteBuffer tval = timeToLive.bindAndGet(options);
117+
ByteBuffer tval = timeToLive.bindAndGet(context);
118118
if (tval == null)
119119
return 0;
120120

src/java/org/apache/cassandra/cql3/ColumnsExpression.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,9 @@ public Kind kind()
356356
* Returns the key, index or fieldname specifying the selected element.
357357
* @return the key, index or fieldname specifying the selected element.
358358
*/
359-
public ByteBuffer element(QueryOptions options)
359+
public ByteBuffer element(FunctionContext context)
360360
{
361-
return element.bindAndGet(options);
361+
return element.bindAndGet(context);
362362
}
363363

364364
/**

src/java/org/apache/cassandra/cql3/ElementExpression.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ public void addFunctionsTo(List<Function> functions)
158158
/**
159159
* Returns the ByteBuffer representation of the key or index.
160160
*
161-
* @param options the query options
161+
* @param context the query options
162162
* @return the ByteBuffer representation of the key or index.
163163
*/
164-
public ByteBuffer bindAndGet(QueryOptions options)
164+
public ByteBuffer bindAndGet(FunctionContext context)
165165
{
166-
return keyOrIndex.bindAndGet(options);
166+
return keyOrIndex.bindAndGet(context);
167167
}
168168

169169
public String toCQLString()
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package org.apache.cassandra.cql3;
20+
21+
import java.time.Instant;
22+
23+
import org.apache.cassandra.cql3.functions.Arguments;
24+
import org.apache.cassandra.cql3.functions.FunctionArguments;
25+
import org.apache.cassandra.db.marshal.TimeUUIDType;
26+
import org.apache.cassandra.transport.ProtocolVersion;
27+
import org.apache.cassandra.utils.Clock.Global;
28+
import org.apache.cassandra.utils.TimeUUID;
29+
30+
public interface FunctionContext
31+
{
32+
NoTimeOrQueryFunctionContext NONE = new NoTimeOrQueryFunctionContext() {};
33+
34+
interface RealTimeFunctionContext extends FunctionContext
35+
{
36+
@Override default byte[] nextTimeUUIDAsBytes() { return TimeUUID.Generator.nextTimeUUIDAsBytes(); }
37+
@Override default Instant now() { return Global.currentTime(); }
38+
@Override default long nowMicros() { return Global.currentTimeMicros(); }
39+
@Override default long nowMillis() { return Global.currentTimeMillis(); }
40+
}
41+
42+
interface NoTimeFunctionContext extends FunctionContext
43+
{
44+
@Override default byte[] nextTimeUUIDAsBytes() { throw new UnsupportedOperationException(); }
45+
@Override default Instant now() { throw new UnsupportedOperationException(); }
46+
@Override default long nowMicros() { throw new UnsupportedOperationException(); }
47+
@Override default long nowMillis() { throw new UnsupportedOperationException(); }
48+
}
49+
50+
interface NoTimeOrQueryFunctionContext extends NoTimeFunctionContext
51+
{
52+
@Override default QueryOptions options() { throw new UnsupportedOperationException(); }
53+
}
54+
55+
interface PartialFunctionContext extends FunctionContext
56+
{
57+
default long nowMillis() { return nowMicros() / 1000; }
58+
default Instant now()
59+
{
60+
long nowMicros = nowMicros();
61+
return Instant.ofEpochSecond(nowMicros / 1000_000, (nowMicros % 1000_000) * 1000);
62+
}
63+
}
64+
65+
abstract class MicrosFunctionContext implements PartialFunctionContext
66+
{
67+
final long atMicros;
68+
private long timeUuidNanos;
69+
70+
public MicrosFunctionContext(long atMicros)
71+
{
72+
this.atMicros = atMicros;
73+
}
74+
75+
@Override public long nowMicros() { return atMicros; }
76+
77+
@Override
78+
public byte[] nextTimeUUIDAsBytes()
79+
{
80+
return TimeUUID.toBytes(TimeUUID.unixMicrosToMsb(atMicros), TimeUUIDType.signedBytesToNativeLong(timeUuidNanos++));
81+
}
82+
}
83+
84+
QueryOptions options();
85+
Instant now();
86+
long nowMillis();
87+
long nowMicros();
88+
byte[] nextTimeUUIDAsBytes();
89+
90+
default ProtocolVersion getProtocolVersion() { return options().getProtocolVersion(); }
91+
92+
default Arguments noArguments()
93+
{
94+
return new FunctionArguments(this);
95+
}
96+
}

src/java/org/apache/cassandra/cql3/Json.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,12 @@ public boolean containsBindMarker()
251251
}
252252

253253
@Override
254-
public Terminal bind(QueryOptions options) throws InvalidRequestException
254+
public Terminal bind(FunctionContext context) throws InvalidRequestException
255255
{
256-
Term term = options.getJsonColumnValue(marker.bindIndex, column.name, marker.columns);
256+
Term term = context.options().getJsonColumnValue(marker.bindIndex, column.name, marker.columns);
257257
return term == null
258258
? (defaultUnset ? Constants.UNSET_VALUE : null)
259-
: term.bind(options);
259+
: term.bind(context);
260260
}
261261

262262
@Override

src/java/org/apache/cassandra/cql3/Operation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ public void collectMarkerSpecification(VariableSpecifications boundNames, Object
116116
* Execute the operation.
117117
*
118118
* @param partitionKey partition key for the update.
119-
* @param params parameters of the update.
119+
* @param builder parameters of the update.
120120
*/
121-
public abstract void execute(DecoratedKey partitionKey, UpdateParameters params) throws InvalidRequestException;
121+
public abstract void execute(DecoratedKey partitionKey, RowUpdateBuilder builder) throws InvalidRequestException;
122122

123123
/**
124124
* A parsed raw UPDATE operation.

src/java/org/apache/cassandra/cql3/QueryOptions.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import org.apache.cassandra.config.DataStorageSpec;
3333
import org.apache.cassandra.config.DatabaseDescriptor;
34+
import org.apache.cassandra.cql3.FunctionContext.RealTimeFunctionContext;
3435
import org.apache.cassandra.cql3.terms.Term;
3536
import org.apache.cassandra.db.ConsistencyLevel;
3637
import org.apache.cassandra.db.marshal.UTF8Type;
@@ -53,7 +54,7 @@
5354
/**
5455
* Options for a query.
5556
*/
56-
public abstract class QueryOptions
57+
public abstract class QueryOptions implements RealTimeFunctionContext
5758
{
5859
public static final QueryOptions DEFAULT = new DefaultQueryOptions(ConsistencyLevel.ONE,
5960
Collections.emptyList(),
@@ -378,6 +379,12 @@ public long getCoordinatorReadSizeFailThresholdBytes()
378379
}
379380
}
380381

382+
@Override
383+
public QueryOptions options()
384+
{
385+
return this;
386+
}
387+
381388
static class DefaultQueryOptions extends QueryOptions
382389
{
383390
private final ConsistencyLevel consistency;

src/java/org/apache/cassandra/cql3/QueryProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ else if (readQuery instanceof SinglePartitionReadQuery.Group)
555555
.map(m -> MessagingService.instance().<ReadCommand, ReadResponse>sendWithResult(m, address))
556556
.collect(Collectors.toList()));
557557

558-
ResultSetBuilder result = new ResultSetBuilder(select.getResultMetadata(), select.getSelection().newSelectors(options), false);
558+
ResultSetBuilder result = new ResultSetBuilder(select.getResultMetadata(), options, select.getSelection().newSelectors(options), false);
559559
return future.map(list -> {
560560
int i = 0;
561561
for (Message<ReadResponse> m : list)

0 commit comments

Comments
 (0)