Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CASSGO-11 Support vector type #1828

Open
wants to merge 23 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,32 @@ jobs:
key: ${{ runner.os }}-go-${{ hashFiles('go.mod') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install Java
run: |
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
echo "sdkman_auto_answer=true" >> ~/.sdkman/etc/config
# sdk list java

sdk install java 11.0.24-zulu
echo "JAVA11_HOME=$JAVA_HOME_11_X64" >> $GITHUB_ENV

sdk install java 17.0.12-zulu
echo "JAVA17_HOME=$JAVA_HOME_17_X64" >> $GITHUB_ENV

# by default use JDK 11
sdk default java 11.0.24-zulu
sdk use java 11.0.24-zulu
echo "JAVA_HOME=$JAVA_HOME_11_X64" >> $GITHUB_ENV
echo "PATH=$PATH" >> $GITHUB_ENV
- name: Install CCM
run: pip install "git+https://github.com/riptano/ccm.git@${CCM_VERSION}"
run: |
python3 -m venv ~/venv
~/venv/bin/pip install setuptools
~/venv/bin/pip install "git+https://github.com/riptano/ccm.git@${CCM_VERSION}"
- name: Start cassandra nodes
run: |
source ~/venv/bin/activate
VERSION=${{ matrix.cassandra_version }}
keypath="$(pwd)/testdata/pki"
conf=(
Expand Down Expand Up @@ -107,6 +129,7 @@ jobs:
echo "JVM_EXTRA_OPTS=$JVM_EXTRA_OPTS" >> $GITHUB_ENV
- name: Integration tests
run: |
source ~/venv/bin/activate
export JVM_EXTRA_OPTS="${{env.JVM_EXTRA_OPTS}}"
go test -v -tags "${{ matrix.tags }} gocql_debug" -timeout=5m -race ${{ env.args }}
- name: 'Save ccm logs'
Expand Down Expand Up @@ -135,10 +158,32 @@ jobs:
- uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
- name: Install Java
run: |
curl -s "https://get.sdkman.io" | bash
source "$HOME/.sdkman/bin/sdkman-init.sh"
echo "sdkman_auto_answer=true" >> ~/.sdkman/etc/config
# sdk list java

sdk install java 11.0.24-zulu
echo "JAVA11_HOME=$JAVA_HOME_11_X64" >> $GITHUB_ENV

sdk install java 17.0.12-zulu
echo "JAVA17_HOME=$JAVA_HOME_17_X64" >> $GITHUB_ENV

# by default use JDK 11
sdk default java 11.0.24-zulu
sdk use java 11.0.24-zulu
echo "JAVA_HOME=$JAVA_HOME_11_X64" >> $GITHUB_ENV
echo "PATH=$PATH" >> $GITHUB_ENV
- name: Install CCM
run: pip install "git+https://github.com/riptano/ccm.git@${CCM_VERSION}"
run: |
python3 -m venv ~/venv
~/venv/bin/pip install setuptools
~/venv/bin/pip install "git+https://github.com/riptano/ccm.git@${CCM_VERSION}"
- name: Start cassandra nodes
run: |
source ~/venv/bin/activate
VERSION=${{ matrix.cassandra_version }}
keypath="$(pwd)/testdata/pki"
conf=(
Expand Down Expand Up @@ -197,5 +242,6 @@ jobs:
sleep 30s
- name: Integration tests
run: |
source ~/venv/bin/activate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a reminder to remove the workflow changes from this PR before wrapping up (we'll have to potentially merge #1833 first) when we get a second +1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this PR will wait for #1833. I will remove workflow changes form this PR, rebase and squash commits.

export JVM_EXTRA_OPTS="${{env.JVM_EXTRA_OPTS}}"
go test -v -run=TestAuthentication -tags "${{ matrix.tags }} gocql_debug" -timeout=15s -runauth ${{ env.args }}
52 changes: 28 additions & 24 deletions cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2245,15 +2245,16 @@ func TestViewMetadata(t *testing.T) {
textType = TypeVarchar
}

protoVer := byte(session.cfg.ProtoVersion)
expectedView := ViewMetadata{
Keyspace: "gocql_test",
Name: "basicview",
FieldNames: []string{"birthday", "nationality", "weight", "height"},
FieldTypes: []TypeInfo{
NativeType{typ: TypeTimestamp},
NativeType{typ: textType},
NativeType{typ: textType},
NativeType{typ: textType},
NativeType{typ: TypeTimestamp, proto: protoVer},
NativeType{typ: textType, proto: protoVer},
NativeType{typ: textType, proto: protoVer},
NativeType{typ: textType, proto: protoVer},
},
}

Expand Down Expand Up @@ -2351,18 +2352,19 @@ func TestAggregateMetadata(t *testing.T) {
t.Fatal("expected two aggregates")
}

protoVer := byte(session.cfg.ProtoVersion)
expectedAggregrate := AggregateMetadata{
Keyspace: "gocql_test",
Name: "average",
ArgumentTypes: []TypeInfo{NativeType{typ: TypeInt}},
ArgumentTypes: []TypeInfo{NativeType{typ: TypeInt, proto: protoVer}},
InitCond: "(0, 0)",
ReturnType: NativeType{typ: TypeDouble},
ReturnType: NativeType{typ: TypeDouble, proto: protoVer},
StateType: TupleTypeInfo{
NativeType: NativeType{typ: TypeTuple},
NativeType: NativeType{typ: TypeTuple, proto: protoVer},

Elems: []TypeInfo{
NativeType{typ: TypeInt},
NativeType{typ: TypeBigInt},
NativeType{typ: TypeInt, proto: protoVer},
NativeType{typ: TypeBigInt, proto: protoVer},
},
},
stateFunc: "avgstate",
Expand Down Expand Up @@ -2401,28 +2403,29 @@ func TestFunctionMetadata(t *testing.T) {
avgState := functions[1]
avgFinal := functions[0]

protoVer := byte(session.cfg.ProtoVersion)
avgStateBody := "if (val !=null) {state.setInt(0, state.getInt(0)+1); state.setLong(1, state.getLong(1)+val.intValue());}return state;"
expectedAvgState := FunctionMetadata{
Keyspace: "gocql_test",
Name: "avgstate",
ArgumentTypes: []TypeInfo{
TupleTypeInfo{
NativeType: NativeType{typ: TypeTuple},
NativeType: NativeType{typ: TypeTuple, proto: protoVer},

Elems: []TypeInfo{
NativeType{typ: TypeInt},
NativeType{typ: TypeBigInt},
NativeType{typ: TypeInt, proto: protoVer},
NativeType{typ: TypeBigInt, proto: protoVer},
},
},
NativeType{typ: TypeInt},
NativeType{typ: TypeInt, proto: protoVer},
},
ArgumentNames: []string{"state", "val"},
ReturnType: TupleTypeInfo{
NativeType: NativeType{typ: TypeTuple},
NativeType: NativeType{typ: TypeTuple, proto: protoVer},

Elems: []TypeInfo{
NativeType{typ: TypeInt},
NativeType{typ: TypeBigInt},
NativeType{typ: TypeInt, proto: protoVer},
NativeType{typ: TypeBigInt, proto: protoVer},
},
},
CalledOnNullInput: true,
Expand All @@ -2439,16 +2442,16 @@ func TestFunctionMetadata(t *testing.T) {
Name: "avgfinal",
ArgumentTypes: []TypeInfo{
TupleTypeInfo{
NativeType: NativeType{typ: TypeTuple},
NativeType: NativeType{typ: TypeTuple, proto: protoVer},

Elems: []TypeInfo{
NativeType{typ: TypeInt},
NativeType{typ: TypeBigInt},
NativeType{typ: TypeInt, proto: protoVer},
NativeType{typ: TypeBigInt, proto: protoVer},
},
},
},
ArgumentNames: []string{"state"},
ReturnType: NativeType{typ: TypeDouble},
ReturnType: NativeType{typ: TypeDouble, proto: protoVer},
CalledOnNullInput: true,
Language: "java",
Body: finalStateBody,
Expand Down Expand Up @@ -2557,15 +2560,16 @@ func TestKeyspaceMetadata(t *testing.T) {
if flagCassVersion.Before(3, 0, 0) {
textType = TypeVarchar
}
protoVer := byte(session.cfg.ProtoVersion)
expectedType := UserTypeMetadata{
Keyspace: "gocql_test",
Name: "basicview",
FieldNames: []string{"birthday", "nationality", "weight", "height"},
FieldTypes: []TypeInfo{
NativeType{typ: TypeTimestamp},
NativeType{typ: textType},
NativeType{typ: textType},
NativeType{typ: textType},
NativeType{typ: TypeTimestamp, proto: protoVer},
NativeType{typ: textType, proto: protoVer},
NativeType{typ: textType, proto: protoVer},
NativeType{typ: textType, proto: protoVer},
},
}
if !reflect.DeepEqual(*keyspaceMetadata.UserTypes["basicview"], expectedType) {
Expand Down
13 changes: 13 additions & 0 deletions common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"flag"
"fmt"
"log"
"math/rand"
"net"
"reflect"
"strings"
Expand All @@ -52,6 +53,10 @@ var (
flagCassVersion cassVersion
)

var seededRand *rand.Rand = rand.New(rand.NewSource(time.Now().UnixNano()))

const randCharset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

func init() {
flag.Var(&flagCassVersion, "gocql.cversion", "the cassandra version being tested against")

Expand Down Expand Up @@ -277,6 +282,14 @@ func assertTrue(t *testing.T, description string, value bool) {
}
}

func randomText(size int) string {
result := make([]byte, size)
for i := range result {
result[i] = randCharset[rand.Intn(len(randCharset))]
}
return string(result)
}

func assertEqual(t *testing.T, description string, expected, actual interface{}) {
t.Helper()
if expected != actual {
Expand Down
17 changes: 17 additions & 0 deletions frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"io/ioutil"
"net"
"runtime"
"strconv"
"strings"
"time"
)
Expand Down Expand Up @@ -928,6 +929,22 @@ func (f *framer) readTypeInfo() TypeInfo {
collection.Elem = f.readTypeInfo()

return collection
case TypeCustom:
if strings.HasPrefix(simple.custom, VECTOR_TYPE) {
spec := strings.TrimPrefix(simple.custom, VECTOR_TYPE)
spec = spec[1 : len(spec)-1] // remove parenthesis
idx := strings.LastIndex(spec, ",")
typeStr := spec[:idx]
dimStr := spec[idx+1:]
subType := getCassandraLongType(strings.TrimSpace(typeStr), f.proto, nopLogger{})
dim, _ := strconv.Atoi(strings.TrimSpace(dimStr))
vector := VectorType{
NativeType: simple,
SubType: subType,
Dimensions: dim,
}
return vector
}
}

return simple
Expand Down
Loading
Loading