Skip to content

Commit e843786

Browse files
smiklosovicabsurdfarce
authored andcommitted
Fix TableMetadata.describe() when containing a vector column
patch by Stefan Miklosovic; reviewed by Bret McGuire for CASSJAVA-2
1 parent 01c6151 commit e843786

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

core/src/main/java/com/datastax/oss/driver/internal/core/type/DefaultVectorType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public String getClassName() {
6060
@NonNull
6161
@Override
6262
public String asCql(boolean includeFrozen, boolean pretty) {
63-
return String.format("'%s(%d)'", getClassName(), getDimensions());
63+
return String.format("vector<%s, %d>", getElementType().asCql(true, false), getDimensions());
6464
}
6565

6666
/* ============== General class implementation ============== */
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
package com.datastax.oss.driver.internal.core.metadata.schema;
19+
20+
import static com.datastax.oss.driver.api.core.CqlIdentifier.fromCql;
21+
import static org.assertj.core.api.Assertions.assertThat;
22+
23+
import com.datastax.oss.driver.api.core.metadata.schema.TableMetadata;
24+
import com.datastax.oss.driver.internal.core.type.DefaultVectorType;
25+
import com.datastax.oss.driver.internal.core.type.PrimitiveType;
26+
import com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap;
27+
import com.datastax.oss.protocol.internal.ProtocolConstants.DataType;
28+
import com.google.common.collect.ImmutableList;
29+
import java.util.UUID;
30+
import org.junit.Test;
31+
32+
public class TableMetadataTest {
33+
34+
/** Tests CASSJAVA-2 */
35+
@Test
36+
public void should_describe_table_with_vector_correctly() {
37+
TableMetadata tableMetadata =
38+
new DefaultTableMetadata(
39+
fromCql("ks"),
40+
fromCql("tb"),
41+
UUID.randomUUID(),
42+
false,
43+
false,
44+
ImmutableList.of(
45+
new DefaultColumnMetadata(
46+
fromCql("ks"),
47+
fromCql("ks"),
48+
fromCql("tb"),
49+
new PrimitiveType(DataType.ASCII),
50+
false)),
51+
ImmutableMap.of(),
52+
ImmutableMap.of(
53+
fromCql("a"),
54+
new DefaultColumnMetadata(
55+
fromCql("ks"),
56+
fromCql("ks"),
57+
fromCql("tb"),
58+
new DefaultVectorType(new PrimitiveType(DataType.INT), 3),
59+
false)),
60+
ImmutableMap.of(),
61+
ImmutableMap.of());
62+
63+
String describe1 = tableMetadata.describe(true);
64+
65+
assertThat(describe1).contains("vector<int, 3>,");
66+
}
67+
}

0 commit comments

Comments
 (0)