Skip to main content

Unomi Query Language

Unomi Query Language(UQL) is a library for managing Apache Unomi with easy to use query language. It connects to unomi API and performs actions described in UQL.

Currently it has implemented the following query types:

  • SELECT
  • CREATE
  • DELETE

SELECT query statement

Optional parts of the statement are in square brackets []. Multiple choice but required statement parts are in round brackets ().

    SELECT 
    [FRESH] 
    (EVENT | RULE | SEGMENT | PROFILE)
        [WHERE where condition]
        [OFFSET integer]
        [LIMIT integer]

SELECT statement examples

With select query you can search the following data types:

  • EVENT
  • PROFILE
  • RULE
  • SEGMENT

The simplest example of SELECT query looks like this:

    SELECT PROFILE

It finds all profiles in the Unomi storage.

    SELECT PROFILE OFFSET 100 LIMIT 20

limits the results to 20 records and skips first 100 records

    SELECT EVENT WHERE type=”view”

finds events with eventType equal to view.

    SELECT EVENT 
        WHERE type=”view” 
            AND (scope=”my-site-1” OR scope=”my-site-2”) 
            AND properties.target.pageInfo=”page-info’

finds view events that are in scope “my-site-1” OR “my-site-2” and target has property pageInfo that equals “page -info”. You can limit or offset results with LIMIT and OFFSET as in the above example.

WHERE|WHEN condition statement

The following grammar rules define expression syntax in UQL.

expr:
  | expr OR (expr AND expr)
  | expr AND (expr OR expr)

that means that expressions with similar operations e.g. OR must be in brackets. The following where statement is forbidden:

field1=1 AND field2=2 OR field3=3

correct statement is either:

field1=1 AND (field2=2 OR field3=3)

or

(field1=1 AND field2=2) OR field3=3

There is no auto resolution of priority operations

###Available operations mappings

Unomi operator maps to UQL where condition statement in the following way

* exists -> field EXISTS
* between -> BETWEEN number AND number
* equals -> filed EQUALS
* notEquals -> field != string|number
* greaterThanOrEqualTo -> field >= number
* lessThanOrEqualTo -> field <= number
* greaterThan -> field > number
* lessThan -> field < number
* missing -> field NOT EXISTS
* contains -> CONTAINS

CREATE statement

Create statements can be used to create rules and segments.

    CREATE (RULE|SEGMENT)
        [READONLY]
        [DISABLED]
        [HIDDEN]
    [WITH TAGS [tag1, tag2, ...]]
    "rule or segment name"
    [DESCRIBE "rule or segment description"]
    IN SCOPE "scope"
    WHEN where condition
    [THEN prefindedAction(), …]

When using CREATE SEGMENT statement there is no THEN part of statement.

Example of CREATE STATEMENT

    CREATE SEGMENT
        WITH TAGS ["important"]
        "At least 1 visit"
        DESCRIBE "First time visitor"
        IN SCOPE \"site-1\"
        WHEN profile:properties.nbOfVisits>=1

Example of CREATE RULE

    CREATE RULE 
        "if identify event then copy event properties to profile" 
        DESCRIBE "Copies user data from events target properties to profile"
        IN SCOPE "my-site" 
        WHEN event:type="identify" AND event:scope = "my-site"  
        THEN CopyEventsToProfileProperties()

DELETE statement

DELETE 
(RULE|SEGMENT|PROFILE) 
“rule or segment or profile id”

Example of delete rule statement:

DELETE RULE “my-rule-id” 

Python usage example

import json

from unomi_query_language.query.dispatcher import Host, Dispatcher
from unomi_query_language.query.parser import Parser
from unomi_query_language.query.grammar.grammars import read
from pprint import pprint

from unomi_query_language.query.transformers.select_transformer import SelectTransformer

// Parse select statement 

p = Parser(read('uql_select.lark'), start='select')
t = p.parse(
    """
    SELECT EVENT WHERE type="click"
    """
)

query = SelectTransformer().transform(t)

// Connect to unomi

host = Host('localhost', port=8181, protocol='http').credentials('karaf','karaf')
dispatcher = Dispatcher(host)
response = dispatcher.fetch(query)

// Read response

if response.status_code == 200:
    pprint(json.loads(response.content))
else:
    print(response.content)

Metadata

Release files for unomi-query-language 0.1.20

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for unomi-query-language 0.1.20
File Interpreter ABI Platform
unomi_query_language-0.1.20-py3-none-any.whl Python 3 none any Details

Release files / unomi_query_language-0.1.20-py3-none-any.whl

Download URL unomi_query_language-0.1.20-py3-none-any.whl
Size 62.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
988506f8ba21cd6c36b88e6f9f05054dc45bf7d3ecb03c0bcd392604417852af
BLAKE2b-256 checksum
How to use checksums
560662d2ad7ba6076b623b30b92071a55461c7c19da1ad50ec72ce2004da709f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.5

Release history Release notifications | RSS feed

This release

0.1.20 This release

1 release file

0.1.19

1 release file

0.1.18

1 release file

0.1.17

1 release file

0.1.16

1 release file

0.1.15

1 release file

0.1.14

1 release file

0.1.13

1 release file

0.1.12

1 release file

0.1.11

1 release file

0.1.10

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page