Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] More operators and basic functions #290

Open
lveillard opened this issue Jun 16, 2023 · 1 comment
Open

[Feature Request] More operators and basic functions #290

lveillard opened this issue Jun 16, 2023 · 1 comment

Comments

@lveillard
Copy link

lveillard commented Jun 16, 2023

Bravo for the great additions of 2.18!

I would love to show you this list of common operators and functions that would be great to have in typeDB. Some have been already added in this new patch but a lot of them are missing.

SurrealDB has been building these operators and functions thanks to their user base, and i think they have a pretty complete lib

Operations:

- && or AND // Checks whether both of two values are truthy
- || or OR // Checks whether either of two values is truthy
- ?? // Check whether either of two values are truthy and not NULL
- ?: // Check whether either of two values are truthy
- = or IS // Check whether two values are equal
- != or IS NOT // Check whether two values are not equal
- == // Check whether two values are exactly equal
- ?= // Check whether any value in a set is equal to a value
- *= // Check whether all values in a set are equal to a value
- ~ // Compare two values for equality using fuzzy matching
- !~ // Compare two values for inequality using fuzzy matching
- ?~ // Check whether any value in a set is equal to a value using fuzzy matching
- *~ // Check whether all values in a set are equal to a value using fuzzy matching
- < // Check whether a value is less than another value
- <= // Check whether a value is less than or equal to another value
- > // Check whether a value is greater than another value
- >= // Check whether a value is greater than or equal to another value
- + // Add two values together
- - // Subtract a value from another value
- * or × // Multiply two values together
- / or ÷ // Divide a value by another value
- ** // Raises a base value by another value
- IN // Checks whether a value is contained within another value
- NOT IN // Checks whether a value is not contained within another value
- CONTAINS or ∋ // Checks whether a value contains another value
- CONTAINSNOT or ∌ // Checks whether a value does not contain another value
- CONTAINSALL or ⊇ // Checks whether a value contains all other values
- CONTAINSANY or ⊃ // Checks whether a value contains any other value
- CONTAINSNONE or ⊅ // Checks whether a value contains none of the following values
- INSIDE or ∈ // Checks whether a value is contained within another value
- NOTINSIDE or NOT IN or ∉ // Checks whether a value is not contained within another value
- ALLINSIDE or ⊆ // Checks whether all values are contained within other values
- ANYINSIDE or ⊂ // Checks whether any value is contained within other values
- NONEINSIDE or ⊄ // Checks whether no value is contained within other values
- OUTSIDE // Checks whether a geometry type is outside of another geometry type
- INTERSECTS // Checks whether a geometry type intersects another geometry type

Functions

- count()

- is-alphanum()
- is-alpha()
- is-ascii()
- is-datetime()
- is-domain()
- is-email()
- is-hexadecimal()
- is-latitude()
- is-longitude()
- is-numeric()
- is-semver()
- is-url()
- is-uuid()

- math-abs()
- math-ceil()
- math-fixed()
- math-floor()
- math-max()
- math-mean()
- math-median()
- math-min()
- math-product()
- math-round()
- math-sqrt()
- math-sum()

- rand()
- rand-bool()
- rand-enum()
- rand-float()
- rand-guid()
- rand-int()
- rand-string()
- rand-time()
- rand-uuid()
- rand-uuid-v4()
- rand-uuid-v7()

- string-concat()
- string-endsWith()
- string-join()
- string-len()
- string-lowercase()
- string-repeat()
- string-replace()
- string-reverse()
- string-slice()
- string-slug()
- string-split()
- string-startsWith()
- string-trim()
- string-uppercase()
- string-words()

- time-day()
- time-floor()
- time-format()
- time-group()
- time-hour()
- time-minute()
- time-month()
- time-nano()
- time-now()
- time-round()
- time-second()
- time-timezone()
- time-unix()
- time-wday()
- time-week()
- time-yday()
- time-year()

⚠Notice that some of this functions can be used for key use-cases like autogenerate ids (particularly important as you will kill iids) and add timestamps when creating variables.
a default word on attributes would enable using these like this

Schema functions

#uuid key
define 
id sub attribute, value string, default rand-uuid-v4();
person own id @key;


related to typedb/typedb#6175

Mutation functions

or some could be used as well on mutations like this:

insert $a has timestamp time-now()

or something like this for autoincrement

optional {
   match
      $person isa Person, has id $id
      ?nextId = max($id) +1

   insert 
      $newPerson isa Person, has name "Peter", has id ?nextId
   }

optional {
  match
     not {  $person isa Person, has id $id };
  insert
     $newPerson isa Person, has name "Peter", has id 1
}

obviously something like id sub attribute, value long, default autoincrement(); would be even better, the example is just to show how powerful this can become

@shreyas1599
Copy link

@lveillard has already written a pretty exhaustive list! For my use case, I'd like the arithmetic operations enabled for long and double done on this #260 to work with datetime. Specifically,

  • adding days to a given date
  • function/arithmetic operation that can subtract two dates and output the number of days/weeks/months/years between the two given dates.
  • Or a function that converts the datetime to unix time so that arithmetic operations on long and double can be used

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants