├── .gitignore ├── .travis.yml ├── CMakeLists.txt ├── Makefile ├── README.md ├── appveyor.yml ├── hgimport.sh ├── src ├── common │ ├── dirent-windows.h │ ├── fsync.h │ ├── mutils.c │ ├── mutils.h │ ├── stream.c │ ├── stream.h │ └── strptime.c ├── embedded │ ├── decompress.c │ ├── embedded.c │ ├── embedded.h │ ├── inlined_scripts.c │ ├── inlined_scripts.py │ └── undef.h ├── gdk │ ├── gdk.h │ ├── gdk_aggr.c │ ├── gdk_align.c │ ├── gdk_atomic.h │ ├── gdk_atoms.c │ ├── gdk_atoms.h │ ├── gdk_bat.c │ ├── gdk_batop.c │ ├── gdk_bbp.c │ ├── gdk_bbp.h │ ├── gdk_calc.c │ ├── gdk_calc.h │ ├── gdk_calc_compare.h │ ├── gdk_calc_private.h │ ├── gdk_cand.h │ ├── gdk_cross.c │ ├── gdk_delta.c │ ├── gdk_delta.h │ ├── gdk_firstn.c │ ├── gdk_group.c │ ├── gdk_hash.c │ ├── gdk_hash.h │ ├── gdk_heap.c │ ├── gdk_imprints.c │ ├── gdk_imprints.h │ ├── gdk_join.c │ ├── gdk_logger.c │ ├── gdk_logger.h │ ├── gdk_orderidx.c │ ├── gdk_posix.c │ ├── gdk_posix.h │ ├── gdk_private.h │ ├── gdk_project.c │ ├── gdk_qsort.c │ ├── gdk_qsort_impl.h │ ├── gdk_sample.c │ ├── gdk_search.c │ ├── gdk_select.c │ ├── gdk_ssort.c │ ├── gdk_ssort_impl.h │ ├── gdk_storage.c │ ├── gdk_storage.h │ ├── gdk_system.c │ ├── gdk_system.h │ ├── gdk_system_private.h │ ├── gdk_tm.c │ ├── gdk_tm.h │ ├── gdk_unique.c │ ├── gdk_utils.c │ ├── gdk_utils.h │ └── gdk_value.c ├── mal │ ├── mal │ │ ├── mal.c │ │ ├── mal.h │ │ ├── mal_atom.c │ │ ├── mal_atom.h │ │ ├── mal_builder.c │ │ ├── mal_builder.h │ │ ├── mal_client.c │ │ ├── mal_client.h │ │ ├── mal_dataflow.c │ │ ├── mal_dataflow.h │ │ ├── mal_errors.h │ │ ├── mal_exception.c │ │ ├── mal_exception.h │ │ ├── mal_function.c │ │ ├── mal_function.h │ │ ├── mal_import.c │ │ ├── mal_import.h │ │ ├── mal_instruction.c │ │ ├── mal_instruction.h │ │ ├── mal_interpreter.c │ │ ├── mal_interpreter.h │ │ ├── mal_linker.c │ │ ├── mal_linker.h │ │ ├── mal_listing.c │ │ ├── mal_listing.h │ │ ├── mal_module.c │ │ ├── mal_module.h │ │ ├── mal_namespace.c │ │ ├── mal_namespace.h │ │ ├── mal_parser.c │ │ ├── mal_parser.h │ │ ├── mal_private.h │ │ ├── mal_resolve.c │ │ ├── mal_resolve.h │ │ ├── mal_resource.c │ │ ├── mal_resource.h │ │ ├── mal_runtime.c │ │ ├── mal_runtime.h │ │ ├── mal_scenario.c │ │ ├── mal_scenario.h │ │ ├── mal_session.c │ │ ├── mal_session.h │ │ ├── mal_stack.c │ │ ├── mal_stack.h │ │ ├── mal_type.c │ │ ├── mal_type.h │ │ ├── mal_utils.c │ │ └── mal_utils.h │ ├── modules │ │ ├── 00_aggr_hge.mal │ │ ├── 00_batExtensions_hge.mal │ │ ├── 00_batcalc_hge.mal │ │ ├── 00_calc_hge.mal │ │ ├── 00_iterator_hge.mal │ │ ├── 00_language_hge.mal │ │ ├── 00_mkey_hge.mal │ │ ├── 01_batcalc.mal │ │ ├── 01_calc.mal │ │ ├── aggr.c │ │ ├── aggr.mal │ │ ├── algebra.c │ │ ├── algebra.h │ │ ├── algebra.mal │ │ ├── bat5.c │ │ ├── bat5.h │ │ ├── bat5.mal │ │ ├── batExtensions.c │ │ ├── batExtensions.h │ │ ├── batExtensions.mal │ │ ├── batcalc.c │ │ ├── batmmath.c │ │ ├── batmmath.h │ │ ├── batmmath.mal │ │ ├── batmtime.mal │ │ ├── batstr.c │ │ ├── batstr.mal │ │ ├── blob.c │ │ ├── blob.h │ │ ├── blob.mal │ │ ├── calc.c │ │ ├── group.c │ │ ├── group.h │ │ ├── group.mal │ │ ├── iterator.c │ │ ├── iterator.h │ │ ├── iterator.mal │ │ ├── language.c │ │ ├── language.h │ │ ├── language.mal │ │ ├── mal_init.mal │ │ ├── manifold.c │ │ ├── manifold.h │ │ ├── manifold.mal │ │ ├── mat.c │ │ ├── mat.h │ │ ├── mat.mal │ │ ├── mkey.c │ │ ├── mkey.h │ │ ├── mkey.mal │ │ ├── mmath.c │ │ ├── mmath.h │ │ ├── mmath.mal │ │ ├── mtime.c │ │ ├── mtime.h │ │ ├── mtime.mal │ │ ├── orderidx.c │ │ ├── orderidx.h │ │ ├── orderidx.mal │ │ ├── pcre.c │ │ ├── pcre.mal │ │ ├── projectionpath.c │ │ ├── projectionpath.h │ │ ├── sample.c │ │ ├── sample.h │ │ ├── sample.mal │ │ ├── str.c │ │ ├── str.h │ │ ├── str.mal │ │ ├── tablet.c │ │ ├── tablet.h │ │ └── tablet.mal │ ├── optimizer │ │ ├── opt_aliases.c │ │ ├── opt_aliases.h │ │ ├── opt_candidates.c │ │ ├── opt_candidates.h │ │ ├── opt_coercion.c │ │ ├── opt_coercion.h │ │ ├── opt_commonTerms.c │ │ ├── opt_commonTerms.h │ │ ├── opt_constants.c │ │ ├── opt_constants.h │ │ ├── opt_costModel.c │ │ ├── opt_costModel.h │ │ ├── opt_dataflow.c │ │ ├── opt_dataflow.h │ │ ├── opt_deadcode.c │ │ ├── opt_deadcode.h │ │ ├── opt_emptybind.c │ │ ├── opt_emptybind.h │ │ ├── opt_evaluate.c │ │ ├── opt_evaluate.h │ │ ├── opt_garbageCollector.c │ │ ├── opt_garbageCollector.h │ │ ├── opt_generator.c │ │ ├── opt_generator.h │ │ ├── opt_inline.c │ │ ├── opt_inline.h │ │ ├── opt_macro.c │ │ ├── opt_macro.h │ │ ├── opt_matpack.c │ │ ├── opt_matpack.h │ │ ├── opt_mergetable.c │ │ ├── opt_mergetable.h │ │ ├── opt_mitosis.c │ │ ├── opt_mitosis.h │ │ ├── opt_multiplex.c │ │ ├── opt_multiplex.h │ │ ├── opt_pipes.c │ │ ├── opt_pipes.h │ │ ├── opt_prelude.c │ │ ├── opt_prelude.h │ │ ├── opt_profiler.c │ │ ├── opt_profiler.h │ │ ├── opt_projectionpath.c │ │ ├── opt_projectionpath.h │ │ ├── opt_pushselect.c │ │ ├── opt_pushselect.h │ │ ├── opt_remap.c │ │ ├── opt_remap.h │ │ ├── opt_reorder.c │ │ ├── opt_reorder.h │ │ ├── opt_support.c │ │ ├── opt_support.h │ │ ├── opt_wrapper.c │ │ ├── optimizer.c │ │ ├── optimizer.h │ │ ├── optimizer.mal │ │ └── optimizer_private.h │ └── sqlbackend │ │ ├── 40_sql.mal │ │ ├── 41_sql_hge.mal │ │ ├── mal_backend.c │ │ ├── mal_backend.h │ │ ├── rel_bin.c │ │ ├── rel_bin.h │ │ ├── sql.c │ │ ├── sql.h │ │ ├── sql.mal │ │ ├── sql_aggr_bte.mal │ │ ├── sql_aggr_dbl.mal │ │ ├── sql_aggr_flt.mal │ │ ├── sql_aggr_hge.mal │ │ ├── sql_aggr_int.mal │ │ ├── sql_aggr_lng.mal │ │ ├── sql_aggr_sht.mal │ │ ├── sql_assert.c │ │ ├── sql_assert.h │ │ ├── sql_bat2time.c │ │ ├── sql_cast.c │ │ ├── sql_cast.h │ │ ├── sql_cast_impl_down_from_flt.h │ │ ├── sql_cast_impl_int.h │ │ ├── sql_cast_impl_up_to_flt.h │ │ ├── sql_cat.c │ │ ├── sql_cat.h │ │ ├── sql_decimal.mal │ │ ├── sql_decimal_hge.mal │ │ ├── sql_execute.c │ │ ├── sql_execute.h │ │ ├── sql_fround.c │ │ ├── sql_fround_impl.h │ │ ├── sql_gencode.c │ │ ├── sql_gencode.h │ │ ├── sql_hge.mal │ │ ├── sql_inspect.mal │ │ ├── sql_optimizer.c │ │ ├── sql_optimizer.h │ │ ├── sql_orderidx.c │ │ ├── sql_orderidx.h │ │ ├── sql_rank.c │ │ ├── sql_rank.h │ │ ├── sql_rank.mal │ │ ├── sql_result.c │ │ ├── sql_result.h │ │ ├── sql_round.c │ │ ├── sql_round_impl.h │ │ ├── sql_scenario.c │ │ ├── sql_scenario.h │ │ ├── sql_statement.c │ │ ├── sql_statement.h │ │ ├── sql_statistics.c │ │ ├── sql_statistics.h │ │ ├── sql_transaction.c │ │ ├── sql_transaction.h │ │ ├── sql_transaction.mal │ │ ├── sql_upgrades.c │ │ ├── sql_upgrades.h │ │ ├── sql_user.c │ │ ├── sql_user.h │ │ └── sqlcatalog.mal ├── monetdb_config.h ├── monetdb_config.h.in └── sql │ ├── common │ ├── sql_backend.c │ ├── sql_backend.h │ ├── sql_changeset.c │ ├── sql_hash.c │ ├── sql_keyword.c │ ├── sql_list.c │ ├── sql_mem.c │ ├── sql_stack.c │ ├── sql_string.c │ ├── sql_string.h │ ├── sql_types.c │ └── sql_types.h │ ├── include │ ├── sql_catalog.h │ ├── sql_hash.h │ ├── sql_keyword.h │ ├── sql_list.h │ ├── sql_mem.h │ ├── sql_query.h │ ├── sql_relation.h │ └── sql_stack.h │ ├── scripts │ ├── 09_like.sql │ ├── 10_math.sql │ ├── 11_times.sql │ ├── 13_date.sql │ ├── 14_inet.sql │ ├── 15_querylog.sql │ ├── 16_tracelog.sql │ ├── 17_temporal.sql │ ├── 18_index.sql │ ├── 20_vacuum.sql │ ├── 21_dependency_views.sql │ ├── 22_clients.sql │ ├── 25_debug.sql │ ├── 26_sysmon.sql │ ├── 27_rejects.sql │ ├── 39_analytics.sql │ ├── 39_analytics_hge.sql │ ├── 41_md5sum.sql │ ├── 46_profiler.sql │ ├── 51_sys_schema_extension.sql │ ├── 75_storagemodel.sql │ ├── 80_statistics.sql │ ├── 97_comments.sql │ └── 99_system.sql │ ├── server │ ├── rel_distribute.c │ ├── rel_distribute.h │ ├── rel_dump.c │ ├── rel_dump.h │ ├── rel_exp.c │ ├── rel_exp.h │ ├── rel_optimizer.c │ ├── rel_optimizer.h │ ├── rel_partition.c │ ├── rel_partition.h │ ├── rel_planner.c │ ├── rel_planner.h │ ├── rel_prop.c │ ├── rel_prop.h │ ├── rel_psm.c │ ├── rel_psm.h │ ├── rel_rel.c │ ├── rel_rel.h │ ├── rel_remote.c │ ├── rel_remote.h │ ├── rel_schema.c │ ├── rel_schema.h │ ├── rel_select.c │ ├── rel_select.h │ ├── rel_semantic.c │ ├── rel_semantic.h │ ├── rel_sequence.c │ ├── rel_sequence.h │ ├── rel_trans.c │ ├── rel_trans.h │ ├── rel_updates.c │ ├── rel_updates.h │ ├── rel_xml.c │ ├── rel_xml.h │ ├── sql_atom.c │ ├── sql_atom.h │ ├── sql_datetime.c │ ├── sql_datetime.h │ ├── sql_decimal.c │ ├── sql_decimal.h │ ├── sql_env.c │ ├── sql_env.h │ ├── sql_mvc.c │ ├── sql_mvc.h │ ├── sql_parser.h │ ├── sql_parser.tab.c │ ├── sql_parser.tab.h │ ├── sql_parser.y │ ├── sql_privileges.c │ ├── sql_privileges.h │ ├── sql_qc.c │ ├── sql_qc.h │ ├── sql_scan.c │ ├── sql_scan.h │ ├── sql_semantic.c │ ├── sql_semantic.h │ ├── sql_symbol.c │ └── sql_symbol.h │ └── storage │ ├── bat │ ├── bat_logger.c │ ├── bat_logger.h │ ├── bat_storage.c │ ├── bat_storage.h │ ├── bat_table.c │ ├── bat_table.h │ ├── bat_utils.c │ ├── bat_utils.h │ ├── nop_logger.c │ ├── nop_logger.h │ ├── res_table.c │ └── res_table.h │ ├── sql_catalog.c │ ├── sql_storage.h │ ├── store.c │ ├── store_dependency.c │ ├── store_dependency.h │ ├── store_sequence.c │ └── store_sequence.h └── tests ├── readme └── readme.c ├── sqlitelogic ├── md5.c ├── select1.test ├── select2.test ├── select3.test ├── select4.test ├── select5.test ├── slt_monetdblite.c ├── sqllogictest.c └── sqllogictest.h └── tpchq1 ├── lineitem.tbl └── test1.c /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_store 2 | .project 3 | .cproject 4 | build 5 | *.so 6 | MonetDBLite_*.t* 7 | .settings 8 | *.o 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | script: make test 3 | dist: trusty 4 | 5 | matrix: 6 | include: 7 | - os: osx 8 | osx_image: xcode6.4 9 | 10 | - os: osx 11 | osx_image: xcode7.3 12 | 13 | - os: osx 14 | osx_image: xcode8.3 15 | 16 | - os: osx 17 | osx_image: xcode9.3 18 | 19 | - os: linux 20 | addons: 21 | apt: 22 | sources: 23 | - ubuntu-toolchain-r-test 24 | packages: 25 | - g++-4.9 26 | env: 27 | - MATRIX_EVAL="export CC=gcc-4.9" 28 | 29 | - os: linux 30 | addons: 31 | apt: 32 | sources: 33 | - ubuntu-toolchain-r-test 34 | packages: 35 | - g++-5 36 | env: 37 | - MATRIX_EVAL="export CC=gcc-5" 38 | 39 | - os: linux 40 | addons: 41 | apt: 42 | sources: 43 | - ubuntu-toolchain-r-test 44 | packages: 45 | - g++-6 46 | env: 47 | - MATRIX_EVAL="export CC=gcc-6" 48 | 49 | - os: linux 50 | addons: 51 | apt: 52 | sources: 53 | - ubuntu-toolchain-r-test 54 | packages: 55 | - g++-7 56 | env: 57 | - MATRIX_EVAL="export CC=gcc-7" 58 | 59 | - os: linux 60 | addons: 61 | apt: 62 | sources: 63 | - ubuntu-toolchain-r-test 64 | packages: 65 | - g++-8 66 | env: 67 | - MATRIX_EVAL="export CC=gcc-8" 68 | 69 | - os: linux 70 | addons: 71 | apt: 72 | sources: 73 | - llvm-toolchain-trusty-3.9 74 | packages: 75 | - clang-3.9 76 | env: 77 | - MATRIX_EVAL="export CC=clang-3.9" 78 | 79 | - os: linux 80 | addons: 81 | apt: 82 | sources: 83 | - llvm-toolchain-trusty-4.0 84 | packages: 85 | - clang-4.0 86 | env: 87 | - MATRIX_EVAL="export CC=clang-4.0" 88 | 89 | - os: linux 90 | addons: 91 | apt: 92 | sources: 93 | - llvm-toolchain-trusty-5.0 94 | packages: 95 | - clang-5.0 96 | env: 97 | - MATRIX_EVAL="export CC=clang-5.0" 98 | 99 | before_install: 100 | - eval "${MATRIX_EVAL}" 101 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | clone_depth: 1 2 | image: 3 | - Visual Studio 2017 4 | environment: 5 | matrix: 6 | - name: mingw64 7 | install_script: set "PATH=C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin;%PATH%" 8 | build_script: mingw32-make 9 | test_script: mingw32-make test 10 | 11 | # - mingw_bin: 'C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin' 12 | # - mingw_bin: 'C:\mingw-w64\x86_64-7.3.0-posix-seh-rt_v5-rev0\mingw64\bin' 13 | - name: vs32 14 | install_script: cmake . 15 | build_script: cmake --build . 16 | test_script: Debug\test_readme.exe && Debug\test_sqlitelogic.exe --engine MonetDBLite --halt --verify tests\sqlitelogic\select1.test 17 | 18 | - name: vs64 19 | install_script: cmake -G "Visual Studio 15 2017 Win64" . 20 | build_script: cmake --build . 21 | test_script: Debug\test_readme.exe && Debug\test_sqlitelogic.exe --engine MonetDBLite --halt --verify tests\sqlitelogic\select1.test 22 | 23 | install: 24 | - "%install_script%" 25 | build_script: 26 | - "%build_script%" 27 | test_script: 28 | - "%test_script%" 29 | -------------------------------------------------------------------------------- /hgimport.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | git config merge.renameLimit 999999 3 | 4 | # this assumes a git remote like this 5 | # hg hg::https://dev.monetdb.org/hg/MonetDB/ 6 | # and this hg extension 7 | # https://github.com/fingolfin/git-remote-hg 8 | 9 | git pull && \ 10 | git pull hg branches/Aug2018 11 | git status --porcelain | awk '{if ($1=="DU") print $2}' | xargs git rm # && \ 12 | make init 13 | git rm -rf sql/test 14 | -------------------------------------------------------------------------------- /src/common/fsync.h: -------------------------------------------------------------------------------- 1 | /* Emulate fsync on platforms that lack it, primarily Windows and 2 | cross-compilers like MinGW. 3 | 4 | This is derived from sqlite3 sources. 5 | http://www.sqlite.org/cvstrac/rlog?f=sqlite/src/os_win.c 6 | http://www.sqlite.org/copyright.html 7 | 8 | Written by Richard W.M. Jones 9 | 10 | Copyright (C) 2008-2012 Free Software Foundation, Inc. 11 | 12 | This library is free software; you can redistribute it and/or 13 | modify it under the terms of the GNU Lesser General Public 14 | License as published by the Free Software Foundation; either 15 | version 2.1 of the License, or (at your option) any later version. 16 | 17 | This library is distributed in the hope that it will be useful, 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 | Lesser General Public License for more details. 21 | 22 | You should have received a copy of the GNU General Public License 23 | along with this program. If not, see . */ 24 | 25 | #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 26 | 27 | /* FlushFileBuffers */ 28 | #define WIN32_LEAN_AND_MEAN 29 | #include 30 | #include 31 | #include 32 | 33 | extern int fsync (int fd); 34 | 35 | int 36 | fsync (int fd) 37 | { 38 | HANDLE h = (HANDLE) _get_osfhandle (fd); 39 | DWORD err; 40 | 41 | if (h == INVALID_HANDLE_VALUE) 42 | { 43 | errno = EBADF; 44 | return -1; 45 | } 46 | 47 | if (!FlushFileBuffers (h)) 48 | { 49 | /* Translate some Windows errors into rough approximations of Unix 50 | * errors. MSDN is useless as usual - in this case it doesn't 51 | * document the full range of errors. 52 | */ 53 | err = GetLastError (); 54 | switch (err) 55 | { 56 | case ERROR_ACCESS_DENIED: 57 | /* For a read-only handle, fsync should succeed, even though we have 58 | no way to sync the access-time changes. */ 59 | return 0; 60 | 61 | /* eg. Trying to fsync a tty. */ 62 | case ERROR_INVALID_HANDLE: 63 | errno = EINVAL; 64 | break; 65 | 66 | default: 67 | errno = EIO; 68 | } 69 | return -1; 70 | } 71 | 72 | return 0; 73 | } 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /src/common/mutils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2017 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _MUTILS_H_ 10 | #define _MUTILS_H_ 11 | 12 | #define mutils_export extern 13 | 14 | 15 | #ifndef S_IRUSR 16 | #define S_IRUSR 0000400 /* read permission, owner */ 17 | #endif 18 | #ifndef S_IWUSR 19 | #define S_IWUSR 0000200 /* write permission, owner */ 20 | #endif 21 | #ifndef S_IRGRP 22 | #define S_IRGRP 0000040 /* read permission, group */ 23 | #endif 24 | #ifndef S_IWGRP 25 | #define S_IWGRP 0000020 /* write permission, grougroup */ 26 | #endif 27 | #ifndef S_IROTH 28 | #define S_IROTH 0000004 /* read permission, other */ 29 | #endif 30 | #ifndef S_IWOTH 31 | #define S_IWOTH 0000002 /* write permission, other */ 32 | #endif 33 | 34 | #define MONETDB_MODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) 35 | 36 | #define F_TEST 3 /* test a region for other processes locks. */ 37 | #define F_TLOCK 2 /* test and lock a region for exclusive use */ 38 | #define F_ULOCK 0 /* unlock a previously locked region */ 39 | #define F_LOCK 1 /* lock a region for exclusive use */ 40 | 41 | mutils_export int MT_lockf(char *filename, int mode, off_t off, off_t len); 42 | 43 | #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 44 | extern int fsync (int fd); 45 | extern int winerror(int e); 46 | #endif 47 | 48 | 49 | #endif /* _MUTILS_H_ */ 50 | -------------------------------------------------------------------------------- /src/embedded/inlined_scripts.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import re 4 | import zlib 5 | 6 | # these includes are skipped 7 | blacklist = ('remote', 'srvpool', 'mal_mapi', 'json', 'json_util', 'mcurl', 'xml', 'batxml', 'recycle', 'txtsim', 'tokenizer', 'zorder', '70_vault', '80_lsst', '80_udf', '23_skyserver', '24_zorder', '40_json', '80_udf') 8 | 9 | def mal_include(filename): 10 | if os.path.isdir(filename): 11 | files = os.listdir(filename) 12 | files.sort() 13 | ret = "" 14 | for f in files: 15 | if f.endswith(".mal") and not f.startswith(blacklist): 16 | ret += mal_include(os.path.join(filename, f)) 17 | return ret 18 | elif os.path.isfile(filename): 19 | print filename 20 | content = open(filename).read() + "\n" 21 | content = re.sub("^#.*$", "", content, flags=re.MULTILINE) 22 | while True: 23 | match = re.search("include (\\w+);", content) 24 | if (match == None): break 25 | modname = match.groups(0)[0] 26 | if not modname.startswith(blacklist): 27 | incfile = mal_include(modname + ".mal" if os.path.isfile(modname + ".mal") else modname) 28 | content = content[:match.start()] + incfile + content[match.end():] 29 | return content 30 | else: 31 | return "" 32 | 33 | def to_hex(s, n=1024): 34 | result = "{" 35 | for chunk in [s[i:i+n] for i in range(0, len(s), n)]: 36 | result += ",".join(str(ord(c)) for c in chunk) + ",\n" 37 | return "\n" + result + "0}" 38 | 39 | os.chdir(sys.argv[1]) 40 | mi = mal_include("mal_init.mal") 41 | #print(mi) 42 | s = zlib.compress(mi, 9) 43 | outf = open(sys.argv[2], "w") 44 | outf.write("unsigned char mal_init_inline_arr[] = " + to_hex(s) + ";\n") 45 | outf.write("unsigned char* mal_init_inline = 0;\n") 46 | 47 | s = "" 48 | files = os.listdir("createdb") 49 | files.sort() 50 | for f in files: 51 | if f.endswith(".sql") and not f.startswith(blacklist): 52 | print(f) 53 | s += open(os.path.join("createdb", f)).read() + "\n" 54 | s = zlib.compress(s, 9) 55 | outf.write("\nunsigned char createdb_inline_arr[] = " + to_hex(s) + ";\n") 56 | outf.write("unsigned char* createdb_inline = 0;\n") 57 | 58 | -------------------------------------------------------------------------------- /src/embedded/undef.h: -------------------------------------------------------------------------------- 1 | extern FILE* embedded_stdout; 2 | extern FILE* embedded_stderr; 3 | 4 | #define exit(status) ((void) (status)) 5 | #undef stdout 6 | #define stdout embedded_stdout 7 | #undef stderr 8 | #define stderr embedded_stderr 9 | 10 | #ifdef HAVE_EMBEDDED_R 11 | #define srand(seed) ((void) (seed)) 12 | extern int embedded_r_rand(void); 13 | #define rand embedded_r_rand 14 | #endif 15 | 16 | -------------------------------------------------------------------------------- /src/gdk/gdk_cand.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | /* This macro initializes the variables start, end, cnt, cand, and 10 | * candend that were passed as arguments from the input parameters b 11 | * and s (the candidate list). Start and end are the start and end 12 | * BUNs of b that need to be considered. They are relative to the 13 | * start of the heap. Cand and candend point into the candidate list, 14 | * if present. Note that if the candidate list is dense, cand and 15 | * candend are set to NULL and start and end are adjusted instead. */ 16 | #define CANDINIT(b, s, start, end, cnt, cand, candend) \ 17 | do { \ 18 | start = 0; \ 19 | end = cnt = BATcount(b); \ 20 | cand = candend = NULL; \ 21 | if (s) { \ 22 | assert(BATttype(s) == TYPE_oid); \ 23 | if (BATcount(s) == 0) { \ 24 | start = end = 0; \ 25 | } else { \ 26 | if (BATtdense(s)) { \ 27 | start = (s)->tseqbase; \ 28 | end = start + BATcount(s); \ 29 | } else { \ 30 | oid x = (b)->hseqbase; \ 31 | start = SORTfndfirst((s), &x); \ 32 | x += BATcount(b); \ 33 | end = SORTfndfirst((s), &x); \ 34 | cand = (const oid *) Tloc((s), start); \ 35 | candend = (const oid *) Tloc((s), end); \ 36 | if (cand == candend) { \ 37 | start = end = 0; \ 38 | } else { \ 39 | assert(cand < candend); \ 40 | end = cand[end-start-1] + 1; \ 41 | start = *cand; \ 42 | } \ 43 | } \ 44 | assert(start <= end); \ 45 | if (start <= (b)->hseqbase) \ 46 | start = 0; \ 47 | else if (start >= (b)->hseqbase + cnt) \ 48 | start = cnt; \ 49 | else \ 50 | start -= (b)->hseqbase; \ 51 | if (end >= (b)->hseqbase + cnt) \ 52 | end = cnt; \ 53 | else if (end <= (b)->hseqbase) \ 54 | end = 0; \ 55 | else \ 56 | end -= (b)->hseqbase; \ 57 | } \ 58 | } \ 59 | } while (0) 60 | -------------------------------------------------------------------------------- /src/gdk/gdk_delta.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _GDK_DELTA_H_ 10 | #define _GDK_DELTA_H_ 11 | 12 | /* 13 | * We make sure here that the BUNs section of a BAT at least starts 4 14 | * bytes from the BUN start. This ensures that the first data item of 15 | * e.g. a BAT[void,bit] is (at least) integer aligned. This optimizes 16 | * processing on such BATs (DDBENCH). 17 | */ 18 | #define DELTAinit(P1) \ 19 | do { \ 20 | BATsetcount((P1), 0); \ 21 | (P1)->theap.free = 0; \ 22 | (P1)->batInserted = 0; \ 23 | (P1)->tshift = ATOMelmshift(Tsize(P1)); \ 24 | } while (0) 25 | /* 26 | * Upon saving a BAT, we should convert the delta marker BUN pointers 27 | * into indexes and convert them back into pointers upon reload. 28 | * 29 | * The BATdirty(b) tells you whether a BAT's main memory 30 | * representation differs from its saved image on stable storage. But 31 | * *not* whether it has changed since last transaction commit (it can 32 | * be storage-clean, but transaction-dirty). For this we have 33 | * DELTAdirty(b). 34 | */ 35 | #define DELTAdirty(b) ((b)->batInserted < BUNlast(b)) 36 | 37 | #endif /* _GDK_DELTA_H_ */ 38 | -------------------------------------------------------------------------------- /src/gdk/gdk_imprints.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef GDK_IMPS_H 10 | #define GDK_IMPS_H 11 | 12 | /* 13 | * the cache dictionary struct 14 | */ 15 | typedef struct { 16 | unsigned int cnt:24, /* cnt of pages <= IMPS_MAX_CNT */ 17 | repeat:1, /* repeat flag */ 18 | flags:7; /* reserved flags for future */ 19 | } cchdc_t; 20 | 21 | /* hard bounds */ 22 | #define IMPS_MAX_CNT ((1 << 24) - 1) /* 24 one bits */ 23 | #define IMPS_PAGE 64 24 | 25 | /* auxiliary macros */ 26 | #define IMPSsetBit(B, X, Y) ((X) | ((uint##B##_t) 1 << (Y))) 27 | #define IMPSunsetBit(B, X, Y) ((X) & ~((uint##B##_t) 1 << (Y))) 28 | #define IMPSisSet(B, X, Y) (((X) & ((uint##B##_t) 1 << (Y))) != 0) 29 | 30 | #endif /* GDK_IMPS_H */ 31 | -------------------------------------------------------------------------------- /src/gdk/gdk_storage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _GDK_STORAGE_H_ 10 | #define _GDK_STORAGE_H_ 11 | 12 | extern void DESCclean(BAT *); 13 | 14 | #endif /* _GDK_STORAGE_H_ */ 15 | -------------------------------------------------------------------------------- /src/gdk/gdk_system_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | /* This file should not be included in any file outside of this directory */ 10 | 11 | #ifndef LIBGDK 12 | #error this file should not be included outside its source directory 13 | #endif 14 | 15 | __hidden void join_detached_threads(void) 16 | __attribute__((__visibility__("hidden"))); 17 | void MT_exit_thread(int status); 18 | __hidden void MT_global_exit(int status) 19 | // __attribute__((__noreturn__)) 20 | __attribute__((__visibility__("hidden"))); 21 | __hidden int MT_kill_thread(MT_Id t) 22 | __attribute__((__visibility__("hidden"))); 23 | -------------------------------------------------------------------------------- /src/gdk/gdk_tm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _GDK_TM_H_ 10 | #define _GDK_TM_H_ 11 | 12 | #define SYSTRANSACTION "tmp" 13 | #define MAXTM 10 14 | 15 | #endif /* _GDK_TM_H_ */ 16 | -------------------------------------------------------------------------------- /src/mal/mal/mal_atom.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _MAL_ATOM_H 10 | #define _MAL_ATOM_H 11 | 12 | /* #define MAL_ATOM_DEBUG */ 13 | 14 | mal_export int malAtomSize(int size, const char *name); 15 | mal_export str malAtomProperty(MalBlkPtr mb, InstrPtr pci); 16 | mal_export str malAtomDefinition(str name, int tpe); 17 | mal_export void mal_atom_reset(void); 18 | 19 | #endif /* _MAL_ATOM_H*/ 20 | -------------------------------------------------------------------------------- /src/mal/mal/mal_dataflow.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _MAL_DATAFLOW_H 10 | #define _MAL_DATAFLOW_H 11 | 12 | #include "mal.h" 13 | #include "mal_client.h" 14 | 15 | mal_export str runMALdataflow(Client cntxt, MalBlkPtr mb, int startpc, int stoppc, MalStkPtr stk); 16 | mal_export str deblockdataflow(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 17 | mal_export void stopMALdataflow(void); 18 | mal_export void mal_dataflow_reset(void); 19 | 20 | #endif /* _MAL_DATAFLOW_H*/ 21 | -------------------------------------------------------------------------------- /src/mal/mal/mal_exception.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _MAL_EXCEPTION_H 10 | #define _MAL_EXCEPTION_H 11 | #include "mal_instruction.h" 12 | 13 | /* #define _DEBUG_EXCEPTION_ trace the exception handling */ 14 | 15 | /* These are the exceptions known, adding new ones here requires to also 16 | * add the "full" name to the exceptionNames array in mal_exception.c */ 17 | enum malexception { 18 | MAL=0, 19 | ILLARG, 20 | OUTOFBNDS, 21 | IO, 22 | INVCRED, 23 | OPTIMIZER, 24 | STKOF, 25 | SYNTAX, 26 | TYPE, 27 | LOADER, 28 | PARSE, 29 | ARITH, 30 | PERMD, 31 | SQL 32 | }; 33 | 34 | #define MAL_SUCCEED ((str) 0) /* no error */ 35 | 36 | #define throw \ 37 | return createException 38 | #define rethrow(FCN, TMP, PRV) \ 39 | {if ((TMP = PRV) != MAL_SUCCEED) return(TMP);} 40 | 41 | mal_export str createException(enum malexception, const char *, 42 | _In_z_ _Printf_format_string_ const char *, ...) 43 | __attribute__((__format__(__printf__, 3, 4))); 44 | /*FIXmal_export str createMalException(MalBlkPtr mb, int pc, enum malexception type, const char *prev, const char *format, ...);*/ 45 | mal_export str createMalException(MalBlkPtr , int , enum malexception , 46 | _In_z_ _Printf_format_string_ const char *, ...) 47 | __attribute__((__format__(__printf__, 4, 5))); 48 | mal_export void showException(stream *out, enum malexception, const char *, 49 | _In_z_ _Printf_format_string_ const char *, ...) 50 | __attribute__((__format__(__printf__, 4, 5))); 51 | mal_export void showScriptException(stream *out, MalBlkPtr, int, enum malexception, 52 | _In_z_ _Printf_format_string_ const char *, ...) 53 | __attribute__((__format__(__printf__, 5, 6))); 54 | mal_export int isExceptionVariable(str nme); 55 | 56 | mal_export enum malexception getExceptionType(const char *); 57 | mal_export str getExceptionPlace(const char *); 58 | mal_export str getExceptionMessageAndState(const char *); 59 | mal_export str getExceptionMessage(const char *); 60 | mal_export void dumpExceptionsToStream(stream *out, str msg); 61 | mal_export void freeException(str); 62 | 63 | #include "mal_errors.h" 64 | #endif /* _MAL_EXCEPTION_H*/ 65 | -------------------------------------------------------------------------------- /src/mal/mal/mal_function.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _MAL_FCN_H 10 | #define _MAL_FCN_H 11 | 12 | #include "mal_instruction.h" 13 | #include "mal_module.h" 14 | #include "mal_resolve.h" 15 | 16 | #define getLastUpdate(L,I) ((L)->var[I].updated) 17 | #define getEndScope(L,I) ((L)->var[I].eolife) 18 | #define getBeginScope(L,I) ((L)->var[I].declared) 19 | 20 | /* #define DEBUG_MAL_FCN */ 21 | /* #define DEBUG_CLONE */ 22 | 23 | mal_export Symbol newFunction(str mod, str nme,int kind); 24 | mal_export int getPC(MalBlkPtr mb, InstrPtr p); 25 | 26 | mal_export Symbol getFunctionSymbol(Module scope, InstrPtr p); 27 | mal_export void chkFlow(MalBlkPtr mb); 28 | mal_export void chkDeclarations(MalBlkPtr mb); 29 | mal_export void clrDeclarations(MalBlkPtr mb); 30 | mal_export int isLoopBarrier(MalBlkPtr mb, int pc); 31 | mal_export int getBlockExit(MalBlkPtr mb,int pc); 32 | mal_export int getBlockBegin(MalBlkPtr mb,int pc); 33 | mal_export void setVariableScope(MalBlkPtr mb); 34 | 35 | mal_export void printFunction(stream *fd, MalBlkPtr mb, MalStkPtr stk, int flg); 36 | mal_export void fprintFunction(FILE *fd, MalBlkPtr mb, MalStkPtr stk, int flg); 37 | mal_export void debugFunction(stream *fd, MalBlkPtr mb, MalStkPtr stk, int flg, int first, int size); 38 | 39 | mal_export int getBarrierEnvelop(MalBlkPtr mb); 40 | 41 | mal_export Symbol cloneFunction(Module scope, Symbol proc, MalBlkPtr mb, InstrPtr p); 42 | 43 | #include "mal_exception.h" 44 | 45 | #define MAXDEPTH 32 46 | #endif /* _MAL_FCN_H*/ 47 | -------------------------------------------------------------------------------- /src/mal/mal/mal_import.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _MAL_IMPORT_H 10 | #define _MAL_IMPORT_H 11 | 12 | #include "mal_exception.h" 13 | #include "mal_client.h" 14 | #include "mal_session.h" 15 | #include "mal_utils.h" 16 | 17 | mal_export str malInclude(Client c, str name, int listing); 18 | mal_export void slash_2_dir_sep(str fname); 19 | mal_export str evalFile(str fname, int listing); 20 | mal_export str compileString(Symbol *fcn, Client c, str s); 21 | mal_export str callString(Client c, str s, int listing); 22 | #endif /* _MAL_IMPORT_H */ 23 | -------------------------------------------------------------------------------- /src/mal/mal/mal_linker.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _MAL_LINKER_H 10 | #define _MAL_LINKER_H 11 | 12 | #define MAL_EXT ".mal" 13 | #define SQL_EXT ".sql" 14 | 15 | #ifdef HAVE_DLFCN_H 16 | #include 17 | #else 18 | #define RTLD_LAZY 1 19 | #define RTLD_NOW 2 20 | #define RTLD_GLOBAL 4 21 | #define RTLD_NOW_REPORT_ERROR 8 22 | #endif 23 | 24 | /* #define DEBUG_MAL_LINKER */ 25 | #define MONET64 1 26 | mal_export MALfcn getAddress(str fcnname); 27 | mal_export char *MSP_locate_sqlscript(const char *mod_name, bit recurse); 28 | mal_export str loadLibrary(str modulename, int flag); 29 | mal_export char *locate_file(const char *basename, const char *ext, bit recurse); 30 | mal_export int malLibraryEnabled(str name); 31 | mal_export char* malLibraryHowToEnable(str name); 32 | mal_export char * MSP_locate_script(const char *filename); 33 | 34 | #endif /* _MAL_LINKER_H */ 35 | -------------------------------------------------------------------------------- /src/mal/mal/mal_listing.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _MAL_LISTING_H 10 | #define _MAL_LISTING_H 11 | 12 | #include "mal_type.h" 13 | #include "mal_stack.h" 14 | #include "mal_instruction.h" 15 | 16 | #define DEBUG_MAL_LIST 17 | 18 | mal_export str fcnDefinition(MalBlkPtr mb, InstrPtr p, str s, int flg, str base, size_t len); 19 | mal_export void printInstruction(stream *fd, MalBlkPtr mb, MalStkPtr stk, InstrPtr p, int flg); 20 | mal_export void fprintInstruction(FILE *fd, MalBlkPtr mb, MalStkPtr stk, InstrPtr p, int flg); 21 | mal_export str instructionCall(MalBlkPtr mb, InstrPtr p, str s, str base, size_t len); 22 | mal_export void promptInstruction(stream *fd, MalBlkPtr mb, MalStkPtr stk, InstrPtr p, int flg); 23 | mal_export str instruction2str(MalBlkPtr mb, MalStkPtr stl, InstrPtr p, int hidden); 24 | mal_export str shortStmtRendering(MalBlkPtr mb, MalStkPtr stl, InstrPtr p); 25 | mal_export str mal2str(MalBlkPtr mb, int first, int last); 26 | mal_export void showMalBlkHistory(stream *out, MalBlkPtr mb); 27 | 28 | #endif /* _MAL_LIST_H */ 29 | -------------------------------------------------------------------------------- /src/mal/mal/mal_module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _MAL_SCOPE_H_ 10 | #define _MAL_SCOPE_H_ 11 | 12 | #include "mal.h" 13 | /* #define MAL_SCOPE_DEBUG */ 14 | 15 | #define MAXSCOPE 256 16 | 17 | typedef struct SCOPEDEF { 18 | struct SCOPEDEF *link; /* module with same index value */ 19 | str name; /* index in namespace */ 20 | Symbol *space; /* type dispatcher table */ 21 | int isAtomModule; /* atom module definition ? */ 22 | void *dll; /* dlopen handle */ 23 | str help; /* short description of module functionality*/ 24 | } *Module, ModuleRecord; 25 | 26 | mal_export Module userModule(void); 27 | mal_export Module globalModule(str nme); 28 | mal_export Module fixModule(str nme); 29 | mal_export Module getModule(str nme); 30 | mal_export void freeModule(Module cur); 31 | mal_export void insertSymbol(Module scope, Symbol prg); 32 | mal_export void deleteSymbol(Module scope, Symbol prg); 33 | mal_export Module findModule(Module scope, str name); 34 | mal_export Symbol findSymbol(Module usermodule, str mod, str fcn); 35 | mal_export Symbol findSymbolInModule(Module v, str fcn); 36 | mal_export void mal_module_reset(void); 37 | mal_export void getModuleList(Module** out, int* length); 38 | mal_export void freeModuleList(Module* list); 39 | mal_export void listModules(stream *out, Module s); 40 | mal_export void dumpModules(stream *out); 41 | 42 | #define getSymbolIndex(N) (int)(*(char*)(N)) 43 | 44 | #endif /* _MAL_SCOPE_H_ */ 45 | -------------------------------------------------------------------------------- /src/mal/mal/mal_namespace.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _MAL_NAMESPACE_H 10 | #define _MAL_NAMESPACE_H 11 | 12 | mal_export void initNamespace(void); 13 | mal_export void finishNamespace(void); 14 | mal_export str putName(const char *nme); 15 | mal_export str putNameLen(const char *nme, size_t len); 16 | mal_export str getName(const char *nme); 17 | mal_export str getNameLen(const char *nme, size_t len); 18 | mal_export void delName(const char *nme, size_t len); 19 | 20 | mal_export void mal_namespace_reset(void); 21 | 22 | #define MAXIDENTLEN 1024 23 | 24 | #endif /* _MAL_NAMESPACE_H */ 25 | -------------------------------------------------------------------------------- /src/mal/mal/mal_parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _MAL_PARSER_H 10 | #define _MAL_PARSER_H 11 | 12 | #include "mal_import.h" 13 | 14 | #define MAXERRORS 250 15 | 16 | #define CURRENT(c) (c->fdin->buf + c->fdin->pos + c->yycur) 17 | #define currChar(X) (*CURRENT(X)) 18 | #define peekChar(X) (*((X)->fdin->buf + (X)->fdin->pos + (X)->yycur+1)) 19 | #define nextChar(X) X->yycur++ 20 | #define prevChar(X) if(X->yycur) X->yycur-- 21 | 22 | mal_export void initParser(void); /* needed in src/mal/mal.c */ 23 | mal_export void parseMAL(Client cntxt, Symbol curPrg, int skipcomments, int lines); 24 | 25 | #endif /* _MAL_PARSER_H */ 26 | 27 | -------------------------------------------------------------------------------- /src/mal/mal/mal_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2017 MonetDB B.V. 7 | */ 8 | 9 | /* This file should not be included in any file outside of this directory */ 10 | 11 | #ifndef LIBMAL 12 | #error this file should not be included outside its source directory 13 | #endif 14 | 15 | __hidden extern MT_Lock mal_namespaceLock; 16 | 17 | extern volatile ATOMIC_TYPE mal_running; 18 | #ifdef ATOMIC_LOCK 19 | extern MT_Lock mal_runningLock; 20 | #endif 21 | -------------------------------------------------------------------------------- /src/mal/mal/mal_resolve.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _MAL_RESOLVE_H 10 | #define _MAL_RESOLVE_H 11 | 12 | #include "mal_exception.h" 13 | #include "mal_function.h" 14 | #include "mal_listing.h" 15 | #include "mal_exception.h" 16 | 17 | /* 18 | #define DEBUG_MAL_RESOLVE 1 19 | */ 20 | #define MAXTYPEVAR 10 21 | 22 | mal_export void chkProgram(Module s, MalBlkPtr mb); 23 | mal_export int chkInstruction(Module s, MalBlkPtr mb, InstrPtr p); 24 | mal_export void chkTypes(Module s, MalBlkPtr mb, int silent); 25 | mal_export void typeChecker(Module scope, MalBlkPtr mb, InstrPtr p, int silent); 26 | 27 | extern str traceFcnName; 28 | mal_export void expandMacro(MalBlkPtr mb, InstrPtr p, MalBlkPtr mc); 29 | 30 | /* 31 | * @- Type resolution algorithm. 32 | * Every actual argument of a function call should be type compatible 33 | * with the formal argument, and the function result type should be 34 | * compatible with the destination variable. 35 | * In both cases the 'receiving' variable may not be fully qualified, 36 | * i.e. of type 'any'. The type resolution algorithm creates the concrete 37 | * type for subsequent use. 38 | */ 39 | mal_export int resolveType(int dsttype, int srctype); 40 | 41 | #endif /* _MAL_RESOLVE_H*/ 42 | -------------------------------------------------------------------------------- /src/mal/mal/mal_resource.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _MAL_RESOURCE_H 10 | #define _MAL_RESOURCE_H 11 | 12 | #include "mal_interpreter.h" 13 | #include "gdk_atomic.h" 14 | 15 | #define TIMESLICE (3 * 60 * 1000 * 1000) /* usec , 3 minute high priority */ 16 | #define DELAYUNIT 2 /* ms delay in parallel processing decisions */ 17 | #define MAX_DELAYS 1000 /* never wait more then 2000 ms */ 18 | 19 | //#define heapinfo(X,Id) (((X) && (X)->base && ((X)->parentid == 0 || (X)->parentid == Id)) ? (X)->free : 0) 20 | #define heapinfo(X,Id) (((X) && (X)->base ) ? (X)->free : 0) 21 | #define hashinfo(X,Id) ((X) && (X) != (Hash *) 1 ? heapinfo(&(X)->heap, Id) : 0) 22 | 23 | #define USE_MAL_ADMISSION 24 | #ifdef USE_MAL_ADMISSION 25 | mal_export int MALadmission(lng argclaim, lng hotclaim); 26 | #endif 27 | 28 | #define FAIRNESS_THRESHOLD (MAX_DELAYS * DELAYUNIT) 29 | 30 | mal_export lng getMemoryClaim(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, int i, int flag); 31 | mal_export void MALresourceFairness(lng usec); 32 | mal_export size_t MALrunningThreads(void); 33 | 34 | #endif /* _MAL_RESOURCE_H*/ 35 | -------------------------------------------------------------------------------- /src/mal/mal/mal_runtime.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _MAL_RUNTIME_H 10 | #define _MAL_RUNTIME_H 11 | 12 | #include "mal.h" 13 | #include "mal_client.h" 14 | #include "mal_instruction.h" 15 | 16 | /* During MAL interpretation we collect performance event data. 17 | * Their management is orchestrated from here. 18 | * We need to maintain some state from ProfileBegin 19 | */ 20 | typedef struct{ 21 | lng ticks; /* at start of this profile interval */ 22 | } *RuntimeProfile, RuntimeProfileRecord; 23 | 24 | /* The actual running queries are assembled in a queue 25 | * for external inspection and manipulation 26 | */ 27 | typedef struct QRYQUEUE{ 28 | Client cntxt; 29 | MalBlkPtr mb; 30 | MalStkPtr stk; 31 | int tag; 32 | str query; 33 | str status; 34 | lng start; 35 | lng runtime; 36 | } *QueryQueue; 37 | mal_export int qtop; 38 | 39 | mal_export void runtimeProfileInit(Client cntxt, MalBlkPtr mb, MalStkPtr stk); 40 | mal_export void runtimeProfileFinish(Client cntxt, MalBlkPtr mb, MalStkPtr stk); 41 | mal_export void runtimeProfileBegin(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, RuntimeProfile prof); 42 | mal_export void runtimeProfileExit(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci, RuntimeProfile prof); 43 | mal_export void finishSessionProfiler(Client cntxt); 44 | mal_export lng getVolume(MalStkPtr stk, InstrPtr pci, int rd); 45 | 46 | mal_export void mal_runtime_reset(void); 47 | mal_export QueryQueue QRYqueue; 48 | #endif 49 | -------------------------------------------------------------------------------- /src/mal/mal/mal_scenario.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _MAL_SCENARIO_H 10 | #define _MAL_SCENARIO_H 11 | 12 | #include "mal_import.h" 13 | 14 | #define MAL_SCENARIO_READER 0 15 | #define MAL_SCENARIO_PARSER 1 16 | #define MAL_SCENARIO_OPTIMIZE 2 17 | #define MAL_SCENARIO_SCHEDULER 3 18 | #define MAL_SCENARIO_ENGINE 4 19 | #define MAL_SCENARIO_INITCLIENT 5 20 | #define MAL_SCENARIO_EXITCLIENT 6 21 | #define MAL_SCENARIO_CALLBACK 7 22 | 23 | /*#define MAL_SCENARIO_DEBUG*/ 24 | /* 25 | * @- 26 | * The scenario descriptions contains all information to 27 | * implement the scenario. Each client gets a copy. 28 | * An exception or error detected while parsing is turned 29 | * into an exception and aborts the scenario. 30 | */ 31 | #define MAXSCEN 8 32 | 33 | typedef struct SCENARIO { 34 | str name, language; 35 | str initSystem; 36 | MALfcn initSystemCmd; 37 | str exitSystem; 38 | MALfcn exitSystemCmd; 39 | str initClient; 40 | MALfcn initClientCmd; 41 | str exitClient; 42 | MALfcn exitClientCmd; 43 | str reader; 44 | MALfcn readerCmd; 45 | void *readerState; 46 | str parser; 47 | MALfcn parserCmd; 48 | void *parserState; 49 | str optimizer; 50 | MALfcn optimizerCmd; 51 | void *optimizerState; 52 | str tactics; 53 | MALfcn tacticsCmd; 54 | void *tacticsState; 55 | str engine; 56 | MALfcn engineCmd; 57 | void *engineState; 58 | str callback; 59 | MALfcn callbackCmd; 60 | void *callbackState; 61 | struct SCENARIO *next; 62 | } *Scenario; 63 | 64 | mal_export str setScenario(Client c, str nme); 65 | mal_export str runScenario(Client c, int once); 66 | mal_export str getScenarioLanguage(Client c); 67 | mal_export Scenario getFreeScenario(void); 68 | 69 | mal_export void showCurrentScenario(void); 70 | mal_export void showScenarioByName(stream *f, str s); 71 | mal_export void showScenario(stream *f, Scenario s); 72 | mal_export void showAllScenarios(stream *f); 73 | mal_export void resetScenario(Client c); 74 | mal_export Scenario findScenario(str nme); 75 | mal_export void updateScenario(str scen, str nme, MALfcn fcn); 76 | 77 | mal_export str defaultScenario(Client c); 78 | 79 | #endif /* _MAL_SCENARIO_H */ 80 | -------------------------------------------------------------------------------- /src/mal/mal/mal_session.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _MAL_SESSION_H 10 | #define _MAL_SESSION_H 11 | 12 | #include "mal_scenario.h" 13 | 14 | mal_export str malBootstrap(void); 15 | mal_export str MSserveClient(void *dummy); 16 | mal_export str MSinitClientPrg(Client cntxt, str mod, str nme); 17 | mal_export void MSscheduleClient(str command, str challenge, bstream *fin, stream *fout, protocol_version protocol, size_t blocksize, int compute_column_widths); 18 | 19 | mal_export str MALreader(Client c); 20 | mal_export str MALinitClient(Client c); 21 | mal_export str MALexitClient(Client c); 22 | mal_export str MALparser(Client c); 23 | mal_export str MALengine(Client c); 24 | mal_export str MALcallback(Client c, str msg); 25 | mal_export void MSresetInstructions(MalBlkPtr mb, int start); 26 | mal_export void MSresetVariables(Client cntxt, MalBlkPtr mb, MalStkPtr glb, int start); 27 | mal_export int MALcommentsOnly(MalBlkPtr mb); 28 | 29 | #endif /* _MAL_SESSION_H */ 30 | 31 | -------------------------------------------------------------------------------- /src/mal/mal/mal_stack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _MAL_STACK_H_ 10 | #define _MAL_STACK_H_ 11 | #include "mal.h" 12 | 13 | #define stackSize(CNT) (sizeof(ValRecord)*(CNT) + offsetof(MalStack, stk)) 14 | 15 | mal_export MalStkPtr newGlobalStack(int size); 16 | mal_export MalStkPtr reallocGlobalStack(MalStkPtr s, int cnt); 17 | mal_export void freeStack(MalStkPtr stk); 18 | mal_export void clearStack(MalStkPtr s); 19 | 20 | #define VARfreeze(X) if(X){X->frozen=TRUE;} 21 | #define VARfixate(X) if(X){X->constant=TRUE;} 22 | 23 | #define getStkRecord(S,P,I) &(S)->stk[(P)->argv[I]] 24 | #define getStkValue(S,P,I) ( getStkType(S,P,I)== TYPE_str? \ 25 | getStkRecord(S,P,I)->val.sval :\ 26 | getStkRecord(S,P,I)->val.pval ) 27 | #define getStkType(S,P,I) (S)->stk[(P)->argv[I]].vtype 28 | #define setStkType(S,P,I,T) (S)->stk[(P)->argv[I]].vtype = T 29 | #endif /* _MAL_STACK_H_ */ 30 | -------------------------------------------------------------------------------- /src/mal/mal/mal_type.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef MAL_TYPE_H 10 | #define MAL_TYPE_H 11 | #include "mal.h" 12 | 13 | /* #define DEBUG_MAL_TYPE 1 */ 14 | 15 | #define malVARG " malVARG" 16 | #define TMPMARKER '_' 17 | #define REFMARKER 'X' 18 | #define REFMARKERC 'C' 19 | 20 | #define newBatType(T) (1<<16 | (T & 0377) ) 21 | #define getBatType(X) ((X) & 0377 ) 22 | #define isaBatType(X) ((1<<16) & (X) && (X)!= TYPE_any) 23 | 24 | #define isAnyExpression(X) ((X) >> 17) 25 | #define isPolymorphic(X) (isAnyExpression(X) || (X)== TYPE_any) 26 | 27 | #define setTypeIndex(X,I) X |= ((I & 017)<<18); 28 | #define getTypeIndex(X) (((X)>>18) & 017) 29 | 30 | #define isPolyType(X) (isAnyExpression(X) && getTypeIndex(X)>0) 31 | /* 32 | * The symbol/instruction kinds are introduced here instead of reusing the defines 33 | * derived from the parser to avoid a loop in the define-structure. 34 | */ 35 | 36 | #define RAISEsymbol 21 /* flow of control modifiers */ 37 | #define CATCHsymbol 22 38 | #define RETURNsymbol 23 39 | #define BARRIERsymbol 24 40 | #define REDOsymbol 25 41 | #define LEAVEsymbol 26 42 | #define YIELDsymbol 27 43 | #define EXITsymbol 29 44 | 45 | #define ASSIGNsymbol 40 /* interpreter entry points */ 46 | #define ENDsymbol 41 47 | #define NOOPsymbol 43 /* no operation required */ 48 | 49 | #define COMMANDsymbol 61 /* these tokens should be the last group !! */ 50 | #define FUNCTIONsymbol 62 /* the designate the signature start */ 51 | #define FACTORYsymbol 63 /* the co-routine infrastructure */ 52 | #define PATTERNsymbol 64 /* the MAL self-reflection commands */ 53 | 54 | #define FCNcall 50 /* internal symbols */ 55 | #define FACcall 51 56 | #define CMDcall 52 57 | #define THRDcall 53 58 | #define PATcall 54 /* pattern call */ 59 | 60 | #define REMsymbol 99 /* commentary to be retained */ 61 | 62 | 63 | mal_export str getTypeName(malType tpe); 64 | mal_export str getTypeIdentifier(malType tpe); 65 | mal_export int getAtomIndex(const char *nme, int len, int deftpe); 66 | #define idcmp(n, m) strcmp(n, m) 67 | mal_export int isIdentifier(str s); 68 | mal_export int findGDKtype(int type); /* used in src/mal/mal_interpreter.c */ 69 | 70 | #endif /* MAL_TYPE_H */ 71 | -------------------------------------------------------------------------------- /src/mal/mal/mal_utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | /* 10 | * (c) M. Kersten 11 | * Passing strings between front-end and kernel often require marshalling. 12 | */ 13 | #include "monetdb_config.h" 14 | #include "mal_utils.h" 15 | 16 | void 17 | mal_unquote(char *msg) 18 | { 19 | char *p = msg, *s; 20 | 21 | s = p; 22 | while (*p) { 23 | if (*p == '\\') { 24 | p++; 25 | switch (*p) { 26 | case 'n': 27 | *s = '\n'; 28 | break; 29 | case 't': 30 | *s = '\t'; 31 | break; 32 | case 'r': 33 | *s = '\r'; 34 | break; 35 | case 'f': 36 | *s = '\f'; 37 | break; 38 | case '0': 39 | case '1': 40 | case '2': 41 | case '3': 42 | /* this could be the start of 43 | an octal sequence, check it 44 | out */ 45 | if (p[1] && p[2] && p[1] >= '0' && p[1] <= '7' && p[2] >= '0' && p[2] <= '7') { 46 | *s = (char)(((p[0] - '0') << 6) | ((p[1] - '0') << 3) | (p[2] - '0')); 47 | p += 2; 48 | break; 49 | } 50 | /* fall through */ 51 | default: 52 | *s = *p; 53 | break; 54 | } 55 | p++; 56 | } else { 57 | *s = *p++; 58 | } 59 | s++; 60 | } 61 | *s = 0; /* close string */ 62 | } 63 | 64 | char * 65 | mal_quote(const char *msg, size_t size) 66 | { 67 | char *s = GDKmalloc(size * 2 + 1); /* we absolutely don't need more than this (until we start producing octal escapes */ 68 | char *t = s; 69 | 70 | if ( s == NULL) 71 | return NULL; 72 | while (size > 0) { 73 | size--; 74 | switch (*msg) { 75 | case '"': 76 | *t++ = '\\'; 77 | *t++ = '"'; 78 | break; 79 | case '\n': 80 | *t++ = '\\'; 81 | *t++ = 'n'; 82 | break; 83 | case '\t': 84 | *t++ = '\\'; 85 | *t++ = 't'; 86 | break; 87 | case '\\': 88 | *t++ = '\\'; 89 | *t++ = '\\'; 90 | break; 91 | default: 92 | *t++ = *msg; 93 | break; 94 | } 95 | msg++; 96 | /* also deal with binaries */ 97 | } 98 | *t = 0; 99 | return s; 100 | } 101 | -------------------------------------------------------------------------------- /src/mal/mal/mal_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef MAL_UTILS_H 10 | #define MAL_UTILS_H 11 | #include "mal.h" 12 | 13 | mal_export str mal_quote(const char *msg, size_t size); 14 | mal_export void mal_unquote(char *msg); 15 | 16 | #endif /* MAL_UTILS_H */ 17 | -------------------------------------------------------------------------------- /src/mal/modules/00_batExtensions_hge.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | command bat.imprints(b:bat[:hge]) 8 | address CMDBATimprints; 9 | 10 | command bat.imprintsize(b:bat[:hge]):lng 11 | address CMDBATimprintsize; 12 | 13 | -------------------------------------------------------------------------------- /src/mal/modules/00_iterator_hge.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | module iterator; 8 | 9 | command next(step:hge,last:hge):hge 10 | address ITRnext_hge; 11 | -------------------------------------------------------------------------------- /src/mal/modules/00_language_hge.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | module language; 8 | 9 | unsafe command assert(v:hge,term:str):void 10 | address MALassertHge; 11 | -------------------------------------------------------------------------------- /src/mal/modules/00_mkey_hge.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | module mkey; 8 | 9 | pattern hash(v:hge):lng 10 | address MKEYhash 11 | comment "calculate a hash value"; 12 | -------------------------------------------------------------------------------- /src/mal/modules/batExtensions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _BAT_EXTENSIONS_ 10 | #define _BAT_EXTENSIONS_ 11 | 12 | #include "algebra.h" 13 | #include "bat5.h" 14 | #include "mal_client.h" 15 | #include "mal_interpreter.h" 16 | 17 | mal_export str CMDBATnewColumn(Client cntxt, MalBlkPtr m, MalStkPtr s, InstrPtr p); 18 | mal_export str CMDBATnew(Client cntxt, MalBlkPtr m, MalStkPtr s, InstrPtr p); 19 | mal_export str CMDBATnew_persistent(Client cntxt, MalBlkPtr m, MalStkPtr s, InstrPtr p); 20 | mal_export str CMDBATsingle(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 21 | mal_export str CMDBATpartition(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 22 | mal_export str CMDBATpartition2(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 23 | mal_export str CMDBATimprints(void *ret, bat *bid); 24 | mal_export str CMDBATimprintsize(lng *ret, bat *bid); 25 | 26 | #endif /* _BAT_EXTENSIONS_ */ 27 | -------------------------------------------------------------------------------- /src/mal/modules/batExtensions.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | pattern bat.new(tt:any_1) :bat[:any_1] 8 | address CMDBATnew; 9 | pattern bat.new(tt:any_1, size:int) :bat[:any_1] 10 | address CMDBATnew; 11 | pattern bat.new(tt:any_1, size:lng, persist:bit) :bat[:any_1] 12 | address CMDBATnew; 13 | pattern bat.new(tt:any_1, size:int, persist:bit) :bat[:any_1] 14 | address CMDBATnew; 15 | pattern bat.new(tt:any_1, size:lng) :bat[:any_1] 16 | address CMDBATnew 17 | comment "Creates a new empty transient BAT, with tail-types as indicated."; 18 | 19 | pattern bat.single(val:any_1):bat[:any_1] 20 | address CMDBATsingle 21 | comment "Create a BAT with a single elemenet"; 22 | 23 | pattern bat.partition(b:bat[:any_1]):bat[:any_1]... 24 | address CMDBATpartition 25 | comment "Create a serie of slices over the BAT argument. The BUNs are distributed evenly."; 26 | 27 | pattern bat.partition(b:bat[:any_1], pieces:int, n:int):bat[:any_1] 28 | address CMDBATpartition2 29 | comment "Create the n-th slice over the BAT broken into several pieces."; 30 | 31 | command bat.imprints(b:bat[:bte]) :void 32 | address CMDBATimprints; 33 | command bat.imprints(b:bat[:sht]) :void 34 | address CMDBATimprints; 35 | command bat.imprints(b:bat[:int]) :void 36 | address CMDBATimprints; 37 | command bat.imprints(b:bat[:lng]) :void 38 | address CMDBATimprints; 39 | command bat.imprints(b:bat[:flt]) :void 40 | address CMDBATimprints; 41 | command bat.imprints(b:bat[:dbl]) :void 42 | address CMDBATimprints 43 | comment "Check for existence or create an imprint index on the BAT."; 44 | 45 | command bat.imprintsize(b:bat[:bte]):lng 46 | address CMDBATimprintsize; 47 | command bat.imprintsize(b:bat[:sht]):lng 48 | address CMDBATimprintsize; 49 | command bat.imprintsize(b:bat[:int]):lng 50 | address CMDBATimprintsize; 51 | command bat.imprintsize(b:bat[:lng]):lng 52 | address CMDBATimprintsize; 53 | command bat.imprintsize(b:bat[:flt]):lng 54 | address CMDBATimprintsize; 55 | command bat.imprintsize(b:bat[:dbl]):lng 56 | address CMDBATimprintsize 57 | comment "Return the storage size of the imprints index structure."; 58 | 59 | -------------------------------------------------------------------------------- /src/mal/modules/blob.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | /* 10 | * @* Implementation Code 11 | */ 12 | #ifndef __BLOB_H__ 13 | #define __BLOB_H__ 14 | #include "mal.h" 15 | #include "mal_exception.h" 16 | 17 | typedef struct blob { 18 | size_t nitems; 19 | /*unsigned */ char data[FLEXIBLE_ARRAY_MEMBER]; 20 | } blob; 21 | 22 | #define sqlblob blob 23 | 24 | mal_export int TYPE_blob; 25 | mal_export int TYPE_sqlblob; 26 | 27 | mal_export var_t blobsize(size_t nitems); 28 | mal_export ssize_t SQLBLOBfromstr(const char *instr, size_t *l, blob **val); 29 | mal_export ssize_t SQLBLOBtostr(str *tostr, size_t *l, const blob *pin); 30 | 31 | mal_export var_t BLOBput(Heap *h, var_t *bun, const blob *val); 32 | mal_export const blob * BLOBnull(void); 33 | 34 | 35 | #endif /* __BLOB_H__ */ 36 | -------------------------------------------------------------------------------- /src/mal/modules/blob.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | module blob; 8 | 9 | atom blob; 10 | 11 | command tostr() address BLOBtostr; 12 | command fromstr() address BLOBfromstr; 13 | command cmp() address BLOBcmp; 14 | command hash() address BLOBhash; 15 | command null() address BLOBnull; 16 | command read() address BLOBread; 17 | command write() address BLOBwrite; 18 | command put() address BLOBput; 19 | command del() address BLOBdel; 20 | command length() address BLOBlength; 21 | command heap() address BLOBheap; 22 | 23 | command blob(s:blob):blob 24 | address BLOBblob_blob 25 | comment "Noop routine."; 26 | 27 | command blob(s:str):blob 28 | address BLOBblob_fromstr; 29 | 30 | # @+ string functions 31 | # Manipulation functions to extract strings from blobs and vice versa. 32 | # Not to be confused with blob parsing and printing. 33 | command tostring(v:blob) :str 34 | address BLOBfromblob 35 | comment "get the bytes from blob as a string, till 36 | the first 0 byte or the end of the blob"; 37 | command tostring(v:blob, index:int ) :str 38 | address BLOBfromidx 39 | comment "get the bytes from blob as a string, 40 | starting at byte 'index' till the first 41 | 0 byte or the end of the blob."; 42 | command toblob(v:str) :blob 43 | address BLOBtoblob 44 | comment "store a string as a blob."; 45 | command nitems(b:blob):int 46 | address BLOBnitems 47 | comment " get the number of bytes in this blob."; 48 | 49 | atom sqlblob:blob; 50 | 51 | command tostr() address SQLBLOBtostr; 52 | command fromstr() address SQLBLOBfromstr; 53 | 54 | command sqlblob(s:sqlblob):sqlblob 55 | address BLOBblob_blob 56 | comment "Noop routine."; 57 | 58 | command sqlblob(s:str):sqlblob 59 | address BLOBsqlblob_fromstr; 60 | 61 | module blob; 62 | 63 | command prelude() :void 64 | address BLOBprelude; 65 | 66 | blob.prelude(); 67 | 68 | module calc; 69 | 70 | command blob(b:blob):blob address BLOBblob_blob; 71 | command blob(s:str):blob address BLOBblob_fromstr; 72 | command sqlblob(b:sqlblob):sqlblob address BLOBblob_blob; 73 | command sqlblob(s:str):sqlblob address BLOBsqlblob_fromstr; 74 | -------------------------------------------------------------------------------- /src/mal/modules/group.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _GROUP_H_ 10 | #define _GROUP_H_ 11 | #include "gdk.h" 12 | 13 | mal_export str GRPgroup1(bat *ngid, bat *next, bat *nhis, const bat *bid); 14 | mal_export str GRPgroup2(bat *ngid, bat *next, bat *nhis, 15 | const bat *bid, const bat *sid); 16 | mal_export str GRPgroup3(bat *ngid, bat *next, const bat *bid); 17 | mal_export str GRPgroup4(bat *ngid, bat *next, 18 | const bat *bid, const bat *sid); 19 | mal_export str GRPsubgroup2(bat *ngid, bat *next, bat *nhis, 20 | const bat *bid, const bat *gid); 21 | mal_export str GRPsubgroup3(bat *ngid, bat *next, bat *nhis, 22 | const bat *bid, const bat *sid, 23 | const bat *gid); 24 | mal_export str GRPsubgroup4(bat *ngid, bat *next, bat *nhis, 25 | const bat *bid, const bat *gid, 26 | const bat *eid, const bat *hid); 27 | mal_export str GRPsubgroup5(bat *ngid, bat *next, bat *nhis, 28 | const bat *bid, const bat *sid, 29 | const bat *gid, const bat *eid, const bat *hid); 30 | mal_export str GRPsubgroup6(bat *ngid, bat *next, 31 | const bat *bid, const bat *gid); 32 | mal_export str GRPsubgroup7(bat *ngid, bat *next, 33 | const bat *bid, const bat *sid, 34 | const bat *gid); 35 | mal_export str GRPsubgroup8(bat *ngid, bat *next, 36 | const bat *bid, const bat *gid, 37 | const bat *eid, const bat *hid); 38 | mal_export str GRPsubgroup9(bat *ngid, bat *next, 39 | const bat *bid, const bat *sid, 40 | const bat *gid, const bat *eid, const bat *hid); 41 | 42 | #endif /* _GROUP_H_ */ 43 | -------------------------------------------------------------------------------- /src/mal/modules/iterator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _ITERATOR_ 10 | #define _ITERATOR_ 11 | 12 | #include "mal.h" 13 | #include "mal_interpreter.h" 14 | 15 | mal_export str ITRnewChunk(lng *res, bat *vid, bat *bid, lng *granule); 16 | mal_export str ITRnextChunk(lng *res, bat *vid, bat *bid, lng *granule); 17 | mal_export str ITRbunIterator(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 18 | mal_export str ITRbunNext(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 19 | 20 | mal_export str ITRnext_oid(oid *i, oid *step, oid *last); 21 | mal_export str ITRnext_lng(lng *i, lng *step, lng *last); 22 | #ifdef HAVE_HGE 23 | mal_export str ITRnext_hge(hge *i, hge *step, hge *last); 24 | #endif 25 | mal_export str ITRnext_int(int *i, int *step, int *last); 26 | mal_export str ITRnext_sht(sht *i, sht *step, sht *last); 27 | mal_export str ITRnext_flt(flt *i, flt *step, flt *last); 28 | mal_export str ITRnext_dbl(dbl *i, dbl *step, dbl *last); 29 | #endif 30 | -------------------------------------------------------------------------------- /src/mal/modules/iterator.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | module iterator; 8 | 9 | command new(b:bat[:any_2], size:lng) (:lng,:bat[:any_2]) 10 | address ITRnewChunk 11 | comment "Create an iterator with fixed granule size. 12 | The result is a view."; 13 | 14 | command next(b:bat[:any_2], size:lng) (:lng, :bat[:any_2]) 15 | address ITRnextChunk 16 | comment "Produce the next chunk for processing."; 17 | 18 | pattern new(b:bat[:any_2]) (h:oid, t:any_2) 19 | address ITRbunIterator 20 | comment "Process the buns one by one extracted from a void table."; 21 | 22 | pattern next(b:bat[:any_2]) (h:oid, t:any_2) 23 | address ITRbunNext 24 | comment "Produce the next bun for processing."; 25 | 26 | command next(step:oid,last:oid):oid 27 | address ITRnext_oid; 28 | command next(step:sht,last:sht):sht 29 | address ITRnext_sht; 30 | command next(step:int,last:int):int 31 | address ITRnext_int; 32 | command next(step:lng,last:lng):lng 33 | address ITRnext_lng; 34 | command next(step:flt,last:flt):flt 35 | address ITRnext_flt; 36 | command next(step:dbl,last:dbl):dbl 37 | address ITRnext_dbl 38 | comment "Advances the iterator with a fixed value"; 39 | -------------------------------------------------------------------------------- /src/mal/modules/language.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | /* 10 | * @+ Dummy code 11 | */ 12 | #ifndef _LANGUAGE_H 13 | #define _LANGUAGE_H 14 | #include "mal.h" 15 | #include "mal_module.h" 16 | #include "mal_session.h" 17 | #include "mal_resolve.h" 18 | #include "mal_client.h" 19 | #include "mal_interpreter.h" 20 | #include "mal_dataflow.h" 21 | 22 | mal_export str CMDraise(str *ret, str *msg); 23 | mal_export str MALassertBit(void *ret, bit *val, str *msg); 24 | mal_export str MALassertStr(void *ret, str *val, str *msg); 25 | mal_export str MALassertOid(void *ret, oid *val, str *msg); 26 | mal_export str MALassertSht(void *ret, sht *val, str *msg); 27 | mal_export str MALassertInt(void *ret, int *val, str *msg); 28 | mal_export str MALassertLng(void *ret, lng *val, str *msg); 29 | #ifdef HAVE_HGE 30 | mal_export str MALassertHge(void *ret, hge *val, str *msg); 31 | #endif 32 | mal_export str MALstartDataflow( Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 33 | mal_export str MALpass( Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 34 | mal_export str MALgarbagesink( Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 35 | mal_export str CMDregisterFunction(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 36 | mal_export str CMDcallString(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 37 | mal_export str CMDcallFunction(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 38 | mal_export str CMDcallBAT(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 39 | mal_export str CMDevalFile(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 40 | mal_export str MALassertTriple(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); 41 | #endif /* _LANGUAGE_H */ 42 | -------------------------------------------------------------------------------- /src/mal/modules/language.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | module language; 8 | 9 | pattern call(s:str):void 10 | address CMDcallString 11 | comment "Evaluate a MAL string program."; 12 | pattern call(m:str,f:str):void 13 | address CMDcallFunction; 14 | pattern call(s:bat[:str]):void 15 | address CMDcallBAT 16 | comment "Evaluate a program stored in a BAT."; 17 | pattern source(f:str):void 18 | address CMDevalFile 19 | comment "Merge the instructions stored in the file with the current program."; 20 | 21 | unsafe command raise(msg:str) :str 22 | address CMDraise 23 | comment "Raise an exception labeled 24 | with a specific message."; 25 | unsafe command assert(v:bit,term:str):void 26 | address MALassertBit; 27 | unsafe command assert(v:sht,term:str):void 28 | address MALassertSht; 29 | unsafe command assert(v:int,term:str):void 30 | address MALassertInt; 31 | unsafe command assert(v:lng,term:str):void 32 | address MALassertLng; 33 | unsafe command assert(v:str,term:str):void 34 | address MALassertStr; 35 | unsafe command assert(v:oid,term:str):void 36 | address MALassertOid; 37 | unsafe pattern assert(v:any_1,pname:str,oper:str,val:any_2):void 38 | address MALassertTriple 39 | comment "Assertion test."; 40 | 41 | pattern dataflow():bit 42 | address MALstartDataflow 43 | comment "The current guarded block is executed using dataflow control. "; 44 | 45 | pattern sink(v:any...):void 46 | address MALgarbagesink 47 | comment "Variables to be considered together when triggering garbage collection. 48 | Used in the dataflow blocks to avoid early release of values."; 49 | 50 | pattern pass(v:any_1) 51 | address MALpass 52 | comment "Cheap instruction to disgard storage while retaining the dataflow dependency"; 53 | 54 | pattern block(v:int,w:any...):int 55 | address deblockdataflow 56 | comment "Block on availability of all variables w, and then pass on v"; 57 | 58 | pattern register(m:str,f:str,code:str,help:str):void 59 | address CMDregisterFunction 60 | comment"Compile the code string to MAL and register it as a function."; 61 | -------------------------------------------------------------------------------- /src/mal/modules/mal_init.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | # (c) Martin Kersten 8 | # MAL Startup file 9 | # Upon starting the Monet/MAL server we need to initialize the symbol table. 10 | # This encompasses loading the signatures of several key modules. 11 | # They are listed below. 12 | # 13 | # Beware, since libraries are loaded dynamically, there is an implicit 14 | # dependency. For example, the mapi module initializer uses the bat module. 15 | # It should be loaded after the bat module. 16 | # 17 | # The negative effect is that this module is inspected as part of 18 | # the function resolution scheme. 19 | # 20 | # The remainder interprets the signatures and resolves the address bindings. 21 | # The signatures may exists without the corresponding function implementation 22 | # to be loaded. This way, MAL programs can be normally compiled, and only 23 | # upon use of the function will it create the necessary exception. 24 | # 25 | # The order of the includes defines the dependencies. 26 | include mmath; 27 | # The kernel stuff to make it work 28 | include bat5; 29 | include batExtensions; 30 | include algebra; 31 | include orderidx; 32 | #include calc; --- moved to autoload/01_calc 33 | include status; 34 | include groupby; 35 | include group; 36 | include aggr; 37 | include mkey; 38 | 39 | # Atom extensions 40 | include blob; 41 | include str; 42 | include mtime; 43 | 44 | # The hardwired multiplex extensions 45 | include batmmath; 46 | #include batcalc; -- moved to autoload/01_batcalc 47 | include batmtime; 48 | include batstr; 49 | 50 | # MAL related extensions 51 | include pcre; 52 | include bbp; 53 | include manifold; 54 | 55 | include mat; 56 | include manual; 57 | include language; 58 | 59 | include profiler; 60 | include querylog; 61 | include sysmon; 62 | include sample; 63 | 64 | include optimizer; 65 | 66 | include iterator; 67 | 68 | 69 | # Any extensions (MAL scripts) that should be automatically loaded upon 70 | # startup can be placed in the autoload directory. One typically finds 71 | # the SQL module in here, but it can also be used to load custom scripts. 72 | include autoload; 73 | -------------------------------------------------------------------------------- /src/mal/modules/manifold.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | /* 10 | * M. Kersten 11 | * Default multiplex operator implementation 12 | */ 13 | #ifndef _MANIFOLD_LIB_ 14 | #define _MANIFOLD_LIB_ 15 | #include 16 | 17 | #include "mal.h" 18 | #include "mal_exception.h" 19 | #include "mal_interpreter.h" 20 | 21 | /* #define _DEBUG_MANIFOLD_*/ 22 | 23 | mal_export MALfcn MANIFOLDtypecheck(Client cntxt, MalBlkPtr mb, InstrPtr pci, int checkprops); 24 | mal_export str MANIFOLDevaluate(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 25 | mal_export str MANIFOLDremapMultiplex(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); 26 | 27 | #endif /* _MANIFOLD_LIB_ */ 28 | -------------------------------------------------------------------------------- /src/mal/modules/manifold.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | module mal; 8 | module batmal; 9 | 10 | pattern mal.multiplex(mod:str,fcn:str,a:any...):any... 11 | address MANIFOLDremapMultiplex; 12 | 13 | pattern batmal.multiplex(mod:str,fcn:str,a:any...):any... 14 | address MANIFOLDremapMultiplex; 15 | 16 | pattern mal.manifold(mod:str,fcn:str, a:any...):bat[:any] 17 | address MANIFOLDevaluate; 18 | -------------------------------------------------------------------------------- /src/mal/modules/mat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _MAT_H 10 | #define _MAT_H 11 | 12 | #include "mal_resolve.h" 13 | #include "mal_exception.h" 14 | #include "mal_interpreter.h" 15 | 16 | mal_export str MATpack(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); 17 | mal_export str MATpackIncrement(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); 18 | mal_export str MATpackValues(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); 19 | 20 | #endif /* _MAT_H */ 21 | -------------------------------------------------------------------------------- /src/mal/modules/mat.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | module mat; 8 | 9 | pattern new(b:bat[:any_2]...):bat[:any_2] 10 | address MATpack 11 | comment "Define a Merge Association Table (MAT). Fall back to the pack operation 12 | when this is called "; 13 | 14 | pattern pack(:any_2...):bat[:any_2] 15 | address MATpackValues 16 | comment "Materialize the MAT (of values) into a BAT"; 17 | 18 | pattern pack(b:bat[:any_2]...):bat[:any_2] 19 | address MATpack 20 | comment "Materialize the MAT into a BAT"; 21 | 22 | pattern packIncrement(b:bat[:any_2],pieces:int):bat[:any_2] 23 | address MATpackIncrement 24 | comment "Prepare incremental mat pack"; 25 | 26 | pattern packIncrement(b:bat[:any_2],c:bat[:any_2]):bat[:any_2] 27 | address MATpackIncrement 28 | comment "Prepare incremental mat pack"; 29 | -------------------------------------------------------------------------------- /src/mal/modules/mkey.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | module mkey; 8 | 9 | command rotate(v:lng, nbits:int) :lng 10 | address MKEYrotate 11 | comment "left-rotate an int by nbits"; 12 | 13 | pattern hash(v:any):lng 14 | address MKEYhash 15 | comment "calculate a hash value"; 16 | 17 | pattern hash(v:bit):lng 18 | address MKEYhash 19 | comment "calculate a hash value"; 20 | pattern hash(v:bte):lng 21 | address MKEYhash 22 | comment "calculate a hash value"; 23 | pattern hash(v:sht):lng 24 | address MKEYhash 25 | comment "calculate a hash value"; 26 | pattern hash(v:int):lng 27 | address MKEYhash 28 | comment "calculate a hash value"; 29 | pattern hash(v:flt):lng 30 | address MKEYhash 31 | comment "calculate a hash value"; 32 | pattern hash(v:dbl):lng 33 | address MKEYhash 34 | comment "calculate a hash value"; 35 | pattern hash(v:lng):lng 36 | address MKEYhash 37 | comment "calculate a hash value"; 38 | pattern hash(v:str):lng 39 | address MKEYhash 40 | comment "calculate a hash value"; 41 | 42 | pattern bulk_rotate_xor_hash(h:lng, nbits:int, v:any) :lng 43 | address MKEYrotate_xor_hash 44 | comment "post: [:xor=]([:rotate=](h, nbits), [hash](b))"; 45 | 46 | command bulk_rotate_xor_hash(h:lng, nbits:int, b:bat[:any_1]) 47 | :bat[:lng] 48 | address MKEYconstbulk_rotate_xor_hash 49 | comment "pre: h and b should be synced on head 50 | post: [:xor=]([:rotate=](h, nbits), [hash](b))"; 51 | 52 | pattern bulk_rotate_xor_hash(h:bat[:lng], nbits:int, v:any) 53 | :bat[:lng] 54 | address MKEYbulkconst_rotate_xor_hash 55 | comment "pre: h and b should be synced on head 56 | post: [:xor=]([:rotate=](h, nbits), [hash](b))"; 57 | 58 | command bulk_rotate_xor_hash(h:bat[:lng], nbits:int, b:bat[:any_1]) 59 | :bat[:lng] 60 | address MKEYbulk_rotate_xor_hash 61 | comment "pre: h and b should be synced on head 62 | post: [:xor=]([:rotate=](h, nbits), [hash](b))"; 63 | 64 | module batmkey; 65 | 66 | command hash(b:bat[:any_1]) :bat[:lng] 67 | address MKEYbathash 68 | comment "calculate a hash value"; 69 | -------------------------------------------------------------------------------- /src/mal/modules/mmath.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef __MMATH_H__ 10 | #define __MMATH_H__ 11 | #include "mal.h" 12 | #include "mal_exception.h" 13 | 14 | #define unopbaseM5_export(X1,X2)\ 15 | mal_export str MATHunary##X1##X2(X2 *res, const X2 *a); 16 | 17 | #define unopM5_export(X1)\ 18 | unopbaseM5_export(X1,dbl)\ 19 | unopbaseM5_export(X1,flt) 20 | 21 | #define binopbaseM5_export(X1,X2,X3)\ 22 | mal_export str MATHbinary##X1##X2(X2 *res, const X2 *a, const X3 *b); 23 | 24 | #define binopM5_export(X1)\ 25 | binopbaseM5_export(X1,dbl,dbl)\ 26 | binopbaseM5_export(X1,flt,flt) 27 | 28 | unopM5_export(_ACOS) 29 | unopM5_export(_ASIN) 30 | unopM5_export(_ATAN) 31 | binopM5_export(_ATAN2) 32 | unopM5_export(_COS) 33 | unopM5_export(_SIN) 34 | unopM5_export(_TAN) 35 | unopM5_export(_COT) 36 | 37 | unopM5_export(_COSH) 38 | unopM5_export(_SINH) 39 | unopM5_export(_TANH) 40 | unopM5_export(_RADIANS) 41 | unopM5_export(_DEGREES) 42 | 43 | unopM5_export(_EXP) 44 | unopM5_export(_LOG) 45 | unopM5_export(_LOG10) 46 | 47 | binopM5_export(_POW) 48 | unopM5_export(_SQRT) 49 | unopM5_export(_CBRT) 50 | 51 | unopM5_export(_CEIL) 52 | unopbaseM5_export(_FABS,dbl) 53 | unopM5_export(_FLOOR) 54 | binopbaseM5_export(_ROUND,dbl,int) 55 | binopbaseM5_export(_ROUND,flt,int) 56 | 57 | mal_export str MATHunary_ISNAN(bit *res, const dbl *a); 58 | mal_export str MATHunary_ISINF(int *res, const dbl *a); 59 | mal_export str MATHunary_FINITE(bit *res, const dbl *a); 60 | mal_export str MATHrandint(int *res); 61 | mal_export str MATHrandintarg(int *res, const int *dummy); 62 | mal_export str MATHsrandint(void *ret, const int *seed); 63 | mal_export str MATHsqlrandint(int *res, const int *seed); 64 | mal_export str MATHpi(dbl *pi); 65 | #endif /* __MMATH_H__ */ 66 | -------------------------------------------------------------------------------- /src/mal/modules/orderidx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _OIDX_H 10 | #define _OIDX_H 11 | 12 | #include "mal.h" 13 | #include "mal_builder.h" 14 | #include "mal_instruction.h" 15 | #include "mal_interpreter.h" 16 | #include "mal_namespace.h" 17 | 18 | #ifdef WIN32 19 | #if !defined(LIBMAL) && !defined(LIBATOMS) && !defined(LIBKERNEL) && !defined(LIBMAL) && !defined(LIBOPTIMIZER) && !defined(LIBSCHEDULER) && !defined(LIBMONETDB5) 20 | #define orderidx_export extern __declspec(dllimport) 21 | #else 22 | #define orderidx_export extern __declspec(dllexport) 23 | #endif 24 | #else 25 | #define orderidx_export extern 26 | #endif 27 | 28 | //#define _DEBUG_OIDX_ 29 | orderidx_export str OIDXcreate(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 30 | orderidx_export str OIDXcreateImplementation(Client cntxt, int tpe, BAT *b, int pieces); 31 | orderidx_export str OIDXdropImplementation(Client cntxt, BAT *b); 32 | orderidx_export str OIDXorderidx(bat *ret, const bat *bid, const bit *stable); 33 | orderidx_export str OIDXmerge(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 34 | orderidx_export str OIDXhasorderidx(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 35 | orderidx_export str OIDXgetorderidx(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 36 | #endif /* _OIDX_H */ 37 | -------------------------------------------------------------------------------- /src/mal/modules/orderidx.mal: -------------------------------------------------------------------------------- 1 | pattern bat.orderidx(bv:bat[:any_1]):void 2 | address OIDXcreate 3 | comment "Introduces the OID index arrangement of ordered values"; 4 | 5 | pattern bat.orderidx(bv:bat[:any_1], pieces:int):void 6 | address OIDXcreate 7 | comment "Introduces the OID index arrangement of ordered values"; 8 | 9 | pattern bat.orderidx(bv:bat[:any_1], l:bat[:any_1]...):void 10 | address OIDXmerge 11 | comment "Consolidates the OID index arrangement"; 12 | 13 | pattern bat.hasorderidx(bv:bat[:any_1]):bit 14 | address OIDXhasorderidx 15 | comment "Return true if order index exists"; 16 | 17 | pattern bat.getorderidx(bv:bat[:any_1]):bat[:oid] 18 | address OIDXgetorderidx 19 | comment "Return the order index if it exists"; 20 | 21 | command algebra.orderidx(bv:bat[:any_1], stable:bit):bat[:any_1] 22 | address OIDXorderidx 23 | comment "Create an order index"; 24 | -------------------------------------------------------------------------------- /src/mal/modules/projectionpath.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #include "monetdb_config.h" 10 | #include "projectionpath.h" 11 | 12 | str 13 | ALGprojectionpath(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) 14 | { 15 | int i, top = 0; 16 | bat *bid; 17 | bat *r = getArgReference_bat(stk, pci, 0); 18 | BAT *b, **joins = (BAT**)GDKzalloc(pci->argc * sizeof(BAT*)); 19 | int error = 0; 20 | 21 | (void) mb; 22 | (void) cntxt; 23 | 24 | assert(pci->argc > 1); 25 | if ( joins == NULL) 26 | throw(MAL, "algebra.projectionpath", SQLSTATE(HY001) MAL_MALLOC_FAIL); 27 | for (i = pci->retc; i < pci->argc; i++) { 28 | bid = getArgReference_bat(stk, pci, i); 29 | b = BATdescriptor(*bid); 30 | if (b == NULL) { 31 | error = 1; 32 | } else { 33 | if (i + 1 < pci->argc && ATOMtype(b->ttype) != TYPE_oid) { 34 | error = 1; 35 | } 36 | else joins[top++] = b; 37 | } 38 | if (error) { 39 | while (top-- > 0) 40 | BBPunfix(joins[top]->batCacheid); 41 | GDKfree(joins); 42 | throw(MAL, "algebra.projectionpath", "%s", b ? SEMANTIC_TYPE_MISMATCH : INTERNAL_BAT_ACCESS); 43 | } 44 | } 45 | joins[top] = NULL; 46 | b = BATprojectchain(joins); 47 | while (top-- > 0) 48 | BBPunfix(joins[top]->batCacheid); 49 | GDKfree(joins); 50 | if ( b) 51 | BBPkeepref( *r = b->batCacheid); 52 | else 53 | throw(MAL, "algebra.projectionpath", INTERNAL_OBJ_CREATE); 54 | return MAL_SUCCEED; 55 | } 56 | -------------------------------------------------------------------------------- /src/mal/modules/projectionpath.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _OPT_PROJECTIONPATH_ 10 | #define _OPT_PROJECTIONPATH_ 11 | 12 | #include "mal_client.h" 13 | #include "mal_interpreter.h" 14 | 15 | mal_export str ALGprojectionpath(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/mal/modules/sample.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | /* 10 | * @a Lefteris Sidirourgos 11 | * @d 30/08/2011 12 | * @+ The sampling facilities 13 | */ 14 | 15 | #ifndef _SAMPLE_H_ 16 | #define _SAMPLE_H_ 17 | 18 | #include "mal.h" 19 | 20 | /* #define _DEBUG_SAMPLE_ */ 21 | 22 | mal_export str 23 | SAMPLEuniform(bat *r, bat *b, lng *s); 24 | 25 | mal_export str 26 | SAMPLEuniform_dbl(bat *r, bat *b, dbl *p); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/mal/modules/sample.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | # 8 | # @a Lefteris Sidirourgos 9 | # @d 30/08/2011 10 | # @+ The sampling facilities 11 | # 12 | 13 | module sample; 14 | 15 | command subuniform(b:bat[:any],s:lng):bat[:oid] 16 | address SAMPLEuniform 17 | comment "Returns the oids of a uniform sample of size s"; 18 | 19 | command subuniform(b:bat[:any],p:dbl):bat[:oid] 20 | address SAMPLEuniform_dbl 21 | comment "Returns the oids of a uniform sample of size = (p x count(b)), where 0 <= p <= 1.0"; 22 | -------------------------------------------------------------------------------- /src/mal/modules/tablet.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | module tablet; 8 | #currently empty 9 | -------------------------------------------------------------------------------- /src/mal/optimizer/opt_aliases.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _OPT_ALIASES_ 10 | #define _OPT_ALIASES_ 11 | #include "opt_prelude.h" 12 | #include "opt_support.h" 13 | #include "mal_exception.h" 14 | 15 | mal_export int OPTisAlias(InstrPtr p); 16 | mal_export void OPTaliasRemap(InstrPtr p, int *alias); 17 | mal_export str OPTaliasesImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/mal/optimizer/opt_candidates.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _OPT_CANDIDATES_ 10 | #define _OPT_CANDIDATES_ 11 | #include "opt_prelude.h" 12 | #include "opt_support.h" 13 | #include "mal_exception.h" 14 | 15 | mal_export str OPTcandidatesImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/mal/optimizer/opt_coercion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _OPT_COERCION_ 10 | #define _OPT_COERCION_ 11 | #include "opt_prelude.h" 12 | #include "mal_interpreter.h" 13 | #include "opt_support.h" 14 | 15 | mal_export str OPTcoercionImplementation(Client cntxt,MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/mal/optimizer/opt_commonTerms.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _OPT_COMMONTERMS_ 10 | #define _OPT_COMMONTERMS_ 11 | #include "opt_prelude.h" 12 | #include "opt_support.h" 13 | 14 | 15 | mal_export str OPTcommonTermsImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 16 | 17 | /* #define DEBUG_OPT_COMMONTERMS_MORE */ 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/mal/optimizer/opt_constants.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _OPT_CONSTANTS_ 10 | #define _OPT_CONSTANTS_ 11 | #include "opt_prelude.h" 12 | #include "opt_support.h" 13 | #include "mal_exception.h" 14 | 15 | mal_export str OPTconstantsImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/mal/optimizer/opt_costModel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _OPT_COSTMODEL_H_ 10 | #define _OPT_COSTMODEL_H_ 11 | 12 | #include "mal.h" 13 | #include 14 | #include "mal_interpreter.h" 15 | #include "opt_support.h" 16 | #include "opt_prelude.h" 17 | 18 | mal_export str OPTcostModelImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 19 | 20 | #endif /* _OPT_COSTMODEL_H_ */ 21 | -------------------------------------------------------------------------------- /src/mal/optimizer/opt_dataflow.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _OPT_DATAFLOW_ 10 | #define _OPT_DATAFLOW_ 11 | #include "opt_prelude.h" 12 | #include "opt_support.h" 13 | 14 | mal_export str OPTdataflowImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/mal/optimizer/opt_deadcode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _OPT_DEADCODE_ 10 | #define _OPT_DEADCODE_ 11 | #include "opt_prelude.h" 12 | #include "opt_support.h" 13 | #include "mal_interpreter.h" 14 | #include "mal_instruction.h" 15 | #include "mal_function.h" 16 | 17 | mal_export str OPTdeadcodeImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/mal/optimizer/opt_emptybind.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _MAL_EMPTYBIND_ 10 | #define _MAL_EMPTYBIND_ 11 | #include "opt_prelude.h" 12 | #include "opt_support.h" 13 | 14 | mal_export str OPTemptybindImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); 15 | 16 | #define OPTDEBUGemptybind if ( optDebug & ((lng) 1 <usermodule, putName(modnme), fcnnme); 67 | if (s == NULL) 68 | throw(MAL, "optimizer.optimize", SQLSTATE(HY002) SEMANTIC_OPERATION_MISSING); 69 | removeInstruction(mb, pci); 70 | addtoMalBlkHistory(s->def); 71 | return optimizeMALBlock(cntxt, s->def); 72 | } 73 | 74 | -------------------------------------------------------------------------------- /src/mal/optimizer/optimizer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _OPTIMIZER_H 10 | #define _OPTIMIZER_H 11 | /* #define OPTIMIZER_DEBUG*/ 12 | 13 | #include "mal_interpreter.h" 14 | #include "mal_scenario.h" 15 | #include "mal_namespace.h" 16 | #include "opt_support.h" 17 | #include "opt_prelude.h" 18 | 19 | mal_export str optimizer_prelude(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); 20 | mal_export str QOToptimize(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 21 | 22 | #endif /* _OPTIMIZER_H */ 23 | -------------------------------------------------------------------------------- /src/mal/optimizer/optimizer_private.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | /* This file should not be included in any file outside of this directory */ 10 | 11 | #ifndef LIBOPTIMIZER 12 | #error this file should not be included outside its source directory 13 | #endif 14 | 15 | void optimizerInit(void); 16 | void optPipeInit(void); 17 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/40_sql.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | # This loads the MonetDB/SQL module 8 | include sql; 9 | include sqlcatalog; 10 | include sql_transaction; 11 | include wlr; 12 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/41_sql_hge.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | # This loads the 128-bit support for the MonetDB/SQL module 8 | include sql_hge; 9 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/mal_backend.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #include "monetdb_config.h" 10 | #include "sql.h" 11 | #include "mal_backend.h" 12 | 13 | backend * 14 | backend_reset(backend *b) 15 | { 16 | b->out = b->client->fdout; 17 | b->language = 0; 18 | b->depth = 0; 19 | 20 | b->vtop = 0; 21 | b->q = NULL; 22 | b->mb = NULL; 23 | b->mvc_var = 0; 24 | b->output_format = OFMT_CSV; 25 | return b; 26 | } 27 | 28 | backend * 29 | backend_create(mvc *m, Client c) 30 | { 31 | backend *b = MNEW(backend); 32 | 33 | if( b== NULL) 34 | return NULL; 35 | b->console = isAdministrator(c); 36 | b->mvc = m; 37 | b->client = c; 38 | b->mvc_var = 0; 39 | b->output_format = OFMT_CSV; 40 | return backend_reset(b); 41 | } 42 | 43 | void 44 | backend_destroy(backend *b) 45 | { 46 | _DELETE(b); 47 | } 48 | 49 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/mal_backend.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef MAL_BACKEND_H 10 | #define MAL_BACKEND_H 11 | 12 | #include "mal.h" 13 | #include "mal_client.h" 14 | #include "sql_mvc.h" 15 | #include "sql_qc.h" 16 | 17 | /* 18 | * The back-end structure collects the information needed to support 19 | * compilation and execution of the SQL code against the Monet Version 5 20 | * back end. Note that the back-end can be called upon by the front-end 21 | * to handle specific tasks, such as catalog management (sql_mvc) 22 | * and query execution (sql_qc). For this purpose, the front-end needs 23 | * access to operations defined in the back-end, in particular for 24 | * freeing the stack and code segment. 25 | */ 26 | 27 | typedef enum output_format { 28 | OFMT_CSV = 0, 29 | OFMT_JSON = 1, 30 | OFMT_NONE = 3 31 | } ofmt; 32 | 33 | typedef struct backend { 34 | char console; 35 | char language; /* 'S' or 's' or 'X' */ 36 | char depth; 37 | mvc *mvc; 38 | stream *out; 39 | ofmt output_format; /* csv, json */ 40 | Client client; 41 | MalBlkPtr mb; /* needed during mal generation */ 42 | int mvc_var; 43 | int vtop; /* top of the variable stack before the current function */ 44 | cq *q; /* pointer to the cached query */ 45 | } backend; 46 | 47 | extern backend *backend_reset(backend *b); 48 | extern backend *backend_create(mvc *m, Client c); 49 | extern void backend_destroy(backend *b); 50 | 51 | #endif /*MAL_BACKEND_H*/ 52 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/rel_bin.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _REL_BIN_H_ 10 | #define _REL_BIN_H_ 11 | 12 | #include "rel_semantic.h" 13 | #include "sql_statement.h" 14 | #include "mal_backend.h" 15 | 16 | extern stmt * output_rel_bin(backend *be, sql_rel *rel); 17 | 18 | extern stmt * sql_parse(backend *be, sql_allocator *sa, char *query, char mode); 19 | 20 | extern list *rel_dependencies(sql_allocator *sa, sql_rel *r); 21 | 22 | #endif /*_REL_BIN_H_*/ 23 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_aggr_bte.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | function aggr.covar(e1:bat[:bte], e2:bat[:bte]):dbl; 8 | e0:bat[:sht] := batcalc.*(e1,e2); 9 | s0:dbl := aggr.avg(e0); 10 | # ignore "mutual" NILs: 11 | e1n := algebra.select(e1, nil:bte,nil:bte,false,false,false); 12 | e12n := algebra.select(e1,e1n,nil:bte,nil:bte,false,false,false); 13 | s1:dbl := batcalc.avg(e1,e12n); 14 | s2:dbl := batcalc.avg(e2,e12n); 15 | s3:dbl := calc.*(s1,s2); 16 | v:dbl := calc.-(s0,s3); 17 | return v; 18 | end aggr.covar; 19 | 20 | function aggr.corr(e1:bat[:bte], e2:bat[:bte]):dbl; 21 | cv := aggr.covar(e1,e2); 22 | sd1 := aggr.stdev(e1); 23 | sd2 := aggr.stdev(e2); 24 | sd := calc.*(sd1,sd2); 25 | sdn := calc.==(sd,0:dbl); 26 | sds := calc.ifthenelse(sdn,nil:dbl,sd); 27 | res := calc./(cv,sds); 28 | return res; 29 | end aggr.corr; 30 | 31 | function aggr.subcovar(e1:bat[:bte], e2:bat[:bte], g:bat[:oid], e:bat[:any_2], f:bit):bat[:dbl]; 32 | e0:bat[:sht] := batcalc.*(e1,e2); 33 | s0:bat[:dbl] := aggr.subavg(e0,g,e,f,true); 34 | # ignore "mutual" NILs: 35 | t := calc.not(f); 36 | e1n := algebra.select(e1, nil:bte,nil:bte,t,t,false); 37 | e12n := algebra.select(e1,e1n,nil:bte,nil:bte,t,t,false); 38 | s1:bat[:dbl] := aggr.subavg(e1,g,e,e12n,f,true); 39 | s2:bat[:dbl] := aggr.subavg(e2,g,e,e12n,f,true); 40 | s3:bat[:dbl] := batcalc.*(s1,s2); 41 | v:bat[:dbl] := batcalc.-(s0,s3); 42 | return v; 43 | end aggr.subcovar; 44 | 45 | function aggr.subcorr(e1:bat[:bte], e2:bat[:bte], g:bat[:oid],e:bat[:any_2], f:bit):bat[:dbl]; 46 | cv := aggr.subcovar(e1,e2,g,e,f); 47 | sd1 := aggr.substdevp(e1,g,e,f,true); 48 | sd2 := aggr.substdevp(e2,g,e,f,true); 49 | sd := batcalc.*(sd1,sd2); 50 | sdn := batcalc.==(sd,0:dbl); 51 | sds := batcalc.ifthenelse(sdn,nil:dbl,sd); 52 | res := batcalc./(cv,sds); 53 | return res; 54 | end aggr.subcorr; 55 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_aggr_dbl.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | function aggr.covar(e1:bat[:dbl], e2:bat[:dbl]):dbl; 8 | e0:bat[:dbl] := batcalc.*(e1,e2); 9 | s0:dbl := aggr.avg(e0); 10 | # ignore "mutual" NILs: 11 | e1n := algebra.select(e1, nil:dbl,nil:dbl,false,false,false); 12 | e12n := algebra.select(e1,e1n,nil:dbl,nil:dbl,false,false,false); 13 | s1:dbl := batcalc.avg(e1,e12n); 14 | s2:dbl := batcalc.avg(e2,e12n); 15 | s3:dbl := calc.*(s1,s2); 16 | v:dbl := calc.-(s0,s3); 17 | return v; 18 | end aggr.covar; 19 | 20 | function aggr.corr(e1:bat[:dbl], e2:bat[:dbl]):dbl; 21 | cv := aggr.covar(e1,e2); 22 | sd1 := aggr.stdev(e1); 23 | sd2 := aggr.stdev(e2); 24 | sd := calc.*(sd1,sd2); 25 | sdn := calc.==(sd,0:dbl); 26 | sds := calc.ifthenelse(sdn,nil:dbl,sd); 27 | res := calc./(cv,sds); 28 | return res; 29 | end aggr.corr; 30 | 31 | function aggr.subcovar(e1:bat[:dbl], e2:bat[:dbl], g:bat[:oid], e:bat[:any_2], f:bit):bat[:dbl]; 32 | e0:bat[:dbl] := batcalc.*(e1,e2); 33 | s0:bat[:dbl] := aggr.subavg(e0,g,e,f,true); 34 | # ignore "mutual" NILs: 35 | t := calc.not(f); 36 | e1n := algebra.select(e1, nil:dbl,nil:dbl,t,t,false); 37 | e12n := algebra.select(e1,e1n,nil:dbl,nil:dbl,t,t,false); 38 | s1:bat[:dbl] := aggr.subavg(e1,g,e,e12n,f,true); 39 | s2:bat[:dbl] := aggr.subavg(e2,g,e,e12n,f,true); 40 | s3:bat[:dbl] := batcalc.*(s1,s2); 41 | v:bat[:dbl] := batcalc.-(s0,s3); 42 | return v; 43 | end aggr.subcovar; 44 | 45 | function aggr.subcorr(e1:bat[:dbl], e2:bat[:dbl], g:bat[:oid],e:bat[:any_2], f:bit):bat[:dbl]; 46 | cv := aggr.subcovar(e1,e2,g,e,f); 47 | sd1 := aggr.substdevp(e1,g,e,f,true); 48 | sd2 := aggr.substdevp(e2,g,e,f,true); 49 | sd := batcalc.*(sd1,sd2); 50 | sdn := batcalc.==(sd,0:dbl); 51 | sds := batcalc.ifthenelse(sdn,nil:dbl,sd); 52 | res := batcalc./(cv,sds); 53 | return res; 54 | end aggr.subcorr; 55 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_aggr_flt.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | function aggr.covar(e1:bat[:flt], e2:bat[:flt]):dbl; 8 | e0:bat[:dbl] := batcalc.*(e1,e2); 9 | s0:dbl := aggr.avg(e0); 10 | # ignore "mutual" NILs: 11 | e1n := algebra.select(e1, nil:flt,nil:flt,false,false,false); 12 | e12n := algebra.select(e1,e1n,nil:flt,nil:flt,false,false,false); 13 | s1:dbl := batcalc.avg(e1,e12n); 14 | s2:dbl := batcalc.avg(e2,e12n); 15 | s3:dbl := calc.*(s1,s2); 16 | v:dbl := calc.-(s0,s3); 17 | return v; 18 | end aggr.covar; 19 | 20 | function aggr.corr(e1:bat[:flt], e2:bat[:flt]):dbl; 21 | cv := aggr.covar(e1,e2); 22 | sd1 := aggr.stdev(e1); 23 | sd2 := aggr.stdev(e2); 24 | sd := calc.*(sd1,sd2); 25 | sdn := calc.==(sd,0:dbl); 26 | sds := calc.ifthenelse(sdn,nil:dbl,sd); 27 | res := calc./(cv,sds); 28 | return res; 29 | end aggr.corr; 30 | 31 | function aggr.subcovar(e1:bat[:flt], e2:bat[:flt], g:bat[:oid], e:bat[:any_2], f:bit):bat[:dbl]; 32 | e0:bat[:dbl] := batcalc.*(e1,e2); 33 | s0:bat[:dbl] := aggr.subavg(e0,g,e,f,true); 34 | # ignore "mutual" NILs: 35 | t := calc.not(f); 36 | e1n := algebra.select(e1, nil:flt,nil:flt,t,t,false); 37 | e12n := algebra.select(e1,e1n,nil:flt,nil:flt,t,t,false); 38 | s1:bat[:dbl] := aggr.subavg(e1,g,e,e12n,f,true); 39 | s2:bat[:dbl] := aggr.subavg(e2,g,e,e12n,f,true); 40 | s3:bat[:dbl] := batcalc.*(s1,s2); 41 | v:bat[:dbl] := batcalc.-(s0,s3); 42 | return v; 43 | end aggr.subcovar; 44 | 45 | function aggr.subcorr(e1:bat[:flt], e2:bat[:flt], g:bat[:oid],e:bat[:any_2], f:bit):bat[:dbl]; 46 | cv := aggr.subcovar(e1,e2,g,e,f); 47 | sd1 := aggr.substdevp(e1,g,e,f,true); 48 | sd2 := aggr.substdevp(e2,g,e,f,true); 49 | sd := batcalc.*(sd1,sd2); 50 | sdn := batcalc.==(sd,0:dbl); 51 | sds := batcalc.ifthenelse(sdn,nil:dbl,sd); 52 | res := batcalc./(cv,sds); 53 | return res; 54 | end aggr.subcorr; 55 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_aggr_hge.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | function aggr.covar(e1:bat[:hge], e2:bat[:hge]):dbl; 8 | e0:bat[:hge] := batcalc.*(e1,e2); 9 | s0:dbl := aggr.avg(e0); 10 | # ignore "mutual" NILs: 11 | e1n := algebra.select(e1, nil:hge,nil:hge,false,false,false); 12 | e12n := algebra.select(e1,e1n,nil:hge,nil:hge,false,false,false); 13 | s1:dbl := batcalc.avg(e1,e12n); 14 | s2:dbl := batcalc.avg(e2,e12n); 15 | s3:dbl := calc.*(s1,s2); 16 | v:dbl := calc.-(s0,s3); 17 | return v; 18 | end aggr.covar; 19 | 20 | function aggr.corr(e1:bat[:hge], e2:bat[:hge]):dbl; 21 | cv := aggr.covar(e1,e2); 22 | sd1 := aggr.stdev(e1); 23 | sd2 := aggr.stdev(e2); 24 | sd := calc.*(sd1,sd2); 25 | sdn := calc.==(sd,0:dbl); 26 | sds := calc.ifthenelse(sdn,nil:dbl,sd); 27 | res := calc./(cv,sds); 28 | return res; 29 | end aggr.corr; 30 | 31 | function aggr.subcovar(e1:bat[:hge], e2:bat[:hge], g:bat[:oid], e:bat[:any_2], f:bit):bat[:dbl]; 32 | e0:bat[:hge] := batcalc.*(e1,e2); 33 | s0:bat[:dbl] := aggr.subavg(e0,g,e,f,true); 34 | # ignore "mutual" NILs: 35 | t := calc.not(f); 36 | e1n := algebra.select(e1, nil:hge,nil:hge,t,t,false); 37 | e12n := algebra.select(e1,e1n,nil:hge,nil:hge,t,t,false); 38 | s1:bat[:dbl] := aggr.subavg(e1,g,e,e12n,f,true); 39 | s2:bat[:dbl] := aggr.subavg(e2,g,e,e12n,f,true); 40 | s3:bat[:dbl] := batcalc.*(s1,s2); 41 | v:bat[:dbl] := batcalc.-(s0,s3); 42 | return v; 43 | end aggr.subcovar; 44 | 45 | function aggr.subcorr(e1:bat[:hge], e2:bat[:hge], g:bat[:oid],e:bat[:any_2], f:bit):bat[:dbl]; 46 | cv := aggr.subcovar(e1,e2,g,e,f); 47 | sd1 := aggr.substdevp(e1,g,e,f,true); 48 | sd2 := aggr.substdevp(e2,g,e,f,true); 49 | sd := batcalc.*(sd1,sd2); 50 | sdn := batcalc.==(sd,0:dbl); 51 | sds := batcalc.ifthenelse(sdn,nil:dbl,sd); 52 | res := batcalc./(cv,sds); 53 | return res; 54 | end aggr.subcorr; 55 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_aggr_int.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | function aggr.covar(e1:bat[:int], e2:bat[:int]):dbl; 8 | e0:bat[:lng] := batcalc.*(e1,e2); 9 | s0:dbl := aggr.avg(e0); 10 | # ignore "mutual" NILs: 11 | e1n := algebra.select(e1, nil:int,nil:int,false,false,false); 12 | e12n := algebra.select(e1,e1n,nil:int,nil:int,false,false,false); 13 | s1:dbl := batcalc.avg(e1,e12n); 14 | s2:dbl := batcalc.avg(e2,e12n); 15 | s3:dbl := calc.*(s1,s2); 16 | v:dbl := calc.-(s0,s3); 17 | return v; 18 | end aggr.covar; 19 | 20 | function aggr.corr(e1:bat[:int], e2:bat[:int]):dbl; 21 | cv := aggr.covar(e1,e2); 22 | sd1 := aggr.stdev(e1); 23 | sd2 := aggr.stdev(e2); 24 | sd := calc.*(sd1,sd2); 25 | sdn := calc.==(sd,0:dbl); 26 | sds := calc.ifthenelse(sdn,nil:dbl,sd); 27 | res := calc./(cv,sds); 28 | return res; 29 | end aggr.corr; 30 | 31 | function aggr.subcovar(e1:bat[:int], e2:bat[:int], g:bat[:oid], e:bat[:any_2], f:bit):bat[:dbl]; 32 | e0:bat[:lng] := batcalc.*(e1,e2); 33 | s0:bat[:dbl] := aggr.subavg(e0,g,e,f,true); 34 | # ignore "mutual" NILs: 35 | t := calc.not(f); 36 | e1n := algebra.select(e1, nil:int,nil:int,t,t,false); 37 | e12n := algebra.select(e1,e1n,nil:int,nil:int,t,t,false); 38 | s1:bat[:dbl] := aggr.subavg(e1,g,e,e12n,f,true); 39 | s2:bat[:dbl] := aggr.subavg(e2,g,e,e12n,f,true); 40 | s3:bat[:dbl] := batcalc.*(s1,s2); 41 | v:bat[:dbl] := batcalc.-(s0,s3); 42 | return v; 43 | end aggr.subcovar; 44 | 45 | function aggr.subcorr(e1:bat[:int], e2:bat[:int], g:bat[:oid],e:bat[:any_2], f:bit):bat[:dbl]; 46 | cv := aggr.subcovar(e1,e2,g,e,f); 47 | sd1 := aggr.substdevp(e1,g,e,f,true); 48 | sd2 := aggr.substdevp(e2,g,e,f,true); 49 | sd := batcalc.*(sd1,sd2); 50 | sdn := batcalc.==(sd,0:dbl); 51 | sds := batcalc.ifthenelse(sdn,nil:dbl,sd); 52 | res := batcalc./(cv,sds); 53 | return res; 54 | end aggr.subcorr; 55 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_aggr_lng.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | function aggr.covar(e1:bat[:lng], e2:bat[:lng]):dbl; 8 | # TODO: 9 | # replace lng by hge in case we have hge to avoid overflow 10 | e0:bat[:lng] := batcalc.*(e1,e2); 11 | s0:dbl := aggr.avg(e0); 12 | # ignore "mutual" NILs: 13 | e1n := algebra.select(e1, nil:lng,nil:lng,false,false,false); 14 | e12n := algebra.select(e1,e1n,nil:lng,nil:lng,false,false,false); 15 | s1:dbl := batcalc.avg(e1,e12n); 16 | s2:dbl := batcalc.avg(e2,e12n); 17 | s3:dbl := calc.*(s1,s2); 18 | v:dbl := calc.-(s0,s3); 19 | return v; 20 | end aggr.covar; 21 | 22 | function aggr.corr(e1:bat[:lng], e2:bat[:lng]):dbl; 23 | cv := aggr.covar(e1,e2); 24 | sd1 := aggr.stdev(e1); 25 | sd2 := aggr.stdev(e2); 26 | sd := calc.*(sd1,sd2); 27 | sdn := calc.==(sd,0:dbl); 28 | sds := calc.ifthenelse(sdn,nil:dbl,sd); 29 | res := calc./(cv,sds); 30 | return res; 31 | end aggr.corr; 32 | 33 | function aggr.subcovar(e1:bat[:lng], e2:bat[:lng], g:bat[:oid], e:bat[:any_2], f:bit):bat[:dbl]; 34 | e0:bat[:lng] := batcalc.*(e1,e2); # ? lng -> hge ? 35 | s0:bat[:dbl] := aggr.subavg(e0,g,e,f,true); 36 | # ignore "mutual" NILs: 37 | t := calc.not(f); 38 | e1n := algebra.select(e1, nil:lng,nil:lng,t,t,false); 39 | e12n := algebra.select(e1,e1n,nil:lng,nil:lng,t,t,false); 40 | s1:bat[:dbl] := aggr.subavg(e1,g,e,e12n,f,true); 41 | s2:bat[:dbl] := aggr.subavg(e2,g,e,e12n,f,true); 42 | s3:bat[:dbl] := batcalc.*(s1,s2); 43 | v:bat[:dbl] := batcalc.-(s0,s3); 44 | return v; 45 | end aggr.subcovar; 46 | 47 | function aggr.subcorr(e1:bat[:lng], e2:bat[:lng], g:bat[:oid],e:bat[:any_2], f:bit):bat[:dbl]; 48 | cv := aggr.subcovar(e1,e2,g,e,f); 49 | sd1 := aggr.substdevp(e1,g,e,f,true); 50 | sd2 := aggr.substdevp(e2,g,e,f,true); 51 | sd := batcalc.*(sd1,sd2); 52 | sdn := batcalc.==(sd,0:dbl); 53 | sds := batcalc.ifthenelse(sdn,nil:dbl,sd); 54 | res := batcalc./(cv,sds); 55 | return res; 56 | end aggr.subcorr; 57 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_aggr_sht.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | function aggr.covar(e1:bat[:sht], e2:bat[:sht]):dbl; 8 | e0:bat[:int] := batcalc.*(e1,e2); 9 | s0:dbl := aggr.avg(e0); 10 | # ignore "mutual" NILs: 11 | e1n := algebra.select(e1, nil:sht,nil:sht,false,false,false); 12 | e12n := algebra.select(e1,e1n,nil:sht,nil:sht,false,false,false); 13 | s1:dbl := batcalc.avg(e1,e12n); 14 | s2:dbl := batcalc.avg(e2,e12n); 15 | s3:dbl := calc.*(s1,s2); 16 | v:dbl := calc.-(s0,s3); 17 | return v; 18 | end aggr.covar; 19 | 20 | function aggr.corr(e1:bat[:sht], e2:bat[:sht]):dbl; 21 | cv := aggr.covar(e1,e2); 22 | sd1 := aggr.stdev(e1); 23 | sd2 := aggr.stdev(e2); 24 | sd := calc.*(sd1,sd2); 25 | sdn := calc.==(sd,0:dbl); 26 | sds := calc.ifthenelse(sdn,nil:dbl,sd); 27 | res := calc./(cv,sds); 28 | return res; 29 | end aggr.corr; 30 | 31 | function aggr.subcovar(e1:bat[:sht], e2:bat[:sht], g:bat[:oid], e:bat[:any_2], f:bit):bat[:dbl]; 32 | e0:bat[:int] := batcalc.*(e1,e2); 33 | s0:bat[:dbl] := aggr.subavg(e0,g,e,f,true); 34 | # ignore "mutual" NILs: 35 | t := calc.not(f); 36 | e1n := algebra.select(e1, nil:sht,nil:sht,t,t,false); 37 | e12n := algebra.select(e1,e1n,nil:sht,nil:sht,t,t,false); 38 | s1:bat[:dbl] := aggr.subavg(e1,g,e,e12n,f,true); 39 | s2:bat[:dbl] := aggr.subavg(e2,g,e,e12n,f,true); 40 | s3:bat[:dbl] := batcalc.*(s1,s2); 41 | v:bat[:dbl] := batcalc.-(s0,s3); 42 | return v; 43 | end aggr.subcovar; 44 | 45 | function aggr.subcorr(e1:bat[:sht], e2:bat[:sht], g:bat[:oid],e:bat[:any_2], f:bit):bat[:dbl]; 46 | cv := aggr.subcovar(e1,e2,g,e,f); 47 | sd1 := aggr.substdevp(e1,g,e,f,true); 48 | sd2 := aggr.substdevp(e2,g,e,f,true); 49 | sd := batcalc.*(sd1,sd2); 50 | sdn := batcalc.==(sd,0:dbl); 51 | sds := batcalc.ifthenelse(sdn,nil:dbl,sd); 52 | res := batcalc./(cv,sds); 53 | return res; 54 | end aggr.subcorr; 55 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _SQL_ASSERT_H_ 10 | #define _SQL_ASSERT_H_ 11 | #include "sql.h" 12 | 13 | sql5_export str SQLassert(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 14 | sql5_export str SQLassertInt(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 15 | sql5_export str SQLassertLng(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 16 | #ifdef HAVE_HGE 17 | sql5_export str SQLassertHge(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 18 | #endif 19 | 20 | #endif /* _SQL_ASSERT_H_ */ 21 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_execute.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _SQL_EXECUTE_H_ 10 | #define _SQL_EXECUTE_H_ 11 | #include "sql.h" 12 | 13 | sql5_export str SQLstatementIntern(Client c, str *expr, str nme, bit execute, bit output, res_table **result); 14 | sql5_export str SQLengineIntern(Client c, backend *be); 15 | sql5_export str RAstatement(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 16 | sql5_export str RAstatement2(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 17 | sql5_export void SQLdestroyResult(res_table *destroy); 18 | 19 | #endif /* _SQL_EXECUTE_H_ */ 20 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_fround.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #include "monetdb_config.h" 10 | #include "sql.h" 11 | #include "sql_result.h" 12 | #include "sql_gencode.h" 13 | #include "sql_storage.h" 14 | #include "sql_scenario.h" 15 | #include "store_sequence.h" 16 | #include "sql_datetime.h" 17 | #include "rel_optimizer.h" 18 | #include "rel_distribute.h" 19 | #include "rel_select.h" 20 | #include "rel_exp.h" 21 | #include "rel_dump.h" 22 | #include "mal_instruction.h" 23 | 24 | #define CONCAT_2(a, b) a##b 25 | #define CONCAT_3(a, b, c) a##b##c 26 | 27 | #define NIL(t) CONCAT_2(t, _nil) 28 | #define ISNIL(t) CONCAT_3(is_, t, _nil) 29 | #define TPE(t) CONCAT_2(TYPE_, t) 30 | #define GDKmin(t) CONCAT_3(GDK_, t, _min) 31 | #define GDKmax(t) CONCAT_3(GDK_, t, _max) 32 | #define FUN(a, b) CONCAT_3(a, _, b) 33 | 34 | #define STRING(a) #a 35 | 36 | #define TYPE flt 37 | #include "sql_fround_impl.h" 38 | #undef TYPE 39 | 40 | #define TYPE dbl 41 | #include "sql_fround_impl.h" 42 | #undef TYPE 43 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_gencode.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _SQL2MAL_H 10 | #define _SQL2MAL_H 11 | 12 | #include "sql.h" 13 | #include "mal_backend.h" 14 | #include "sql_atom.h" 15 | #include "sql_statement.h" 16 | #include "sql_env.h" 17 | #include "sql_mvc.h" 18 | #include "mal_function.h" 19 | 20 | sql5_export Symbol backend_dumpproc(backend *be, Client c, cq *q, sql_rel *r); 21 | sql5_export int backend_callinline(backend *be, Client c); 22 | sql5_export int backend_dumpstmt(backend *be, MalBlkPtr mb, sql_rel *r, int top, int addend, char *query); 23 | sql5_export void backend_call(backend *be, Client c, cq *q); 24 | sql5_export void initSQLreferences(void); 25 | sql5_export int monet5_resolve_function(ptr M, sql_func *f); 26 | sql5_export int backend_create_func(backend *be, sql_func *f, list *restypes, list *ops); 27 | extern int backend_create_subfunc(backend *be, sql_subfunc *f, list *ops); 28 | extern int backend_create_subaggr(backend *be, sql_subaggr *f); 29 | 30 | sql5_export int monet5_create_relational_function(mvc *m, const char *mod, const char *name, sql_rel *rel, stmt *call, list *rel_ops, int inline_func); 31 | 32 | extern void _rel_print(mvc *sql, sql_rel *rel); 33 | 34 | extern int constantAtom(backend *be, MalBlkPtr mb, atom *a); 35 | extern InstrPtr table_func_create_result(MalBlkPtr mb, InstrPtr q, sql_func *f, list *restypes); 36 | extern InstrPtr relational_func_create_result(mvc *sql, MalBlkPtr mb, InstrPtr q, sql_rel *f); 37 | 38 | #endif /* _SQL2MAL_H */ 39 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_inspect.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | 8 | command sql_environment() (name:bat[:str],value:bat[:str]) 9 | address INSPECTgetEnvironment 10 | comment "Collect the environment variables."; -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_optimizer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _SQL_OPTIMIZER_H_ 10 | #define _SQL_OPTIMIZER_H_ 11 | #include "sql.h" 12 | 13 | //#define _SQL_OPTIMIZER_DEBUG 14 | sql5_export str SQLoptimizeQuery(Client c, MalBlkPtr mb); 15 | sql5_export str SQLoptimizeFunction(Client c, MalBlkPtr mb); 16 | sql5_export void SQLaddQueryToCache(Client c); 17 | sql5_export str SQLoptimizer(Client c); 18 | sql5_export void SQLsetAccessMode(Client c); 19 | sql5_export str getSQLoptimizer(mvc *m); 20 | 21 | #endif /* _SQL_OPTIMIZER_H_ */ 22 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_orderidx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | /* (co) M.L. Kersten */ 10 | #ifndef _SQL_ORDERIDX_DEF 11 | #define _SQL_ORDERIDX_DEF 12 | 13 | /* #define DEBUG_SQL_ORDERIDX */ 14 | 15 | #include "sql.h" 16 | 17 | sql5_export str sql_createorderindex(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 18 | sql5_export str sql_droporderindex(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 19 | 20 | #endif /* _SQL_ORDERIDX_DEF */ 21 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_rank.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _SQL_RANK_H 10 | #define _SQL_RANK_H 11 | 12 | #include "sql.h" 13 | 14 | sql5_export str SQLdiff(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 15 | sql5_export str SQLrow_number(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 16 | sql5_export str SQLrank(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 17 | sql5_export str SQLdense_rank(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 18 | 19 | #endif /* _SQL_RANK_H */ 20 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_rank.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | module sql; 8 | 9 | pattern sql.diff(b:any_1) :bit 10 | address SQLdiff 11 | comment "return true if cur != prev row"; 12 | 13 | pattern batsql.diff(b:bat[:any_1]) :bat[:bit] 14 | address SQLdiff 15 | comment "return true if cur != prev row"; 16 | 17 | pattern sql.diff(p:bit, b:any_1) :bit 18 | address SQLdiff 19 | comment "return true if cur != prev row"; 20 | 21 | pattern batsql.diff(p:bat[:bit], b:bat[:any_1]) :bat[:bit] 22 | address SQLdiff 23 | comment "return true if cur != prev row"; 24 | 25 | 26 | pattern sql.row_number(b:any_1, p:bit, o:bit) :int 27 | address SQLrow_number 28 | comment "return the row_numer-ed groups"; 29 | 30 | pattern batsql.row_number(b:bat[:any_1], p:any_2, o:any_3) :bat[:int] 31 | address SQLrow_number 32 | comment "return the row_numer-ed groups"; 33 | 34 | pattern sql.rank(b:any_1, p:bit, o:bit) :int 35 | address SQLrank 36 | comment "return the ranked groups"; 37 | 38 | pattern batsql.rank(b:bat[:any_1], p:any_2, o:any_3) :bat[:int] 39 | address SQLrank 40 | comment "return the ranked groups"; 41 | 42 | pattern sql.dense_rank(b:any_1, p:bit, o:bit) :int 43 | address SQLdense_rank 44 | comment "return the densely ranked groups"; 45 | 46 | pattern batsql.dense_rank(b:bat[:any_1], p:any_2, o:any_3) :bat[:int] 47 | address SQLdense_rank 48 | comment "return the densely ranked groups"; 49 | 50 | command aggr.exist(b:bat[:any_2], h:any_1):bit 51 | address ALGexist; 52 | 53 | command aggr.exist(b:bat[:any_2]):bit 54 | address SQLexist; 55 | 56 | pattern aggr.exist(v:any_2):bit 57 | address SQLexist_val; 58 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_result.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef sql_result_H 10 | #define sql_result_H 11 | 12 | #include "mal_client.h" 13 | #include "stream.h" 14 | #include "sql.h" 15 | #include "sql_mvc.h" 16 | #include "sql_catalog.h" 17 | #include "sql_qc.h" 18 | #include "sql_parser.h" /* sql_error */ 19 | 20 | extern int mvc_export_affrows(backend *b, stream *s, lng val, str w, oid query_id, lng starttime, lng maloptimizer); 21 | extern int mvc_export_operation(backend *b, stream *s, str w, lng starttime, lng maloptimizer); 22 | extern int mvc_export_result(backend *b, stream *s, int res_id, lng starttime, lng maloptimizer); 23 | extern int mvc_export_head(backend *b, stream *s, int res_id, int only_header, int compute_lengths, lng starttime, lng maloptimizer); 24 | extern int mvc_export_chunk(backend *b, stream *s, int res_id, BUN offset, BUN nr); 25 | 26 | extern int mvc_export_prepare(mvc *c, stream *s, cq *q, str w); 27 | 28 | extern str mvc_import_table(Client cntxt, BAT ***bats, mvc *c, bstream *s, sql_table *t, char *sep, char *rsep, char *ssep, char *ns, lng nr, lng offset, int locked, int best); 29 | extern int mvc_result_table(mvc *m, oid query_id, int nr_cols, int type, BAT *order); 30 | 31 | extern int mvc_result_column(mvc *m, char *tn, char *name, char *typename, int digits, int scale, BAT *b); 32 | extern int mvc_result_value(mvc *m, const char *tn, const char *name, const char *typename, int digits, int scale, ptr *p, int mtype); 33 | 34 | extern int convert2str(mvc *m, int eclass, int d, int sc, int has_tz, ptr p, int mtype, char **buf, int len); 35 | 36 | #endif /* sql_result_H */ 37 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_round.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #include "monetdb_config.h" 10 | #include "sql.h" 11 | #include "sql_result.h" 12 | #include "sql_gencode.h" 13 | #include "sql_storage.h" 14 | #include "sql_scenario.h" 15 | #include "store_sequence.h" 16 | #include "sql_datetime.h" 17 | #include "rel_optimizer.h" 18 | #include "rel_distribute.h" 19 | #include "rel_select.h" 20 | #include "rel_exp.h" 21 | #include "rel_dump.h" 22 | #include "mal_instruction.h" 23 | 24 | #define CONCAT_2(a, b) a##b 25 | #define CONCAT_3(a, b, c) a##b##c 26 | 27 | #define NIL(t) CONCAT_2(t, _nil) 28 | #define ISNIL(t) CONCAT_3(is_, t, _nil) 29 | #define TPE(t) CONCAT_2(TYPE_, t) 30 | #define GDKmin(t) CONCAT_3(GDK_, t, _min) 31 | #define GDKmax(t) CONCAT_3(GDK_, t, _max) 32 | #define FUN(a, b) CONCAT_3(a, _, b) 33 | 34 | #define STRING(a) #a 35 | 36 | #define BIG lng /* a larger type */ 37 | 38 | #define TYPE bte 39 | #include "sql_round_impl.h" 40 | #undef TYPE 41 | 42 | #define TYPE sht 43 | #include "sql_round_impl.h" 44 | #undef TYPE 45 | 46 | #define TYPE int 47 | #include "sql_round_impl.h" 48 | #undef TYPE 49 | 50 | #define TYPE lng 51 | #include "sql_round_impl.h" 52 | #undef TYPE 53 | 54 | #ifdef HAVE_HGE 55 | #undef BIG 56 | #define BIG hge 57 | #define TYPE hge 58 | #include "sql_round_impl.h" 59 | #undef TYPE 60 | #endif 61 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_statistics.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | /* (co) M.L. Kersten */ 10 | #ifndef _SQL_STATISTICS_DEF 11 | #define _SQL_STATISTICS_DEF 12 | 13 | /* #define DEBUG_SQL_STATISTICS */ 14 | 15 | #include "sql.h" 16 | 17 | sql5_export str sql_analyze(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 18 | 19 | #endif /* _SQL_STATISTICS_DEF */ 20 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_transaction.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | /* 10 | * (author) M Kersten, N Nes 11 | */ 12 | #ifndef _SQL_TRANSACTION_H 13 | #define _SQL_TRANSACTION_H 14 | 15 | #include "sql.h" 16 | #include "mal_backend.h" 17 | #include "sql_atom.h" 18 | #include "sql_statement.h" 19 | #include "sql_env.h" 20 | #include "sql_mvc.h" 21 | #include "mal_function.h" 22 | 23 | sql5_export str SQLtransaction_begin(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) ; 24 | sql5_export str SQLtransaction_release(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) ; 25 | sql5_export str SQLtransaction_commit(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) ; 26 | sql5_export str SQLtransaction_abort(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) ; 27 | sql5_export str SQLtransaction_rollback(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) ; 28 | sql5_export str SQLtransaction(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) ; 29 | 30 | #endif /* _SQL_TRANSACTION_H */ 31 | 32 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_transaction.mal: -------------------------------------------------------------------------------- 1 | # This Source Code Form is subject to the terms of the Mozilla Public 2 | # License, v. 2.0. If a copy of the MPL was not distributed with this 3 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | # Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | module sql; 8 | 9 | pattern transaction_release(chain:int,name:str):void 10 | address SQLtransaction_release 11 | comment "A transaction statement (type can be commit,release,rollback or start)"; 12 | 13 | pattern transaction_commit(chain:int,name:str):void 14 | address SQLtransaction_commit 15 | comment "A transaction statement (type can be commit,release,rollback or start)"; 16 | 17 | pattern transaction_rollback(chain:int,name:str):void 18 | address SQLtransaction_rollback 19 | comment "A transaction statement (type can be commit,release,rollback or start)"; 20 | 21 | pattern transaction_begin(chain:int,name:str):void 22 | address SQLtransaction_begin 23 | comment "A transaction statement (type can be commit,release,rollback or start)"; 24 | 25 | unsafe pattern transaction() 26 | address SQLtransaction2 27 | comment "Start an autocommit transaction"; 28 | 29 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_upgrades.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _SQL_UPGRADES_H_ 10 | #define _SQL_UPGRADES_H_ 11 | #include "sql.h" 12 | 13 | sql5_export void SQLupgrades(Client c, mvc *m); 14 | 15 | #endif /* _SQL_UPGRADES_H_ */ 16 | -------------------------------------------------------------------------------- /src/mal/sqlbackend/sql_user.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _SQL_USER_H_ 10 | #define _SQL_USER_H_ 11 | #include "sql.h" /* includes sql_backend.h */ 12 | 13 | sql5_export void monet5_user_init(backend_functions *be_funcs); 14 | sql5_export str monet5_user_set_def_schema(mvc *m, oid user /* mal user id */); 15 | sql5_export str monet5_user_get_def_schema(mvc *m, int user /* sql user id */); 16 | 17 | #endif /* _SQL_USER_H_ */ 18 | -------------------------------------------------------------------------------- /src/sql/common/sql_changeset.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #include "monetdb_config.h" 10 | #include "sql_catalog.h" 11 | 12 | void 13 | cs_new(changeset * cs, sql_allocator *sa, fdestroy destroy) 14 | { 15 | cs->sa = sa; 16 | cs->destroy = destroy; 17 | cs->set = NULL; 18 | cs->dset = NULL; 19 | cs->nelm = NULL; 20 | } 21 | 22 | void 23 | cs_destroy(changeset * cs) 24 | { 25 | if (cs->set) { 26 | list_destroy(cs->set); 27 | cs->set = NULL; 28 | } 29 | if (cs->dset) { 30 | list_destroy(cs->dset); 31 | cs->dset = NULL; 32 | } 33 | } 34 | 35 | void 36 | cs_add(changeset * cs, void *elm, int flag) 37 | { 38 | if (!cs->set) 39 | cs->set = list_new(cs->sa, cs->destroy); 40 | list_append(cs->set, elm); 41 | if (flag == TR_NEW && !cs->nelm) 42 | cs->nelm = cs->set->t; 43 | } 44 | 45 | void 46 | cs_add_before(changeset * cs, node *n, void *elm) 47 | { 48 | list_append_before(cs->set, n, elm); 49 | } 50 | 51 | void 52 | cs_del(changeset * cs, node *elm, int flag) 53 | { 54 | if (flag == TR_NEW) { /* remove just added */ 55 | if (cs->nelm == elm) 56 | cs->nelm = elm->next; 57 | list_remove_node(cs->set, elm); 58 | } else { 59 | if (!cs->dset) 60 | cs->dset = list_new(cs->sa, cs->destroy); 61 | list_move_data(cs->set, cs->dset, elm->data); 62 | } 63 | } 64 | 65 | int 66 | cs_size(changeset * cs) 67 | { 68 | if (cs->set) 69 | return list_length(cs->set); 70 | return 0; 71 | } 72 | 73 | node * 74 | cs_first_node(changeset * cs) 75 | { 76 | return cs->set->h; 77 | } 78 | 79 | node * 80 | cs_last_node(changeset * cs) 81 | { 82 | return cs->set->t; 83 | } 84 | 85 | void 86 | cs_remove_node(changeset * cs, node *n) 87 | { 88 | node *nxt = n->next; 89 | 90 | list_remove_node(cs->set, n); 91 | if (cs->nelm == n) 92 | cs->nelm = nxt; 93 | } 94 | -------------------------------------------------------------------------------- /src/sql/common/sql_hash.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #include "monetdb_config.h" 10 | #include "sql_mem.h" 11 | #include "sql_hash.h" 12 | 13 | static unsigned int 14 | log_base2(unsigned int n) 15 | { 16 | unsigned int l ; 17 | 18 | for (l = 0; n; l++) 19 | n >>= 1 ; 20 | return l ; 21 | } 22 | 23 | 24 | sql_hash * 25 | hash_new(sql_allocator *sa, int size, fkeyvalue key) 26 | { 27 | int i; 28 | sql_hash *ht = SA_ZNEW(sa, sql_hash); 29 | 30 | if (ht == NULL) 31 | return NULL; 32 | ht->sa = sa; 33 | ht->size = (1<key = key; 35 | ht->buckets = SA_NEW_ARRAY(sa, sql_hash_e*, ht->size); 36 | for(i = 0; i < ht->size; i++) 37 | ht->buckets[i] = NULL; 38 | return ht; 39 | } 40 | 41 | sql_hash_e* 42 | hash_add(sql_hash *h, int key, void *value) 43 | { 44 | sql_hash_e *e = SA_ZNEW(h->sa, sql_hash_e); 45 | 46 | if (e == NULL) 47 | return NULL; 48 | e->chain = h->buckets[key&(h->size-1)]; 49 | h->buckets[key&(h->size-1)] = e; 50 | e->key = key; 51 | e->value = value; 52 | return e; 53 | } 54 | 55 | void 56 | hash_del(sql_hash *h, int key, void *value) 57 | { 58 | sql_hash_e *e = h->buckets[key&(h->size-1)], *p = NULL; 59 | 60 | while (e && (e->key != key || e->value != value)) { 61 | p = e; 62 | e = e->chain; 63 | } 64 | if (e) { 65 | if (p) 66 | p->chain = e->chain; 67 | else 68 | h->buckets[key&(h->size-1)] = e->chain; 69 | } 70 | } 71 | 72 | unsigned int 73 | hash_key(const char *k) 74 | { 75 | unsigned int h = 0; 76 | 77 | while (*k) { 78 | h += *k; 79 | h += (h << 10); 80 | h ^= (h >> 6); 81 | k++; 82 | } 83 | h += (h << 3); 84 | h ^= (h >> 11); 85 | h += (h << 15); 86 | return h; 87 | } 88 | -------------------------------------------------------------------------------- /src/sql/common/sql_stack.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #include "monetdb_config.h" 10 | #include "sql_stack.h" 11 | 12 | sql_stack * 13 | sql_stack_new(sql_allocator *sa, int size) 14 | { 15 | sql_stack *s = SA_NEW(sa, sql_stack); 16 | if (s == NULL) 17 | return NULL; 18 | 19 | s -> sa = sa; 20 | s -> size = size; 21 | s -> top = 0; 22 | s -> values = SA_NEW_ARRAY(sa, void*, size); 23 | if (s->values == NULL) { 24 | _DELETE(s); 25 | return NULL; 26 | } 27 | s -> values[s->top++] = NULL; 28 | return s; 29 | } 30 | 31 | void 32 | sql_stack_push(sql_stack *s, void *v) 33 | { 34 | if (s->top >= s->size) { 35 | size_t osz = s->size; 36 | s->size *= 2; 37 | s->values = SA_RENEW_ARRAY(s->sa, void*, s->values, s->size, osz); 38 | if (s->values == NULL) 39 | return; 40 | } 41 | s->values[s->top++] = v; 42 | } 43 | 44 | void * 45 | sql_stack_pop(sql_stack *s) 46 | { 47 | return s->values[--s->top]; 48 | } 49 | -------------------------------------------------------------------------------- /src/sql/common/sql_string.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _SQL_STRING_H_ 10 | #define _SQL_STRING_H_ 11 | 12 | #define D__SQL 16 13 | 14 | #define _(String) (String) 15 | #define N_(String) (String) 16 | 17 | extern char *mkLower(char *v); 18 | extern char *toLower(const char *v); 19 | extern char *toUpper(const char *v); 20 | extern char *strconcat(const char *s1, const char *s2); 21 | extern char *strip_extra_zeros(char *v); 22 | extern char *sql2str(char *s); 23 | extern char *sql_strdup(char *s); 24 | extern char *sql_escape_str(char *s); 25 | extern const char *sql_escape_ident(const char *s); 26 | extern char *sql_message(_In_z_ _Printf_format_string_ const char *format, ...) 27 | __attribute__((__format__(__printf__, 1, 2))); 28 | extern char *sa_message(sql_allocator *sa, _In_z_ _Printf_format_string_ const char *format, ...) 29 | __attribute__((__format__(__printf__, 2, 3))); 30 | 31 | #endif /*_SQL_STRING_H_*/ 32 | 33 | -------------------------------------------------------------------------------- /src/sql/include/sql_hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef SQL_HASH_H 10 | #define SQL_HASH_H 11 | 12 | /* sql_hash implementation 13 | * used to optimize search in expression and statement lists 14 | */ 15 | 16 | #include "sql_mem.h" 17 | 18 | #define HASH_MIN_SIZE 4 19 | 20 | typedef int (*fkeyvalue) (void *data); 21 | 22 | typedef struct sql_hash_e { 23 | int key; 24 | void *value; 25 | struct sql_hash_e *chain; 26 | } sql_hash_e; 27 | 28 | typedef struct sql_hash { 29 | sql_allocator *sa; 30 | int size; /* power of 2 */ 31 | sql_hash_e **buckets; 32 | fkeyvalue key; 33 | } sql_hash; 34 | 35 | extern sql_hash *hash_new(sql_allocator *sa, int size, fkeyvalue key); 36 | extern sql_hash_e *hash_add(sql_hash *ht, int key, void *value); 37 | extern void hash_del(sql_hash *ht, int key, void *value); 38 | 39 | extern unsigned int hash_key(const char *n); 40 | 41 | #endif /* SQL_HASH_H */ 42 | -------------------------------------------------------------------------------- /src/sql/include/sql_keyword.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef SQL_KEYWORD_H 10 | #define SQL_KEYWORD_H 11 | 12 | /* we need to define these here as the parser header file is generated to late. 13 | * The numbers get remapped in the scanner. 14 | */ 15 | #define KW_ALIAS 4000 16 | #define KW_TYPE 4001 17 | 18 | typedef struct keyword { 19 | char *keyword; 20 | int len; 21 | int token; 22 | struct keyword *next; 23 | } keyword; 24 | 25 | extern int keywords_insert(char *k, int token); 26 | extern keyword *find_keyword(char *text); 27 | extern int keyword_exists(char *text); 28 | 29 | extern void keyword_init(void); 30 | extern void keyword_exit(void); 31 | 32 | #endif /* SQL_KEYWORD_H */ 33 | -------------------------------------------------------------------------------- /src/sql/include/sql_query.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _SQL_QUERY_H_ 10 | #define _SQL_QUERY_H_ 11 | 12 | typedef enum sql_query_t { 13 | Q_PARSE = 0, 14 | Q_TABLE = 1, 15 | Q_UPDATE = 2, 16 | Q_SCHEMA = 3, 17 | Q_TRANS = 4, 18 | Q_PREPARE = 5, 19 | Q_BLOCK = 6 20 | } sql_query_t; 21 | 22 | #endif /* _SQL_QUERY_H_ */ 23 | -------------------------------------------------------------------------------- /src/sql/include/sql_stack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef SQL_STACK_H 10 | #define SQL_STACK_H 11 | 12 | /* sql_stack implementation 13 | * used by mvc structure for variable stack 14 | * trigger stack 15 | * Multi statement stack (intermediate results) 16 | * .... 17 | * stmt generation 18 | * stmt dependency (close to stmt generation) 19 | */ 20 | 21 | #include "sql_mem.h" 22 | 23 | typedef struct sql_stack { 24 | sql_allocator *sa; 25 | int size; 26 | int top; 27 | void **values; 28 | } sql_stack; 29 | 30 | extern sql_stack *sql_stack_new(sql_allocator *sa, int size); 31 | extern void sql_stack_push(sql_stack *s, void *v); 32 | extern void *sql_stack_pop(sql_stack *s); 33 | 34 | #endif /* SQL_STACK_H */ 35 | -------------------------------------------------------------------------------- /src/sql/scripts/09_like.sql: -------------------------------------------------------------------------------- 1 | -- This Source Code Form is subject to the terms of the Mozilla Public 2 | -- License, v. 2.0. If a copy of the MPL was not distributed with this 3 | -- file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -- 5 | -- Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | create filter function "like"(val string, pat string, esc string) external name algebra."like"; 8 | create filter function "ilike"(val string, pat string, esc string) external name algebra."ilike"; 9 | create filter function "like"(val string, pat string) external name algebra."like"; 10 | create filter function "ilike"(val string, pat string) external name algebra."ilike"; 11 | 12 | grant execute on filter function "like" (string, string, string) to public; 13 | grant execute on filter function "ilike" (string, string, string) to public; 14 | grant execute on filter function "like" (string, string) to public; 15 | grant execute on filter function "ilike" (string, string) to public; 16 | -------------------------------------------------------------------------------- /src/sql/scripts/10_math.sql: -------------------------------------------------------------------------------- 1 | -- This Source Code Form is subject to the terms of the Mozilla Public 2 | -- License, v. 2.0. If a copy of the MPL was not distributed with this 3 | -- file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -- 5 | -- Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | CREATE FUNCTION degrees(r double) 8 | RETURNS double 9 | RETURN r*180/pi(); 10 | 11 | CREATE FUNCTION radians(d double) 12 | RETURNS double 13 | RETURN d*pi()/180; 14 | 15 | grant execute on function degrees to public; 16 | grant execute on function radians to public; 17 | -------------------------------------------------------------------------------- /src/sql/scripts/11_times.sql: -------------------------------------------------------------------------------- 1 | -- This Source Code Form is subject to the terms of the Mozilla Public 2 | -- License, v. 2.0. If a copy of the MPL was not distributed with this 3 | -- file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -- 5 | -- Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | -- Provide a simple equivalent for the UNIX times command 8 | -- times 0 ms user 0 ms system 0 ms 0 reads 0 writes 9 | 10 | create procedure times() 11 | external name sql.times; 12 | 13 | grant execute on procedure times to public; 14 | -------------------------------------------------------------------------------- /src/sql/scripts/13_date.sql: -------------------------------------------------------------------------------- 1 | -- This Source Code Form is subject to the terms of the Mozilla Public 2 | -- License, v. 2.0. If a copy of the MPL was not distributed with this 3 | -- file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -- 5 | -- Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | create function str_to_date(s string, format string) returns date 8 | external name mtime."str_to_date"; 9 | 10 | create function date_to_str(d date, format string) returns string 11 | external name mtime."date_to_str"; 12 | 13 | create function str_to_time(s string, format string) returns time 14 | external name mtime."str_to_time"; 15 | 16 | create function time_to_str(d time, format string) returns string 17 | external name mtime."time_to_str"; 18 | 19 | create function str_to_timestamp(s string, format string) returns timestamp 20 | external name mtime."str_to_timestamp"; 21 | 22 | create function timestamp_to_str(d timestamp, format string) returns string 23 | external name mtime."timestamp_to_str"; 24 | 25 | grant execute on function str_to_date to public; 26 | grant execute on function date_to_str to public; 27 | grant execute on function str_to_time to public; 28 | grant execute on function time_to_str to public; 29 | grant execute on function str_to_timestamp to public; 30 | grant execute on function timestamp_to_str to public; 31 | -------------------------------------------------------------------------------- /src/sql/scripts/14_inet.sql: -------------------------------------------------------------------------------- 1 | -- This Source Code Form is subject to the terms of the Mozilla Public 2 | -- License, v. 2.0. If a copy of the MPL was not distributed with this 3 | -- file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -- 5 | -- Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | CREATE TYPE inet EXTERNAL NAME inet; 8 | 9 | CREATE FUNCTION "broadcast" (p inet) RETURNS inet 10 | EXTERNAL NAME inet."broadcast"; 11 | GRANT EXECUTE ON FUNCTION "broadcast"(inet) TO PUBLIC; 12 | CREATE FUNCTION "host" (p inet) RETURNS clob 13 | EXTERNAL NAME inet."host"; 14 | GRANT EXECUTE ON FUNCTION "host"(inet) TO PUBLIC; 15 | CREATE FUNCTION "masklen" (p inet) RETURNS int 16 | EXTERNAL NAME inet."masklen"; 17 | GRANT EXECUTE ON FUNCTION "masklen"(inet) TO PUBLIC; 18 | CREATE FUNCTION "setmasklen" (p inet, mask int) RETURNS inet 19 | EXTERNAL NAME inet."setmasklen"; 20 | GRANT EXECUTE ON FUNCTION "setmasklen"(inet, int) TO PUBLIC; 21 | CREATE FUNCTION "netmask" (p inet) RETURNS inet 22 | EXTERNAL NAME inet."netmask"; 23 | GRANT EXECUTE ON FUNCTION "netmask"(inet) TO PUBLIC; 24 | CREATE FUNCTION "hostmask" (p inet) RETURNS inet 25 | EXTERNAL NAME inet."hostmask"; 26 | GRANT EXECUTE ON FUNCTION "hostmask"(inet) TO PUBLIC; 27 | CREATE FUNCTION "network" (p inet) RETURNS inet 28 | EXTERNAL NAME inet."network"; 29 | GRANT EXECUTE ON FUNCTION "network"(inet) TO PUBLIC; 30 | CREATE FUNCTION "text" (p inet) RETURNS clob 31 | EXTERNAL NAME inet."text"; 32 | GRANT EXECUTE ON FUNCTION "text"(inet) TO PUBLIC; 33 | CREATE FUNCTION "abbrev" (p inet) RETURNS clob 34 | EXTERNAL NAME inet."abbrev"; 35 | GRANT EXECUTE ON FUNCTION "abbrev"(inet) TO PUBLIC; 36 | 37 | CREATE FUNCTION "left_shift"(i1 inet, i2 inet) RETURNS boolean 38 | EXTERNAL NAME inet."<<"; 39 | GRANT EXECUTE ON FUNCTION "left_shift"(inet, inet) TO PUBLIC; 40 | CREATE FUNCTION "right_shift"(i1 inet, i2 inet) RETURNS boolean 41 | EXTERNAL NAME inet.">>"; 42 | GRANT EXECUTE ON FUNCTION "right_shift"(inet, inet) TO PUBLIC; 43 | 44 | CREATE FUNCTION "left_shift_assign"(i1 inet, i2 inet) RETURNS boolean 45 | EXTERNAL NAME inet."<<="; 46 | GRANT EXECUTE ON FUNCTION "left_shift_assign"(inet, inet) TO PUBLIC; 47 | CREATE FUNCTION "right_shift_assign"(i1 inet, i2 inet) RETURNS boolean 48 | EXTERNAL NAME inet.">>="; 49 | GRANT EXECUTE ON FUNCTION "right_shift_assign"(inet, inet) TO PUBLIC; 50 | -------------------------------------------------------------------------------- /src/sql/scripts/16_tracelog.sql: -------------------------------------------------------------------------------- 1 | -- This Source Code Form is subject to the terms of the Mozilla Public 2 | -- License, v. 2.0. If a copy of the MPL was not distributed with this 3 | -- file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -- 5 | -- Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | -- make the offline tracing table available for inspection 8 | create function sys.tracelog() 9 | returns table ( 10 | event integer, -- event counter 11 | clk varchar(20), -- wallclock, no mtime in kernel 12 | pc varchar(50), -- module.function[nr] 13 | thread int, -- thread identifier 14 | ticks bigint, -- time in microseconds 15 | rrsMB bigint, -- resident memory in MB 16 | vmMB bigint, -- virtual size in MB 17 | reads bigint, -- number of blocks read 18 | writes bigint, -- number of blocks written 19 | minflt bigint, -- minor page faults 20 | majflt bigint, -- major page faults 21 | nvcsw bigint, -- non-volantary conext switch 22 | stmt string -- actual statement executed 23 | ) 24 | external name sql.dump_trace; 25 | 26 | create view sys.tracelog as select * from sys.tracelog(); 27 | -------------------------------------------------------------------------------- /src/sql/scripts/17_temporal.sql: -------------------------------------------------------------------------------- 1 | -- This Source Code Form is subject to the terms of the Mozilla Public 2 | -- License, v. 2.0. If a copy of the MPL was not distributed with this 3 | -- file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -- 5 | -- Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | -- assume milliseconds when converted to TIMESTAMP 8 | create function sys."epoch"(sec BIGINT) returns TIMESTAMP 9 | external name timestamp."epoch"; 10 | 11 | create function sys."epoch"(sec INT) returns TIMESTAMP 12 | external name timestamp."epoch"; 13 | 14 | create function sys."epoch"(ts TIMESTAMP) returns INT 15 | external name timestamp."epoch"; 16 | 17 | create function sys."epoch"(ts TIMESTAMP WITH TIME ZONE) returns INT 18 | external name timestamp."epoch"; 19 | 20 | grant execute on function sys."epoch" (BIGINT) to public; 21 | grant execute on function sys."epoch" (INT) to public; 22 | grant execute on function sys."epoch" (TIMESTAMP) to public; 23 | grant execute on function sys."epoch" (TIMESTAMP WITH TIME ZONE) to public; 24 | -------------------------------------------------------------------------------- /src/sql/scripts/18_index.sql: -------------------------------------------------------------------------------- 1 | -- This Source Code Form is subject to the terms of the Mozilla Public 2 | -- License, v. 2.0. If a copy of the MPL was not distributed with this 3 | -- file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -- 5 | -- Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | -- Experimental oid index 8 | 9 | create procedure sys.createorderindex(sys string, tab string, col string) 10 | external name sql.createorderindex; 11 | 12 | create procedure sys.droporderindex(sys string, tab string, col string) 13 | external name sql.droporderindex; 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/sql/scripts/20_vacuum.sql: -------------------------------------------------------------------------------- 1 | -- This Source Code Form is subject to the terms of the Mozilla Public 2 | -- License, v. 2.0. If a copy of the MPL was not distributed with this 3 | -- file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -- 5 | -- Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | -- Vacuum a relational table should be done with care. 8 | -- For, the oid's are used in join-indices. 9 | 10 | -- Vacuum of tables may improve IO performance and disk footprint. 11 | -- The foreign key constraints should be dropped before 12 | -- and re-established after the cluster operation. 13 | 14 | create procedure shrink(sys string, tab string) 15 | external name sql.shrink; 16 | 17 | create procedure reuse(sys string, tab string) 18 | external name sql.reuse; 19 | 20 | create procedure vacuum(sys string, tab string) 21 | external name sql.vacuum; 22 | 23 | -------------------------------------------------------------------------------- /src/sql/scripts/22_clients.sql: -------------------------------------------------------------------------------- 1 | -- This Source Code Form is subject to the terms of the Mozilla Public 2 | -- License, v. 2.0. If a copy of the MPL was not distributed with this 3 | -- file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -- 5 | -- Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | create function sys.password_hash (username string) 8 | returns string 9 | external name sql.password; 10 | 11 | create function sys.remote_table_credentials (tablename string) 12 | returns table ("uri" string, "username" string, "hash" string) 13 | external name sql.rt_credentials; 14 | 15 | create function sys.sessions() 16 | returns table("user" string, "login" timestamp, "sessiontimeout" bigint, "lastcommand" timestamp, "querytimeout" bigint, "active" bool) 17 | external name sql.sessions; 18 | create view sys.sessions as select * from sys.sessions(); 19 | 20 | create procedure sys.shutdown(delay tinyint) 21 | external name sql.shutdown; 22 | 23 | create procedure sys.shutdown(delay tinyint, force bool) 24 | external name sql.shutdown; 25 | 26 | -- control the query and session time out 27 | create procedure sys.settimeout("query" bigint) 28 | external name clients.settimeout; 29 | create procedure sys.settimeout("query" bigint, "session" bigint) 30 | external name clients.settimeout; 31 | create procedure sys.setsession("timeout" bigint) 32 | external name clients.setsession; 33 | -------------------------------------------------------------------------------- /src/sql/scripts/25_debug.sql: -------------------------------------------------------------------------------- 1 | -- This Source Code Form is subject to the terms of the Mozilla Public 2 | -- License, v. 2.0. If a copy of the MPL was not distributed with this 3 | -- file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -- 5 | -- Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | -- show the optimizer statistics maintained by the SQL frontend 8 | create function sys.optimizer_stats() 9 | returns table (optname string, count int, timing bigint) 10 | external name inspect.optimizer_stats; 11 | 12 | 13 | -- SQL QUERY CACHE 14 | -- The SQL query cache returns a table with the query plans kept 15 | 16 | create function sys.queryCache() 17 | returns table (query string, count int) 18 | external name sql.dump_cache; 19 | 20 | -- Trace the SQL input 21 | create procedure sys.querylog(filename string) 22 | external name sql.logfile; 23 | 24 | -- MONETDB KERNEL SECTION 25 | -- optimizer pipe catalog 26 | create function sys.optimizers () 27 | returns table (name string, def string, status string) 28 | external name sql.optimizers; 29 | create view sys.optimizers as select * from sys.optimizers(); 30 | 31 | -- The environment table 32 | create view sys.environment as select * from sys.env(); 33 | GRANT SELECT ON sys.environment TO PUBLIC; 34 | 35 | -- The BAT buffer pool overview 36 | create function sys.bbp () 37 | returns table (id int, name string, 38 | ttype string, count BIGINT, refcnt int, lrefcnt int, 39 | location string, heat int, dirty string, 40 | status string, kind string) 41 | external name bbp.get; 42 | 43 | create function sys.malfunctions() 44 | returns table("module" string, "function" string, "signature" string, "address" string, "comment" string) 45 | external name "manual"."functions"; 46 | 47 | create procedure sys.evalAlgebra( ra_stmt string, opt bool) 48 | external name sql."evalAlgebra"; 49 | 50 | -- enqueue a flush log, ie as soon as no transactions are active 51 | -- flush the log and cleanup the used storage 52 | create procedure sys.flush_log () 53 | external name sql."flush_log"; 54 | 55 | create function sys.debug(debug int) returns integer 56 | external name mdb."setDebug"; 57 | -------------------------------------------------------------------------------- /src/sql/scripts/26_sysmon.sql: -------------------------------------------------------------------------------- 1 | -- This Source Code Form is subject to the terms of the Mozilla Public 2 | -- License, v. 2.0. If a copy of the MPL was not distributed with this 3 | -- file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -- 5 | -- Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | -- System monitoring 8 | 9 | -- show status of all active SQL queries. 10 | create function sys.queue() 11 | returns table( 12 | qtag bigint, 13 | "user" string, 14 | started timestamp, 15 | estimate timestamp, 16 | progress int, 17 | status string, 18 | tag oid, 19 | query string 20 | ) 21 | external name sql.sysmon_queue; 22 | 23 | create view sys.queue as select * from sys.queue(); 24 | 25 | -- operations to manipulate the state of havoc queries 26 | create procedure sys.pause(tag int) 27 | external name sql.sysmon_pause; 28 | create procedure sys.resume(tag int) 29 | external name sql.sysmon_resume; 30 | create procedure sys.stop(tag int) 31 | external name sql.sysmon_stop; 32 | 33 | create procedure sys.pause(tag bigint) 34 | external name sql.sysmon_pause; 35 | create procedure sys.resume(tag bigint) 36 | external name sql.sysmon_resume; 37 | create procedure sys.stop(tag bigint) 38 | external name sql.sysmon_stop; 39 | -------------------------------------------------------------------------------- /src/sql/scripts/27_rejects.sql: -------------------------------------------------------------------------------- 1 | -- This Source Code Form is subject to the terms of the Mozilla Public 2 | -- License, v. 2.0. If a copy of the MPL was not distributed with this 3 | -- file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -- 5 | -- Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | -- COPY into reject management 8 | 9 | create function sys.rejects() 10 | returns table( 11 | rowid bigint, 12 | fldid int, 13 | "message" string, 14 | "input" string 15 | ) 16 | external name sql.copy_rejects; 17 | 18 | grant execute on function rejects to public; 19 | 20 | create view sys.rejects as select * from sys.rejects(); 21 | create procedure sys.clearrejects() 22 | external name sql.copy_rejects_clear; 23 | -------------------------------------------------------------------------------- /src/sql/scripts/39_analytics_hge.sql: -------------------------------------------------------------------------------- 1 | -- This Source Code Form is subject to the terms of the Mozilla Public 2 | -- License, v. 2.0. If a copy of the MPL was not distributed with this 3 | -- file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -- 5 | -- Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | create aggregate stddev_samp(val HUGEINT) returns DOUBLE 8 | external name "aggr"."stdev"; 9 | GRANT EXECUTE ON AGGREGATE stddev_samp(HUGEINT) TO PUBLIC; 10 | create aggregate stddev_pop(val HUGEINT) returns DOUBLE 11 | external name "aggr"."stdevp"; 12 | GRANT EXECUTE ON AGGREGATE stddev_pop(HUGEINT) TO PUBLIC; 13 | create aggregate var_samp(val HUGEINT) returns DOUBLE 14 | external name "aggr"."variance"; 15 | GRANT EXECUTE ON AGGREGATE var_samp(HUGEINT) TO PUBLIC; 16 | create aggregate var_pop(val HUGEINT) returns DOUBLE 17 | external name "aggr"."variancep"; 18 | GRANT EXECUTE ON AGGREGATE var_pop(HUGEINT) TO PUBLIC; 19 | create aggregate median(val HUGEINT) returns HUGEINT 20 | external name "aggr"."median"; 21 | GRANT EXECUTE ON AGGREGATE median(HUGEINT) TO PUBLIC; 22 | create aggregate quantile(val HUGEINT, q DOUBLE) returns HUGEINT 23 | external name "aggr"."quantile"; 24 | GRANT EXECUTE ON AGGREGATE quantile(HUGEINT, DOUBLE) TO PUBLIC; 25 | create aggregate corr(e1 HUGEINT, e2 HUGEINT) returns DOUBLE 26 | external name "aggr"."corr"; 27 | GRANT EXECUTE ON AGGREGATE corr(HUGEINT, HUGEINT) TO PUBLIC; 28 | -------------------------------------------------------------------------------- /src/sql/scripts/41_md5sum.sql: -------------------------------------------------------------------------------- 1 | -- This Source Code Form is subject to the terms of the Mozilla Public 2 | -- License, v. 2.0. If a copy of the MPL was not distributed with this 3 | -- file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -- 5 | -- Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | -- (co) Arjen de Rijke 8 | 9 | create function sys.md5(v string) 10 | returns string external name clients.md5sum; 11 | 12 | grant execute on function md5 to public; 13 | -------------------------------------------------------------------------------- /src/sql/scripts/46_profiler.sql: -------------------------------------------------------------------------------- 1 | -- This Source Code Form is subject to the terms of the Mozilla Public 2 | -- License, v. 2.0. If a copy of the MPL was not distributed with this 3 | -- file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -- 5 | -- Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | -- start/stop collecting MDBS profiler traces in a profiler_logs pool with a specific heartbeat 8 | create schema profiler; 9 | 10 | create procedure profiler.start() external name profiler."start"; 11 | create procedure profiler.stop() external name profiler.stop; 12 | 13 | create procedure profiler.setheartbeat(beat int) external name profiler.setheartbeat; 14 | create function profiler.getlimit() returns integer external name profiler.getlimit; 15 | create procedure profiler.setlimit(lim integer) external name profiler.setlimit; 16 | -------------------------------------------------------------------------------- /src/sql/scripts/80_statistics.sql: -------------------------------------------------------------------------------- 1 | -- This Source Code Form is subject to the terms of the Mozilla Public 2 | -- License, v. 2.0. If a copy of the MPL was not distributed with this 3 | -- file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -- 5 | -- Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | -- Author M.Kersten 8 | -- This script gives the database administrator insight in the actual 9 | -- value distribution over all tables in the database. 10 | 11 | 12 | CREATE TABLE sys.statistics( 13 | "column_id" integer, 14 | "type" string, 15 | width integer, 16 | stamp timestamp, 17 | "sample" bigint, 18 | "count" bigint, 19 | "unique" bigint, 20 | "nils" bigint, 21 | minval string, 22 | maxval string, 23 | sorted boolean, 24 | revsorted boolean); 25 | 26 | create procedure sys.analyze(minmax int, "sample" bigint) 27 | external name sql.analyze; 28 | 29 | create procedure sys.analyze(minmax int, "sample" bigint, sch string) 30 | external name sql.analyze; 31 | 32 | create procedure sys.analyze(minmax int, "sample" bigint, sch string, tbl string) 33 | external name sql.analyze; 34 | 35 | create procedure sys.analyze(minmax int, "sample" bigint, sch string, tbl string, col string) 36 | external name sql.analyze; 37 | -------------------------------------------------------------------------------- /src/sql/scripts/99_system.sql: -------------------------------------------------------------------------------- 1 | -- This Source Code Form is subject to the terms of the Mozilla Public 2 | -- License, v. 2.0. If a copy of the MPL was not distributed with this 3 | -- file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 | -- 5 | -- Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 6 | 7 | -- only system functions until now 8 | create table sys.systemfunctions (function_id integer not null); 9 | grant select on sys.systemfunctions to public; 10 | insert into systemfunctions select id from functions; 11 | 12 | create trigger system_update_schemas after update on sys.schemas for each statement call sys_update_schemas(); 13 | create trigger system_update_tables after update on sys._tables for each statement call sys_update_tables(); 14 | 15 | -- only system tables until now 16 | update _tables set system = true; 17 | 18 | -- only system schemas until now 19 | update schemas set system = true; 20 | 21 | -- correct invalid FK schema ids, set them to schema id 2000 (the "sys" schema) 22 | UPDATE sys.types SET schema_id = (SELECT id FROM sys.schemas WHERE name = 'sys') WHERE schema_id = 0 AND schema_id NOT IN (SELECT id from sys.schemas); 23 | UPDATE sys.functions SET schema_id = (SELECT id FROM sys.schemas WHERE name = 'sys') WHERE schema_id = 0 AND schema_id NOT IN (SELECT id from sys.schemas); 24 | 25 | -- make sure all gets commited 26 | COMMIT; 27 | -------------------------------------------------------------------------------- /src/sql/server/rel_distribute.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _REL_DISTRIBUTE_H_ 10 | #define _REL_DISTRIBUTE_H_ 11 | 12 | #include "sql_relation.h" 13 | #include "sql_mvc.h" 14 | 15 | extern sql_rel * rel_distribute(mvc *sql, sql_rel *rel); 16 | 17 | #endif /*_REL_DISTRIBUTE_H_*/ 18 | -------------------------------------------------------------------------------- /src/sql/server/rel_dump.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _REL_DUMP_H_ 10 | #define _REL_DUMP_H_ 11 | 12 | #include "sql_relation.h" 13 | #include "sql_mvc.h" 14 | 15 | extern void rel_print_(mvc *sql, stream *fout, sql_rel *rel, int depth, list *refs, int decorate); 16 | extern void rel_print_refs(mvc *sql, stream* fout, sql_rel *rel, int depth, list *refs, int decorate); 17 | extern const char *op2string(operator_type op); 18 | 19 | extern sql_rel *rel_read(mvc *sql, char *ra, int *pos, list *refs); 20 | 21 | #endif /*_REL_DUMP_H_*/ 22 | -------------------------------------------------------------------------------- /src/sql/server/rel_optimizer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _REL_OPTIMIZER_H_ 10 | #define _REL_OPTIMIZER_H_ 11 | 12 | #include "sql_relation.h" 13 | #include "sql_mvc.h" 14 | 15 | extern sql_rel * rel_optimizer(mvc *sql, sql_rel *rel, int value_based_opt); 16 | 17 | extern int exp_joins_rels(sql_exp *e, list *rels); 18 | 19 | extern void *name_find_column( sql_rel *rel, char *rname, char *name, int pnr, sql_rel **bt ); 20 | 21 | extern sql_rel * rel_dce(mvc *sql, sql_rel *rel); 22 | 23 | #endif /*_REL_OPTIMIZER_H_*/ 24 | -------------------------------------------------------------------------------- /src/sql/server/rel_partition.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _REL_PARTITION_H_ 10 | #define _REL_PARTITION_H_ 11 | 12 | #include "rel_semantic.h" 13 | 14 | extern sql_rel * rel_partition(mvc *sql, sql_rel *rel); 15 | 16 | #endif /*_REL_PARTITION_H_*/ 17 | -------------------------------------------------------------------------------- /src/sql/server/rel_planner.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _REL_PLANNER_H_ 10 | #define _REL_PLANNER_H_ 11 | 12 | #include "sql_relation.h" 13 | #include "sql_mvc.h" 14 | 15 | extern sql_rel * rel_planner(mvc *sql, list *rels, list *djes, list *ojes); 16 | 17 | #endif /*_REL_PLANNER_H_ */ 18 | -------------------------------------------------------------------------------- /src/sql/server/rel_prop.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #include "monetdb_config.h" 10 | #include "sql_relation.h" 11 | #include "rel_prop.h" 12 | 13 | prop * 14 | prop_create( sql_allocator *sa, int kind, prop *pre ) 15 | { 16 | prop *p = SA_NEW(sa, prop); 17 | 18 | p->kind = kind; 19 | p->value = 0; 20 | p->p = pre; 21 | return p; 22 | } 23 | 24 | prop * 25 | prop_copy( sql_allocator *sa, prop *p ) 26 | { 27 | prop *np = NULL; 28 | 29 | for(; p; p = p->p) { 30 | np = prop_create(sa, p->kind, np); 31 | np->value = p->value; 32 | } 33 | return np; 34 | } 35 | 36 | prop * 37 | prop_remove( prop *plist, prop *p ) 38 | { 39 | prop *op = plist; 40 | 41 | if (plist == p) 42 | return p->p; 43 | for(; op; op = op->p) { 44 | if (op->p == p) { 45 | op->p = p->p; 46 | break; 47 | } 48 | } 49 | return plist; 50 | } 51 | 52 | prop * 53 | find_prop( prop *p, int kind) 54 | { 55 | while(p) { 56 | if (p->kind == kind) 57 | return p; 58 | p = p->p; 59 | } 60 | return p; 61 | } 62 | 63 | const char * 64 | propkind2string( prop *p) 65 | { 66 | switch(p->kind) { 67 | #define PT(TYPE) case PROP_##TYPE : return #TYPE 68 | PT(COUNT); 69 | PT(JOINIDX); 70 | PT(HASHIDX); 71 | PT(SORTIDX); 72 | PT(HASHCOL); 73 | PT(FETCH); 74 | PT(REMOTE); 75 | PT(USED); 76 | } 77 | return "UNKNOWN"; 78 | } 79 | 80 | char * 81 | propvalue2string( prop *p) 82 | { 83 | char buf [BUFSIZ]; 84 | 85 | if (p->value) { 86 | switch(p->kind) { 87 | case PROP_JOINIDX: { 88 | sql_idx *i = p->value; 89 | 90 | snprintf(buf, BUFSIZ, "%s.%s.%s", i->t->s->base.name, i->t->base.name, i->base.name); 91 | return _STRDUP(buf); 92 | } 93 | case PROP_REMOTE: { 94 | char *uri = p->value; 95 | 96 | return _STRDUP(uri); 97 | } 98 | default: 99 | break; 100 | } 101 | } 102 | return _STRDUP(""); 103 | } 104 | -------------------------------------------------------------------------------- /src/sql/server/rel_prop.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _REL_PROP_H_ 10 | #define _REL_PROP_H_ 11 | 12 | typedef struct prop { 13 | int kind; /* kind of property */ 14 | void *value; /* property value */ 15 | struct prop *p; /* some relations may have many properties, 16 | which are kept in a chain list */ 17 | } prop; 18 | 19 | #define PROP_COUNT 0 20 | #define PROP_JOINIDX 1 /* could use join idx */ 21 | #define PROP_HASHIDX 2 /* is hash idx */ 22 | #define PROP_SORTIDX 3 /* is sorted */ 23 | #define PROP_HASHCOL 4 /* could use hash idx */ 24 | #define PROP_FETCH 5 /* fetchjoin */ 25 | #define PROP_REMOTE 6 /* uri for remote execution */ 26 | #define PROP_USED 10 /* number of times exp is used */ 27 | 28 | extern prop * prop_create( sql_allocator *sa, int kind, prop *pre ); 29 | extern prop * prop_copy( sql_allocator *sa, prop *p); 30 | extern prop * prop_remove( prop *plist, prop *p); 31 | extern prop * find_prop( prop *p, int kind); 32 | extern const char * propkind2string( prop *p); 33 | extern char * propvalue2string( prop *p); 34 | 35 | #endif /* _REL_PROP_H_ */ 36 | 37 | -------------------------------------------------------------------------------- /src/sql/server/rel_psm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _REL_PSM_H_ 10 | #define _REL_PSM_H_ 11 | 12 | #include "sql_list.h" 13 | #include "sql_relation.h" 14 | #include "sql_symbol.h" 15 | #include "sql_mvc.h" 16 | 17 | extern sql_func *resolve_func( mvc *sql, sql_schema *s, const char *name, dlist *typelist, int type, char *op, int if_exists); 18 | extern sql_rel *rel_psm(mvc *sql, symbol *sym); 19 | extern sql_rel *rel_select_with_into( mvc *sql, symbol *sq); 20 | 21 | extern sql_rel *rel_psm_stmt(sql_allocator *sa, sql_exp *e); 22 | 23 | #endif /*_REL_PSM_H_*/ 24 | -------------------------------------------------------------------------------- /src/sql/server/rel_remote.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _REL_REMOTE_H_ 10 | #define _REL_REMOTE_H_ 11 | 12 | #include "sql_relation.h" 13 | 14 | extern int mapiuri_valid( const char *uri); 15 | extern const char *mapiuri_uri(const char *uri, sql_allocator *sa); 16 | extern const char *mapiuri_database(const char *uri, sql_allocator *sa); 17 | extern const char *mapiuri_schema(const char *uri, sql_allocator *sa, const char *fallback); 18 | extern const char *mapiuri_table(const char *uri, sql_allocator *sa, const char *fallback); 19 | 20 | #endif /*_REL_REMOTE_H_*/ 21 | -------------------------------------------------------------------------------- /src/sql/server/rel_schema.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _REL_SCHEMA_H_ 10 | #define _REL_SCHEMA_H_ 11 | 12 | #include "sql_list.h" 13 | #include "sql_symbol.h" 14 | 15 | extern sql_rel *rel_schemas(mvc *sql, symbol *sym); 16 | 17 | extern sql_rel *rel_create_table(mvc *sql, sql_schema *ss, int temp, 18 | const char *sname, const char *name, 19 | symbol *table_elements_or_subquery, 20 | int commit_action, const char *loc, 21 | const char *username, const char *passwd, 22 | bool pw_encrypted, int if_not_exists); 23 | extern sql_rel *rel_list(sql_allocator *sa, sql_rel *l, sql_rel *r); 24 | extern sql_table * mvc_create_table_as_subquery( mvc *sql, sql_rel *sq, sql_schema *s, const char *tname, dlist *column_spec, int temp, int commit_action ); 25 | 26 | #endif /*_REL_SCHEMA_H_*/ 27 | -------------------------------------------------------------------------------- /src/sql/server/rel_select.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _REL_SELECT_H_ 10 | #define _REL_SELECT_H_ 11 | 12 | #include "rel_semantic.h" 13 | #include "sql_semantic.h" 14 | 15 | extern sql_rel *rel_selects(mvc *sql, symbol *sym); 16 | extern sql_rel *schema_selects(mvc *sql, sql_schema *s, symbol *sym); 17 | extern sql_rel * rel_subquery(mvc *sql, sql_rel *rel, symbol *sq, exp_kind ek, int apply); 18 | extern sql_rel * rel_logical_exp(mvc *sql, sql_rel *rel, symbol *sc, int f); 19 | extern sql_exp * rel_logical_value_exp(mvc *sql, sql_rel **rel, symbol *sc, int f); 20 | extern sql_exp *rel_column_exp(mvc *sql, sql_rel **rel, symbol *column_e, int f); 21 | 22 | extern sql_exp * rel_value_exp(mvc *sql, sql_rel **rel, symbol *se, int f, exp_kind ek); 23 | extern sql_exp * rel_value_exp2(mvc *sql, sql_rel **rel, symbol *se, int f, exp_kind ek, int *is_last); 24 | 25 | /* TODO rename to exp_check_type + move to rel_exp.c */ 26 | extern sql_exp *rel_check_type(mvc *sql, sql_subtype *t, sql_exp *exp, int tpe); 27 | extern sql_exp *rel_unop_(mvc *sql, sql_exp *e, sql_schema *s, char *fname, int card); 28 | extern sql_exp *rel_binop_(mvc *sql, sql_exp *l, sql_exp *r, sql_schema *s, char *fname, int card); 29 | extern sql_exp *rel_nop_(mvc *sql, sql_exp *l, sql_exp *r, sql_exp *r2, sql_exp *r3, sql_schema *s, char *fname, int card); 30 | 31 | extern sql_rel *rel_with_query(mvc *sql, symbol *q); 32 | extern sql_rel *table_ref(mvc *sql, sql_rel *rel, symbol *tableref, int lateral); 33 | 34 | 35 | extern sql_rel *rel_loader_function(mvc* sql, symbol* s, list *fexps, sql_subfunc **loader_function); 36 | 37 | #endif /*_REL_SELECT_H_*/ 38 | -------------------------------------------------------------------------------- /src/sql/server/rel_semantic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _REL_SEMANTIC_H_ 10 | #define _REL_SEMANTIC_H_ 11 | 12 | #include "sql_list.h" 13 | #include "sql_symbol.h" 14 | #include "sql_parser.h" 15 | #include "sql_relation.h" 16 | 17 | extern sql_rel *rel_semantic(mvc *sql, symbol *sym); 18 | extern sql_rel *rel_parse(mvc *m, sql_schema *s, char *query, char emode); 19 | 20 | #endif /*_REL_SEMANTIC_H_*/ 21 | 22 | -------------------------------------------------------------------------------- /src/sql/server/rel_sequence.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _REL_SEQUENCE_H_ 10 | #define _REL_SEQUENCE_H_ 11 | 12 | #include "sql_symbol.h" 13 | #include "store_sequence.h" 14 | 15 | extern sql_rel *rel_sequences(mvc *sql, symbol *s); 16 | extern char* sql_next_seq_name(mvc *sql); 17 | 18 | #endif /*_REL_SEQUENCE_H_*/ 19 | -------------------------------------------------------------------------------- /src/sql/server/rel_trans.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #include "monetdb_config.h" 10 | #include "rel_trans.h" 11 | #include "rel_select.h" 12 | #include "rel_rel.h" 13 | #include "rel_exp.h" 14 | #include "sql_parser.h" 15 | 16 | static sql_rel * 17 | rel_trans(mvc *sql, int trans_type, int nr, char *name) 18 | { 19 | sql_rel *rel = rel_create(sql->sa); 20 | list *exps = new_exp_list(sql->sa); 21 | if(!rel || !exps) 22 | return NULL; 23 | 24 | append(exps, exp_atom_int(sql->sa, nr)); 25 | if (name) 26 | append(exps, exp_atom_clob(sql->sa, name)); 27 | rel->l = NULL; 28 | rel->r = NULL; 29 | rel->op = op_ddl; 30 | rel->flag = trans_type; 31 | rel->exps = exps; 32 | rel->card = 0; 33 | rel->nrcols = 0; 34 | return rel; 35 | } 36 | 37 | sql_rel * 38 | rel_transactions(mvc *sql, symbol *s) 39 | { 40 | sql_rel *ret = NULL; 41 | 42 | switch (s->token) { 43 | case TR_RELEASE: 44 | ret = rel_trans(sql, DDL_RELEASE, 0, s->data.sval); 45 | break; 46 | case TR_COMMIT: 47 | assert(s->type == type_int); 48 | ret = rel_trans(sql, DDL_COMMIT, s->data.i_val, NULL); 49 | break; 50 | case TR_SAVEPOINT: 51 | ret = rel_trans(sql, DDL_COMMIT, 0, s->data.sval); 52 | break; 53 | case TR_ROLLBACK: { 54 | dnode *n = s->data.lval->h; 55 | assert(n->type == type_int); 56 | ret= rel_trans(sql, DDL_ROLLBACK, n->data.i_val, n->next->data.sval); 57 | } break; 58 | case TR_START: 59 | case TR_MODE: 60 | assert(s->type == type_int); 61 | ret = rel_trans(sql, DDL_TRANS, s->data.i_val, NULL); 62 | break; 63 | default: 64 | return sql_error(sql, 01, SQLSTATE(42000) "Transaction unknown Symbol(%p)->token = %s", (void*) s, token2string(s->token)); 65 | } 66 | return ret; 67 | } 68 | -------------------------------------------------------------------------------- /src/sql/server/rel_trans.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _REL_TRANS_H_ 10 | #define _REL_TRANS_H_ 11 | 12 | #include "sql_symbol.h" 13 | #include "sql_mvc.h" 14 | #include "sql_relation.h" 15 | 16 | extern sql_rel *rel_transactions(mvc *sql, symbol *sym); 17 | 18 | #endif /*_REL_TRANS_H_*/ 19 | 20 | -------------------------------------------------------------------------------- /src/sql/server/rel_updates.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _REL_UPDATES_H_ 10 | #define _REL_UPDATES_H_ 11 | 12 | #include "sql_list.h" 13 | #include "sql_symbol.h" 14 | #include "sql_mvc.h" 15 | #include "sql_relation.h" 16 | 17 | extern sql_exp **table_update_array(mvc *sql, sql_table *t); 18 | extern sql_rel *rel_update(mvc *sql, sql_rel *t, sql_rel *uprel, sql_exp **updates, list *exps); 19 | 20 | extern sql_rel *rel_insert(mvc *sql, sql_rel *t, sql_rel *inserts); 21 | extern sql_rel *rel_delete(sql_allocator *sa, sql_rel *t, sql_rel *deletes); 22 | extern sql_rel *rel_truncate(sql_allocator *sa, sql_rel *t, int drop_action, int check_identity); 23 | 24 | extern sql_exp * rel_parse_val(mvc *m, char *query, char emode); 25 | 26 | extern sql_rel *rel_updates(mvc *sql, symbol *sym); 27 | 28 | #endif /*_REL_UPDATES_H_*/ 29 | -------------------------------------------------------------------------------- /src/sql/server/rel_xml.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _REL_XML_H_ 10 | #define _REL_XML_H_ 11 | 12 | #include "rel_semantic.h" 13 | #include "sql_semantic.h" 14 | 15 | extern sql_exp *rel_xml(mvc *sql, sql_rel **rel, symbol *s, int f, exp_kind knd); 16 | 17 | #endif /*_REL_XML_H_ */ 18 | -------------------------------------------------------------------------------- /src/sql/server/sql_datetime.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _SQL_DATETIME_H_ 10 | #define _SQL_DATETIME_H_ 11 | 12 | #include "sql_mvc.h" 13 | #include "sql_symbol.h" 14 | 15 | typedef enum inttype { 16 | iyear = 1, 17 | imonth, 18 | iday, 19 | ihour, 20 | imin, 21 | isec, 22 | iquarter, 23 | iweek 24 | } itype; 25 | 26 | int parse_interval_qualifier(mvc *sql, struct dlist *pers, int *sk, int *ek, int *sp, int *ep); 27 | /* returns 0 for month intervals, 28 | * 1 for sec intervals, 29 | * in both cases sk/ek contain the start and end qualifiers 30 | * <0 for errors */ 31 | 32 | lng qualifier2multiplier( int sk ); 33 | /* returns the multiplier for the given interval qualifier */ 34 | 35 | int parse_interval(mvc *sql, lng sign, char *str, int sk, int ek, int sp, int ep, lng *i); 36 | /* returns 0 for month intervals and value in val, 37 | * 1 for sec intervals and value in val, 38 | * <0 for errors */ 39 | 40 | int interval_from_str(char *str, int d, int p, lng *val); 41 | /* returns 0 for month intervals and value in val, 42 | * 1 for sec intervals and value in val, 43 | * <0 for errors */ 44 | 45 | char *datetime_field(itype field); 46 | /* returns the datetime_field string representation */ 47 | 48 | int inttype2digits( int sk, int ek ); 49 | int digits2sk( int digits); 50 | int digits2ek( int digits ); 51 | 52 | #endif /*_SQL_DATETIME_H_*/ 53 | 54 | -------------------------------------------------------------------------------- /src/sql/server/sql_decimal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #include "monetdb_config.h" 10 | 11 | #include "sql_decimal.h" 12 | 13 | #ifdef HAVE_HGE 14 | hge 15 | #else 16 | lng 17 | #endif 18 | decimal_from_str(char *dec, char **end) 19 | { 20 | #ifdef HAVE_HGE 21 | hge res = 0; 22 | const hge max0 = GDK_hge_max / 10, max1 = GDK_hge_max % 10; 23 | #else 24 | lng res = 0; 25 | const lng max0 = GDK_lng_max / 10, max1 = GDK_lng_max % 10; 26 | #endif 27 | int neg = 0; 28 | 29 | while(isspace((unsigned char) *dec)) 30 | dec++; 31 | if (*dec == '-') { 32 | neg = 1; 33 | dec++; 34 | } else if (*dec == '+') { 35 | dec++; 36 | } 37 | for (; *dec && ((*dec >= '0' && *dec <= '9') || *dec == '.'); dec++) { 38 | if (*dec != '.') { 39 | if (res > max0 || (res == max0 && *dec - '0' > max1)) 40 | break; 41 | res *= 10; 42 | res += *dec - '0'; 43 | } 44 | } 45 | while(isspace((unsigned char) *dec)) 46 | dec++; 47 | if (end) 48 | *end = dec; 49 | if (neg) 50 | return -res; 51 | else 52 | return res; 53 | } 54 | 55 | char * 56 | #ifdef HAVE_HGE 57 | decimal_to_str(hge v, sql_subtype *t) 58 | #else 59 | decimal_to_str(lng v, sql_subtype *t) 60 | #endif 61 | { 62 | char buf[64]; 63 | int scale = t->scale, cur = 63, neg = (v<0), i, done = 0; 64 | 65 | if (v<0) v = -v; 66 | 67 | buf[cur--] = 0; 68 | if (scale){ 69 | for (i=0; i= -1); 85 | return _STRDUP(buf+cur+1); 86 | } 87 | 88 | -------------------------------------------------------------------------------- /src/sql/server/sql_decimal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _SQL_DECIMAL_H 10 | #define _SQL_DECIMAL_H 11 | 12 | #include "sql_mem.h" 13 | #include "sql_types.h" 14 | #include "gdk.h" 15 | 16 | #ifdef HAVE_HGE 17 | extern hge decimal_from_str(char *dec, char **end); 18 | extern char * decimal_to_str(hge v, sql_subtype *t); 19 | #else 20 | extern lng decimal_from_str(char *dec, char **end); 21 | extern char * decimal_to_str(lng v, sql_subtype *t); 22 | #endif 23 | 24 | #endif /* _SQL_DECIMAL_H */ 25 | 26 | -------------------------------------------------------------------------------- /src/sql/server/sql_env.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _SQL_ENV_H_ 10 | #define _SQL_ENV_H_ 11 | 12 | #include "sql_parser.h" 13 | #include "sql_symbol.h" 14 | #include "sql_mvc.h" 15 | 16 | extern str sql_update_var(mvc *sql, const char *name, char *sval, lng sgn); 17 | 18 | extern int sql_create_env(mvc *sql, sql_schema *s); 19 | 20 | #define NR_KEEPQUERY_ARGS 4 21 | #define NR_KEEPCALL_ARGS 9 22 | 23 | #endif /* _SQL_ENV_H_ */ 24 | -------------------------------------------------------------------------------- /src/sql/server/sql_qc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _SQL_QC_H_ 10 | #define _SQL_QC_H_ 11 | 12 | #include "sql_mem.h" 13 | #include "sql_list.h" 14 | #include "sql_symbol.h" 15 | #include "sql_backend.h" 16 | 17 | #define DEFAULT_CACHESIZE 100 18 | typedef struct cq { 19 | struct cq *next; /* link them into a queue */ 20 | int type; /* sql_query_t: Q_PARSE,Q_SCHEMA,.. */ 21 | sql_allocator *sa; /* the symbols are allocated from this sa */ 22 | sql_rel *rel; /* relational query */ 23 | symbol *s; /* the SQL parse tree */ 24 | sql_subtype *params; /* parameter types */ 25 | int paramlen; /* number of parameters */ 26 | backend_stack stk; /* V4 state information */ 27 | backend_code code; /* V4 state information */ 28 | int id; /* cache identity */ 29 | int key; /* the hash key for the query text */ 30 | char *codestring; /* keep code in string form to aid debugging */ 31 | char *name; /* name of cache query */ 32 | int no_mitosis; /* run query without mitosis */ 33 | int count; /* number of times the query is matched */ 34 | } cq; 35 | 36 | typedef struct qc { 37 | int clientid; 38 | int id; 39 | int nr; 40 | cq *q; 41 | } qc; 42 | 43 | extern qc *qc_create(int clientid, int seqnr); 44 | extern void qc_destroy(qc *cache); 45 | extern void qc_clean(qc *cache); 46 | extern cq *qc_find(qc *cache, int id); 47 | extern cq *qc_match(qc *cache, symbol *s, atom **params, int plen, int key); 48 | extern cq *qc_insert(qc *cache, sql_allocator *sa, sql_rel *r, char *qname, symbol *s, atom **params, int paramlen, int key, int type, char *codedstr, int no_mitosis); 49 | extern void qc_delete(qc *cache, cq *q); 50 | extern int qc_size(qc *cache); 51 | extern int qc_isaquerytemplate(char *nme); 52 | extern int qc_isapreparedquerytemplate(char *nme); 53 | 54 | #endif /*_SQL_QC_H_*/ 55 | 56 | -------------------------------------------------------------------------------- /src/sql/server/sql_scan.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _SQL_SCAN_H_ 10 | #define _SQL_SCAN_H_ 11 | 12 | #include "sql_mem.h" 13 | #include "sql_list.h" 14 | #include "stream.h" 15 | 16 | typedef enum { LINE_1, LINE_N } prot; 17 | 18 | struct scanner { 19 | bstream *rs; 20 | stream *ws; 21 | stream *log; 22 | 23 | int yynext; /* next token, lr(1) isn't powerful enough for sql */ 24 | int yylast; /* previous token, to detect superfluous semi-colons */ 25 | int yysval; /* start of current token */ 26 | int yyval; /* current token */ 27 | int yycur; /* next char in the queue */ 28 | char yybak; /* sometimes it's needed to write an EOS marker */ 29 | int as; /* start of query part of view's etc */ 30 | int key; /* query hash */ 31 | int started; /* found at least one token */ 32 | prot mode; /* which mode (line (1,N), blocked) */ 33 | char *schema; /* Keep schema name of create statement, 34 | needed AUTO_INCREMENT, SERIAL */ 35 | char *errstr; /* error message from the bowels of 36 | * the scanner */ 37 | }; 38 | 39 | #define QUERY(scanner) (scanner.rs->buf+scanner.rs->pos) 40 | 41 | extern char *query_cleaned(const char *query); 42 | extern void scanner_init(struct scanner *s, bstream *rs, stream *ws); 43 | extern void scanner_reset_key(struct scanner *s); 44 | extern void scanner_query_processed(struct scanner *s); 45 | 46 | extern int scanner_init_keywords(void); 47 | #endif /* _SQL_SCAN_H_ */ 48 | 49 | -------------------------------------------------------------------------------- /src/sql/server/sql_semantic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef _SQL_SEMANTIC_H_ 10 | #define _SQL_SEMANTIC_H_ 11 | 12 | #include "sql_list.h" 13 | #include "sql_symbol.h" 14 | #include "sql_parser.h" 15 | 16 | typedef struct exp_kind_t { 17 | bte type; 18 | bte card; 19 | bit reduce; 20 | } exp_kind; 21 | 22 | extern sql_schema *cur_schema(mvc *sql); 23 | extern sql_schema *tmp_schema(mvc *sql); 24 | extern char *qname_schema(dlist *qname); 25 | extern char *qname_table(dlist *qname); 26 | extern char *qname_catalog(dlist *qname); 27 | #define qname_module(qname) qname_schema(qname) 28 | #define qname_fname(qname) qname_table(qname) 29 | 30 | extern sql_subtype *supertype(sql_subtype *super, sql_subtype *r, sql_subtype *i); 31 | 32 | typedef enum { 33 | type_set, /* set operations have very limiting coersion rules */ 34 | type_equal, 35 | type_equal_no_any, 36 | type_cast /* also truncate */ 37 | } check_type; 38 | 39 | /* literals in the parser are kept outside of the abstract syntax tree 40 | in the arg array, this to allow for more reuse of cached queries */ 41 | 42 | extern atom *sql_add_arg(mvc *sql, atom *v); 43 | extern atom *sql_set_arg(mvc *sql, int nr, atom *v); 44 | extern atom *sql_bind_arg(mvc *sql, int nr); 45 | extern void sql_destroy_args(mvc *sql); /* used in backend */ 46 | 47 | /* SQL's parameters '?' (in prepare statements) and parameters of sql 48 | * functions and procedures are kept in the param list. */ 49 | 50 | extern void sql_add_param(mvc *sql, const char *name, sql_subtype *st); 51 | extern sql_arg *sql_bind_param(mvc *sql, const char *name); 52 | /* once the type of the '?' parameters is known it's set using the set_type 53 | * function */ 54 | extern int set_type_param(mvc *sql, sql_subtype *type, int nr); 55 | extern void sql_destroy_params(mvc *sql); /* used in backend */ 56 | 57 | extern char *symbol2string(mvc *sql, symbol *s, char **err); 58 | extern char *dlist2string(mvc *sql, dlist *s, char **err); 59 | 60 | extern char * toUpperCopy(char *dest, const char *src); 61 | 62 | #endif /*_SQL_SEMANTIC_H_*/ 63 | 64 | -------------------------------------------------------------------------------- /src/sql/storage/bat/bat_logger.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef BAT_LOGGER_H 10 | #define BAT_LOGGER_H 11 | 12 | #include "sql_storage.h" 13 | #include "gdk_logger.h" 14 | 15 | extern logger *bat_logger; 16 | 17 | extern void bat_logger_init( logger_functions *lf ); 18 | extern void bat_logger_init_shared( logger_functions *lf ); 19 | 20 | #endif /*BAT_LOGGER_H */ 21 | -------------------------------------------------------------------------------- /src/sql/storage/bat/bat_storage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef BATSTORAGE_H 10 | #define BATSTORAGE_H 11 | 12 | #include "sql_storage.h" 13 | #include "bat_logger.h" 14 | 15 | typedef struct sql_delta { 16 | char *name; /* name of the main bat */ 17 | int bid; 18 | oid ibase; /* ibase: first id of inserts */ 19 | int ibid; /* bat with inserts */ 20 | int uibid; /* bat with updates */ 21 | int uvbid; /* bat with updates */ 22 | size_t cnt; /* number of tuples (excluding the deletes) */ 23 | size_t ucnt; /* number of updates */ 24 | BAT *cached; /* cached copy, used for schema bats only */ 25 | int wtime; /* time stamp */ 26 | struct sql_delta *next; /* possibly older version of the same column/idx */ 27 | } sql_delta; 28 | 29 | typedef struct sql_dbat { 30 | char *dname; /* name of the persistent deletes bat */ 31 | int dbid; /* bat with deletes */ 32 | size_t cnt; 33 | BAT *cached; /* cached copy, used for schema bats only */ 34 | int wtime; /* time stamp */ 35 | struct sql_dbat *next; /* possibly older version of the same deletes */ 36 | } sql_dbat; 37 | 38 | /* initialize bat storage call back functions interface */ 39 | extern void bat_storage_init( store_functions *sf ); 40 | 41 | extern int dup_bat(sql_trans *tr, sql_table *t, sql_delta *obat, sql_delta *bat, int type, int oc_isnew, int c_isnew); 42 | extern sql_delta * timestamp_delta( sql_delta *d, int ts); 43 | extern sql_dbat * timestamp_dbat( sql_dbat *d, int ts); 44 | 45 | #endif /*BATSTORAGE_H */ 46 | 47 | -------------------------------------------------------------------------------- /src/sql/storage/bat/bat_table.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef BAT_TABLE_H 10 | #define BAT_TABLE_H 11 | 12 | #include "sql_storage.h" 13 | #include "bat_storage.h" 14 | #include "bat_utils.h" 15 | 16 | /* initialize bat storage call back functions interface */ 17 | extern void bat_table_init( table_functions *tf ); 18 | 19 | #endif /*BAT_TABLE_H*/ 20 | -------------------------------------------------------------------------------- /src/sql/storage/bat/bat_utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef BAT_UTILS_H 10 | #define BAT_UTILS_H 11 | 12 | #include "sql_storage.h" 13 | #include "gdk_logger.h" 14 | 15 | /* when returning a log_bid, errors are reported using BID_NIL */ 16 | #define BID_NIL 0 17 | 18 | #define bat_set_access(b,access) b->batRestricted = access 19 | #define bat_clear(b) bat_set_access(b,BAT_WRITE);BATclear(b,true);bat_set_access(b,BAT_READ) 20 | 21 | extern BAT *temp_descriptor(log_bid b); 22 | extern BAT *quick_descriptor(log_bid b); 23 | extern void temp_destroy(log_bid b); 24 | extern void temp_dup(log_bid b); 25 | extern log_bid temp_create(BAT *b); 26 | extern log_bid temp_copy(log_bid b, int temp); 27 | 28 | extern void bat_destroy(BAT *b); 29 | extern BAT *bat_new(int tt, BUN size, int role); 30 | 31 | extern BUN append_inserted(BAT *b, BAT *i ); 32 | 33 | extern BAT *ebats[MAXATOMS]; 34 | 35 | #define isEbat(b) (ebats[b->ttype] && ebats[b->ttype] == b) 36 | 37 | extern log_bid ebat2real(log_bid b, oid ibase); 38 | extern log_bid e_bat(int type); 39 | extern BAT *e_BAT(int type); 40 | extern log_bid ebat_copy(log_bid b, oid ibase, int temp); 41 | extern int bat_utils_init(void); 42 | 43 | extern sql_table * tr_find_table( sql_trans *tr, sql_table *t); 44 | extern sql_column * tr_find_column( sql_trans *tr, sql_column *c); 45 | extern sql_idx * tr_find_idx( sql_trans *tr, sql_idx *i); 46 | 47 | 48 | #endif /* BAT_UTILS_H */ 49 | -------------------------------------------------------------------------------- /src/sql/storage/bat/nop_logger.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2017 MonetDB B.V. 7 | */ 8 | 9 | #include "monetdb_config.h" 10 | #include "nop_logger.h" 11 | 12 | static int 13 | nl_create(int debug, const char *logdir, int cat_version, int keep_persisted_log_files) 14 | { 15 | (void) debug; 16 | (void) logdir; 17 | (void) cat_version; 18 | (void) keep_persisted_log_files; 19 | return LOG_OK; 20 | } 21 | 22 | 23 | static void 24 | nl_destroy(void) 25 | { 26 | 27 | } 28 | 29 | 30 | 31 | static int 32 | nl_restart(void) 33 | { 34 | 35 | return LOG_OK; 36 | } 37 | 38 | static int 39 | nl_cleanup(int keep_persisted_log_files) 40 | { 41 | (void) keep_persisted_log_files; 42 | return LOG_OK; 43 | } 44 | 45 | 46 | static int 47 | nl_changes(void) 48 | { 49 | return 0; 50 | } 51 | 52 | 53 | static int 54 | nl_get_sequence(int seq, lng *id) 55 | { 56 | (void) seq; 57 | *id = 42; 58 | return LOG_OK; 59 | } 60 | 61 | 62 | static int 63 | nl_log_isnew(void) 64 | { 65 | return 1; 66 | } 67 | 68 | 69 | static int 70 | nl_tstart(void) 71 | { 72 | return LOG_OK; 73 | } 74 | 75 | static int 76 | nl_tend(void) 77 | { 78 | return LOG_OK; 79 | } 80 | 81 | static int 82 | nl_sequence(int seq, lng id) 83 | { 84 | (void) seq; 85 | (void) id; 86 | return LOG_OK; 87 | } 88 | 89 | 90 | static int 91 | nl_isdestroyed(void) 92 | { 93 | return 0; 94 | } 95 | 96 | 97 | void 98 | nop_logger_init( logger_functions *lf ) 99 | { 100 | lf->create = nl_create; 101 | lf->destroy = nl_destroy; 102 | lf->restart = nl_restart; 103 | lf->cleanup = nl_cleanup; 104 | lf->changes = nl_changes; 105 | lf->get_sequence = nl_get_sequence; 106 | lf->log_isnew = nl_log_isnew; 107 | lf->log_tstart = nl_tstart; 108 | lf->log_tend = nl_tend; 109 | lf->log_sequence = nl_sequence; 110 | lf->log_isdestroyed = nl_isdestroyed; 111 | } 112 | -------------------------------------------------------------------------------- /src/sql/storage/bat/nop_logger.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef NOP_LOGGER_H 10 | #define NOP_LOGGER_H 11 | 12 | #include "sql_storage.h" 13 | 14 | extern void nop_logger_init( logger_functions *lf ); 15 | 16 | #endif /*NOP_LOGGER_H */ 17 | -------------------------------------------------------------------------------- /src/sql/storage/bat/res_table.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef RES_TABLE_H 10 | #define RES_TABLE_H 11 | 12 | #include "sql_catalog.h" 13 | 14 | #endif /* RES_TABLE_H */ 15 | -------------------------------------------------------------------------------- /src/sql/storage/store_dependency.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef STORE_DEPEND_H 10 | #define STORE_DEPEND_H 11 | 12 | #include "sql_types.h" 13 | #include "sql_backend.h" 14 | #include "store_sequence.h" 15 | 16 | #endif /*STORE_DEPEND_H */ 17 | -------------------------------------------------------------------------------- /src/sql/storage/store_sequence.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This Source Code Form is subject to the terms of the Mozilla Public 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2018 MonetDB B.V. 7 | */ 8 | 9 | #ifndef STORE_SEQ_H 10 | #define STORE_SEQ_H 11 | 12 | #include "sql_catalog.h" 13 | 14 | extern void* sequences_init(void); 15 | extern void sequences_exit(void); 16 | 17 | extern int seq_next_value(sql_sequence *seq, lng *val); 18 | 19 | /* for bulk next values, the API is split in 3 parts */ 20 | 21 | typedef struct seqbulk { 22 | void *internal_seq; 23 | sql_sequence *seq; 24 | BUN cnt; 25 | int save; 26 | } seqbulk; 27 | 28 | extern seqbulk *seqbulk_create(sql_sequence *seq, BUN cnt); 29 | extern int seqbulk_next_value(seqbulk *seq, lng *val); 30 | extern void seqbulk_destroy(seqbulk *seq); 31 | 32 | extern int seq_get_value(sql_sequence *seq, lng *val); 33 | extern int seq_restart(sql_sequence *seq, lng start); 34 | 35 | #endif /* STORE_SEQ_H */ 36 | -------------------------------------------------------------------------------- /tests/readme/readme.c: -------------------------------------------------------------------------------- 1 | #include "embedded.h" 2 | #include 3 | 4 | #define error(msg) {fprintf(stderr, "Failure: %s\n", msg); return -1;} 5 | 6 | int main(void) { 7 | char* err = 0; 8 | void* conn = 0; 9 | monetdb_result* result = 0; 10 | size_t r, c; 11 | 12 | // first argument is a string for the db directory or NULL for in-memory mode 13 | err = monetdb_startup(NULL, 0, 0); 14 | if (err != 0) 15 | error(err) 16 | 17 | conn = monetdb_connect(); 18 | if (conn == NULL) 19 | error("Connection failed") 20 | 21 | err = monetdb_query(conn, "CREATE TABLE test (x integer, y string)", 1, 22 | NULL, NULL, NULL); 23 | if (err != 0) 24 | error(err) 25 | 26 | err = monetdb_query(conn, 27 | "INSERT INTO test VALUES (42, 'Hello'), (NULL, 'World')", 1, NULL, 28 | NULL, NULL); 29 | if (err != 0) 30 | error(err) 31 | 32 | err = monetdb_query(conn, "SELECT x, y FROM test; ", 1, &result, NULL, 33 | NULL); 34 | if (err != 0) 35 | error(err) 36 | 37 | fprintf(stdout, "Query result with %d cols and %d rows\n", (int) result->ncols, 38 | (int) result->nrows); 39 | 40 | for (r = 0; r < result->nrows; r++) { 41 | for (c = 0; c < result->ncols; c++) { 42 | monetdb_column* rcol = monetdb_result_fetch(result, c); 43 | switch (rcol->type) { 44 | case monetdb_int32_t: { 45 | monetdb_column_int32_t * col = (monetdb_column_int32_t *) rcol; 46 | if (col->data[r] == col->null_value) { 47 | printf("NULL"); 48 | } else { 49 | printf("%d", (int) col->data[r]); 50 | } 51 | break; 52 | } 53 | case monetdb_str: { 54 | monetdb_column_str * col = (monetdb_column_str *) rcol; 55 | if (col->is_null(col->data[r])) { 56 | printf("NULL"); 57 | } else { 58 | printf("%s", (char*) col->data[r]); 59 | } 60 | break; 61 | } 62 | default: { 63 | printf("UNKNOWN"); 64 | } 65 | } 66 | 67 | if (c + 1 < result->ncols) { 68 | printf(", "); 69 | } 70 | } 71 | printf("\n"); 72 | } 73 | 74 | monetdb_cleanup_result(conn, result); 75 | monetdb_disconnect(conn); 76 | monetdb_shutdown(); 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /tests/sqlitelogic/sqllogictest.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** Copyright (c) 2008 D. Richard Hipp 3 | ** 4 | ** This program is free software; you can redistribute it and/or 5 | ** modify it under the terms of the GNU General Public 6 | ** License version 2 as published by the Free Software Foundation. 7 | ** 8 | ** This program is distributed in the hope that it will be useful, 9 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | ** General Public License for more details. 12 | ** 13 | ** You should have received a copy of the GNU General Public 14 | ** License along with this library; if not, write to the 15 | ** Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 | ** Boston, MA 02111-1307, USA. 17 | ** 18 | ** Author contact information: 19 | ** drh@hwaci.com 20 | ** http://www.hwaci.com/drh/ 21 | ** 22 | ******************************************************************************* 23 | ** 24 | ** This module defines the interfaces to the sqllogictest program. 25 | */ 26 | 27 | 28 | /* 29 | ** The interface to each database engine is an instance of the 30 | ** following structure. 31 | */ 32 | typedef struct DbEngine DbEngine; 33 | struct DbEngine { 34 | const char *zName; /* Name of this engine */ 35 | void *pAuxData; /* Aux data passed to xConnect */ 36 | int (*xConnect)(void*, const char *zCon, void **ppConn, const char *zOpt); 37 | int (*xGetEngineName)(void*, const char **zName); 38 | int (*xStatement)(void*, 39 | const char *zSql, 40 | int bQuiet); /* True to suppress printing errors. */ 41 | int (*xQuery)(void*, const char *zSql, const char *zTypes, 42 | char ***pazResult, int *pnResult); 43 | int (*xFreeResults)(void*, char **azResult, int nResult); 44 | int (*xDisconnect)(void*); 45 | }; 46 | 47 | /* 48 | ** Each database engine interface invokes the following routine 49 | ** to register itself with the main sqllogictest driver. 50 | */ 51 | void sqllogictestRegisterEngine(const DbEngine*); 52 | 53 | 54 | /* 55 | ** MD5 hashing routines. 56 | */ 57 | void md5_add(const char *z); 58 | const char *md5_finish(void); 59 | --------------------------------------------------------------------------------