| 239 | } |
| 240 | |
| 241 | SIValue AR_PROPERTY(SIValue *argv, int argc, void *private_data) { |
| 242 | // return NULL for missing graph entity |
| 243 | if(SI_TYPE(argv[0]) == T_NULL) return SI_NullVal(); |
| 244 | |
| 245 | // AR_PROPERTY may be invoked from AR_SUBSCRIPT in a case like: |
| 246 | // WITH {val: 5} AS map RETURN map["val"] |
| 247 | // As such, we need to validate the argument's type independently of the invocation validation. |
| 248 | if(SI_TYPE(argv[1]) != T_STRING) { |
| 249 | // String indexes are only permitted on maps, not arrays. |
| 250 | Error_SITypeMismatch(argv[1], T_STRING); |
| 251 | return SI_NullVal(); |
| 252 | } |
| 253 | |
| 254 | // inputs: |
| 255 | // argv[0] - node/edge/map/point |
| 256 | // argv[1] - property string |
| 257 | // argv[2] - property index |
| 258 | |
| 259 | //-------------------------------------------------------------------------- |
| 260 | // Process inputs |
| 261 | //-------------------------------------------------------------------------- |
| 262 | |
| 263 | SIValue obj = argv[0]; |
| 264 | if(SI_TYPE(obj) & SI_GRAPHENTITY) { |
| 265 | // retrieve entity property |
| 266 | GraphEntity *graph_entity = (GraphEntity *)obj.ptrval; |
| 267 | const char *prop_name = argv[1].stringval; |
| 268 | Attribute_ID prop_idx = argv[2].longval; |
| 269 | |
| 270 | // We have the property string, attempt to look up the index now. |
| 271 | if(prop_idx == ATTRIBUTE_ID_NONE) { |
| 272 | GraphContext *gc = QueryCtx_GetGraphCtx(); |
| 273 | prop_idx = GraphContext_GetAttributeID(gc, prop_name); |
| 274 | } |
| 275 | |
| 276 | // Retrieve the property. |
| 277 | SIValue *value = GraphEntity_GetProperty(graph_entity, prop_idx); |
| 278 | return SI_ConstValue(value); |
| 279 | } else if(SI_TYPE(obj) & T_MAP) { |
| 280 | // retrieve map key |
| 281 | SIValue key = argv[1]; |
| 282 | SIValue value; |
| 283 | |
| 284 | Map_Get(obj, key, &value); |
| 285 | // Return a volatile copy of the value, as it may be heap-allocated. |
| 286 | return SI_ShareValue(value); |
| 287 | } else if(SI_TYPE(obj) & T_POINT) { |
| 288 | // retrieve property key |
| 289 | SIValue key = argv[1]; |
| 290 | return Point_GetCoordinate(obj, key); |
| 291 | } else { |
| 292 | // unexpected type SI_TYPE(obj) |
| 293 | return SI_NullVal(); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | SIValue AR_TYPEOF(SIValue *argv, int argc, void *private_data) { |
| 298 | return SI_ConstStringVal(SIType_ToString(SI_TYPE(argv[0]))); |
no test coverage detected