view README.rst @ 43:1cfe9d8a07e8

Implemented an aggregate tutorial.
author Sjoerd Mullender <sjoerd@acm.org>
date Thu, 10 Jun 2021 16:22:08 +0200 (2021-06-10)
parents b67deab098f9
children 8122094c79b1
line wrap: on
line source
.. This Source Code Form is subject to the terms of the Mozilla Public
.. License, v. 2.0.  If a copy of the MPL was not distributed with this
.. file, You can obtain one at http://mozilla.org/MPL/2.0/.
..
.. Copyright 2013-2021 MonetDB B.V.

.. This document is written in reStructuredText (see
   http://docutils.sourceforge.net/ for more information).
   Use ``rst2html.py`` to convert this file to HTML.

===================================
Implementing User-Defined Functions
===================================

:Author: Sjoerd Mullender
:Organization: CWI, MonetDB B.V.
:Abstract: In this short tutorial we describe how to create a simple
   UDF for MonetDB/SQL.

Introduction
------------

In this directory there are a number of tutorials for creating
user-defined functions.  It is recommended to go through these
tutorials in the order presented here, since they will go from simple
to more complicated.

These tutorials are about extending MonetDB/SQL using one or more
functions written in C.  There are other ways in which to extend the
functionality of MonetDB/SQL that may be easier to implement.  See
`Embedded Python/NumPy in MonetDB`__ and `Embedded R in MonetDB`__.

__ https://www.monetdb.org/blog/embedded-pythonnumpy-monetdb
__ https://www.monetdb.org/content/embedded-r-monetdb

Setting Up
----------

These tutorials work completely outside the source of the MonetDB
suite.  You do not need to copy the source of MonetDB, and you do not
need to recompile the MonetDB sources.  You do need to install some
extra packages that are not normally installed.

On Fedora and RedHat-based systems you need to install the packages
``MonetDB-SQL-server5-devel``, ``MonetDB5-server-devel``,
``MonetDB-devel``, and ``MonetDB-stream-devel``.  On Debian and Ubuntu
you need to install the packages ``monetdb5-sql-dev``,
``monetdb5-server-dev``, ``libmonetdb-dev``, and
``libmonetdb-stream-dev``.  These packages are available from the
`MonetDB download site`__.

__ https://dev.monetdb.org/downloads/

Tutorials
---------

reverse
.......

Start with the tutorial in the ``reverse`` subdirectory.  In this
tutorial you will create a simple user-defined function (UDF) that
takes one (string) value as input and produces one (string) value as
output.

regexp
......

The tutorial in the ``regexp`` subdirectory contains an example of a
FILTER FUNCTION.  These functions are used to filter values in a
column.  The simplest example of a filter is (given a table ``t`` that
has an integer column ``c``):

.. code-block:: sql

  SELECT * FROM t WHERE c = 0;

This query filters the table t and selects all rows where the value of
column ``c`` is equal to ``0``.

gmean
.....

The tutorial in the ``gmean`` subdirectory contains an example of an
AGGREGATE FUNCTION.  These functions are used to calculate aggregates
over columns of values.  Aggregates can be simple or grouped.