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

When using Resp 2 FTAggregateWithArgs does not return an error when using the "as" option #3220

Open
michaeltch opened this issue Jan 8, 2025 · 1 comment
Assignees
Labels

Comments

@michaeltch
Copy link

I have provided an example program that doesn't panic when the command run on the database should return an error.

Expected Behavior

Panic with error message (error) Unknown argument AS at position 4 for <main>

Current Behavior

The resulting pointer is nil and error is empty causing no panic.
result: 0x0

Steps to Reproduce

package main

import (
	"context"
	"strings"

	"github.com/redis/go-redis/v9"
)

func createIndexAndLoadData(client *redis.Client, ctx context.Context) {
	if _, err := client.FTCreate(ctx,
		"temp",
		&redis.FTCreateOptions{Prefix: []interface{}{"user:"}},
		&redis.FieldSchema{FieldName: "__key", FieldType: redis.SearchFieldTypeText},
	).Result(); err != nil && !strings.Contains(err.Error(), "Index already exists") {
		panic(err)
	}

	if _, err := client.HSet(ctx, "user:1", []string{"__key", "v1"}).Result(); err != nil {
		panic(err)
	}
}

func runAggregateQuery(client *redis.Client, ctx context.Context) {
	filterOpts := &redis.FTAggregateOptions{
		Load: []redis.FTAggregateLoad{
			{
				Field: "@__key",
				As:    "key",
			},
		},
	}
	result, err := client.FTAggregateWithArgs(ctx, "temp", "*", filterOpts).Result()
	if err != nil {
		panic(err)
	}
	println("result:", result)
}

func main() {
	ctx := context.Background()
	client := redis.NewClient(&redis.Options{
		Addr:     "localhost:6379",
		Protocol: 2,
	})

	createIndexAndLoadData(client, ctx)

	runAggregateQuery(client, ctx)
}

Removing the As field fixes the issue and a proper response is returned.

Context (Environment)

Attempting to recreate a separate issue. The database is OSS 6.2.7.

bitsark added a commit to bitsark/go-redis that referenced this issue Jan 9, 2025
* LOAD has NO AS param(https://redis.io/docs/latest/commands/ft.aggregate/)

* fix typo: WITHCOUT -> WITHCOUNT
bitsark added a commit to bitsark/go-redis that referenced this issue Feb 6, 2025
    * Compatible with known RediSearch issue in test
@ndyakov
Copy link
Collaborator

ndyakov commented Feb 6, 2025

Hello @michaeltch, thank you for reporting this!
There were couple of different problems we found with FTAggregateWithArgs. Some are resolved in #3263 , once merged I will check if your case is addressed. I assume an additional fix will be needed to enable As in the Load, but let's see.
cc @bitsark I saw that you were working on this, please use the above PR as a base or wait for it to be merged.

@ndyakov ndyakov self-assigned this Feb 6, 2025
@ndyakov ndyakov added the bug label Feb 6, 2025
bitsark added a commit to bitsark/go-redis that referenced this issue Feb 7, 2025
    * fixed the calculation bug of the count of load params
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants