Expressions

## Expressions Expressions — Query language expressions. |

## Functions

rasqal_expression * | rasqal_new_0op_expression ()
rasqal_expression * | rasqal_new_1op_expression ()
rasqal_expression * | rasqal_new_2op_expression ()
rasqal_expression * | rasqal_new_3op_expression ()
rasqal_expression * | rasqal_new_4op_expression ()
rasqal_expression * | rasqal_new_aggregate_function_expression ()
rasqal_expression * | rasqal_new_cast_expression ()
rasqal_expression * | rasqal_new_function_expression ()
rasqal_expression * | rasqal_new_group_concat_expression ()
rasqal_expression * | rasqal_new_literal_expression ()
rasqal_expression * | rasqal_new_set_expression ()
rasqal_expression * | rasqal_new_string_op_expression ()
rasqal_expression * | rasqal_new_expression_from_expression ()
rasqal_expression * | rasqal_new_expr_seq_expression ()
void | rasqal_free_expression ()
int | rasqal_expression_compare ()
rasqal_literal * | rasqal_expression_evaluate ()
rasqal_literal * | rasqal_expression_evaluate2 ()
const char * | rasqal_expression_op_label ()
int | rasqal_expression_print ()
void | rasqal_expression_print_op ()
int | (*rasqal_expression_visit_fn) ()
int | rasqal_expression_visit ()
rasqal_evaluation_context * | rasqal_new_evaluation_context ()
void | rasqal_free_evaluation_context ()
int | rasqal_evaluation_context_set_base_uri ()
int | rasqal_evaluation_context_set_rand_seed ()

## Types and Values

typedef | rasqal_expression
enum | rasqal_expression_flags
| rasqal_evaluation_context
enum | rasqal_op
enum | rasqal_compare_flags
enum | rasqal_pattern_flags

## Description

Expressions form an expression tree that can be evaluated using `rasqal_expression_evaluate()` over rasqal_op operators, rasqal_literal constants and rasqal_variable values bound in some rasqal_query_result. The result is a rasqal_literal value.

## Functions

### rasqal_new_0op_expression ()

    rasqal_expression *
    rasqal_new_0op_expression (rasqal_world *world,
                               rasqal_op op);

#### Returns

### rasqal_new_1op_expression ()

    rasqal_expression *
    rasqal_new_1op_expression (rasqal_world *world,
                               rasqal_op op,
                               rasqal_expression *arg);

#### Returns

### rasqal_new_2op_expression ()

    rasqal_expression *
    rasqal_new_2op_expression (rasqal_world *world,
                               rasqal_op op,
                               rasqal_expression *arg1,
                               rasqal_expression *arg2);

#### Returns

### rasqal_new_3op_expression ()

    rasqal_expression *
    rasqal_new_3op_expression (rasqal_world *world,
                               rasqal_op op,
                               rasqal_expression *arg1,
                               rasqal_expression *arg2,
                               rasqal_expression *arg3);

#### Returns

### rasqal_new_4op_expression ()

    rasqal_expression *
    rasqal_new_4op_expression (rasqal_world *world,
                               rasqal_op op,
                               rasqal_expression *arg1,
                               rasqal_expression *arg2,
                               rasqal_expression *arg3,
                               rasqal_expression *arg4);

#### Returns

### rasqal_new_aggregate_function_expression ()

    rasqal_expression *
    rasqal_new_aggregate_function_expression
                                   (rasqal_world *world,
                                    rasqal_op op,
                                    rasqal_expression *arg1,
                                    raptor_sequence *params,
                                    unsigned int flags);

#### Returns

### rasqal_new_cast_expression ()

    rasqal_expression *
    rasqal_new_cast_expression (rasqal_world *world,
                                raptor_uri *name,
                                rasqal_expression *value);

#### Returns

### rasqal_new_function_expression ()

    rasqal_expression *
    rasqal_new_function_expression (rasqal_world *world,
                                    raptor_uri *name,
                                    raptor_sequence *args,
                                    raptor_sequence *params,
                                    unsigned int flags);

#### Returns

### rasqal_new_group_concat_expression ()

    rasqal_expression *
    rasqal_new_group_concat_expression (rasqal_world *world,
                                        unsigned int flags,
                                        raptor_sequence *args,
                                        rasqal_literal *separator);

#### Returns

### rasqal_new_literal_expression ()

    rasqal_expression *
    rasqal_new_literal_expression (rasqal_world *world,
                                   rasqal_literal *literal);

#### Returns

### rasqal_new_set_expression ()

    rasqal_expression *
    rasqal_new_set_expression (rasqal_world *world,
                               rasqal_op op,
                               rasqal_expression *arg1,
                               raptor_sequence *args);

