Skip to content

Commit

Permalink
feat: mongo to couchbase array index format change
Browse files Browse the repository at this point in the history
* array index change
  • Loading branch information
shyam-cb authored Mar 14, 2024
1 parent 6b0b73b commit 864ab83
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions internal/mongo/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ func buildExpression(parts []string, parent string, l int) string {
field := inner

if parent == "" {
return fmt.Sprintf("DISTINCT ARRAY %s FOR %s IN %s END", field, item, items)
return fmt.Sprintf("ALL ARRAY %s FOR %s IN %s END", field, item, items)
}
return fmt.Sprintf("(DISTINCT ARRAY %s FOR %s IN %s END)", field, item, items)
return fmt.Sprintf("(ALL ARRAY %s FOR %s IN %s END)", field, item, items)
}

func formatFieldReference(field string) string {
Expand Down
8 changes: 4 additions & 4 deletions internal/mongo/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ var _ = Describe("mongo to couchbase index ", func() {
Context("success", func() {
It("output data should match with the test data", func() {
input := "k2[].n1k1[].n2k1.n3k1 ASC INCLUDE MISSING,.n2k1.n3k2.n4k1 DESC,.n2k2 ASC"
output := "DISTINCT ARRAY (DISTINCT ARRAY FLATTEN_KEYS(`l2Item`.`n2k1`.`n3k1` ASC INCLUDE MISSING,`l2Item`.`n2k1`.`n3k2`.`n4k1` DESC,`l2Item`.`n2k2` ASC) FOR `l2Item` IN `l1Item`.`n1k1` END) FOR `l1Item` IN `k2` END"
output := "ALL ARRAY (ALL ARRAY FLATTEN_KEYS(`l2Item`.`n2k1`.`n3k1` ASC INCLUDE MISSING,`l2Item`.`n2k1`.`n3k2`.`n4k1` DESC,`l2Item`.`n2k2` ASC) FOR `l2Item` IN `l1Item`.`n1k1` END) FOR `l1Item` IN `k2` END"
result := mongo.GenerateCouchbaseArrayIndex(input)
Expect(result).To(Equal(output))
})
It("output data should match with the test data", func() {
input := "k2[].n1k1.n2k1[].n3k1.n4k1[].n5k1 ASC INCLUDE MISSING,.n5k2.n6k1.n7k1 DESC,.n5k3 ASC"
output := "DISTINCT ARRAY (DISTINCT ARRAY (DISTINCT ARRAY FLATTEN_KEYS(`l3Item`.`n5k1` ASC INCLUDE MISSING,`l3Item`.`n5k2`.`n6k1`.`n7k1` DESC,`l3Item`.`n5k3` ASC) FOR `l3Item` IN `l2Item`.`n3k1`.`n4k1` END) FOR `l2Item` IN `l1Item`.`n1k1`.`n2k1` END) FOR `l1Item` IN `k2` END"
output := "ALL ARRAY (ALL ARRAY (ALL ARRAY FLATTEN_KEYS(`l3Item`.`n5k1` ASC INCLUDE MISSING,`l3Item`.`n5k2`.`n6k1`.`n7k1` DESC,`l3Item`.`n5k3` ASC) FOR `l3Item` IN `l2Item`.`n3k1`.`n4k1` END) FOR `l2Item` IN `l1Item`.`n1k1`.`n2k1` END) FOR `l1Item` IN `k2` END"
result := mongo.GenerateCouchbaseArrayIndex(input)
Expect(result).To(Equal(output))
})
Expand Down Expand Up @@ -291,7 +291,7 @@ var _ = Describe("mongo to couchbase index ", func() {
fieldPath["k2.n1k1.n2k1.n3k1"] = "k2[].n1k1[].n2k1.n3k1"
fieldPath["k2.n1k1.n2k1.n3k2.n4k1"] = "k2[].n1k1[].n2k1.n3k2.n4k1"
fieldPath["k2.n1k1.n2k2"] = "k2[].n1k1[].n2k2"
arrayExpression := "DISTINCT ARRAY (DISTINCT ARRAY FLATTEN_KEYS(`l2Item`.`n2k1`.`n3k1` ASC,`l2Item`.`n2k1`.`n3k2`.`n4k1` DESC,`l2Item`.`n2k2` ASC) FOR `l2Item` IN `l1Item`.`n1k1` END) FOR `l1Item` IN `k2` END"
arrayExpression := "ALL ARRAY (ALL ARRAY FLATTEN_KEYS(`l2Item`.`n2k1`.`n3k1` ASC,`l2Item`.`n2k1`.`n3k2`.`n4k1` DESC,`l2Item`.`n2k2` ASC) FOR `l2Item` IN `l1Item`.`n1k1` END) FOR `l1Item` IN `k2` END"
fields := []string{
"`k1`.`n1k1` ASC INCLUDE MISSING",
arrayExpression,
Expand Down Expand Up @@ -364,7 +364,7 @@ var _ = Describe("mongo to couchbase index ", func() {
fieldPath["k2.n1k1.n2k1.n3k1"] = "k2[].n1k1[].n2k1.n3k1"
fieldPath["k2.n1k1.n2k1.n3k2.n4k1"] = "k2[].n1k1[].n2k1.n3k2.n4k1"
fieldPath["k2.n1k1.n2k2"] = "k2[].n1k1[].n2k2"
arrayExpression := "DISTINCT ARRAY (DISTINCT ARRAY FLATTEN_KEYS(`l2Item`.`n2k1`.`n3k1` ASC,`l2Item`.`n2k1`.`n3k2`.`n4k1` DESC,`l2Item`.`n2k2` ASC) FOR `l2Item` IN `l1Item`.`n1k1` END) FOR `l1Item` IN `k2` END"
arrayExpression := "ALL ARRAY (ALL ARRAY FLATTEN_KEYS(`l2Item`.`n2k1`.`n3k1` ASC,`l2Item`.`n2k1`.`n3k2`.`n4k1` DESC,`l2Item`.`n2k2` ASC) FOR `l2Item` IN `l1Item`.`n1k1` END) FOR `l1Item` IN `k2` END"
fields := []string{
"`k1`.`n1k1` ASC INCLUDE MISSING",
arrayExpression,
Expand Down

0 comments on commit 864ab83

Please sign in to comment.