RutledgePaulV / q-builders

Type safe database agnostic query builders.
MIT License
55 stars 26 forks source link

possible bug, depending on data #11

Closed berlinguyinca closed 8 years ago

berlinguyinca commented 8 years ago

dear Paul,

today we were running some queries using the following RSQL:

chemicalCompound.metaData=q='name=="total exact mass" and value=gt=411.31 and value=lt=411.4'

which generated the following mongo query

{ "chemicalCompound.metaData" : { "$elemMatch" : { "$and" : [ { "name" : "total exact mass"} , { "value" : { "$gt" : "411.31"}} , { "value" : { "$lt" : "411.4"}}]}}}

which is great!

Sadly it mapped the numbered arguments as String instead of Double, which caused the backend not to find any data. The correct query, would have been:

{ "chemicalCompound.metaData" : { "$elemMatch" : { "$and" : [ { "name" : "total exact mass"} , { "value" : { "$gt" : 411.31}} , { "value" : { "$lt" : 411.4}}]}}}

Is there some way, to specify in the pipeline. To map our results?

I have the feeling that this is related to our Metadata Object not specifying a type (Sorry it's scala)

case class MetaData( category: String , computed: Boolean, deleted: Boolean, hidden: Boolean, name: String, score: Score, unit: String, url: String, @JsonDeserialize(using = classOf[NumberDeserializer]) value: Any )

It can be any object, since we do not force the user to specify if it's a double or a string,etc. This is related to our data matrix

And we have a custom mapper, to serialize this based on the following logic

class NumberDeserializer extends JsonDeserializer[Any] {

override def deserialize(jsonParser: JsonParser, deserializationContext: DeserializationContext): Any = {

try {
  val jsonNode: JsonNode = jsonParser.getCodec.readTree(jsonParser)

  val content = jsonNode.textValue

  if (content != null) {
    if (content.toLowerCase.equals("true")) {
      true
    }
    else if (content.toLowerCase().equals("false")) {
      false
    }
    else {
      try {
        content.toInt
      } catch {
        case e: NumberFormatException => try {
          content.toDouble
        }
        catch {
          case e2: NumberFormatException => content
        }
      }
    }
  }
  else{
    content
  }
}
catch {
  case e: Exception => e.printStackTrace()
}

} }

Which basically tries to figure out the correct value from the given JSON for our object. So that our queries can be executed by number.

Is it possible that we can register such a mapper somewhere in your code, to be able to map our unusual configuration?

thanks again!

RutledgePaulV commented 8 years ago

Hi @berlinguyinca , I'm transferring this issue to rest-query-engine since it's actually related to code there not here (not that there's any reason you should have known that). Please see:

https://github.com/RutledgePaulV/rest-query-engine/issues/3

berlinguyinca commented 8 years ago

thanks!

On Mon, Mar 7, 2016 at 5:46 PM, Paul Rutledge notifications@github.com wrote:

Hi @berlinguyinca https://github.com/berlinguyinca , I'm transferring this issue to rest-query-engine since it's actually related to code there not here (not that there's any reason you should have known that). Please see:

RutledgePaulV/rest-query-engine#3 https://github.com/RutledgePaulV/rest-query-engine/issues/3

— Reply to this email directly or view it on GitHub https://github.com/RutledgePaulV/q-builders/issues/11#issuecomment-193550059 .


Lead Developer - Fiehnlab, UC Davis

gert wohlgemuth

work: http://fiehnlab.ucdavis.edu/staff/wohlgemuth

phone: 530 665 9477

coding blog: http://codingandmore.blogspot.com

linkedin: http://www.linkedin.com/profile/view?id=28611299&trk=tab_pro