#### Returns

### rasqal_new_string_op_expression ()

    rasqal_expression *
    rasqal_new_string_op_expression (rasqal_world *world,
                                     rasqal_op op,
                                     rasqal_expression *arg1,
                                     rasqal_literal *literal);

#### Returns

### rasqal_new_expression_from_expression ()

    rasqal_expression *
    rasqal_new_expression_from_expression (rasqal_expression *e);

#### Returns

### rasqal_new_expr_seq_expression ()

    rasqal_expression *
    rasqal_new_expr_seq_expression (rasqal_world *world,
                                    rasqal_op op,
                                    raptor_sequence *args);

#### Returns

### rasqal_free_expression ()

    void
    rasqal_free_expression (rasqal_expression *e);

### rasqal_expression_compare ()

    int
    rasqal_expression_compare (rasqal_expression *e1,
                               rasqal_expression *e2,
                               int flags,
                               int *error_p);

#### Returns

### rasqal_expression_evaluate ()

    rasqal_literal *
    rasqal_expression_evaluate (rasqal_world *world,
                                raptor_locator *locator,
                                rasqal_expression *e,
                                int flags);

`rasqal_expression_evaluate` is deprecated and should not be used in newly-written code.

#### Returns

### rasqal_expression_evaluate2 ()

    rasqal_literal *
    rasqal_expression_evaluate2 (rasqal_expression *e,
                                 rasqal_evaluation_context *eval_context,
                                 int *error_p);

#### Returns

### rasqal_expression_op_label ()

    const char *
    rasqal_expression_op_label (rasqal_op op);

#### Returns

### rasqal_expression_print ()

    int
    rasqal_expression_print (rasqal_expression *e,
                             FILE *fh);

#### Returns

### rasqal_expression_print_op ()

    void
    rasqal_expression_print_op (rasqal_expression *e,
                                FILE *fh);

### rasqal_expression_visit_fn ()

    int
    (*rasqal_expression_visit_fn) (void *user_data,
                                   rasqal_expression *e);

User function to visit an expression and operate on it with `rasqal_expression_visit()`

#### Parameters

user_data | user data passed in with `rasqal_expression_visit()` |
e | current expression |

#### Returns

non-0 to truncate the visit

### rasqal_expression_visit ()

    int
    rasqal_expression_visit (rasqal_expression *e,
                             rasqal_expression_visit_fn fn,
                             void *user_data);

#### Returns

### rasqal_new_evaluation_context ()

    rasqal_evaluation_context *
    rasqal_new_evaluation_context (rasqal_world *world,
                                   raptor_locator *locator,
                                   int flags);

#### Returns

### rasqal_free_evaluation_context ()

    void
    rasqal_free_evaluation_context (rasqal_evaluation_context *eval_context);

### rasqal_evaluation_context_set_base_uri ()

    int
    rasqal_evaluation_context_set_base_uri
                                   (rasqal_evaluation_context *eval_context,
                                    raptor_uri *base_uri);

#### Returns

### rasqal_evaluation_context_set_rand_seed ()

    int
    rasqal_evaluation_context_set_rand_seed
                                   (rasqal_evaluation_context *eval_context,
                                    unsigned int seed);

#### Returns

## Types and Values

### rasqal_expression

    typedef struct rasqal_expression_s rasqal_expression;

Expression with arguments

### enum rasqal_expression_flags

Flags for expressions.

#### Members

RASQAL_EXPR_FLAG_DISTINCT | Distinct |
RASQAL_EXPR_FLAG_AGGREGATE | Aggregate function expression |

### rasqal_evaluation_context

    typedef struct {
      rasqal_world *world;
      raptor_uri* base_uri;
      raptor_locator *locator;
      int flags;
      unsigned int seed;
      rasqal_random* random;
    } rasqal_evaluation_context;

A context for evaluating an expression such as with `rasqal_expression_evaluate2()`

#### Members

rasqal_world *`world`; | rasqal world |
raptor_uri *`base_uri`; | base URI of expression context (or NULL) |
raptor_locator *`locator`; | locator or NULL |
int `flags`; | expression comparison flags |
unsigned int `seed`; | random seeed |
rasqal_random *`random`; | random number generator object |

### enum rasqal_op

Rasqal expression operators. A mixture of unary, binary and tertiary operators (string matches). Also includes casting and two ordering operators from ORDER BY in SPARQL.

#### Members

