<!-- 
RSS generated by JIRA (5.2.4#845-sha1:c9f4cc41abe72fb236945343a1f485c2c844dac9) at Tue May 21 14:59:44 CDT 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://www.couchbase.com/issues/si/jira.issueviews:issue-xml/PCBC-137/PCBC-137.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Couchbase</title>
    <link>http://www.couchbase.com/issues</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>5.2.4</version>
        <build-number>845</build-number>
        <build-date>26-12-2012</build-date>
    </build-info>

<item>
            <title>[PCBC-137] view querying needs to be more straightforward; e.g. character strings of decimal digits are serialised over the REST API as integers in view requests</title>
                <link>http://www.couchbase.com/issues/browse/PCBC-137</link>
                <project id="10049" key="PCBC">Couchbase PHP client library</project>
                        <description>Given this code:&lt;br/&gt;
&lt;br/&gt;
&amp;nbsp;$key = &amp;quot;1&amp;quot;;&lt;br/&gt;
&amp;nbsp;$result = $cb-&amp;gt;view(&amp;quot;design&amp;quot;, &amp;quot;view&amp;quot;, array(&amp;quot;key&amp;quot;=&amp;gt;$key));&lt;br/&gt;
&lt;br/&gt;
The PHP library will serialize this to a REST request as follows:&lt;br/&gt;
&lt;br/&gt;
GET /bucket/_design/design/_view/view?key=1&lt;br/&gt;
&lt;br/&gt;
This will be deserialized by couchbase as the integer value 1, not as the string value &amp;quot;1&amp;quot;.  Consequently, any key that is a string of decimal digits cannot be retrieved from a view with the PHP library.&lt;br/&gt;
&lt;br/&gt;
This workaround can be used:&lt;br/&gt;
&lt;br/&gt;
$key = &amp;quot;1&amp;quot;;&lt;br/&gt;
$result = $cb-&amp;gt;view(&amp;quot;design&amp;quot;, &amp;quot;view&amp;quot;, array(&amp;quot;key&amp;quot;=&amp;gt;&amp;#39;&amp;quot;&amp;#39;.$key.&amp;#39;&amp;quot;&amp;#39;));&lt;br/&gt;
&lt;br/&gt;
The library will serialize this to a REST request as follows:&lt;br/&gt;
&lt;br/&gt;
GET /bucket/_design/design/_view/view?key=&amp;quot;1&amp;quot;&lt;br/&gt;
&lt;br/&gt;
And couchbase will deserialize this as the string value &amp;quot;1&amp;quot;.&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
</description>
                <environment></environment>
            <key id="20415">PCBC-137</key>
            <summary>view querying needs to be more straightforward; e.g. character strings of decimal digits are serialised over the REST API as integers in view requests</summary>
                <type id="1" iconUrl="http://www.couchbase.com/issues/images/icons/issuetypes/bug.png">Bug</type>
                                <priority id="1" iconUrl="http://www.couchbase.com/issues/images/icons/priorities/blocker.png">Blocker</priority>
                    <status id="5" iconUrl="http://www.couchbase.com/issues/images/icons/statuses/resolved.png">Resolved</status>
                    <resolution id="1">Fixed</resolution>
                    <security id="10011">Public</security>
                        <assignee username="ingenthr">Matt Ingenthron</assignee>
                                <reporter username="michael8robinson">Michael Robinson</reporter>
                        <labels>
                    </labels>
                <created>Thu, 25 Oct 2012 07:19:18 -0500</created>
                <updated>Tue, 11 Dec 2012 19:59:32 -0600</updated>
                    <resolved>Fri, 23 Nov 2012 20:21:18 -0600</resolved>
                            <version>1.1.0-dp5</version>
                                <fixVersion>1.1.0</fixVersion>
                                                <votes>0</votes>
                        <watches>3</watches>
                                                    <comments>
                    <comment id="42484" author="ingenthr" created="Thu, 25 Oct 2012 12:55:14 -0500"  >Mark: I saw you mention this earlier.  Can you provide an assessment on this?</comment>
                    <comment id="42511" author="mnunberg" created="Thu, 25 Oct 2012 14:15:04 -0500"  >This is a more generalized bug or task of making php aware of the view parameters it passes.&lt;br/&gt;
&lt;br/&gt;
Currently it only serializes the key-value pairs in the array as is. Having php know about where to place quotes would mean making the client aware abotu the variations in the view parameters, or in other words, implementing all of the view logic in the client library.&lt;br/&gt;
&lt;br/&gt;
For now the user should be aware of this, and if something clearly mandates &amp;quot;quotes&amp;quot; then it should be quoted already when passed to the array.&lt;br/&gt;
&lt;br/&gt;
While it&amp;#39;s not the most elegant solution the fix to this is by far not surgical, and thus i recommend changing the name of this bug</comment>
                    <comment id="42530" author="michael8robinson" created="Thu, 25 Oct 2012 15:53:59 -0500"  >Would logic equivalent to this not solve the problem?&lt;br/&gt;
&lt;br/&gt;
if (is_string($params[&amp;quot;key&amp;quot;])) {&lt;br/&gt;
&amp;nbsp;&amp;nbsp;$paramString += &amp;#39;key=&amp;quot;&amp;#39;.$params[&amp;quot;key&amp;quot;].&amp;#39;&amp;quot;&amp;#39;;&lt;br/&gt;
}&lt;br/&gt;
else {&lt;br/&gt;
&amp;nbsp;&amp;nbsp;$paramString += &amp;#39;key=&amp;#39;.$params[&amp;quot;key&amp;quot;];&lt;br/&gt;
}</comment>
                    <comment id="42536" author="mnunberg" created="Thu, 25 Oct 2012 16:23:10 -0500"  >No, because there are some parameters which do need actual integers.&lt;br/&gt;
&lt;br/&gt;
Maybe the server can tolerate numeric parameters even fi they are enclosed in quotes, but I am not sure about that.&lt;br/&gt;
&lt;br/&gt;
See&lt;br/&gt;
&lt;br/&gt;
&lt;a href=&quot;http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-querying-rest-api.html&quot;&gt;http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-querying-rest-api.html&lt;/a&gt; - and for example, group_level&lt;br/&gt;
&lt;br/&gt;
Basically, the php client needs more logic to know the appropriate type for each parameter and perform the necessary coercion. i.e. numeric values for keys are not the same as numeric values for pagination</comment>
                    <comment id="42574" author="michael8robinson" created="Fri, 26 Oct 2012 04:20:12 -0500"  >Ok, it seems there are two problems at issue:&lt;br/&gt;
&lt;br/&gt;
Problem 1:  As a general case, type coercions across all parameters in the REST query string are not being handled as intelligently as they could be by the PHP library.&lt;br/&gt;
&lt;br/&gt;
Problem 2:  As a special case of problem 1, the PHP library will silently fail to retrieve records from a view if the key happens to be a string of decimal digits.&lt;br/&gt;
&lt;br/&gt;
Without addressing the technical or architectural challenges of problem 1, it seems that, with respect to problem 2, as a general principle, silently failing to retrieve valid records for which a valid request was submitted is generally recognized as undesirable behavior for a database system.&lt;br/&gt;
&lt;br/&gt;
This undesirable behavior could be rectified by the following (and as far as I can see, trivial) change to the serialization logic:&lt;br/&gt;
&lt;br/&gt;
&amp;nbsp;&amp;nbsp;If the parameter is in the set (&amp;quot;key&amp;quot;, &amp;quot;startkey&amp;quot;, &amp;quot;startkey_docid&amp;quot;, &amp;quot;endkey&amp;quot;, &amp;quot;endkey_docid&amp;quot;),&lt;br/&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;and if the PHP type of the corresponding parameter value is &amp;quot;string&amp;quot;,&lt;br/&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;then serialize the parameter value in quotation marks in the REST query string,&lt;br/&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;otherwise serialize the parameter value according to current implementation.&lt;br/&gt;
&lt;br/&gt;
Yes?&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;</comment>
                    <comment id="42575" author="ingenthr" created="Fri, 26 Oct 2012 04:43:45 -0500"  >That does seem to make sense to me Michael.  That&amp;#39;s roughly what we evolved to on the other clients (Java &amp;amp;&amp;amp; .NET), but there things are a bit different because of the types.</comment>
                    <comment id="43840" author="ingenthr" created="Mon, 12 Nov 2012 15:52:03 -0600"  >Michael: can you take the lead on documenting a reasonable view query API.  You have been through this once before, so I think you&amp;#39;d be the best person here.  Simply document it here in this issue and then let&amp;#39;s schedule a quick design review.</comment>
                    <comment id="43879" author="daschl" created="Tue, 13 Nov 2012 04:45:32 -0600"  >Here is my proposal.&lt;br/&gt;
&lt;br/&gt;
I&amp;#39;ve been thinking through and working around this while hacking on Basement (&lt;a href=&quot;https://github.com/daschl/Basement&quot;&gt;https://github.com/daschl/Basement&lt;/a&gt;) and also while extending the Java API. You may see similarities because of this (and you&amp;#39;ll hopefully see why and how it makes sense).&lt;br/&gt;
&lt;br/&gt;
At the lowest level, I think we should provide two ways of passing in queries in there.&lt;br/&gt;
&lt;br/&gt;
1) A plain array as it is now. This way users can work around possible bugs and also have the flexibility if they know what they&amp;#39;re doing. We should clearly state though that they are &amp;quot;on their own&amp;quot; when going down this route.&lt;br/&gt;
&lt;br/&gt;
2) A CouchbaseViewQuery object (sorry, since we don&amp;#39;t support namespaces in the extension). This works nearly similar to the Java-one, with the main difference that we need to care about working out the appropriate result type on our own (since you can pass in everything as a variable).&lt;br/&gt;
&lt;br/&gt;
All further discussion (except noted) refers to the new object and how it should behave.&lt;br/&gt;
&lt;br/&gt;
The construct should either take no params or an array to be initialized with. If it gets an array, it doesn&amp;#39;t set the params directly but calls each setter for the given key to make sure that all rules are properly enforced.&lt;br/&gt;
&lt;br/&gt;
Here is a simplified example. It assumes that all setter methods have the name as the param (like key() when setting/getting the key). If we want bean-style setters the method names need to be changed of course.&lt;br/&gt;
&lt;br/&gt;
	class CouchbaseViewQuery {&lt;br/&gt;
		&lt;br/&gt;
		// holds the params to be exported&lt;br/&gt;
		private $params = array();&lt;br/&gt;
&lt;br/&gt;
		// iterate over the given object an call setters.&lt;br/&gt;
		public function __construct($params = array()) {&lt;br/&gt;
			foreach($params as $key =&amp;gt; $value) {&lt;br/&gt;
				if($value !== null) {&lt;br/&gt;
					$this-&amp;gt;{$key}($value);&lt;br/&gt;
				}&lt;br/&gt;
			}&lt;br/&gt;
		}&lt;br/&gt;
&lt;br/&gt;
		public function reduce($reduce = null) {&lt;br/&gt;
			// getter/setter functionality in each method makes it condensed.&lt;br/&gt;
			if($reduce == null) {&lt;br/&gt;
				return $this-&amp;gt;params[&amp;#39;reduce&amp;#39;];&lt;br/&gt;
			}&lt;br/&gt;
&lt;br/&gt;
			// do appropriate type checking for each param depending on whats&lt;br/&gt;
			// supported.&lt;br/&gt;
			if($reduce === &amp;#39;true&amp;#39; || $reduce === true) {&lt;br/&gt;
				$this-&amp;gt;params[&amp;#39;reduce&amp;#39;] = true;&lt;br/&gt;
			}&lt;br/&gt;
&lt;br/&gt;
			// return object to let chain setters.&lt;br/&gt;
			return $this;&lt;br/&gt;
		}&lt;br/&gt;
&lt;br/&gt;
	}&lt;br/&gt;
&lt;br/&gt;
Depending on how much we want to change the underlying interface, this query object can have either a toArray() or toString() export method that handles either only exporting it to an array, a string or also handle JSON serialization or encoding (don&amp;#39;t know what of this parts is handled by libcouchbase itself).&lt;br/&gt;
&lt;br/&gt;
Here is a possible usage example:&lt;br/&gt;
&lt;br/&gt;
	$query = new CouchbaseViewQuery();&lt;br/&gt;
	$query-&amp;gt;setReduce(true); // equally to $query-&amp;gt;setReduce(&amp;#39;true&amp;#39;); then&lt;br/&gt;
	$cb-&amp;gt;view(&amp;#39;design&amp;#39;, &amp;#39;view&amp;#39;, $query);&lt;br/&gt;
&lt;br/&gt;
Also, all checks and conversions can then be handled transparently and securely by their appropriate setter methods. PHP also provides is_string() and so on to further determine what is passed into the variable.&lt;br/&gt;
&lt;br/&gt;
Also, the export method is then in the position to do semantical checks like throw a warning/exception when reduce is false (or not set) and a group param is passed on. This could also be done in the setter but I&amp;#39;d like to see it done on exporting to reduce the coupling between setters.&lt;br/&gt;
&lt;br/&gt;
The query handling object could look similar to this: &lt;a href=&quot;https://github.com/daschl/Basement/blob/master/README.md#working-with-views&quot;&gt;https://github.com/daschl/Basement/blob/master/README.md#working-with-views&lt;/a&gt; (of course the method signature for view querying is differently, but the Query object would be nearly the same).&lt;br/&gt;
&lt;br/&gt;
Let me know what you think guys,&lt;br/&gt;
Michael&lt;br/&gt;
</comment>
                    <comment id="43880" author="daschl" created="Tue, 13 Nov 2012 04:45:47 -0600"  >For design review.</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
                <customfields>
                                                                                                                                                                                                                    <customfield id="customfield_10081" key="com.pyxis.greenhopper.jira:gh-global-rank">
                <customfieldname>Rank</customfieldname>
                <customfieldvalues>
                    <customfieldvalue>9773</customfieldvalue>
                </customfieldvalues>
            </customfield>
                                                                                    <customfield id="customfield_10181" key="com.atlassian.jira.ext.charting:timeinstatus">
                <customfieldname>Time In Status</customfieldname>
                <customfieldvalues>
                    
                </customfieldvalues>
            </customfield>
                                                </customfields>
    </item>
</channel>
</rss>