kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 2e3795079caa762388deb36a907c06aaef159d30809fb502f63a0d5bf20f3c4f |
|---|---|
| Author | Olivier Michallat <olim7t@users.noreply.github.com> · 2016-04-26 16:21 +02:00 |
| Committer | Olivier Michallat <olim7t@users.noreply.github.com> · 2016-04-26 16:21 +02:00 |
| Parents | ae86723b0d85, 6236a509678d |
4 files changed
modified changelog/README.md +1 −0
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | - [improvement] JAVA-1086: Support Cassandra 3.2 CAST function in QueryBuilder. |
| 17 | 17 | - [bug] JAVA-1095: Check protocol version for custom payload before sending the query. |
| 18 | 18 | - [improvement] JAVA-1133: Add OSGi headers to cassandra-driver-extras. |
| 19 | +- [bug] JAVA-1137: Incorrect string returned by DataType.asFunctionParameterString() for collections and tuples. | |
| 19 | 20 | |
| 20 | 21 | Merged from 2.1 branch: |
| 21 | 22 |
modified driver-core/src/main/java/com/datastax/driver/core/DataType.java +2 −2
| @@ -691,10 +691,10 @@ | ||
| 691 | 691 | public String asFunctionParameterString() { |
| 692 | 692 | if (name == Name.MAP) { |
| 693 | 693 | String template = "%s<%s, %s>"; |
| 694 | - return String.format(template, name, typeArguments.get(0), typeArguments.get(1)); | |
| 694 | + return String.format(template, name, typeArguments.get(0).asFunctionParameterString(), typeArguments.get(1).asFunctionParameterString()); | |
| 695 | 695 | } else { |
| 696 | 696 | String template = "%s<%s>"; |
| 697 | - return String.format(template, name, typeArguments.get(0)); | |
| 697 | + return String.format(template, name, typeArguments.get(0).asFunctionParameterString()); | |
| 698 | 698 | } |
| 699 | 699 | } |
| 700 | 700 | } |
modified driver-core/src/main/java/com/datastax/driver/core/TupleType.java +1 −1
| @@ -190,7 +190,7 @@ | ||
| 190 | 190 | StringBuilder sb = new StringBuilder(); |
| 191 | 191 | for (DataType type : types) { |
| 192 | 192 | sb.append(sb.length() == 0 ? "tuple<" : ", "); |
| 193 | - sb.append(type); | |
| 193 | + sb.append(type.asFunctionParameterString()); | |
| 194 | 194 | } |
| 195 | 195 | return sb.append(">").toString(); |
| 196 | 196 | } |
modified driver-core/src/test/java/com/datastax/driver/core/FunctionMetadataTest.java +39 −1
| @@ -19,7 +19,7 @@ | ||
| 19 | 19 | import org.testng.annotations.Test; |
| 20 | 20 | |
| 21 | 21 | import static com.datastax.driver.core.Assertions.assertThat; |
| 22 | -import static com.datastax.driver.core.DataType.cint; | |
| 22 | +import static com.datastax.driver.core.DataType.*; | |
| 23 | 23 | import static org.assertj.core.api.Assertions.entry; |
| 24 | 24 | |
| 25 | 25 | @CassandraVersion(major = 2.2) |
| @@ -123,6 +123,44 @@ | ||
| 123 | 123 | assertThat(function.toString()).isEqualTo(cqlFunction); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | + /** | |
| 127 | + * Ensures that functions whose arguments contain complex types such as | |
| 128 | + * tuples and collections, and nested combinations thereof, are | |
| 129 | + * correctly parsed. | |
| 130 | + * | |
| 131 | + * @jira_ticket JAVA-1137 | |
| 132 | + */ | |
| 133 | + @Test(groups = "short") | |
| 134 | + public void should_parse_and_format_functions_with_complex_arguments() { | |
| 135 | + // given | |
| 136 | + String cql = String.format("CREATE FUNCTION %s.complex(x tuple<tuple<int>, map<int, int>>) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return 42;';", keyspace); | |
| 137 | + // when | |
| 138 | + session().execute(cql); | |
| 139 | + // then | |
| 140 | + KeyspaceMetadata keyspace = cluster().getMetadata().getKeyspace(this.keyspace); | |
| 141 | + DataType argumentType = cluster().getMetadata().newTupleType(cluster().getMetadata().newTupleType(cint()), map(cint(), cint())); | |
| 142 | + FunctionMetadata function = keyspace.getFunction("complex", argumentType); | |
| 143 | + assertThat(function).isNotNull(); | |
| 144 | + assertThat(function.getKeyspace()).isEqualTo(keyspace); | |
| 145 | + assertThat(function.getSignature()).isEqualTo("complex(tuple<tuple<int>, map<int, int>>)"); | |
| 146 | + assertThat(function.getSimpleName()).isEqualTo("complex"); | |
| 147 | + assertThat(function.getReturnType()).isEqualTo(cint()); | |
| 148 | + assertThat(function.getArguments()) | |
| 149 | + .containsEntry("x", argumentType); | |
| 150 | + assertThat(function.getLanguage()).isEqualTo("java"); | |
| 151 | + assertThat(function.getBody()).isEqualTo("return 42;"); | |
| 152 | + assertThat(function.isCalledOnNullInput()).isFalse(); | |
| 153 | + assertThat(function.toString()) | |
| 154 | + .isEqualTo(cql); | |
| 155 | + assertThat(function.exportAsString()) | |
| 156 | + .isEqualTo(String.format("CREATE FUNCTION %s.complex(\n" | |
| 157 | + + " x tuple<tuple<int>, map<int, int>>)\n" | |
| 158 | + + "RETURNS NULL ON NULL INPUT\n" | |
| 159 | + + "RETURNS int\n" | |
| 160 | + + "LANGUAGE java\n" | |
| 161 | + + "AS 'return 42;';", this.keyspace)); | |
| 162 | + } | |
| 163 | + | |
| 126 | 164 | @Override |
| 127 | 165 | public void onTestContextInitialized() { |
| 128 | 166 | execute( |