Uploaded image for project: 'Teiid'
  1. Teiid
  2. TEIID-5296

With MongoDB, timestamp operations throw exceptions when called on null or missing values

    Details

      Description

      When a query contains timestamp operations like DAYOFMONTH, DAYOFWEEK,.. and these are executed when some cells contain null (or missing field), MongoDB throws an exception. This exception is not handled by Teiid in any way and will fail the whole VDB query:

      Remote com.mongodb.CommandFailureException: 
      { "serverUsed" : "localhost:27017" , 
      "ok" : 0.0 , "errmsg" : "can't convert from BSON type null to Date" , 
      "code" : 16006 , "
      codeName" : "Location16006"}
      

      Perhaps Teiid could work around this somehow so that the VDB query will not fail and affected cells will contain null in the result?

      For example, this Mongo aggregation pipeline which extracts hours from timestamps:

      db.collection.aggregate([
        { 
          $project : {
            hour: {$hour: "$DATEVALUE"}
          }
        }
      ])
      

      could be transformed to this:

      db.collection.aggregate([
        { 
          $project : {
            hour: { $cond: 
              [ { $or: [ 
                         { $eq: [ "$DATEVALUE", null ] }, 
                         { $eq: [ { $type: "$DATEVALUE" }, "missing" ] }                                       
                       ]
                },
                null, 
                { $hour: "$DATEVALUE" } 
              ] 
            }
          }
        }
      ])
      

      after this transformation, the hour field will be null as expected for documents where DATEVALUE is null or missing completely

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                shawkins Steven Hawkins
                Reporter:
                jmartisk Jan Martiska
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: