GOAL: Make filters on character fields work in SQL Server
CONTEXT: Any time we drill down on a character field in a visualization.
DETAILS:
Currently Kibella sends a filter on a character field by enclosing string values in DOUBLE quotes. However, double quotes are not considered valid by SQL Server to enclose strings...
This problem cannot be easily solved on the server side (except for very special --albeit common-- cases, namely SINGLE equality expressions of the form <field> = <value>
) because the filter is applied via a general expression (called "query string" in Kibella). In fact, it is not easy to distinguish field names from field values in a general filtering expression, and decide whether double quotes should be replaced with single quotes or not.
PROPOSED SOLUTIONS:
I propose two possible solutions, the first one (done on the client side) would solve the problem for good, while the second one (done on the server side) would apply for very simple (but fairly common) cases.
The proposed solutions are:
S1) CLIENT SIDE: Have the Kibella client send string values enclosed in SINGLE quotes.
S2) SERVER SIDE: Replace double quotes with single quotes ONLY in field values for expressions of the simple form containing one single equality.
Note that expressions of the form <field1> = <value1> and <field1> = <value2>
will NOT be tackled here.
EXAMPLES:
E1) INCOME table: when we filter on "class of worker" = "Private", we have the ambiguity to solve between a field name and a field value.
The part of the JSON string sent by the Kibella client to the server that is responsible of filtering looks something like this:
"query":{
"query_string":{
"analyze_wildcard":true,
"query":"\"class of worker\" = \"Private\""
}
}
If the proposed solution (S1) is implemented, the JSON string would look like this:
"query":{
"query_string":{
"analyze_wildcard":true,
"query":"\"class of worker\" = 'Private'"
}
}
and this would make the filtering on the value 'Private' automatically work in SQL Server.