MCPcopy
hub / github.com/dosco/graphjin / renderColRefExpression

Method renderColRefExpression

core/internal/dialect/mongodb.go:3885–3910  ·  view source on GitHub ↗

renderColRefExpression emits a same-collection column comparison via $expr. Multi-hop belongs-to comparisons are not supported on MongoDB without pre-injecting a $lookup stage in the pipeline, which is outside the scope of the WHERE-clause renderer; reject those at compile time.

(ctx Context, exp *qcode.Exp)

Source from the content-addressed store, hash-verified

3883// pre-injecting a $lookup stage in the pipeline, which is outside the scope
3884// of the WHERE-clause renderer; reject those at compile time.
3885func (d *MongoDBDialect) renderColRefExpression(ctx Context, exp *qcode.Exp) {
3886 if len(exp.Right.RelPath) > 0 {
3887 ctx.SetError(fmt.Errorf("mongodb: cross-table column reference operands (multi-hop) are not supported; use a same-collection column reference instead"))
3888 return
3889 }
3890 op, ok := colRefMongoOp(exp.Op)
3891 if !ok {
3892 ctx.SetError(fmt.Errorf("mongodb: operator %s does not support column reference operands", exp.Op))
3893 return
3894 }
3895 leftName := exp.Left.Col.Name
3896 if leftName == "id" {
3897 leftName = "_id"
3898 }
3899 rightName := exp.Right.Col.Name
3900 if rightName == "id" {
3901 rightName = "_id"
3902 }
3903 ctx.WriteString(`"$expr":{"`)
3904 ctx.WriteString(op)
3905 ctx.WriteString(`":["$`)
3906 ctx.WriteString(leftName)
3907 ctx.WriteString(`","$`)
3908 ctx.WriteString(rightName)
3909 ctx.WriteString(`"]}`)
3910}
3911
3912func colRefMongoOp(op qcode.ExpOp) (string, bool) {
3913 switch op {

Callers 1

renderExpressionMethod · 0.95

Calls 3

colRefMongoOpFunction · 0.85
SetErrorMethod · 0.65
WriteStringMethod · 0.65

Tested by

no test coverage detected