TRI_associative_pointer_t* TRI_InitialiseFunctionsAql (void) { TRI_associative_pointer_t* functions; bool result = true; functions = (TRI_associative_pointer_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_associative_pointer_t), false); if (!functions) { return NULL; } TRI_InitAssociativePointer(functions, TRI_UNKNOWN_MEM_ZONE, TRI_HashStringKeyAssociativePointer, HashFunction, EqualName, NULL); // . = argument of any type (except collection) // c = collection name, will be converted into list with documents // h = collection name, will be converted into string // z = null // b = bool // n = number // s = string // p = primitive // l = list // a = array // type check functions REGISTER_FUNCTION("IS_NULL", "IS_NULL", true, false, "."); REGISTER_FUNCTION("IS_BOOL", "IS_BOOL", true, false, "."); REGISTER_FUNCTION("IS_NUMBER", "IS_NUMBER", true, false, "."); REGISTER_FUNCTION("IS_STRING", "IS_STRING", true, false, "."); REGISTER_FUNCTION("IS_LIST", "IS_LIST", true, false, "."); REGISTER_FUNCTION("IS_DOCUMENT", "IS_DOCUMENT", true, false, "."); // cast functions REGISTER_FUNCTION("TO_NUMBER", "CAST_NUMBER", true, false, "."); REGISTER_FUNCTION("TO_STRING", "CAST_STRING", true, false, "."); REGISTER_FUNCTION("TO_BOOL", "CAST_BOOL", true, false, "."); // string functions REGISTER_FUNCTION("CONCAT", "STRING_CONCAT", true, false, "sz,sz|+"); REGISTER_FUNCTION("CONCAT_SEPARATOR", "STRING_CONCAT_SEPARATOR", true, false, "s,sz,sz|+"); REGISTER_FUNCTION("CHAR_LENGTH", "STRING_LENGTH", true, false, "s"); REGISTER_FUNCTION("LOWER", "STRING_LOWER", true, false, "s"); REGISTER_FUNCTION("UPPER", "STRING_UPPER", true, false, "s"); REGISTER_FUNCTION("SUBSTRING", "STRING_SUBSTRING", true, false, "s,n|n"); REGISTER_FUNCTION("CONTAINS", "STRING_CONTAINS", true, false, "s,s"); // numeric functions REGISTER_FUNCTION("FLOOR", "NUMBER_FLOOR", true, false, "n"); REGISTER_FUNCTION("CEIL", "NUMBER_CEIL", true, false, "n"); REGISTER_FUNCTION("ROUND", "NUMBER_ROUND", true, false, "n"); REGISTER_FUNCTION("ABS", "NUMBER_ABS", true, false, "n"); REGISTER_FUNCTION("RAND", "NUMBER_RAND", false, false, ""); // list functions REGISTER_FUNCTION("UNION", "UNION", true, false, "l,l|+"); REGISTER_FUNCTION("LENGTH", "LENGTH", true, true, "l"); REGISTER_FUNCTION("MIN", "MIN", true, true, "l"); REGISTER_FUNCTION("MAX", "MAX", true, true, "l"); REGISTER_FUNCTION("SUM", "SUM", true, true, "l"); REGISTER_FUNCTION("UNIQUE", "UNIQUE", true, false, "l"); REGISTER_FUNCTION("REVERSE", "REVERSE", true, false, "l"); REGISTER_FUNCTION("FIRST", "FIRST", true, false, "l"); REGISTER_FUNCTION("LAST", "LAST", true, false, "l"); // document functions REGISTER_FUNCTION("HAS", "HAS", true, false, "az,s"); REGISTER_FUNCTION("MERGE", "MERGE", true, false, "a,a|+"); // geo functions REGISTER_FUNCTION("NEAR", "GEO_NEAR", false, false, "h,n,n,n|s"); REGISTER_FUNCTION("WITHIN", "GEO_WITHIN", false, false, "h,n,n,n|s"); // graph functions REGISTER_FUNCTION("PATHS", "GRAPH_PATHS", false, false, "c,h|s,b"); // misc functions REGISTER_FUNCTION("FAIL", "FAIL", false, false, "|s"); // FAIL is non-deterministic, otherwise query optimisation will fail! REGISTER_FUNCTION("PASSTHRU", "PASSTHRU", false, false, "."); // simple non-deterministic wrapper to avoid optimisations at parse time REGISTER_FUNCTION("COLLECTIONS", "COLLECTIONS", false, false, ""); REGISTER_FUNCTION("NOT_NULL", "NOT_NULL", true, false, ".,."); if (!result) { TRI_FreeFunctionsAql(functions); return NULL; } return functions; }
TRI_associative_pointer_t* TRI_CreateFunctionsAql (void) { TRI_associative_pointer_t* functions; bool result; int res; functions = (TRI_associative_pointer_t*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_associative_pointer_t), false); if (functions == NULL) { return NULL; } res = TRI_InitAssociativePointer(functions, TRI_UNKNOWN_MEM_ZONE, TRI_HashStringKeyAssociativePointer, HashFunction, EqualName, NULL); if (res != TRI_ERROR_NO_ERROR) { TRI_Free(TRI_UNKNOWN_MEM_ZONE, functions); return NULL; } // . = argument of any type (except collection) // c = collection name, will be converted into list with documents // h = collection name, will be converted into string // z = null // b = bool // n = number // s = string // p = primitive // l = list // a = (hash) array/document // r = regex (a string with a special format). note: the regex type is mutually exclusive with all other types result = true; // type check functions REGISTER_FUNCTION("IS_NULL", "IS_NULL", true, false, ".", NULL); REGISTER_FUNCTION("IS_BOOL", "IS_BOOL", true, false, ".", NULL); REGISTER_FUNCTION("IS_NUMBER", "IS_NUMBER", true, false, ".", NULL); REGISTER_FUNCTION("IS_STRING", "IS_STRING", true, false, ".", NULL); REGISTER_FUNCTION("IS_LIST", "IS_LIST", true, false, ".", NULL); REGISTER_FUNCTION("IS_DOCUMENT", "IS_DOCUMENT", true, false, ".", NULL); // cast functions REGISTER_FUNCTION("TO_NUMBER", "CAST_NUMBER", true, false, ".", NULL); REGISTER_FUNCTION("TO_STRING", "CAST_STRING", true, false, ".", NULL); REGISTER_FUNCTION("TO_BOOL", "CAST_BOOL", true, false, ".", NULL); REGISTER_FUNCTION("TO_LIST", "CAST_LIST", true, false, ".", NULL); // string functions REGISTER_FUNCTION("CONCAT", "STRING_CONCAT", true, false, "sz,sz|+", NULL); REGISTER_FUNCTION("CONCAT_SEPARATOR", "STRING_CONCAT_SEPARATOR", true, false, "s,sz,sz|+", NULL); REGISTER_FUNCTION("CHAR_LENGTH", "CHAR_LENGTH", true, false, "s", NULL); REGISTER_FUNCTION("LOWER", "STRING_LOWER", true, false, "s", NULL); REGISTER_FUNCTION("UPPER", "STRING_UPPER", true, false, "s", NULL); REGISTER_FUNCTION("SUBSTRING", "STRING_SUBSTRING", true, false, "s,n|n", NULL); REGISTER_FUNCTION("CONTAINS", "STRING_CONTAINS", true, false, "s,s|b", NULL); REGISTER_FUNCTION("LIKE", "STRING_LIKE", true, false, "s,r|b", NULL); REGISTER_FUNCTION("LEFT", "STRING_LEFT", true, false, "s,n", NULL); REGISTER_FUNCTION("RIGHT", "STRING_RIGHT", true, false, "s,n", NULL); REGISTER_FUNCTION("TRIM", "STRING_TRIM", true, false, "s|n", NULL); // numeric functions REGISTER_FUNCTION("FLOOR", "NUMBER_FLOOR", true, false, "n", NULL); REGISTER_FUNCTION("CEIL", "NUMBER_CEIL", true, false, "n", NULL); REGISTER_FUNCTION("ROUND", "NUMBER_ROUND", true, false, "n", NULL); REGISTER_FUNCTION("ABS", "NUMBER_ABS", true, false, "n", NULL); REGISTER_FUNCTION("RAND", "NUMBER_RAND", false, false, "", NULL); REGISTER_FUNCTION("SQRT", "NUMBER_SQRT", true, false, "n", NULL); // list functions REGISTER_FUNCTION("RANGE", "RANGE", true, false, "n,n|n", NULL); REGISTER_FUNCTION("UNION", "UNION", true, false, "l,l|+", NULL); REGISTER_FUNCTION("UNION_DISTINCT", "UNION_DISTINCT", true, false, "l,l|+", NULL); REGISTER_FUNCTION("MINUS", "MINUS", true, false, "l,l|+", NULL); REGISTER_FUNCTION("INTERSECTION", "INTERSECTION", true, false, "l,l|+", NULL); REGISTER_FUNCTION("LENGTH", "LENGTH", true, true, "las", NULL); REGISTER_FUNCTION("MIN", "MIN", true, true, "l", NULL); REGISTER_FUNCTION("MAX", "MAX", true, true, "l", NULL); REGISTER_FUNCTION("SUM", "SUM", true, true, "l", NULL); REGISTER_FUNCTION("MEDIAN", "MEDIAN", true, true, "l", NULL); REGISTER_FUNCTION("AVERAGE", "AVERAGE", true, true, "l", NULL); REGISTER_FUNCTION("VARIANCE_SAMPLE", "VARIANCE_SAMPLE", true, true, "l", NULL); REGISTER_FUNCTION("VARIANCE_POPULATION", "VARIANCE_POPULATION", true, true, "l", NULL); REGISTER_FUNCTION("STDDEV_SAMPLE", "STDDEV_SAMPLE", true, true, "l", NULL); REGISTER_FUNCTION("STDDEV_POPULATION", "STDDEV_POPULATION", true, true, "l", NULL); REGISTER_FUNCTION("UNIQUE", "UNIQUE", true, false, "l", NULL); // note: REVERSE() can be applied on strings, too REGISTER_FUNCTION("REVERSE", "REVERSE", true, false, "ls", NULL); REGISTER_FUNCTION("FIRST", "FIRST", true, false, "l", NULL); REGISTER_FUNCTION("LAST", "LAST", true, false, "l", NULL); // document functions REGISTER_FUNCTION("HAS", "HAS", true, false, "az,s", NULL); REGISTER_FUNCTION("ATTRIBUTES", "ATTRIBUTES", true, false, "a|b,b", NULL); REGISTER_FUNCTION("MERGE", "MERGE", true, false, "a,a|+", NULL); REGISTER_FUNCTION("MERGE_RECURSIVE", "MERGE_RECURSIVE", true, false, "a,a|+", NULL); REGISTER_FUNCTION("DOCUMENT", "DOCUMENT", false, false, "h.|.", NULL); REGISTER_FUNCTION("MATCHES", "MATCHES", true, false, ".,l|b", NULL); REGISTER_FUNCTION("UNSET", "UNSET", true, false, "a,sl|+", NULL); REGISTER_FUNCTION("KEEP", "KEEP", true, false, "a,sl|+", NULL); // geo functions REGISTER_FUNCTION("NEAR", "GEO_NEAR", false, false, "h,n,n|nz,s", NULL); REGISTER_FUNCTION("WITHIN", "GEO_WITHIN", false, false, "h,n,n,n|s", NULL); // fulltext functions REGISTER_FUNCTION("FULLTEXT", "FULLTEXT", false, false, "h,s,s", NULL); // graph functions REGISTER_FUNCTION("PATHS", "GRAPH_PATHS", false, false, "c,h|s,b", &OptimisePaths); REGISTER_FUNCTION("TRAVERSAL", "GRAPH_TRAVERSAL", false, false, "h,h,s,s,a", NULL); REGISTER_FUNCTION("TRAVERSAL_TREE", "GRAPH_TRAVERSAL_TREE", false, false, "h,h,s,s,s,a", NULL); REGISTER_FUNCTION("EDGES", "GRAPH_EDGES", false, false, "h,s,s|l", NULL); REGISTER_FUNCTION("NEIGHBORS", "GRAPH_NEIGHBORS", false, false, "h,h,s,s|l", NULL); // misc functions REGISTER_FUNCTION("FAIL", "FAIL", false, false, "|s", NULL); // FAIL is non-deterministic, otherwise query optimisation will fail! REGISTER_FUNCTION("PASSTHRU", "PASSTHRU", false, false, ".", NULL); // simple non-deterministic wrapper to avoid optimisations at parse time REGISTER_FUNCTION("SLEEP", "SLEEP", false, false, "n", NULL); // sleep function REGISTER_FUNCTION("COLLECTIONS", "COLLECTIONS", false, false, "", NULL); REGISTER_FUNCTION("NOT_NULL", "NOT_NULL", true, false, ".|+", NULL); REGISTER_FUNCTION("FIRST_LIST", "FIRST_LIST", true, false, ".|+", NULL); REGISTER_FUNCTION("FIRST_DOCUMENT", "FIRST_DOCUMENT", true, false, ".|+", NULL); REGISTER_FUNCTION("PARSE_IDENTIFIER", "PARSE_IDENTIFIER", true, false, ".", NULL); if (! result) { TRI_FreeFunctionsAql(functions); return NULL; } return functions; }