Uploaded image for project: 'Couchbase Lite'
  1. Couchbase Lite
  2. CBL-369

FTS and database alias

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.6.0
    • 2.7.0
    • iOS
    • Security Level: Public
    • None
    • CBL Sprint 2, CBL Sprint 3
    • 5

    Description

      Actual Result:

      Error

      Expected Result:

      No Error and get query result.

      What is the last build this test passed:

      This was not added in unit test. so not sure.

      Steps to Reproduce(updated unit test):

      func testWhereMatch() throws {
              Database.log.console.level = .debug
              try loadJSONResource(name: "sentences")
              
              let index = IndexBuilder
                  .fullTextIndex(items: FullTextIndexItem.property("sentence"))
                  .language(nil)
                  .ignoreAccents(false)
              try db.createIndex(index, withName: "sentence")
              
              let alias = "db"
              let s_sentence = SelectResult.expression(Expression.property("sentence")
                  .from(alias))
              let q = QueryBuilder.select([SelectResult.expression(Meta.id.from(alias)), s_sentence])
                  .from(DataSource.database(db).as(alias))
                  .where(FullTextExpression.index("sentence").match("'Dummie woman'"))
                  .orderBy(Ordering.expression(FullTextFunction.rank("sentence")).descending())
              let numRows = try verifyQuery(q) { (n, r) in
                  
              }
              XCTAssertEqual(numRows, 2)
          }
      

      Logs:

      2019-09-06 23:12:23.989531-0700 xctest[85798:4258167] CouchbaseLite Query Info: {Query#2} Compiling JSON query: {"WHAT":[[".db._id"],[".db.sentence"]],"WHERE":["MATCH","sentence","'Dummie woman'"],"FROM":[{"AS":"db"}],"ORDER_BY":[["DESC",["RANK()","sentence"]]]}
      2019-09-06 23:12:23.990462-0700 xctest[85798:4258167] CouchbaseLite Query Info: {Query#2} Compiled as SELECT "db".db.rowid, offsets(fts1."kv_default::sentence"), fl_result("db".key), fl_result(fl_value("db".body, 'sentence')) FROM kv_default AS "db" JOIN "kv_default::sentence" AS fts1 ON fts1.docid = "db".rowid WHERE (fts1."kv_default::sentence" MATCH '''Dummie woman''') AND ("db".flags & 1 = 0) ORDER BY rank(matchinfo(fts1."kv_default::sentence")) DESC
      2019-09-06 23:12:23.990750-0700 xctest[85798:4258167] CouchbaseLite Database ERROR: SQLite error (code 1): no such column: db.db.rowid in "SELECT "db".db.rowid, offsets(fts1."kv_default::sentence"), fl_result("db".key), fl_result(fl_value("db".body, 'sentence')) FROM kv_default AS "db" JOIN "kv_default::sentence" AS fts1 ON fts1.docid = "db".rowid WHERE (fts1."kv_default::sentence" MATCH '''Dummie woman''') AND ("db".flags & 1 = 0) ORDER BY rank(matchinfo(fts1."kv_default::sentence")) DESC"
      2019-09-06 23:12:23.990992-0700 xctest[85798:4258167] CouchbaseLite Database ERROR: no such column: db.db.rowid (1/1)
      2019-09-06 23:12:23.991285-0700 xctest[85798:4258167] CouchbaseLite Database WARNING: {DB#1} SQLite error compiling statement "SELECT "db".db.rowid, offsets(fts1."kv_default::sentence"), fl_result("db".key), fl_result(fl_value("db".body, 'sentence')) FROM kv_default AS "db" JOIN "kv_default::sentence" AS fts1 ON fts1.docid = "db".rowid WHERE (fts1."kv_default::sentence" MATCH '''Dummie woman''') AND ("db".flags & 1 = 0) ORDER BY rank(matchinfo(fts1."kv_default::sentence")) DESC": no such column: db.db.rowid
      <unknown>:0: error: -[CouchbaseLiteSwiftTests.QueryTest testWhereMatch] : failed: caught error: no such column: db.db.rowid
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            Jayahari.Vavachan Jay Vavachan added a comment -

            https://github.com/couchbase/couchbase-lite-core/blob/6e0c8a33eb62e8150cbfa75d0b75cf48e4a5ff39/LiteCore/Query/QueryParser.cc#L288

            This above line is appending an extra "dbAlias".

            if we make the above line to be like below, it will fix the issue.

            extra <<  _dbAlias << ".rowid";
            

            Jayahari.Vavachan Jay Vavachan added a comment - https://github.com/couchbase/couchbase-lite-core/blob/6e0c8a33eb62e8150cbfa75d0b75cf48e4a5ff39/LiteCore/Query/QueryParser.cc#L288 This above line is appending an extra "dbAlias". if we make the above line to be like below, it will fix the issue. extra << _dbAlias << ".rowid" ;
            Jayahari.Vavachan Jay Vavachan added a comment - - edited

            also interesting that, if we change the alias to other than "db", it is working fine.

            Issue not happens with "main", but happens with other names.

            Jayahari.Vavachan Jay Vavachan added a comment - - edited also interesting that, if we change the alias to other than "db", it is working fine. Issue not happens with "main", but happens with other names.
            Jayahari.Vavachan Jay Vavachan added a comment - https://github.com/couchbase/couchbase-lite-core/pull/836
            Jayahari.Vavachan Jay Vavachan added a comment - https://github.com/couchbase/couchbase-lite-core/commit/b7a94380bdd5ade8d6efa74fadfacb6e586cfd56
            Jayahari.Vavachan Jay Vavachan added a comment -

            Closing!

            Jayahari.Vavachan Jay Vavachan added a comment - Closing!

            Build couchbase-lite-ios-2.7.0-29 contains couchbase-lite-ios commit 9b2c98c with commit message:
            CBL-369: unit: FTS and alias issue with db.db.rowid (#2542)

            build-team Couchbase Build Team added a comment - Build couchbase-lite-ios-2.7.0-29 contains couchbase-lite-ios commit 9b2c98c with commit message: CBL-369 : unit: FTS and alias issue with db.db.rowid (#2542)

            People

              Jayahari.Vavachan Jay Vavachan
              Jayahari.Vavachan Jay Vavachan
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty