Skip to content

Commit fe7e2f9

Browse files
committed
cspann: use brackets to format vectors
Postgres uses brackets to format vectors, e.g. [1, 2]. However, our test code currently uses parentheses, e.g. (1, 2). Update our tests to use brackets instead, so that we're more consistent. Epic: CRDB-42943 Release note: None
1 parent dd4cfcf commit fe7e2f9

17 files changed

+2480
-2493
lines changed

pkg/sql/vecindex/cspann/index.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,13 +1045,13 @@ type FormatOptions struct {
10451045
// Format formats the vector index as a tree-formatted string similar to this,
10461046
// for testing and debugging purposes:
10471047
//
1048-
// • 1 (4, 3)
1048+
// • 1 [4, 3]
10491049
// │
1050-
// ├───• vec1 (1, 2)
1051-
// ├───• vec2 (7, 4)
1052-
// └───• vec3 (4, 3)
1050+
// ├───• vec1 [1, 2]
1051+
// ├───• vec2 [7, 4]
1052+
// └───• vec3 [4, 3]
10531053
//
1054-
// Vectors with many dimensions are abbreviated like (5, -1, ..., 2, 8), and
1054+
// Vectors with many dimensions are abbreviated like [5, -1, ..., 2, 8], and
10551055
// values are rounded to 4 decimal places. Centroids are printed next to
10561056
// partition keys.
10571057
func (vi *Index) Format(
@@ -1091,7 +1091,7 @@ func (vi *Index) Format(
10911091
buf.WriteByte(' ')
10921092
utils.WriteVector(&buf, centroid, 4)
10931093
} else {
1094-
buf.WriteString(" (MISSING)\n")
1094+
buf.WriteString(" [MISSING]\n")
10951095
}
10961096
return nil
10971097
}
@@ -1109,9 +1109,9 @@ func (vi *Index) Format(
11091109
utils.WriteVector(&buf, original, 4)
11101110
details := partition.Metadata().StateDetails
11111111
if details.State != ReadyState {
1112-
buf.WriteString(" [")
1112+
buf.WriteString(" (")
11131113
buf.WriteString(details.String())
1114-
buf.WriteByte(']')
1114+
buf.WriteByte(')')
11151115
}
11161116
buf.WriteByte('\n')
11171117

@@ -1145,7 +1145,7 @@ func (vi *Index) Format(
11451145
buf.WriteByte(' ')
11461146
utils.WriteVector(&buf, refs[0].Vector, 4)
11471147
} else {
1148-
buf.WriteString(" (MISSING)")
1148+
buf.WriteString(" [MISSING]")
11491149
}
11501150
buf.WriteByte('\n')
11511151

pkg/sql/vecindex/cspann/index_test.go

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -854,24 +854,11 @@ func (s *testState) parseUseDataset(arg datadriven.CmdArg) vector.T {
854854
return s.Dataset.At(s.parseInt(arg))
855855
}
856856

857-
// parseVector parses a vector string in this form: (1.5, 6, -4).
857+
// parseVector parses a vector string in this form: [1.5, 6, -4].
858858
func (s *testState) parseVector(str string) vector.T {
859-
// Remove parentheses and split by commas.
860-
str = strings.TrimSpace(str)
861-
str = strings.TrimPrefix(str, "(")
862-
str = strings.TrimSuffix(str, ")")
863-
elems := strings.Split(str, ",")
864-
865-
// Construct the vector.
866-
vector := make(vector.T, len(elems))
867-
for i, elem := range elems {
868-
elem = strings.TrimSpace(elem)
869-
value, err := strconv.ParseFloat(elem, 32)
870-
require.NoError(s.T, err)
871-
vector[i] = float32(value)
872-
}
873-
874-
return vector
859+
vec, err := vector.ParseVector(str)
860+
require.NoError(s.T, err)
861+
return vec
875862
}
876863

877864
// parseKeyAndVector parses a line that may contain a key and vector separated
@@ -920,9 +907,9 @@ func (s *testState) loadIndexFromFormat(
920907
// Parse centroid and state.
921908
var details cspann.PartitionStateDetails
922909
details.MakeReady()
923-
idx = strings.Index(line, "[")
910+
idx = strings.Index(line, "(")
924911
if idx != -1 {
925-
require.True(s.T, strings.HasSuffix(line, "]"))
912+
require.True(s.T, strings.HasSuffix(line, ")"))
926913
details = parsePartitionStateDetails(line[idx+1 : len(line)-1])
927914
line = line[:idx-1]
928915
}

0 commit comments

Comments
 (0)