Skip to content

Commit 4099f88

Browse files
committed
wip
1 parent 5c9100c commit 4099f88

39 files changed

Lines changed: 2399 additions & 180 deletions

core/src/main/java/com/datastax/oss/driver/api/core/CassandraVersion.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public class CassandraVersion implements Comparable<CassandraVersion> {
3838
"(\\d+)\\.(\\d+)(\\.\\d+)?(\\.\\d+)?([~\\-]\\w[.\\w]*(?:\\-\\w[.\\w]*)*)?(\\+[.\\w]+)?";
3939
private static final Pattern pattern = Pattern.compile(VERSION_REGEXP);
4040

41+
public static final CassandraVersion V2_1_0 = parse("2.1.0");
42+
public static final CassandraVersion V2_2_0 = parse("2.2.0");
43+
public static final CassandraVersion V3_0_0 = parse("3.0.0");
44+
4145
private final int major;
4246
private final int minor;
4347
private final int patch;

core/src/main/java/com/datastax/oss/driver/api/core/metadata/schema/AggregateMetadata.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,23 @@
1515
*/
1616
package com.datastax.oss.driver.api.core.metadata.schema;
1717

18+
import com.datastax.oss.driver.api.core.CqlIdentifier;
1819
import com.datastax.oss.driver.api.core.type.DataType;
1920
import com.datastax.oss.driver.api.core.type.codec.TypeCodec;
2021

2122
/** A CQL aggregate in the schema metadata. */
2223
public interface AggregateMetadata extends Describable {
23-
KeyspaceMetadata getKeyspace();
24+
CqlIdentifier getKeyspace();
2425

2526
FunctionSignature getSignature();
2627

2728
/**
28-
* The final function of this aggregate, or {@code null} if there is none.
29+
* The signature of the final function of this aggregate, or {@code null} if there is none.
2930
*
3031
* <p>This is the function specified with {@code FINALFUNC} in the {@code CREATE AGGREGATE...}
3132
* statement. It transforms the final value after the aggregation is complete.
3233
*/
33-
FunctionMetadata getFinalFunc();
34+
FunctionSignature getFinalFuncSignature();
3435

3536
/**
3637
* The initial state value of this aggregate, or {@code null} if there is none.
@@ -60,12 +61,12 @@ public interface AggregateMetadata extends Describable {
6061
DataType getReturnType();
6162

6263
/**
63-
* The state function of this aggregate.
64+
* The signature of the state function of this aggregate.
6465
*
6566
* <p>This is the function specified with {@code SFUNC} in the {@code CREATE AGGREGATE...}
6667
* statement. It aggregates the current state with each row to produce a new state.
6768
*/
68-
FunctionMetadata getStateFunc();
69+
FunctionSignature getStateFuncSignature();
6970

7071
/**
7172
* The state type of this aggregate.
@@ -75,4 +76,10 @@ public interface AggregateMetadata extends Describable {
7576
* rows.
7677
*/
7778
DataType getStateType();
79+
80+
@Override
81+
default String describeWithChildren(boolean pretty) {
82+
// An aggregate has no children
83+
return describe(pretty);
84+
}
7885
}

core/src/main/java/com/datastax/oss/driver/api/core/metadata/schema/FunctionMetadata.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717

1818
import com.datastax.oss.driver.api.core.CqlIdentifier;
1919
import com.datastax.oss.driver.api.core.type.DataType;
20+
import com.datastax.oss.driver.internal.core.metadata.schema.ScriptBuilder;
2021
import java.util.List;
2122

2223
/** A CQL function in the schema metadata. */
2324
public interface FunctionMetadata extends Describable {
2425

25-
KeyspaceMetadata getKeyspace();
26+
CqlIdentifier getKeyspace();
2627

2728
FunctionSignature getSignature();
2829

@@ -39,4 +40,48 @@ public interface FunctionMetadata extends Describable {
3940
String getLanguage();
4041

4142
DataType getReturnType();
43+
44+
@Override
45+
default String describe(boolean pretty) {
46+
ScriptBuilder builder = new ScriptBuilder(pretty);
47+
builder
48+
.append("CREATE FUNCTION ")
49+
.append(getKeyspace())
50+
.append(".")
51+
.append(getSignature().getName())
52+
.append("(");
53+
boolean first = true;
54+
for (int i = 0; i < getSignature().getParameterTypes().size(); i++) {
55+
if (first) {
56+
first = false;
57+
} else {
58+
builder.append(",");
59+
}
60+
DataType type = getSignature().getParameterTypes().get(i);
61+
CqlIdentifier name = getParameterNames().get(i);
62+
builder.append(name).append(" ").append(type.asCql(false, pretty));
63+
}
64+
return builder
65+
.append(")")
66+
.newLine()
67+
.append(isCalledOnNullInput() ? "CALLED ON NULL INPUT" : "RETURNS NULL ON NULL INPUT")
68+
.newLine()
69+
.newLine()
70+
.append("RETURNS ")
71+
.append(getReturnType().asCql(false, true))
72+
.newLine()
73+
.append("LANGUAGE ")
74+
.append(getLanguage())
75+
.newLine()
76+
.append("AS '")
77+
.append(getBody())
78+
.append("';")
79+
.build();
80+
}
81+
82+
@Override
83+
default String describeWithChildren(boolean pretty) {
84+
// A function has no children
85+
return describe(pretty);
86+
}
4287
}

core/src/main/java/com/datastax/oss/driver/api/core/type/DataTypes.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public static ListType listOf(DataType elementType) {
6363
return new DefaultListType(elementType, false);
6464
}
6565

66+
public static ListType listOf(DataType elementType, boolean frozen) {
67+
return new DefaultListType(elementType, frozen);
68+
}
69+
6670
public static ListType frozenListOf(DataType elementType) {
6771
return new DefaultListType(elementType, true);
6872
}
@@ -71,6 +75,10 @@ public static SetType setOf(DataType elementType) {
7175
return new DefaultSetType(elementType, false);
7276
}
7377

78+
public static SetType setOf(DataType elementType, boolean frozen) {
79+
return new DefaultSetType(elementType, frozen);
80+
}
81+
7482
public static SetType frozenSetOf(DataType elementType) {
7583
return new DefaultSetType(elementType, true);
7684
}
@@ -79,6 +87,10 @@ public static MapType mapOf(DataType keyType, DataType valueType) {
7987
return new DefaultMapType(keyType, valueType, false);
8088
}
8189

90+
public static MapType mapOf(DataType keyType, DataType valueType, boolean frozen) {
91+
return new DefaultMapType(keyType, valueType, frozen);
92+
}
93+
8294
public static MapType frozenMapOf(DataType keyType, DataType valueType) {
8395
return new DefaultMapType(keyType, valueType, true);
8496
}

core/src/main/java/com/datastax/oss/driver/api/core/type/UserDefinedType.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ default boolean contains(String name) {
4646

4747
List<DataType> getFieldTypes();
4848

49+
UserDefinedType copy(boolean newFrozen);
50+
4951
UdtValue newValue();
5052

5153
AttachmentPoint getAttachmentPoint();

core/src/main/java/com/datastax/oss/driver/internal/core/CassandraProtocolVersionRegistry.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ public class CassandraProtocolVersionRegistry implements ProtocolVersionRegistry
4646

4747
private static final Logger LOG = LoggerFactory.getLogger(CassandraProtocolVersionRegistry.class);
4848

49-
private static final CassandraVersion CASSANDRA_210 = CassandraVersion.parse("2.1.0");
50-
private static final CassandraVersion CASSANDRA_220 = CassandraVersion.parse("2.2.0");
51-
5249
private final String logPrefix;
5350
private final NavigableMap<Integer, ProtocolVersion> versionsByCode;
5451

@@ -133,7 +130,7 @@ public ProtocolVersion highestCommon(Collection<Node> nodes) {
133130
continue;
134131
}
135132
cassandraVersion = cassandraVersion.nextStable();
136-
if (cassandraVersion.compareTo(CASSANDRA_210) < 0) {
133+
if (cassandraVersion.compareTo(CassandraVersion.V2_1_0) < 0) {
137134
throw new UnsupportedProtocolVersionException(
138135
node.getConnectAddress(),
139136
String.format(
@@ -148,7 +145,7 @@ public ProtocolVersion highestCommon(Collection<Node> nodes) {
148145
logPrefix,
149146
node.getConnectAddress(),
150147
cassandraVersion);
151-
if (cassandraVersion.compareTo(CASSANDRA_220) < 0
148+
if (cassandraVersion.compareTo(CassandraVersion.V2_2_0) < 0
152149
&& candidates.remove(CoreProtocolVersion.V4)) {
153150
LOG.debug("[{}] Excluding protocol V4", logPrefix);
154151
}

core/src/main/java/com/datastax/oss/driver/internal/core/adminrequest/AdminResult.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.datastax.oss.driver.api.core.type.codec.TypeCodec;
2020
import com.datastax.oss.driver.api.core.type.codec.TypeCodecs;
2121
import com.datastax.oss.driver.internal.core.util.concurrent.CompletableFutures;
22+
import com.datastax.oss.protocol.internal.ProtocolConstants;
2223
import com.datastax.oss.protocol.internal.response.result.ColumnSpec;
2324
import com.datastax.oss.protocol.internal.response.result.Rows;
2425
import com.google.common.annotations.VisibleForTesting;
@@ -117,6 +118,10 @@ public Double getDouble(String columnName) {
117118
return get(columnName, TypeCodecs.DOUBLE);
118119
}
119120

121+
public boolean isString(String columnName) {
122+
return columnSpecs.get(columnName).type.id == ProtocolConstants.DataType.VARCHAR;
123+
}
124+
120125
public String getString(String columnName) {
121126
return get(columnName, TypeCodecs.TEXT);
122127
}

core/src/main/java/com/datastax/oss/driver/internal/core/metadata/InitContactPointsRefresh.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class InitContactPointsRefresh extends MetadataRefresh {
3636
}
3737

3838
@Override
39-
void compute() {
39+
public void compute() {
4040
assert oldMetadata == DefaultMetadata.EMPTY;
4141
LOG.debug("[{}] Initializing node metadata with contact points {}", logPrefix, contactPoints);
4242

core/src/main/java/com/datastax/oss/driver/internal/core/metadata/MetadataManager.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,11 @@ public CompletionStage<Void> refreshSchema(
131131
v ->
132132
SchemaQueries.newInstance(context, logPrefix)
133133
.execute(kind, keyspace, object, arguments))
134-
.thenApplyAsync(singleThreaded::refreshSchema, adminExecutor);
134+
.thenApplyAsync(singleThreaded::refreshSchema, adminExecutor)
135+
.whenComplete(
136+
(v, error) ->
137+
// Remember the first attempt, whether it was successful or not
138+
singleThreaded.firstSchemaRefreshFuture.complete(null));
135139
}
136140

137141
// The control connection may or may not have been initialized already by TopologyMonitor.
@@ -215,7 +219,7 @@ private void removeNode(InetSocketAddress address) {
215219
}
216220

217221
private Void refreshSchema(SchemaRows schemaRows) {
218-
// TODO complete firstSchemaRefreshFuture at the end
222+
// TODO create and run SchemaParser, apply refresh
219223
throw new UnsupportedOperationException("TODO");
220224
}
221225

core/src/main/java/com/datastax/oss/driver/internal/core/metadata/MetadataRefresh.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*
3333
* @see Cluster#getMetadata()
3434
*/
35-
abstract class MetadataRefresh {
35+
public abstract class MetadataRefresh {
3636
final DefaultMetadata oldMetadata;
3737
DefaultMetadata newMetadata;
3838
final List<Object> events;
@@ -44,5 +44,5 @@ protected MetadataRefresh(DefaultMetadata current, String logPrefix) {
4444
this.events = new ArrayList<>();
4545
}
4646

47-
abstract void compute();
47+
public abstract void compute();
4848
}

0 commit comments

Comments
 (0)