Skip to content

Conversation

@andreyaksenov
Copy link
Contributor

@andreyaksenov andreyaksenov commented Aug 25, 2023

  • box.schema.func.create(): refactored a function description to remove duplicated info. Created a separate function_options table description. The function description now contains the SQL_EXPR example for a tuple constraint. The language attribute description is extended with the new SQL_EXPR value.
  • Mentioned the possibility to use SQL expressions in the Constraint functions section.
  • Removed unnecessary info from box.space._func as this info related to other API members and already documented in other places.

@andreyaksenov andreyaksenov linked an issue Aug 25, 2023 that may be closed by this pull request
@andreyaksenov andreyaksenov force-pushed the sql-expr-func branch 9 times, most recently from e9c06bf to 01206cf Compare August 29, 2023 08:20
@andreyaksenov andreyaksenov requested a review from ImeevMA August 29, 2023 08:46
@andreyaksenov andreyaksenov linked an issue Aug 30, 2023 that may be closed by this pull request
Copy link

@ImeevMA ImeevMA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Thank you for the patch. I have three comments, but they are all minor and can be ignored.

Also, I didn't mention it, but it would be nice to add that SQL_EXPR functions can be created when creating a SQL CHECK constraint using SQL. Moreover, if the above constraint is dropped, the SQL_EXPR function is not removed, which may not be obvious.

t.assert_equals(age_err:unpack().message, 'Check constraint \'check_person\' failed for tuple')
t.assert_equals(name_err:unpack().message, 'Check constraint \'check_person\' failed for tuple')
end)
end No newline at end of file
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a newline.

box.schema.func.create('check_person', {
language = 'SQL_EXPR',
is_deterministic = true,
body = [["age" > 21 AND "name" !='Admin']]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to add space between != and Admin.

~~~~~~~~~~~~~~~~~~~~

Constraints use stored Lua functions, which must return ``true`` when the constraint
Constraints use stored Lua functions or :ref:`SQL expressions <sql_expressions>`, which must return ``true`` when the constraint
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it's worth mentioning that the Lua and SQL_EXPR functions can be used as constraints. For example, C functions can also be used as constraints. Maybe not mention it here?

Copy link
Contributor

@xuniq xuniq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new structure seems good to me.

Comment on lines 18 to 19
Using the :ref:`body <function_options_body>` option, you can make a function "persistent".
In this case, the function is "persistent" because its definition is stored in a snapshot (the :ref:`box.space._func <box_space-func>` system space) and can be recovered if the server restarts.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Using the :ref:`body <function_options_body>` option, you can make a function "persistent".
In this case, the function is "persistent" because its definition is stored in a snapshot (the :ref:`box.space._func <box_space-func>` system space) and can be recovered if the server restarts.
Using the :ref:`body <function_options_body>` option, you can make a function *persistent*.
In this case, the function is persistent because its definition is stored in a snapshot (the :ref:`box.space._func <box_space-func>` system space) and can be recovered if the server restarts.


Whether the function should be executed in an isolated environment.
This means that any operation that accesses the world outside the sandbox is forbidden or has no effect.
Therefore a sandboxed function can only use modules and functions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Therefore a sandboxed function can only use modules and functions
Therefore, a sandboxed function can only use modules and functions

@andreyaksenov andreyaksenov merged commit 30c9b3c into latest Sep 12, 2023
@andreyaksenov andreyaksenov deleted the sql-expr-func branch September 12, 2023 08:08
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

Successfully merging this pull request may close these issues.

feedback: box.schema.func.create() | Tarantool SQL: document SQL_EXPR functions

4 participants