gocqlx icon indicating copy to clipboard operation
gocqlx copied to clipboard

Unable to update the data

Open Arunkumar-hockey opened this issue 1 year ago • 1 comments

func (repo JourneyRepo) UpdateJourneyByID(c context.Context, journey models.Journey) (*models.Journey, error) { // API tracing enabling if span := tracing.TraceSpan(c, "journeyRepo.UpdateJourneyByID"); span != nil { defer span.End() }

session := repo.GetScyllaDBConnection()

// Start building the update query
updStmt := qb.Update("journeys").
	Set("name", "status", "segment_id", "tags", "flow_json", "updated_by", "updated_at").
	Where(qb.Eq("id"), qb.Eq("client_ref_number"))

// Convert to CQL statement
update, names := updStmt.ToCql()

// Create a map for the bind parameters
bindMap := qb.M{
	"id":                journey.ID,
	"client_ref_number": journey.ClientRefNumber,
	"name":              journey.Name,
	"status":            journey.Status,
	"segment_id":        journey.SegmentId,
	"tags":              journey.Tags,
	"flow_json":         journey.FlowJSON,
	"updated_by":        journey.UpdatedBy,
	"updated_at":        journey.UpdatedAt,
}

// Execute the update query
if err := gocqlx.Query(session.Query(update), names).BindMap(bindMap).ExecRelease(); err != nil {
	return nil, err
}

// Return the updated journey
return &journey, nil

}. A error is coming "Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING". Unable to call AllowFiltering(). function.

Arunkumar-hockey avatar Jul 11 '24 11:07 Arunkumar-hockey

Please reformat your issue description, it seems to be broken and provide steps to reproduce your issue

sylwiaszunejko avatar Jul 11 '24 12:07 sylwiaszunejko

func (repo JourneyRepo) UpdateJourneyByID(c context.Context, journey models.Journey) (*models.Journey, error) {
	// API tracing enabling
	if span := tracing.TraceSpan(c, "journeyRepo.UpdateJourneyByID"); span != nil {
		defer span.End()
	}

	session := repo.GetScyllaDBConnection()

	// Start building the update query
	updStmt := qb.Update("journeys").
		Set("name", "status", "segment_id", "tags", "flow_json", "updated_by", "updated_at").
		Where(qb.Eq("id"), qb.Eq("client_ref_number"))

	// Convert to CQL statement
	update, names := updStmt.ToCql()

	// Create a map for the bind parameters
	bindMap := qb.M{
		"id":                journey.ID,
		"client_ref_number": journey.ClientRefNumber,
		"name":              journey.Name,
		"status":            journey.Status,
		"segment_id":        journey.SegmentId,
		"tags":              journey.Tags,
		"flow_json":         journey.FlowJSON,
		"updated_by":        journey.UpdatedBy,
		"updated_at":        journey.UpdatedAt,
	}

	// Execute the update query
	if err := gocqlx.Query(session.Query(update), names).BindMap(bindMap).ExecRelease(); err != nil {
		return nil, err
	}

	// Return the updated journey
	return &journey, nil
}

A error is coming "Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING". Unable to call AllowFiltering(). function.

Just let you know that mostly it is because of problem on data layout. But to make it happen you can add ALLOW FILTERING to the end of the query:

	// Execute the update query
	if err := gocqlx.Query(session.Query(update + ` ALLOW FILTERING`), names).BindMap(bindMap).ExecRelease(); err != nil {
		return nil, err
	}

But you are correct we should add this feature.

dkropachev avatar Sep 06 '24 12:09 dkropachev

Question is answered, for add allow filtering api I have created separate issue.

dkropachev avatar Sep 06 '24 12:09 dkropachev

Thanks Scylladb/Gocqlx team for the solution. My team members are struggling to work with Gocqlx package. Because documentation codes are outdated. Please update everything in the documentation. It will helpfull for everyone.

Thanks & Regards, Arun Kumar K

On Fri, 6 Sep 2024 at 6:28 PM, Dmitry Kropachev @.***> wrote:

Question is answered, for add allow filtering api I have created separate issue https://github.com/scylladb/gocqlx/issues/288.

— Reply to this email directly, view it on GitHub https://github.com/scylladb/gocqlx/issues/280#issuecomment-2333996580, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATZPJAVSZU4LCG6VPXWXRZTZVGRI3AVCNFSM6AAAAABKWYUAS6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMZTHE4TMNJYGA . You are receiving this because you authored the thread.Message ID: @.***>

Arunkumar-hockey avatar Sep 07 '24 10:09 Arunkumar-hockey

@Arunkumar-hockey , thanks, documentation issues will be addressed here, please feel free to add more information.

dkropachev avatar Sep 07 '24 11:09 dkropachev