RASQAL_EXPR_UNKNOWN | Internal |
RASQAL_EXPR_AND | Expression for AND(A, B) |
RASQAL_EXPR_OR | Expression for OR(A, B) |
RASQAL_EXPR_EQ | Expression for A equals B |
RASQAL_EXPR_NEQ | Expression for A not equals B. |
RASQAL_EXPR_LT | Expression for A less than B. |
RASQAL_EXPR_GT | Expression for A greather than B. |
RASQAL_EXPR_LE | Expression for A less than or equal to B. |
RASQAL_EXPR_GE | Expression for A greater than or equal to B. |
RASQAL_EXPR_UMINUS | Expression for -A. |
RASQAL_EXPR_PLUS | Expression for +A. |
RASQAL_EXPR_MINUS | Expression for A-B. |
RASQAL_EXPR_STAR | Expression for A*B. |
RASQAL_EXPR_SLASH | Expression for A/B. |
RASQAL_EXPR_REM | Expression for A/B remainder. |
RASQAL_EXPR_STR_EQ | Expression for A string equals B. |
RASQAL_EXPR_STR_NEQ | Expression for A string not-equals B. |
RASQAL_EXPR_STR_MATCH | Expression for string A matches literal regex B with flags. |
RASQAL_EXPR_STR_NMATCH | Expression for string A not-matches literal regex B with flags. |
RASQAL_EXPR_TILDE | Expression for binary not A. |
RASQAL_EXPR_BANG | Expression for logical not A. |
RASQAL_EXPR_LITERAL | Expression for a rasqal_literal. |
RASQAL_EXPR_FUNCTION | Expression for a function A with arguments (B...). |
RASQAL_EXPR_BOUND | Expression for SPARQL ISBOUND(A). |
RASQAL_EXPR_STR | Expression for SPARQL STR(A). |
RASQAL_EXPR_LANG | Expression for SPARQL LANG(A). |
RASQAL_EXPR_DATATYPE | Expression for SPARQL DATATYPE(A). |
RASQAL_EXPR_ISURI | Expression for SPARQL ISURI(A). |
RASQAL_EXPR_ISBLANK | Expression for SPARQL ISBLANK(A). |
RASQAL_EXPR_ISLITERAL | Expression for SPARQL ISLITERAL(A). |
RASQAL_EXPR_CAST | Expression for cast literal A to type B. |
RASQAL_EXPR_ORDER_COND_ASC | Expression for SPARQL order condition ascending. |
RASQAL_EXPR_ORDER_COND_DESC | Expression for SPARQL order condition descending. |
RASQAL_EXPR_LANGMATCHES | Expression for SPARQL LANGMATCHES(A, B). |
RASQAL_EXPR_REGEX | Expression for string A matches expression regex B with flags. |
RASQAL_EXPR_GROUP_COND_ASC | Obsolete - not used |
RASQAL_EXPR_GROUP_COND_DESC | Obsolete - not used |
RASQAL_EXPR_COUNT | Expression for LAQRS select `COUNT()` aggregate function |
RASQAL_EXPR_VARSTAR | Expression for LAQRS select Variable * |
RASQAL_EXPR_SAMETERM | Expression for SPARQL sameTerm |
RASQAL_EXPR_SUM | Expression for LAQRS select `SUM()` aggregate function |
RASQAL_EXPR_AVG | Expression for LAQRS select `AVG()` aggregate function |
RASQAL_EXPR_MIN | Expression for LAQRS select `MIN()` aggregate function |
RASQAL_EXPR_MAX | Expression for LAQRS select `MAX()` aggregate function |
RASQAL_EXPR_COALESCE | Expression for LAQRS COALESCE(Expr+) |
RASQAL_EXPR_IF | Expression for LAQRS IF(expr, expr, expr) |
RASQAL_EXPR_URI | Expression for LAQRS URI(expr) |
RASQAL_EXPR_IRI | Expression for LAQRS IRI(expr) |
RASQAL_EXPR_STRLANG | Expression for LAQRS STRLANG(expr, expr) |
RASQAL_EXPR_STRDT | Expression for LAQRS STRDT(expr, expr) |
RASQAL_EXPR_BNODE | Expression for LAQRS `BNODE()` and BNODE(expr) |
RASQAL_EXPR_GROUP_CONCAT | Expression for LAQRS GROUP_CONCAT(arglist) aggregate function |
RASQAL_EXPR_SAMPLE | Expression for LAQRS SAMPLE(expr) aggregate function |
RASQAL_EXPR_IN | Expression for LAQRS expr IN ( list of expr ) |
RASQAL_EXPR_NOT_IN | Expression for LAQRS expr NOT IN ( list of expr ) |
RASQAL_EXPR_ISNUMERIC | Expression for SPARQL 1.1 isNUMERIC(expr) |
RASQAL_EXPR_YEAR | Expression for SPARQL 1.1 YEAR(datetime) |
RASQAL_EXPR_MONTH | Expression for SPARQL 1.1 MONTH(datetime) |
RASQAL_EXPR_DAY | Expression for SPARQL 1.1 DAY(datetime) |
RASQAL_EXPR_HOURS | Expression for SPARQL 1.1 HOURS(datetime) |
RASQAL_EXPR_MINUTES | Expression for SPARQL 1.1 MINUTES(datetime) |
RASQAL_EXPR_SECONDS | Expression for SPARQL 1.1 SECONDS(datetime) |
RASQAL_EXPR_TIMEZONE | Expression for SPARQL 1.1 TIMEZONE(datetime) |
RASQAL_EXPR_CURRENT_DATETIME | Expression for LAQRS CURRENT_DATETIME( void ) |
RASQAL_EXPR_NOW | Expression for LAQRS NOW( void ) |
RASQAL_EXPR_FROM_UNIXTIME | Expression for LAQRS FROM_UNIXTIME(int) |
RASQAL_EXPR_TO_UNIXTIME | Expression for LAQRS TO_UNIXTIME(datetime) |
RASQAL_EXPR_CONCAT | Expression for SPARQL 1.1 CONCAT(strings) |
RASQAL_EXPR_STRLEN | Expression for SPARQL 1.1 STRLEN(str) |
RASQAL_EXPR_SUBSTR | Expression for SPARQL 1.1 SUBSTR(str, start[,offset]) |
RASQAL_EXPR_UCASE | Expression for SPARQL 1.1 UCASE(str) |
RASQAL_EXPR_LCASE | Expression for SPARQL 1.1 LCASE(str) |
RASQAL_EXPR_STRSTARTS | Expression for SPARQL 1.1 STRSTARTS(str, str) |
RASQAL_EXPR_STRENDS | Expression for SPARQL 1.1 STRENDS(str, str) |
RASQAL_EXPR_CONTAINS | Expression for SPARQL 1.1 CONTAINS(str, str) |
RASQAL_EXPR_ENCODE_FOR_URI | Expression for SPARQL 1.1 ENCODE_FOR_URI(str) |
RASQAL_EXPR_TZ | Expression for SPARQL 1.1 `TZ()` |
RASQAL_EXPR_RAND | Expression for SPARQL 1.1 `RAND()` |
RASQAL_EXPR_ABS | Expression for SPARQL 1.1 `ABS()` |
RASQAL_EXPR_ROUND | Expression for SPARQL 1.1 `ROUND()` |
RASQAL_EXPR_CEIL | Expression for SPARQL 1.1 `CEIL()` |
RASQAL_EXPR_FLOOR | Expression for SPARQL 1.1 `FLOOR()` |
RASQAL_EXPR_MD5 | Expression for SPARQL 1.1 `MD5()` |
RASQAL_EXPR_SHA1 | Expression for SPARQL 1.1 `SHA1()` |
RASQAL_EXPR_SHA224 | Expression for SPARQL 1.1 `SHA224()` |
RASQAL_EXPR_SHA256 | Expression for SPARQL 1.1 `SHA256()` |
RASQAL_EXPR_SHA384 | Expression for SPARQL 1.1 `SHA384()` |
RASQAL_EXPR_SHA512 | Expression for SPARQL 1.1 `SHA512()` |
RASQAL_EXPR_STRBEFORE | Expression for SPARQL 1.1 `STRBEFORE()` |
RASQAL_EXPR_STRAFTER | Expression for SPARQL 1.1 `STRAFTER()` |
RASQAL_EXPR_REPLACE | Expression for SPARQL 1.1 `REPLACE()` |
RASQAL_EXPR_UUID | Expression for SPARQL 1.1 `UUID()` |
RASQAL_EXPR_STRUUID | Expression for SPARQL 1.1 `STRUUID()` |
RASQAL_EXPR_LAST | Internal |

### enum rasqal_compare_flags

Flags for `rasqal_expression_evaluate()`, `rasqal_literal_compare()` or `rasqal_literal_as_string_flags()`

#### Members

RASQAL_COMPARE_NOCASE | String comparisons are case independent. |
RASQAL_COMPARE_XQUERY | XQuery comparsion rules apply. |
RASQAL_COMPARE_RDF | RDF Term comparsion rules apply. |
RASQAL_COMPARE_URI | Allow comparison of URIs and allow strings to have a boolean value (unused; was for RDQL) |
RASQAL_COMPARE_SAMETERM | SPARQL `sameTerm()` builtin rules apply. |

### enum rasqal_pattern_flags

Flags for rasqal_graph_pattern.

#### Members

RASQAL_PATTERN_FLAGS_OPTIONAL | True when the graph pattern is an optional match. |
RASQAL_PATTERN_FLAGS_LAST | Internal |