typedb / typeql

TypeQL: the power of programming, in your database
https://typedb.com
Mozilla Public License 2.0
218 stars 45 forks source link

TypeQL 3 grammar enhancements #345

Closed dmitrii-ubskii closed 3 months ago

dmitrii-ubskii commented 3 months ago

Usage and product changes

  1. New rich fetch syntax (see below).
  2. Standardise the vocabulary of pipeline, stage, clause, operator. A pipeline consists of stages. Each stage may be an operator, which modifies the data stream without accessing the database (e.g. count, mean($x)), or a clause, which may fetch data from the database to modify the stream (e.g. match, fetch).
  3. list() stream reduce operator.
  4. $x in [$a, $b, $c] and other list expressions now allowed in in-statements (previously stream-only)

New fetch syntax sample

... # incoming pipeline
fetch {
# Printing values directly from pipeline
  "key_1": $x, # var $x (from input stream) holds a value or list
  "key_2": <EXPR>, # <EXPR> is an expression like $x + $y

# Inline attribute retrieval variations
  "key_3": $y.attr, # var $y holds an object with singleton attribute 'attr'
  "key_4": [ $y.attr ], # object var $y has multiple attributes 'attr'
  "key_5": $y.attr[], # object var $y has a list attribute 'attr'

# Function call variations
  "key_6": my_fun1($x,$y), # function my_fun1 has single-return
  "key_7": [ my_fun2($x,$y) ], # function my_fun2 has stream-return

# Match-fetch subqueries
  "key_8": [
    match ...;
    fetch {
      "sub_key": $z, 
      ...
    };
  ]

# Match-reduce-value subqueries
  "key_9": 
    match ...;
    reduce agg($z); # agg could be, e.g., 'count', 'sum', or 'list'

# Nested keys: Nothing stops you from nesting the above!
  "super_key": {
    "sub_key_1": $x,
    "sub_key_2": $y.attr,
    "sub_key_3": [
      ... # some subquery
    ]
  }
};
typedb-bot commented 3 months ago

PR Review Checklist

Do not edit the content of this comment. The PR reviewer should simply update this comment by ticking each review item below, as they get completed.


Trivial Change

Code

Architecture