XEdwin / jcouchdb

Automatically exported from code.google.com/p/jcouchdb
Other
0 stars 0 forks source link

Loading a view using CouchDBUpdater with no reduce function causes view invocation to fail #34

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Create a folder called 'myapp'

2. Create a file all.map.js that contains the contents
function (doc) {
  emit(null, doc);
}
3. Load the folder using CouchDBUpdater
    public static void main(String[] args) throws Exception {
        String dbname = "myappdb";

        CouchDBUpdater updater = new CouchDBUpdater();
        updater.setDesignDocumentDir(new File("/path/to/designdoc/folder"));

        Server server = new ServerImpl(host, port);
        Database database = Database(server, dbname);   

        updater.setDatabase(database);
        updater.setCreateDatabase(false);
        updater.updateDesignDocuments();        
    }

4. Add a document to the database

5. Invoke the view

$ curl http://localhost:5984/myapp/_design/myapp/_view/all
{"rows":[
curl: (18) transfer closed with outstanding read data remaining 

If you look at the database in Futon, you see that both map and reduce for
the view are defined, but reduce is set to 'null'.

If you remove the reduce field, and rerun the query, it works.

$ curl http://localhost:5984/myapp/_design/myapp/_view/all
{"total_rows":1,"offset":0,"rows":[
{"id":"c70351bd38aca6c4c093685431ad1470","key":null,"value":{"_id":"c70351bd38a
a6c4c093685431ad1470","_rev":"1-d2f49d209e96cda0491ea6a8465cd6a4","author":"Davi
d
Van Couvering"}}
]}

I'm using jcouchdb 0.10.0.3, on WinXP.

Note that if you invoke this view using jcouchdb, the parser barfs:

org.svenson.JSONParseException: Unexpected character '￿'
    at org.svenson.tokenize.JSONTokenizer.next(JSONTokenizer.java:233)
    at org.svenson.JSONParser.parseArrayInto(JSONParser.java:445)
    at org.svenson.JSONParser.parseObjectInto(JSONParser.java:620)
    at org.svenson.JSONParser.parse(JSONParser.java:383)
    at org.svenson.JSONParser.parse(JSONParser.java:365)
    at org.jcouchdb.db.Response.getContentAsBean(Response.java:158)
    at org.jcouchdb.db.Database.queryViewInternal(Database.java:827)
    at org.jcouchdb.db.Database.query(Database.java:742)

Under the debugger, I can see that the "character" has the int value 65535

Original issue reported on code.google.com by david.va...@gmail.com on 19 Jan 2010 at 4:54

GoogleCodeExporter commented 9 years ago
I am attaching a patch which appears to fix the problem - tell the View class to
ignore a reduce function if it's null.

Original comment by david.va...@gmail.com on 19 Jan 2010 at 6:17

GoogleCodeExporter commented 9 years ago
Here it the patch - sorry, still getting used to the bug tool UI

Original comment by david.va...@gmail.com on 19 Jan 2010 at 6:19

Attachments:

GoogleCodeExporter commented 9 years ago
This issue was closed by revision r236.

Original comment by ff...@gmx.de on 20 Jan 2010 at 10:51

GoogleCodeExporter commented 9 years ago
waitaminute.. what's the purpose of "extends BaseDocument" ? View is is no 
complete
document, but part of one.

Strange thing is that such a map-only view is included in the tests and worked. 
Maybe
an XP only effect. the 0xFFFFFFFF thing is a bit strange..

@JSONProperty(ignoreIfNull=true) shouldn't be a problem on the other hand. 

Original comment by ff...@gmx.de on 20 Jan 2010 at 10:57