-
Notifications
You must be signed in to change notification settings - Fork 622
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
953e0df
commit 68dd326
Showing
7 changed files
with
303 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//go:build all || cassandra | ||
// +build all cassandra | ||
|
||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/* | ||
* Content before git sha 34fdeebefcbf183ed7f916f931aa0586fdaa1b40 | ||
* Copyright (c) 2016, The Gocql authors, | ||
* provided under the BSD-3-Clause License. | ||
* See the NOTICE file distributed with this work for additional information. | ||
*/ | ||
|
||
package gocql | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestVector_Marshaler(t *testing.T) { | ||
session := createSession(t) | ||
defer session.Close() | ||
|
||
if flagCassVersion.Before(5, 0, 0) { | ||
t.Skip("Vector types have been introduced in Cassandra 5.0") | ||
} | ||
|
||
err := createTable(session, `CREATE TABLE gocql_test.vector_fixed(id int primary key, vec vector<float, 3>);`) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = createTable(session, `CREATE TABLE gocql_test.vector_variable(id int primary key, vec vector<text, 4>);`) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
insertFixVec := []float32{8, 2.5, -5.0} | ||
err = session.Query("INSERT INTO vector_fixed(id, vec) VALUES(?, ?)", 1, insertFixVec).Exec() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
var vf []float32 | ||
err = session.Query("SELECT vec FROM vector_fixed WHERE id = ?", 1).Scan(&vf) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
assertDeepEqual(t, "fixed-size element size vector", insertFixVec, vf) | ||
|
||
longText := randomText(500) | ||
insertVarVec := []string{"apache", "cassandra", longText, "gocql"} | ||
err = session.Query("INSERT INTO vector_variable(id, vec) VALUES(?, ?)", 1, insertVarVec).Exec() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
var vv []string | ||
err = session.Query("SELECT vec FROM vector_variable WHERE id = ?", 1).Scan(&vv) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
assertDeepEqual(t, "variable-size element vector", insertVarVec, vv) | ||
} |