MCPcopy Create free account
hub / github.com/rilldata/rill / writeArrayContainsCondition

Method writeArrayContainsCondition

runtime/metricsview/astexpr.go:661–701  ·  view source on GitHub ↗
(leftExpr string, right *Expression, not bool)

Source from the content-addressed store, hash-verified

659}
660
661func (b *sqlExprBuilder) writeArrayContainsCondition(leftExpr string, right *Expression, not bool) error {
662 vals, ok := right.Value.([]any)
663 if !ok {
664 return fmt.Errorf("the right value must be a list of values for an array IN condition")
665 }
666
667 if len(vals) == 0 {
668 if not {
669 b.writeString("TRUE")
670 } else {
671 b.writeString("FALSE")
672 }
673 return nil
674 }
675
676 b.writeByte('(')
677 if not {
678 b.writeString("NOT ")
679 }
680 arrayContainsFunc, err := b.ast.Dialect.GetArrayContainsFunction()
681 if err != nil {
682 return err
683 }
684 b.writeString(arrayContainsFunc)
685 b.writeByte('(')
686 b.writeParenthesizedString(leftExpr)
687 b.writeString(", [")
688 // not handling NULL values separately as clickhouse hasAny function takes care of it however, duckdb ignores null values in the list_has_any function, but there is no reliable way to make it work,
689 // but even using leftExpr IS NULL does not solve the issue as it checks for null array rather than null values in the array.
690 for i, val := range vals {
691 if i > 0 {
692 b.writeByte(',')
693 }
694 b.writeString("?")
695 b.args = append(b.args, val)
696 }
697 b.writeString("])")
698 b.writeByte(')')
699
700 return nil
701}
702
703func (b *sqlExprBuilder) writeByte(v byte) {
704 _ = b.out.WriteByte(v)

Callers 1

writeBinaryConditionMethod · 0.95

Calls 5

writeStringMethod · 0.95
writeByteMethod · 0.95
ErrorfMethod · 0.65

Tested by

no test coverage detected