Elffuss BraidHub

kikocis/java-driver public

JAVA-998: SchemaChangeListener not invoked for Functions or Aggregates having UDT arguments.
Changeset0029343b4ddc96f174ef792bc633cd244e8225a692207e4d20be90d171d6ce2d
AuthorAlexandre Dutra <alexandre.dutra@datastax.com> · 2015-11-20 16:24 +01:00
CommitterAlexandre Dutra <alexandre.dutra@datastax.com> · 2015-11-25 18:05 +01:00
Parents0e80934e7fe4

Browse the files at this changeset

16 files changed

modified changelog/README.md +1 −0
@@ -4,6 +4,7 @@
44
55 - [bug] JAVA-993: Support for "custom" types after CASSANDRA-10365.
66 - [bug] JAVA-999: Handle unset parameters in QueryLogger.
7+- [bug] JAVA-998: SchemaChangeListener not invoked for Functions or Aggregates having UDT arguments.
78
89
910 ### 3.0.0-alpha5
modified driver-core/src/main/java/com/datastax/driver/core/AggregateMetadata.java +35 −34
@@ -29,7 +29,6 @@
2929 public class AggregateMetadata {
3030
3131 private final KeyspaceMetadata keyspace;
32- private final String fullName;
3332 private final String simpleName;
3433 private final List<DataType> argumentTypes;
3534 private final String finalFuncSimpleName;
@@ -41,11 +40,10 @@
4140 private final DataType stateType;
4241 private final TypeCodec<Object> stateTypeCodec;
4342
44- private AggregateMetadata(KeyspaceMetadata keyspace, String fullName, String simpleName, List<DataType> argumentTypes,
43+ private AggregateMetadata(KeyspaceMetadata keyspace, String simpleName, List<DataType> argumentTypes,
4544 String finalFuncSimpleName, String finalFuncFullName, Object initCond, DataType returnType,
4645 String stateFuncSimpleName, String stateFuncFullName, DataType stateType, TypeCodec<Object> stateTypeCodec) {
4746 this.keyspace = keyspace;
48- this.fullName = fullName;
4947 this.simpleName = simpleName;
5048 this.argumentTypes = argumentTypes;
5149 this.finalFuncSimpleName = finalFuncSimpleName;
@@ -89,7 +87,6 @@
8987 ProtocolVersion protocolVersion = cluster.getConfiguration().getProtocolOptions().getProtocolVersion();
9088 String simpleName = row.getString("aggregate_name");
9189 List<DataType> argumentTypes = parseTypes(ksm, row.getList("argument_types", String.class), version, cluster);
92- String fullName = Metadata.fullFunctionName(simpleName, argumentTypes);
9390 String finalFuncSimpleName = row.getString("final_func");
9491 DataType returnType;
9592 if(version.getMajor() >= 3) {
@@ -111,10 +108,10 @@
111108 initCond = rawInitCond == null ? null : codecRegistry.codecFor(stateType).deserialize(rawInitCond, protocolVersion);
112109 }
113110
114- String finalFuncFullName = finalFuncSimpleName == null ? null : String.format("%s(%s)", finalFuncSimpleName, stateType);
111+ String finalFuncFullName = finalFuncSimpleName == null ? null : Metadata.fullFunctionName(finalFuncSimpleName, Collections.singletonList(stateType));
115112 String stateFuncFullName = makeStateFuncFullName(stateFuncSimpleName, stateType, argumentTypes);
116113
117- return new AggregateMetadata(ksm, fullName, simpleName, argumentTypes,
114+ return new AggregateMetadata(ksm, simpleName, argumentTypes,
118115 finalFuncSimpleName, finalFuncFullName, initCond, returnType, stateFuncSimpleName,
119116 stateFuncFullName, stateType, codecRegistry.codecFor(stateType));
120117 }
@@ -173,37 +170,23 @@
173170 }
174171
175172 private String asCQLQuery(boolean formatted) {
176- //create aggregate test.prettysum(int) SFUNC plus STYPE int FINALFUNC announce INITCOND 0;
177173
178- StringBuilder sb = new StringBuilder();
179-
180- sb
181- .append("CREATE AGGREGATE ")
174+ StringBuilder sb = new StringBuilder("CREATE AGGREGATE ")
182175 .append(Metadata.escapeId(keyspace.getName()))
183- .append('.')
184- .append(Metadata.escapeId(simpleName))
185- .append('(');
176+ .append('.');
186177
187- boolean first = true;
188- for (DataType type : argumentTypes) {
189- if (first)
190- first = false;
191- else
192- sb.append(',');
193- sb.append(type);
194- }
195- sb.append(')');
178+ appendSignature(sb);
196179
197180 TableMetadata.spaceOrNewLine(sb, formatted)
198181 .append("SFUNC ")
199- .append(stateFuncSimpleName)
182+ .append(Metadata.escapeId(stateFuncSimpleName))
200183 .append(" STYPE ")
201- .append(stateType);
184+ .append(stateType.asFunctionParameterString());
202185
203186 if (finalFuncSimpleName != null)
204187 TableMetadata.spaceOrNewLine(sb, formatted)
205188 .append("FINALFUNC ")
206- .append(finalFuncSimpleName);
189+ .append(Metadata.escapeId(finalFuncSimpleName));
207190
208191 if (initCond != null)
209192 TableMetadata.spaceOrNewLine(sb, formatted)
@@ -215,6 +198,21 @@
215198 return sb.toString();
216199 }
217200
201+ private void appendSignature(StringBuilder sb) {
202+ sb
203+ .append(Metadata.escapeId(simpleName))
204+ .append('(');
205+ boolean first = true;
206+ for (DataType type : argumentTypes) {
207+ if (first)
208+ first = false;
209+ else
210+ sb.append(',');
211+ sb.append(type.asFunctionParameterString());
212+ }
213+ sb.append(')');
214+ }
215+
218216 /**
219217 * Returns the keyspace this aggregate belongs to.
220218 *
@@ -225,15 +223,19 @@
225223 }
226224
227225 /**
228- * Returns the full name of this aggregate.
226+ * Returns the CQL signature of this aggregate.
229227 * <p>
230228 * This is the name of the aggregate, followed by the names of the argument types between parentheses,
231229 * like it was specified in the {@code CREATE AGGREGATE...} statement, for example {@code sum(int)}.
230+ * <p>
231+ * Note that the returned signature is not qualified with the keyspace name.
232232 *
233- * @return the full name.
233+ * @return the signature of this aggregate.
234234 */
235- public String getFullName() {
236- return fullName;
235+ public String getSignature() {
236+ StringBuilder sb = new StringBuilder();
237+ appendSignature(sb);
238+ return sb.toString();
237239 }
238240
239241 /**
@@ -243,9 +245,9 @@
243245 * different argument lists, therefore the simple name may not be unique. For example,
244246 * {@code sum(int)} and {@code sum(int,int)} both have the simple name {@code sum}.
245247 *
246- * @return the simple name.
248+ * @return the simple name of this aggregate.
247249 *
248- * @see #getFullName()
250+ * @see #getSignature()
249251 */
250252 public String getSimpleName() {
251253 return simpleName;
@@ -332,7 +334,6 @@
332334 if (other instanceof AggregateMetadata) {
333335 AggregateMetadata that = (AggregateMetadata)other;
334336 return this.keyspace.getName().equals(that.keyspace.getName()) &&
335- this.fullName.equals(that.fullName) &&
336337 this.argumentTypes.equals(that.argumentTypes) &&
337338 Objects.equal(this.finalFuncFullName, that.finalFuncFullName) &&
338339 // Note: this might be a problem if a custom codec has been registered for the initCond's type, with a target Java type that
@@ -348,7 +349,7 @@
348349
349350 @Override
350351 public int hashCode() {
351- return Objects.hashCode(this.keyspace.getName(), this.fullName, this.argumentTypes,
352+ return Objects.hashCode(this.keyspace.getName(), this.argumentTypes,
352353 this.finalFuncFullName, this.initCond, this.returnType, this.stateFuncFullName, this.stateType);
353354 }
354355 }
modified driver-core/src/main/java/com/datastax/driver/core/DataType.java +29 −0
@@ -583,6 +583,23 @@
583583 });
584584 }
585585
586+ /**
587+ * Returns a String representation of this data type
588+ * suitable for inclusion as a parameter type
589+ * in a function or aggregate signature.
590+ * <p>
591+ * In such places, the String representation might vary
592+ * from the canonical one as returned by {@link #toString()};
593+ * e.g. the {@code frozen} keyword is not accepted.
594+ *
595+ * @return a String representation of this data type
596+ * suitable for inclusion as a parameter type
597+ * in a function or aggregate signature.
598+ */
599+ public String asFunctionParameterString() {
600+ return toString();
601+ }
602+
586603 public static class NativeType extends DataType {
587604
588605 private NativeType(DataType.Name name) {
@@ -662,6 +679,18 @@
662679 return String.format(template, name, typeArguments.get(0));
663680 }
664681 }
682+
683+ @Override
684+ public String asFunctionParameterString() {
685+ if (name == Name.MAP) {
686+ String template = "%s<%s, %s>";
687+ return String.format(template, name, typeArguments.get(0), typeArguments.get(1));
688+ }
689+ else {
690+ String template = "%s<%s>";
691+ return String.format(template, name, typeArguments.get(0));
692+ }
693+ }
665694 }
666695
667696 public static class CustomType extends DataType {
modified driver-core/src/main/java/com/datastax/driver/core/FunctionMetadata.java +26 −19
@@ -32,7 +32,6 @@
3232 private static final Logger logger = LoggerFactory.getLogger(FunctionMetadata.class);
3333
3434 private final KeyspaceMetadata keyspace;
35- private final String fullName;
3635 private final String simpleName;
3736 private final Map<String, DataType> arguments;
3837 private final String body;
@@ -41,7 +40,6 @@
4140 private final DataType returnType;
4241
4342 private FunctionMetadata(KeyspaceMetadata keyspace,
44- String fullName,
4543 String simpleName,
4644 Map<String, DataType> arguments,
4745 String body,
@@ -49,7 +47,6 @@
4947 String language,
5048 DataType returnType) {
5149 this.keyspace = keyspace;
52- this.fullName = fullName;
5350 this.simpleName = simpleName;
5451 this.arguments = arguments;
5552 this.body = body;
@@ -94,8 +91,8 @@
9491 // this will be a list of C* types in 2.2 and a list of CQL types in 3.0
9592 List<String> argumentTypes = row.getList("argument_types", String.class);
9693 Map<String, DataType> arguments = buildArguments(ksm, argumentNames, argumentTypes, version, cluster);
97- String fullName = Metadata.fullFunctionName(simpleName, arguments.values());
9894 if (argumentNames.size() != argumentTypes.size()) {
95+ String fullName = Metadata.fullFunctionName(simpleName, arguments.values());
9996 logger.error(String.format("Error parsing definition of function %1$s.%2$s: the number of argument names and types don't match."
10097 + "Cluster.getMetadata().getKeyspace(\"%1$s\").getFunction(\"%2$s\") will be missing.",
10198 ksm.getName(), fullName));
@@ -110,8 +107,7 @@
110107 } else {
111108 returnType = DataTypeClassNameParser.parseOne(row.getString("return_type"), protocolVersion, codecRegistry);
112109 }
113- return new FunctionMetadata(ksm, fullName, simpleName, arguments, body,
114- calledOnNullInput, language, returnType);
110+ return new FunctionMetadata(ksm, simpleName, arguments, body, calledOnNullInput, language, returnType);
115111 }
116112
117113 // Note: the caller ensures that names and types have the same size
@@ -119,7 +115,6 @@
119115 if (names.isEmpty())
120116 return Collections.emptyMap();
121117 ImmutableMap.Builder<String, DataType> builder = ImmutableMap.builder();
122- Metadata metadata = cluster.getMetadata();
123118 CodecRegistry codecRegistry = cluster.getConfiguration().getCodecRegistry();
124119 ProtocolVersion protocolVersion = cluster.getConfiguration().getProtocolOptions().getProtocolVersion();
125120 Iterator<String> iterTypes = types.iterator();
@@ -164,12 +159,10 @@
164159 }
165160
166161 private String asCQLQuery(boolean formatted) {
167- // create function test.sum(a int, b int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java as 'return a+b;';
168162
169- StringBuilder sb = new StringBuilder();
163+ StringBuilder sb = new StringBuilder("CREATE FUNCTION ");
170164
171165 sb
172- .append("CREATE FUNCTION ")
173166 .append(Metadata.escapeId(keyspace.getName()))
174167 .append('.')
175168 .append(Metadata.escapeId(simpleName))
@@ -188,7 +181,7 @@
188181 .append(TableMetadata.spaces(4, formatted))
189182 .append(Metadata.escapeId(name))
190183 .append(' ')
191- .append(type);
184+ .append(type.asFunctionParameterString());
192185 }
193186 sb.append(')');
194187
@@ -221,15 +214,30 @@
221214 }
222215
223216 /**
224- * Returns the full name of this function.
217+ * Returns the CQL signature of this function.
225218 * <p>
226219 * This is the name of the function, followed by the names of the argument types between parentheses,
227220 * for example {@code sum(int,int)}.
221+ * <p>
222+ * Note that the returned signature is not qualified with the keyspace name.
228223 *
229- * @return the full name.
224+ * @return the signature of this function.
230225 */
231- public String getFullName() {
232- return fullName;
226+ public String getSignature() {
227+ StringBuilder sb = new StringBuilder();
228+ sb
229+ .append(Metadata.escapeId(simpleName))
230+ .append('(');
231+ boolean first = true;
232+ for (DataType type : arguments.values()) {
233+ if (first)
234+ first = false;
235+ else
236+ sb.append(',');
237+ sb.append(type.asFunctionParameterString());
238+ }
239+ sb.append(')');
240+ return sb.toString();
233241 }
234242
235243 /**
@@ -239,9 +247,9 @@
239247 * different argument lists, therefore the simple name may not be unique. For example,
240248 * {@code sum(int,int)} and {@code sum(int,int,int)} both have the simple name {@code sum}.
241249 *
242- * @return the simple name.
250+ * @return the simple name of this function.
243251 *
244- * @see #getFullName()
252+ * @see #getSignature()
245253 */
246254 public String getSimpleName() {
247255 return simpleName;
@@ -303,7 +311,6 @@
303311 if (other instanceof FunctionMetadata) {
304312 FunctionMetadata that = (FunctionMetadata)other;
305313 return this.keyspace.getName().equals(that.keyspace.getName()) &&
306- this.fullName.equals(that.fullName) &&
307314 this.arguments.equals(that.arguments) &&
308315 this.body.equals(that.body) &&
309316 this.calledOnNullInput == that.calledOnNullInput &&
@@ -315,6 +322,6 @@
315322
316323 @Override
317324 public int hashCode() {
318- return Objects.hashCode(keyspace.getName(), fullName, arguments, body, calledOnNullInput, language, returnType);
325+ return Objects.hashCode(keyspace.getName(), arguments, body, calledOnNullInput, language, returnType);
319326 }
320327 }
modified driver-core/src/main/java/com/datastax/driver/core/KeyspaceMetadata.java +4 −2
@@ -353,11 +353,13 @@
353353 }
354354
355355 void add(FunctionMetadata function) {
356- functions.put(function.getFullName(), function);
356+ String functionName = Metadata.fullFunctionName(function.getSimpleName(), function.getArguments().values());
357+ functions.put(functionName, function);
357358 }
358359
359360 void add(AggregateMetadata aggregate) {
360- aggregates.put(aggregate.getFullName(), aggregate);
361+ String aggregateName = Metadata.fullFunctionName(aggregate.getSimpleName(), aggregate.getArgumentTypes());
362+ aggregates.put(aggregateName, aggregate);
361363 }
362364
363365 void add(UserType type) {
modified driver-core/src/main/java/com/datastax/driver/core/Metadata.java +37 −7
@@ -134,15 +134,45 @@
134134 return lowercaseAlphanumeric.matcher(ident).matches() ? ident : quote(ident);
135135 }
136136
137- // Builds the internal name of a function/aggregate
138- // Note that if simpleName comes from the user, the caller must call handleId on it before passing it to this method
137+ /**
138+ * Builds the internal name of a function/aggregate, which is similar, but not identical,
139+ * to the function/aggregate signature.
140+ * This is only used to generate keys for internal metadata maps (KeyspaceMetadata.functions and.
141+ * KeyspaceMetadata.aggregates).
142+ * Note that if simpleName comes from the user, the caller must call handleId on it before passing it to this method.
143+ * Note that this method does not necessarily generates a valid CQL function signature.
144+ * Note that argumentTypes can be either a list of strings (schema change events)
145+ * or a list of DataTypes (function lookup from client code).
146+ * This method must ensure that both cases produce the same identifier.
147+ */
139148 static String fullFunctionName(String simpleName, Collection<?> argumentTypes) {
140- return String.format("%s(%s)",
141- simpleName, COMMAS.join(argumentTypes));
149+ StringBuilder sb = new StringBuilder(simpleName);
150+ sb.append('(');
151+ boolean first = true;
152+ for (Object argumentType : argumentTypes) {
153+ if (first)
154+ first = false;
155+ else
156+ sb.append(',');
157+ // user types must be represented by their names only,
158+ // without keyspace prefix, because that's how
159+ // they appear in a schema change event (in targetSignature)
160+ if (argumentType instanceof UserType) {
161+ UserType userType = (UserType)argumentType;
162+ String typeName = Metadata.escapeId(userType.getTypeName());
163+ if (userType.isFrozen())
164+ sb.append("frozen<");
165+ sb.append(typeName);
166+ if (userType.isFrozen())
167+ sb.append(">");
168+ } else {
169+ sb.append(argumentType);
170+ }
171+ }
172+ sb.append(')');
173+ return sb.toString();
142174 }
143175
144- static final Joiner COMMAS = Joiner.on(",");
145-
146176 /**
147177 * Quote a keyspace, table or column identifier to make it case sensitive.
148178 * <p>
@@ -160,7 +190,7 @@
160190 * or even {@link Cluster#connect(String)}.
161191 */
162192 public static String quote(String id) {
163- return '"' + id + '"';
193+ return '"' + id.replace("\"", "\"\"") + '"';
164194 }
165195
166196 /**
modified driver-core/src/main/java/com/datastax/driver/core/SchemaParser.java +16 −10
@@ -205,8 +205,10 @@
205205 if (functionRows != null) {
206206 for (Row functionRow : functionRows) {
207207 FunctionMetadata function = FunctionMetadata.build(keyspace, functionRow, cassandraVersion, cluster);
208- if (function != null)
209- functions.put(function.getFullName(), function);
208+ if (function != null) {
209+ String name = Metadata.fullFunctionName(function.getSimpleName(), function.getArguments().values());
210+ functions.put(name, function);
211+ }
210212 }
211213 }
212214 return functions;
@@ -217,8 +219,10 @@
217219 if (aggregateRows != null) {
218220 for (Row aggregateRow : aggregateRows) {
219221 AggregateMetadata aggregate = AggregateMetadata.build(keyspace, aggregateRow, cassandraVersion, cluster);
220- if (aggregate != null)
221- aggregates.put(aggregate.getFullName(), aggregate);
222+ if (aggregate != null) {
223+ String name = Metadata.fullFunctionName(aggregate.getSimpleName(), aggregate.getArgumentTypes());
224+ aggregates.put(name, aggregate);
225+ }
222226 }
223227 }
224228 return aggregates;
@@ -328,14 +332,15 @@
328332 Iterator<FunctionMetadata> it = oldFunctions.values().iterator();
329333 while (it.hasNext()) {
330334 FunctionMetadata oldFunction = it.next();
331- String functionName = oldFunction.getFullName();
332- if ((functionToRebuild == null || functionToRebuild.equals(functionName)) && !newFunctions.containsKey(functionName)) {
335+ String oldFunctionName = Metadata.fullFunctionName(oldFunction.getSimpleName(), oldFunction.getArguments().values());
336+ if ((functionToRebuild == null || functionToRebuild.equals(oldFunctionName)) && !newFunctions.containsKey(oldFunctionName)) {
333337 it.remove();
334338 metadata.triggerOnFunctionRemoved(oldFunction);
335339 }
336340 }
337341 for (FunctionMetadata newFunction : newFunctions.values()) {
338- FunctionMetadata oldFunction = oldFunctions.put(newFunction.getFullName(), newFunction);
342+ String newFunctionName = Metadata.fullFunctionName(newFunction.getSimpleName(), newFunction.getArguments().values());
343+ FunctionMetadata oldFunction = oldFunctions.put(newFunctionName, newFunction);
339344 if (oldFunction == null) {
340345 metadata.triggerOnFunctionAdded(newFunction);
341346 } else if (!newFunction.equals(oldFunction)) {
@@ -348,14 +353,15 @@
348353 Iterator<AggregateMetadata> it = oldAggregates.values().iterator();
349354 while (it.hasNext()) {
350355 AggregateMetadata oldAggregate = it.next();
351- String aggregateName = oldAggregate.getFullName();
352- if ((aggregateToRebuild == null || aggregateToRebuild.equals(aggregateName)) && !newAggregates.containsKey(aggregateName)) {
356+ String oldAggregateName = Metadata.fullFunctionName(oldAggregate.getSimpleName(), oldAggregate.getArgumentTypes());
357+ if ((aggregateToRebuild == null || aggregateToRebuild.equals(oldAggregateName)) && !newAggregates.containsKey(oldAggregateName)) {
353358 it.remove();
354359 metadata.triggerOnAggregateRemoved(oldAggregate);
355360 }
356361 }
357362 for (AggregateMetadata newAggregate : newAggregates.values()) {
358- AggregateMetadata oldAggregate = oldAggregates.put(newAggregate.getFullName(), newAggregate);
363+ String newAggregateName = Metadata.fullFunctionName(newAggregate.getSimpleName(), newAggregate.getArgumentTypes());
364+ AggregateMetadata oldAggregate = oldAggregates.put(newAggregateName, newAggregate);
359365 if (oldAggregate == null) {
360366 metadata.triggerOnAggregateAdded(newAggregate);
361367 } else if (!newAggregate.equals(oldAggregate)) {
modified driver-core/src/main/java/com/datastax/driver/core/TupleType.java +7 −3
@@ -185,12 +185,16 @@
185185
186186 @Override
187187 public String toString() {
188+ return "frozen<" + asFunctionParameterString() + ">";
189+ }
190+
191+ @Override
192+ public String asFunctionParameterString() {
188193 StringBuilder sb = new StringBuilder();
189194 for (DataType type : types) {
190- sb.append(sb.length() == 0 ? "frozen<tuple<" : ", ");
195+ sb.append(sb.length() == 0 ? "tuple<" : ", ");
191196 sb.append(type);
192197 }
193- return sb.append(">>").toString();
198+ return sb.append(">").toString();
194199 }
195-
196200 }
modified driver-core/src/main/java/com/datastax/driver/core/UserType.java +5 −0
@@ -273,6 +273,11 @@
273273 return "frozen<" + Metadata.escapeId(getKeyspace()) + '.' + Metadata.escapeId(getTypeName()) + ">";
274274 }
275275
276+ @Override
277+ public String asFunctionParameterString() {
278+ return Metadata.escapeId(getTypeName());
279+ }
280+
276281 /**
277282 * A UDT field.
278283 */
modified driver-core/src/test/java/com/datastax/driver/core/AggregateMetadataAssert.java +2 −2
@@ -24,8 +24,8 @@
2424 super(actual, AggregateMetadataAssert.class);
2525 }
2626
27- public AggregateMetadataAssert hasFullName(String name) {
28- assertThat(actual.getFullName()).isEqualTo(name);
27+ public AggregateMetadataAssert hasSignature(String name) {
28+ assertThat(actual.getSignature()).isEqualTo(name);
2929 return this;
3030 }
3131
modified driver-core/src/test/java/com/datastax/driver/core/AggregateMetadataTest.java +50 −6
@@ -16,10 +16,11 @@
1616 package com.datastax.driver.core;
1717
1818 import java.util.Collection;
19-import java.util.Collections;
2019
2120 import org.testng.annotations.Test;
2221
22+import static com.google.common.collect.Lists.newArrayList;
23+
2324 import com.datastax.driver.core.utils.CassandraVersion;
2425
2526 import static com.datastax.driver.core.Assertions.assertThat;
@@ -42,7 +43,7 @@
4243 FunctionMetadata stateFunc = keyspace.getFunction("cat", text(), cint());
4344 AggregateMetadata aggregate = keyspace.getAggregate("cat_tos", cint());
4445 assertThat(aggregate).isNotNull();
45- assertThat(aggregate.getFullName()).isEqualTo("cat_tos(int)");
46+ assertThat(aggregate.getSignature()).isEqualTo("cat_tos(int)");
4647 assertThat(aggregate.getSimpleName()).isEqualTo("cat_tos");
4748 assertThat(aggregate.getArgumentTypes()).containsExactly(cint());
4849 assertThat(aggregate.getFinalFunc()).isNull();
@@ -69,7 +70,7 @@
6970 FunctionMetadata stateFunc = keyspace.getFunction("inc", cint());
7071 AggregateMetadata aggregate = keyspace.getAggregate("mycount");
7172 assertThat(aggregate).isNotNull();
72- assertThat(aggregate.getFullName()).isEqualTo("mycount()");
73+ assertThat(aggregate.getSignature()).isEqualTo("mycount()");
7374 assertThat(aggregate.getSimpleName()).isEqualTo("mycount");
7475 assertThat(aggregate.getArgumentTypes()).isEmpty();
7576 assertThat(aggregate.getFinalFunc()).isNull();
@@ -99,7 +100,7 @@
99100 FunctionMetadata finalFunc = keyspace.getFunction("announce", cint());
100101 AggregateMetadata aggregate = keyspace.getAggregate("prettysum", cint());
101102 assertThat(aggregate).isNotNull();
102- assertThat(aggregate.getFullName()).isEqualTo("prettysum(int)");
103+ assertThat(aggregate.getSignature()).isEqualTo("prettysum(int)");
103104 assertThat(aggregate.getSimpleName()).isEqualTo("prettysum");
104105 assertThat(aggregate.getArgumentTypes()).containsExactly(cint());
105106 assertThat(aggregate.getFinalFunc()).isEqualTo(finalFunc);
@@ -127,7 +128,7 @@
127128 FunctionMetadata stateFunc = keyspace.getFunction("plus2", cint(), cint());
128129 AggregateMetadata aggregate = keyspace.getAggregate("sum", cint());
129130 assertThat(aggregate).isNotNull();
130- assertThat(aggregate.getFullName()).isEqualTo("sum(int)");
131+ assertThat(aggregate.getSignature()).isEqualTo("sum(int)");
131132 assertThat(aggregate.getSimpleName()).isEqualTo("sum");
132133 assertThat(aggregate.getArgumentTypes()).containsExactly(cint());
133134 assertThat(aggregate.getFinalFunc()).isNull();
@@ -140,9 +141,52 @@
140141 + "SFUNC plus2 STYPE int;", this.keyspace));
141142 }
142143
144+ @Test(groups = "short")
145+ public void should_parse_and_format_aggregate_with_udts() {
146+ // given
147+ String cqlFunction = String.format(
148+ "CREATE FUNCTION %s.\"MY_FUNC\"(address1 \"Address\", address2 \"Address\") "
149+ + "CALLED ON NULL INPUT "
150+ + "RETURNS \"Address\" "
151+ + "LANGUAGE java "
152+ + "AS 'return address1;'", keyspace);
153+ String cqlAggregate = String.format(
154+ "CREATE AGGREGATE %s.\"MY_AGGREGATE\"(\"Address\") "
155+ + "SFUNC \"MY_FUNC\" "
156+ + "STYPE \"Address\";",
157+ keyspace);
158+ // when
159+ session.execute(cqlFunction);
160+ session.execute(cqlAggregate);
161+ // then
162+ KeyspaceMetadata keyspace = cluster.getMetadata().getKeyspace(this.keyspace);
163+ UserType addressType = keyspace.getUserType("\"Address\"");
164+ FunctionMetadata stateFunc = keyspace.getFunction("\"MY_FUNC\"", addressType, addressType);
165+ AggregateMetadata aggregate = keyspace.getAggregate("\"MY_AGGREGATE\"", addressType);
166+ assertThat(aggregate).isNotNull();
167+ assertThat(aggregate.getSignature()).isEqualTo("\"MY_AGGREGATE\"(\"Address\")");
168+ assertThat(aggregate.getSimpleName()).isEqualTo("MY_AGGREGATE");
169+ assertThat(aggregate.getArgumentTypes()).containsExactly(addressType);
170+ assertThat(aggregate.getFinalFunc()).isNull();
171+ assertThat(aggregate.getInitCond()).isNull();
172+ assertThat(aggregate.getReturnType()).isEqualTo(addressType);
173+ assertThat(aggregate.getStateFunc()).isEqualTo(stateFunc);
174+ assertThat(aggregate.getStateType()).isEqualTo(addressType);
175+ assertThat(aggregate.toString()).isEqualTo(cqlAggregate);
176+ }
177+
143178 @Override
144179 protected Collection<String> getTableDefinitions() {
145- return Collections.emptyList();
180+ return newArrayList(
181+ String.format("CREATE TYPE IF NOT EXISTS %s.phone (number text)", keyspace),
182+ String.format("CREATE TYPE IF NOT EXISTS %s.\"Address\" ("
183+ + " street text,"
184+ + " city text,"
185+ + " zip int,"
186+ + " phones frozen<set<frozen<phone>>>,"
187+ + " location frozen<tuple<float, float>>"
188+ + ")", keyspace)
189+ );
146190 }
147191
148192 }
modified driver-core/src/test/java/com/datastax/driver/core/DataTypeCqlNameParserTest.java +3 −2
@@ -25,6 +25,7 @@
2525 import static com.datastax.driver.core.Assertions.assertThat;
2626 import static com.datastax.driver.core.DataType.*;
2727 import static com.datastax.driver.core.DataTypeCqlNameParser.parse;
28+import static com.datastax.driver.core.Metadata.quote;
2829
2930 @CassandraVersion(major = 3.0)
3031 public class DataTypeCqlNameParserTest extends CCMBridge.PerClassSingleNodeCluster {
@@ -88,8 +89,8 @@
8889 assertThat(parse("list<list<int>>", cluster, null, null, null, false, false)).isEqualTo(list(list(cint())));
8990 assertThat(parse("set<list<frozen<map<bigint,varchar>>>>", cluster, null, null, null, false, false)).isEqualTo(set(list(map(bigint(), varchar(), true))));
9091
91- UserType keyType = keyspaceMetadata.getUserType("Incr,edibly\" EvilTy<>><<><p\"e");
92- UserType valueType = keyspaceMetadata.getUserType("\"A\"");
92+ UserType keyType = keyspaceMetadata.getUserType(quote("Incr,edibly\" EvilTy<>><<><p\"e"));
93+ UserType valueType = keyspaceMetadata.getUserType(quote("A"));
9394 assertThat(parse("map<frozen<\"Incr,edibly\"\" EvilTy<>><<><p\"\"e\">,frozen<\"A\">>", cluster, keyspace, keyspaceMetadata.userTypes, null, false, false))
9495 .isEqualTo(map(keyType, valueType, false));
9596 }
modified driver-core/src/test/java/com/datastax/driver/core/FunctionMetadataAssert.java +2 −2
@@ -24,8 +24,8 @@
2424 super(actual, FunctionMetadataAssert.class);
2525 }
2626
27- public FunctionMetadataAssert hasFullName(String name) {
28- assertThat(actual.getFullName()).isEqualTo(name);
27+ public FunctionMetadataAssert hasSignature(String name) {
28+ assertThat(actual.getSignature()).isEqualTo(name);
2929 return this;
3030 }
3131
modified driver-core/src/test/java/com/datastax/driver/core/FunctionMetadataTest.java +52 −5
@@ -16,10 +16,12 @@
1616 package com.datastax.driver.core;
1717
1818 import java.util.Collection;
19-import java.util.Collections;
2019
2120 import org.testng.annotations.Test;
2221
22+import static com.google.common.collect.Lists.newArrayList;
23+import static org.assertj.core.api.Assertions.entry;
24+
2325 import com.datastax.driver.core.utils.CassandraVersion;
2426
2527 import static com.datastax.driver.core.Assertions.assertThat;
@@ -39,7 +41,7 @@
3941 FunctionMetadata function = keyspace.getFunction("plus", cint(), cint());
4042 assertThat(function).isNotNull();
4143 assertThat(function.getKeyspace()).isEqualTo(keyspace);
42- assertThat(function.getFullName()).isEqualTo("plus(int,int)");
44+ assertThat(function.getSignature()).isEqualTo("plus(int,int)");
4345 assertThat(function.getSimpleName()).isEqualTo("plus");
4446 assertThat(function.getReturnType()).isEqualTo(cint());
4547 assertThat(function.getArguments())
@@ -71,14 +73,13 @@
7173 FunctionMetadata function = keyspace.getFunction("pi");
7274 assertThat(function).isNotNull();
7375 assertThat(function.getKeyspace()).isEqualTo(keyspace);
74- assertThat(function.getFullName()).isEqualTo("pi()");
76+ assertThat(function.getSignature()).isEqualTo("pi()");
7577 assertThat(function.getSimpleName()).isEqualTo("pi");
7678 assertThat(function.getReturnType()).isEqualTo(DataType.cdouble());
7779 assertThat(function.getArguments()).isEmpty();
7880 assertThat(function.getLanguage()).isEqualTo("java");
7981 assertThat(function.getBody()).isEqualTo("return Math.PI;");
8082 assertThat(function.isCalledOnNullInput()).isTrue();
81- assertThat(keyspace.getFunction("pi")).isEqualTo(function);
8283 assertThat(function.toString())
8384 .isEqualTo(cql);
8485 assertThat(function.exportAsString())
@@ -89,9 +90,55 @@
8990 + "AS 'return Math.PI;';", this.keyspace));
9091 }
9192
93+ @Test(groups = "short")
94+ public void should_parse_and_format_function_with_udts() {
95+ // given
96+ String body =
97+ "//If \"called on null input\", handle nulls\n"
98+ + "if(ADDRESS == null) return previous_total + 0;\n"
99+ + "//User types are converted to com.datastax.driver.core.UDTValue types\n"
100+ + "java.util.Set phones = ADDRESS.getSet(\"phones\", com.datastax.driver.core.UDTValue.class);\n"
101+ + "return previous_total + phones.size();\n";
102+ String cqlFunction = String.format(
103+ "CREATE FUNCTION %s.\"NUM_PHONES_ACCU\"(previous_total int,\"ADDRESS\" \"Address\") "
104+ + "CALLED ON NULL INPUT "
105+ + "RETURNS int "
106+ + "LANGUAGE java "
107+ + "AS "
108+ + "'"
109+ + body
110+ + "';", keyspace);
111+ // when
112+ session.execute(cqlFunction);
113+ // then
114+ KeyspaceMetadata keyspace = cluster.getMetadata().getKeyspace(this.keyspace);
115+ UserType addressType = keyspace.getUserType("\"Address\"");
116+ FunctionMetadata function = keyspace.getFunction("\"NUM_PHONES_ACCU\"", cint(), addressType);
117+ assertThat(function).isNotNull();
118+ assertThat(function.getKeyspace()).isEqualTo(keyspace);
119+
120+ assertThat(function.getSignature()).isEqualTo("\"NUM_PHONES_ACCU\"(int,\"Address\")");
121+ assertThat(function.getSimpleName()).isEqualTo("NUM_PHONES_ACCU");
122+ assertThat(function.getReturnType()).isEqualTo(cint());
123+ assertThat(function.getArguments()).containsExactly(entry("previous_total", cint()), entry("ADDRESS", addressType));
124+ assertThat(function.getLanguage()).isEqualTo("java");
125+ assertThat(function.getBody()).isEqualTo(body);
126+ assertThat(function.isCalledOnNullInput()).isTrue();
127+ assertThat(function.toString()).isEqualTo(cqlFunction);
128+ }
129+
92130 @Override
93131 protected Collection<String> getTableDefinitions() {
94- return Collections.emptyList();
132+ return newArrayList(
133+ String.format("CREATE TYPE IF NOT EXISTS %s.\"Phone\" (number text)", keyspace),
134+ String.format("CREATE TYPE IF NOT EXISTS %s.\"Address\" ("
135+ + " street text,"
136+ + " city text,"
137+ + " zip int,"
138+ + " phones frozen<set<frozen<\"Phone\">>>,"
139+ + " location frozen<tuple<float, float>>"
140+ + ")", keyspace)
141+ );
95142 }
96143
97144 }
modified driver-core/src/test/java/com/datastax/driver/core/SchemaChangesTest.java +38 −37
@@ -268,98 +268,99 @@
268268 @Test(groups = "short", dataProvider = "existingKeyspaceName")
269269 @CassandraVersion(major = 2.2)
270270 public void should_notify_of_function_creation(String keyspace) {
271- session.execute(String.format("CREATE FUNCTION %s.id(i int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return i;'", keyspace));
271+ session.execute(String.format("CREATE FUNCTION %s.\"ID\"(i int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return i;'", keyspace));
272272
273273 for (SchemaChangeListener listener : listeners) {
274274 ArgumentCaptor<FunctionMetadata> added = ArgumentCaptor.forClass(FunctionMetadata.class);
275275 verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onFunctionAdded(added.capture());
276276 assertThat(added.getValue())
277277 .isInKeyspace(handleId(keyspace))
278- .hasFullName("id(int)");
278+ .hasSignature("\"ID\"(int)");
279279 }
280280
281281 for (Metadata m : metadatas)
282- assertThat(m.getKeyspace(keyspace).getFunction("id", DataType.cint()))
282+ assertThat(m.getKeyspace(keyspace).getFunction("\"ID\"", DataType.cint()))
283283 .isNotNull();
284284 }
285285
286286 @Test(groups = "short", dataProvider = "existingKeyspaceName")
287287 @CassandraVersion(major = 2.2)
288288 public void should_notify_of_function_update(String keyspace) {
289- session.execute(String.format("CREATE FUNCTION %s.id(i int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java "
290- + "AS 'return i;'", keyspace));
289+ session.execute(String.format("CREATE TYPE IF NOT EXISTS %s.user (\"ID\" int, name text)", keyspace));
290+ session.execute(String.format("CREATE FUNCTION %s.\"ID\"(user user) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return user.getInt(\"ID\");'", keyspace));
291291
292292 for (Metadata m : metadatas)
293- assertThat(m.getKeyspace(keyspace).getFunction("id", DataType.cint()).getBody())
294- .isEqualTo("return i;");
293+ assertThat(m.getKeyspace(keyspace).getFunction("\"ID\"", m.getKeyspace(keyspace).getUserType("user")).getBody())
294+ .isEqualTo("return user.getInt(\"ID\");");
295295
296- session.execute(String.format("CREATE OR REPLACE FUNCTION %s.id(i int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java "
297- + "AS 'return i + 1;'", keyspace));
296+ session.execute(String.format("CREATE OR REPLACE FUNCTION %s.\"ID\"(user user) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java "
297+ + "AS 'return 1 + user.getInt(\"ID\");'", keyspace));
298298
299299 for (SchemaChangeListener listener : listeners) {
300300 ArgumentCaptor<FunctionMetadata> current = ArgumentCaptor.forClass(FunctionMetadata.class);
301301 ArgumentCaptor<FunctionMetadata> previous = ArgumentCaptor.forClass(FunctionMetadata.class);
302302 verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onFunctionChanged(current.capture(), previous.capture());
303- assertThat(previous.getValue()).hasBody("return i;");
304- assertThat(current.getValue()).hasBody("return i + 1;");
303+ assertThat(previous.getValue()).hasBody("return user.getInt(\"ID\");");
304+ assertThat(current.getValue()).hasBody("return 1 + user.getInt(\"ID\");");
305305 }
306306
307307 for (Metadata m : metadatas)
308- assertThat(m.getKeyspace(keyspace).getFunction("id", DataType.cint()).getBody())
309- .isEqualTo("return i + 1;");
308+ assertThat(m.getKeyspace(keyspace).getFunction("\"ID\"", m.getKeyspace(keyspace).getUserType("user")).getBody())
309+ .isEqualTo("return 1 + user.getInt(\"ID\");");
310310 }
311311
312312 @Test(groups = "short", dataProvider = "existingKeyspaceName")
313313 @CassandraVersion(major = 2.2)
314314 public void should_notify_of_function_drop(String keyspace) {
315- session.execute(String.format("CREATE FUNCTION %s.id(i int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return i;'", keyspace));
316- session.execute(String.format("DROP FUNCTION %s.id", keyspace));
315+ session.execute(String.format("CREATE TYPE IF NOT EXISTS %s.user (\"ID\" int, name text)", keyspace));
316+ session.execute(String.format("CREATE FUNCTION %s.\"ID\"(user user) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return user.getInt(\"ID\");'", keyspace));
317+ session.execute(String.format("DROP FUNCTION %s.\"ID\"", keyspace));
317318
318319 for (SchemaChangeListener listener : listeners) {
319320 ArgumentCaptor<FunctionMetadata> removed = ArgumentCaptor.forClass(FunctionMetadata.class);
320321 verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onFunctionRemoved(removed.capture());
321322 assertThat(removed.getValue())
322323 .isInKeyspace(handleId(keyspace))
323- .hasFullName("id(int)");
324+ .hasSignature("\"ID\"(user)");
324325 }
325326
326327 for (Metadata m : metadatas)
327- assertThat(m.getKeyspace(keyspace).getFunction("id", DataType.cint()))
328+ assertThat(m.getKeyspace(keyspace).getFunction("\"ID\"", m.getKeyspace(keyspace).getUserType("user")))
328329 .isNull();
329330 }
330331
331332 @Test(groups = "short", dataProvider = "existingKeyspaceName")
332333 @CassandraVersion(major = 2.2)
333334 public void should_notify_of_aggregate_creation(String keyspace) {
334- session.execute(String.format("CREATE FUNCTION %s.plus(s int, v int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java"
335+ session.execute(String.format("CREATE FUNCTION %s.\"PLUS\"(s int, v int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java"
335336 + " AS 'return s+v;'", keyspace));
336- session.execute(String.format("CREATE AGGREGATE %s.sum(int) SFUNC plus STYPE int INITCOND 0;", keyspace));
337+ session.execute(String.format("CREATE AGGREGATE %s.\"SUM\"(int) SFUNC \"PLUS\" STYPE int INITCOND 0;", keyspace));
337338
338339 for (SchemaChangeListener listener : listeners) {
339340 ArgumentCaptor<AggregateMetadata> added = ArgumentCaptor.forClass(AggregateMetadata.class);
340341 verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onAggregateAdded(added.capture());
341342 assertThat(added.getValue())
342343 .isInKeyspace(handleId(keyspace))
343- .hasFullName("sum(int)");
344+ .hasSignature("\"SUM\"(int)");
344345 }
345346
346347 for (Metadata m : metadatas)
347- assertThat(m.getKeyspace(keyspace).getAggregate("sum", DataType.cint()))
348+ assertThat(m.getKeyspace(keyspace).getAggregate("\"SUM\"", DataType.cint()))
348349 .isNotNull();
349350 }
350351
351352 @Test(groups = "short", dataProvider = "existingKeyspaceName")
352353 @CassandraVersion(major = 2.2)
353354 public void should_notify_of_aggregate_update(String keyspace) {
354- session.execute(String.format("CREATE FUNCTION %s.plus(s int, v int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java"
355+ session.execute(String.format("CREATE FUNCTION %s.\"PLUS\"(s int, v int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java"
355356 + " AS 'return s+v;'", keyspace));
356- session.execute(String.format("CREATE AGGREGATE %s.sum(int) SFUNC plus STYPE int INITCOND 0", keyspace));
357+ session.execute(String.format("CREATE AGGREGATE %s.\"SUM\"(int) SFUNC \"PLUS\" STYPE int INITCOND 0", keyspace));
357358
358359 for (Metadata m : metadatas)
359- assertThat(m.getKeyspace(keyspace).getAggregate("sum", DataType.cint()).getInitCond())
360+ assertThat(m.getKeyspace(keyspace).getAggregate("\"SUM\"", DataType.cint()).getInitCond())
360361 .isEqualTo(0);
361362
362- session.execute(String.format("CREATE OR REPLACE AGGREGATE %s.sum(int) SFUNC plus STYPE int INITCOND 1", keyspace));
363+ session.execute(String.format("CREATE OR REPLACE AGGREGATE %s.\"SUM\"(int) SFUNC \"PLUS\" STYPE int INITCOND 1", keyspace));
363364
364365 for (SchemaChangeListener listener : listeners) {
365366 ArgumentCaptor<AggregateMetadata> current = ArgumentCaptor.forClass(AggregateMetadata.class);
@@ -370,28 +371,28 @@
370371 }
371372
372373 for (Metadata m : metadatas)
373- assertThat(m.getKeyspace(keyspace).getAggregate("sum", DataType.cint()).getInitCond())
374+ assertThat(m.getKeyspace(keyspace).getAggregate("\"SUM\"", DataType.cint()).getInitCond())
374375 .isEqualTo(1);
375376 }
376377
377378 @Test(groups = "short", dataProvider = "existingKeyspaceName")
378379 @CassandraVersion(major = 2.2)
379380 public void should_notify_of_aggregate_drop(String keyspace) {
380- session.execute(String.format("CREATE FUNCTION %s.plus(s int, v int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java"
381+ session.execute(String.format("CREATE FUNCTION %s.\"PLUS\"(s int, v int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java"
381382 + " AS 'return s+v;'", keyspace));
382- session.execute(String.format("CREATE AGGREGATE %s.sum(int) SFUNC plus STYPE int INITCOND 0", keyspace));
383- session.execute(String.format("DROP AGGREGATE %s.sum", keyspace));
383+ session.execute(String.format("CREATE AGGREGATE %s.\"SUM\"(int) SFUNC \"PLUS\" STYPE int INITCOND 0", keyspace));
384+ session.execute(String.format("DROP AGGREGATE %s.\"SUM\"", keyspace));
384385
385386 for (SchemaChangeListener listener : listeners) {
386387 ArgumentCaptor<AggregateMetadata> removed = ArgumentCaptor.forClass(AggregateMetadata.class);
387388 verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onAggregateRemoved(removed.capture());
388389 assertThat(removed.getValue())
389390 .isInKeyspace(handleId(keyspace))
390- .hasFullName("sum(int)");
391+ .hasSignature("\"SUM\"(int)");
391392 }
392393
393394 for (Metadata m : metadatas)
394- assertThat(m.getKeyspace(keyspace).getAggregate("sum", DataType.cint()))
395+ assertThat(m.getKeyspace(keyspace).getAggregate("\"SUM\"", DataType.cint()))
395396 .isNull();
396397 }
397398
@@ -608,12 +609,12 @@
608609 session1.executeAsync("DROP TABLE \"CaseSensitive\".table1"),
609610 session1.executeAsync("DROP TYPE lowercase.type1"),
610611 session1.executeAsync("DROP TYPE \"CaseSensitive\".type1"),
611- session1.executeAsync("DROP FUNCTION lowercase.id"),
612- session1.executeAsync("DROP FUNCTION \"CaseSensitive\".id"),
613- session1.executeAsync("DROP FUNCTION lowercase.plus"),
614- session1.executeAsync("DROP FUNCTION \"CaseSensitive\".plus"),
615- session1.executeAsync("DROP AGGREGATE lowercase.sum"),
616- session1.executeAsync("DROP AGGREGATE \"CaseSensitive\".sum"),
612+ session1.executeAsync("DROP FUNCTION lowercase.\"ID\""),
613+ session1.executeAsync("DROP FUNCTION \"CaseSensitive\".\"ID\""),
614+ session1.executeAsync("DROP FUNCTION lowercase.\"PLUS\""),
615+ session1.executeAsync("DROP FUNCTION \"CaseSensitive\".\"PLUS\""),
616+ session1.executeAsync("DROP AGGREGATE lowercase.\"SUM\""),
617+ session1.executeAsync("DROP AGGREGATE \"CaseSensitive\".\"SUM\""),
617618 session1.executeAsync("DROP MATERIALIZED VIEW lowercase.mv1"),
618619 session1.executeAsync("DROP MATERIALIZED VIEW \"CaseSensitive\".mv1"),
619620 session1.executeAsync("DROP KEYSPACE lowercase2"),
modified driver-core/src/test/java/com/datastax/driver/core/UserTypesTest.java +9 −9
@@ -49,9 +49,9 @@
4949 @Override
5050 protected Collection<String> getTableDefinitions() {
5151 String type1 = "CREATE TYPE phone (alias text, number text)";
52- String type2 = "CREATE TYPE address (street text, \"ZIP\" int, phones set<frozen<phone>>)";
52+ String type2 = "CREATE TYPE \"\"\"User Address\"\"\" (street text, \"ZIP\"\"\" int, phones set<frozen<phone>>)";
5353
54- String table = "CREATE TABLE user (id int PRIMARY KEY, addr frozen<address>)";
54+ String table = "CREATE TABLE user (id int PRIMARY KEY, addr frozen<\"\"\"User Address\"\"\">)";
5555
5656 return Arrays.asList(type1, type2, table);
5757 }
@@ -70,13 +70,13 @@
7070 PreparedStatement ins = session.prepare("INSERT INTO user(id, addr) VALUES (?, ?)");
7171 PreparedStatement sel = session.prepare("SELECT * FROM user WHERE id=?");
7272
73- UserType addrDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("address");
73+ UserType addrDef = cluster.getMetadata().getKeyspace(keyspace).getUserType(quote("\"User Address\""));
7474 UserType phoneDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("phone");
7575
7676 UDTValue phone1 = phoneDef.newValue().setString("alias", "home").setString("number", "0123548790");
7777 UDTValue phone2 = phoneDef.newValue().setString("alias", "work").setString("number", "0698265251");
7878
79- UDTValue addr = addrDef.newValue().setString("street", "1600 Pennsylvania Ave NW").setInt(quote("ZIP"), 20500).setSet("phones", ImmutableSet.of(phone1, phone2));
79+ UDTValue addr = addrDef.newValue().setString("street", "1600 Pennsylvania Ave NW").setInt(quote("ZIP\""), 20500).setSet("phones", ImmutableSet.of(phone1, phone2));
8080
8181 session.execute(ins.bind(userId, addr));
8282
@@ -100,13 +100,13 @@
100100
101101 try {
102102 session.execute("USE " + keyspace);
103- UserType addrDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("address");
103+ UserType addrDef = cluster.getMetadata().getKeyspace(keyspace).getUserType(quote("\"User Address\""));
104104 UserType phoneDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("phone");
105105
106106 UDTValue phone1 = phoneDef.newValue().setString("alias", "home").setString("number", "0123548790");
107107 UDTValue phone2 = phoneDef.newValue().setString("alias", "work").setString("number", "0698265251");
108108
109- UDTValue addr = addrDef.newValue().setString("street", "1600 Pennsylvania Ave NW").setInt(quote("ZIP"), 20500).setSet("phones", ImmutableSet.of(phone1, phone2));
109+ UDTValue addr = addrDef.newValue().setString("street", "1600 Pennsylvania Ave NW").setInt(quote("ZIP\""), 20500).setSet("phones", ImmutableSet.of(phone1, phone2));
110110
111111 session.execute("INSERT INTO user(id, addr) VALUES (?, ?)", userId, addr);
112112
@@ -134,7 +134,7 @@
134134 assertEquals(addrDef, null);
135135 assertEquals(phoneDef, null);
136136
137- addrDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("address");
137+ addrDef = cluster.getMetadata().getKeyspace(keyspace).getUserType(quote("\"User Address\""));
138138 phoneDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("phone");
139139 assertNotEquals(addrDef, null);
140140 assertNotEquals(phoneDef, null);
@@ -145,14 +145,14 @@
145145 "WITH replication = { 'class' : 'SimpleStrategy', 'replication_factor': '1'}");
146146 session.execute("USE " + nonExistingKeyspace);
147147
148- addrDef = cluster.getMetadata().getKeyspace(nonExistingKeyspace).getUserType("address");
148+ addrDef = cluster.getMetadata().getKeyspace(nonExistingKeyspace).getUserType(quote("\"User Address\""));
149149 phoneDef = cluster.getMetadata().getKeyspace(nonExistingKeyspace).getUserType("phone");
150150 assertEquals(addrDef, null);
151151 assertEquals(phoneDef, null);
152152
153153 session.execute("USE " + keyspace);
154154
155- addrDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("address");
155+ addrDef = cluster.getMetadata().getKeyspace(keyspace).getUserType(quote("\"User Address\""));
156156 phoneDef = cluster.getMetadata().getKeyspace(keyspace).getUserType("phone");
157157 assertNotEquals(addrDef, null);
158158 assertNotEquals(phoneDef, null);