diff --git a/option/query_lambda.go b/option/query_lambda.go index 2dd7d33a..00e01838 100644 --- a/option/query_lambda.go +++ b/option/query_lambda.go @@ -43,3 +43,29 @@ func WithParameter2(name, valueType, value string) QueryLambdaOption { }) } } + +type ListQueryLambdaOptions struct { + Workspace *string +} + +type ListQueryLambdaOption func(request *ListQueryLambdaOptions) + +func WithQueryLambdaWorkspace(name string) ListQueryLambdaOption { + return func(o *ListQueryLambdaOptions) { + + } +} + +type ListQueryLambdaTagsOptions struct { + Workspace *string + QueryLambda *string +} + +type ListQueryLambdaTagsOption func(request *ListQueryLambdaTagsOptions) + +func WithQueryLambda(workspace, name string) ListQueryLambdaTagsOption { + return func(o *ListQueryLambdaTagsOptions) { + o.Workspace = &workspace + o.QueryLambda = &name + } +} diff --git a/query_lambdas.go b/query_lambdas.go index ed153523..59f6b002 100644 --- a/query_lambdas.go +++ b/query_lambdas.go @@ -54,3 +54,147 @@ func (rc *RockClient) ExecuteQueryLambda(ctx context.Context, workspace, name st return resp, nil } + +// GetQueryLambdaVersionByTag gets the query lambda version for a tag. +func (rc *RockClient) GetQueryLambdaVersionByTag(ctx context.Context, + workspace, name, tag string) (openapi.QueryLambdaTag, error) { + var err error + var resp openapi.QueryLambdaTagResponse + + q := rc.QueryLambdasApi.GetQueryLambdaTagVersion(ctx, workspace, name, tag) + err = rc.Retry(ctx, func() error { + resp, _, err = q.Execute() + return err + }) + + if err != nil { + return openapi.QueryLambdaTag{}, err + } + + return resp.GetData(), err +} + +// GetQueryLambdaVersion get the query lambda information for a specific version. +func (rc *RockClient) GetQueryLambdaVersion(ctx context.Context, + workspace, name, version string) (openapi.QueryLambdaVersion, error) { + var err error + var resp openapi.QueryLambdaVersionResponse + + q := rc.QueryLambdasApi.GetQueryLambdaVersion(ctx, workspace, name, version) + err = rc.Retry(ctx, func() error { + resp, _, err = q.Execute() + return err + }) + + if err != nil { + return openapi.QueryLambdaVersion{}, err + } + + return resp.GetData(), err +} + +// ListQueryLambdas lists all query lambdas, unless the option.WithQueryLambdaWorkspace is used. +// +// https://docs.rockset.com/rest-api/#listallquerylambdas +func (rc *RockClient) ListQueryLambdas(ctx context.Context, + options ...option.ListQueryLambdaOption) ([]openapi.QueryLambda, error) { + var err error + var resp openapi.ListQueryLambdasResponse + + opts := option.ListQueryLambdaOptions{} + for _, o := range options { + o(&opts) + } + + if opts.Workspace == nil { + q := rc.QueryLambdasApi.ListAllQueryLambdas(ctx) + err = rc.Retry(ctx, func() error { + resp, _, err = q.Execute() + return err + }) + } else { + q := rc.QueryLambdasApi.ListQueryLambdasInWorkspace(ctx, *opts.Workspace) + err = rc.Retry(ctx, func() error { + resp, _, err = q.Execute() + return err + }) + } + + if err != nil { + return nil, err + } + + return resp.GetData(), err +} + +// ListQueryLambdaTagVersions lists all query lambdas for the tag. +func (rc *RockClient) ListQueryLambdaTagVersions(ctx context.Context, + tag string) ([]openapi.QueryLambdaVersion, error) { + var err error + var resp openapi.ListQueryLambdaVersionsResponse + + q := rc.QueryLambdasApi.ListQueryLambdaTagVersions(ctx, tag) + err = rc.Retry(ctx, func() error { + resp, _, err = q.Execute() + return err + }) + + if err != nil { + return nil, err + } + + return resp.GetData(), err +} + +// ListQueryLambdaVersions lists all versions for a query lambda. +func (rc *RockClient) ListQueryLambdaVersions(ctx context.Context, + workspace, name string) ([]openapi.QueryLambdaVersion, error) { + var err error + var resp openapi.ListQueryLambdaVersionsResponse + + q := rc.QueryLambdasApi.ListQueryLambdaVersions(ctx, workspace, name) + err = rc.Retry(ctx, func() error { + resp, _, err = q.Execute() + return err + }) + + if err != nil { + return nil, err + } + + return resp.GetData(), err +} + +// ListQueryLambdaTags lists all tags for the organization, or for a specific query lambda if the +// option.WithQueryLambda is used. +func (rc *RockClient) ListQueryLambdaTags(ctx context.Context, + options ...option.ListQueryLambdaTagsOption) ([]openapi.QueryLambdaTag, error) { + var err error + var resp openapi.ListQueryLambdaTagsResponse + + opts := option.ListQueryLambdaTagsOptions{} + + for _, o := range options { + o(&opts) + } + + if opts.Workspace == nil { + q := rc.QueryLambdasApi.ListOrganizationTags(ctx) + err = rc.Retry(ctx, func() error { + resp, _, err = q.Execute() + return err + }) + } else { + q := rc.QueryLambdasApi.ListQueryLambdaTags(ctx, *opts.Workspace, *opts.QueryLambda) + err = rc.Retry(ctx, func() error { + resp, _, err = q.Execute() + return err + }) + } + + if err != nil { + return nil, err + } + + return resp.GetData(), err +} diff --git a/query_lambdas_test.go b/query_lambdas_test.go new file mode 100644 index 00000000..89621cd9 --- /dev/null +++ b/query_lambdas_test.go @@ -0,0 +1,140 @@ +package rockset_test + +import ( + "testing" + + "github.com/rs/zerolog" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/rockset/rockset-go-client" + "github.com/rockset/rockset-go-client/option" +) + +func TestRockClient_GetQueryLambdaVersionByTag(t *testing.T) { + skipUnlessIntegrationTest(t) + + ctx := testCtx() + + rc, err := rockset.NewClient() + require.NoError(t, err) + + version, err := rc.GetQueryLambdaVersionByTag(ctx, "commons", "events", "v2") + require.NoError(t, err) + assert.Equal(t, "2", *version.Version.Version) +} + +func TestRockClient_GetQueryLambdaVersion(t *testing.T) { + skipUnlessIntegrationTest(t) + + ctx := testCtx() + + rc, err := rockset.NewClient() + require.NoError(t, err) + + version, err := rc.GetQueryLambdaVersion(ctx, "commons", "events", "2") + require.NoError(t, err) + assert.Equal(t, "events", *version.Name) +} + +func TestRockClient_ListQueryLambdas(t *testing.T) { + skipUnlessIntegrationTest(t) + + ctx := testCtx() + log := zerolog.Ctx(ctx) + + rc, err := rockset.NewClient() + require.NoError(t, err) + + lambdas, err := rc.ListQueryLambdas(ctx) + require.NoError(t, err) + + for _, l := range lambdas { + log.Printf("lambda: %s", *l.Name) + } +} + +func TestRockClient_ListQueryLambdas_workspace(t *testing.T) { + skipUnlessIntegrationTest(t) + + ctx := testCtx() + log := zerolog.Ctx(ctx) + + rc, err := rockset.NewClient() + require.NoError(t, err) + + lambdas, err := rc.ListQueryLambdas(ctx, option.WithQueryLambdaWorkspace("commons")) + require.NoError(t, err) + + for _, l := range lambdas { + log.Printf("lambda: %s", *l.Name) + } +} + +func TestRockClient_ListQueryLambdaTagVersions(t *testing.T) { + skipUnlessIntegrationTest(t) + + ctx := testCtx() + log := zerolog.Ctx(ctx) + + rc, err := rockset.NewClient() + require.NoError(t, err) + + versions, err := rc.ListQueryLambdaTagVersions(ctx, "latest") + require.NoError(t, err) + + for _, l := range versions { + log.Printf("version: %s", *l.Version) + } +} + +func TestRockClient_ListQueryLambdaVersions(t *testing.T) { + skipUnlessIntegrationTest(t) + + ctx := testCtx() + log := zerolog.Ctx(ctx) + + rc, err := rockset.NewClient() + require.NoError(t, err) + + versions, err := rc.ListQueryLambdaVersions(ctx, "commons", "events") + require.NoError(t, err) + + for _, l := range versions { + log.Printf("version: %s", *l.Version) + } +} + +func TestRockClient_ListQueryLambdaTags(t *testing.T) { + skipUnlessIntegrationTest(t) + + ctx := testCtx() + log := zerolog.Ctx(ctx) + + rc, err := rockset.NewClient() + require.NoError(t, err) + + tags, err := rc.ListQueryLambdaTags(ctx) + require.NoError(t, err) + + for _, tag := range tags { + log.Printf("tag: %s", *tag.TagName) + } +} + +func TestRockClient_ListQueryLambdaTags_forQL(t *testing.T) { + skipUnlessIntegrationTest(t) + + ctx := testCtx() + log := zerolog.Ctx(ctx) + + rc, err := rockset.NewClient() + require.NoError(t, err) + + tags, err := rc.ListQueryLambdaTags(ctx, option.WithQueryLambda("commons", "events")) + require.NoError(t, err) + + for _, tag := range tags { + log.Printf("tag: %s", *tag.TagName) + } +} diff --git a/version.go b/version.go index e4c43d95..06ff19ca 100644 --- a/version.go +++ b/version.go @@ -1,4 +1,4 @@ package rockset // Version is the Rockset client version -const Version = "0.12.2" +const Version = "0.12.3"