├── src ├── .gitignore ├── dummy.c ├── monetdblite │ ├── .gitignore │ ├── src │ │ ├── mal │ │ │ ├── modules │ │ │ │ ├── tablet.mal │ │ │ │ ├── 00_iterator_hge.mal │ │ │ │ ├── 00_language_hge.mal │ │ │ │ ├── 00_mkey_hge.mal │ │ │ │ ├── 00_batExtensions_hge.mal │ │ │ │ ├── projectionpath.h │ │ │ │ ├── manifold.mal │ │ │ │ ├── sample.h │ │ │ │ ├── mat.h │ │ │ │ ├── sample.mal │ │ │ │ ├── orderidx.mal │ │ │ │ ├── manifold.h │ │ │ │ ├── mat.mal │ │ │ │ ├── blob.h │ │ │ │ ├── batExtensions.h │ │ │ │ ├── iterator.h │ │ │ │ ├── iterator.mal │ │ │ │ ├── orderidx.h │ │ │ │ ├── projectionpath.c │ │ │ │ ├── group.h │ │ │ │ ├── language.h │ │ │ │ ├── batmmath.h │ │ │ │ ├── mmath.h │ │ │ │ ├── mkey.mal │ │ │ │ └── language.mal │ │ │ ├── sqlbackend │ │ │ │ ├── 41_sql_hge.mal │ │ │ │ ├── 40_sql.mal │ │ │ │ ├── sql_inspect.mal │ │ │ │ ├── sql_upgrades.h │ │ │ │ ├── sql_statistics.h │ │ │ │ ├── sql_user.h │ │ │ │ ├── rel_bin.h │ │ │ │ ├── sql_orderidx.h │ │ │ │ ├── sql_rank.h │ │ │ │ ├── sql_optimizer.h │ │ │ │ ├── sql_assert.h │ │ │ │ ├── sql_execute.h │ │ │ │ ├── mal_backend.c │ │ │ │ ├── sql_transaction.mal │ │ │ │ ├── sql_fround.c │ │ │ │ ├── sql_transaction.h │ │ │ │ ├── sql_round.c │ │ │ │ ├── mal_backend.h │ │ │ │ ├── sql_gencode.h │ │ │ │ ├── sql_rank.mal │ │ │ │ ├── sql_result.h │ │ │ │ ├── sql_aggr_bte.mal │ │ │ │ ├── sql_aggr_dbl.mal │ │ │ │ ├── sql_aggr_flt.mal │ │ │ │ ├── sql_aggr_hge.mal │ │ │ │ ├── sql_aggr_int.mal │ │ │ │ ├── sql_aggr_sht.mal │ │ │ │ └── sql_aggr_lng.mal │ │ │ ├── mal │ │ │ │ ├── mal_utils.h │ │ │ │ ├── mal_atom.h │ │ │ │ ├── mal_private.h │ │ │ │ ├── mal_dataflow.h │ │ │ │ ├── mal_import.h │ │ │ │ ├── mal_namespace.h │ │ │ │ ├── mal_parser.h │ │ │ │ ├── mal_linker.h │ │ │ │ ├── mal_stack.h │ │ │ │ ├── mal_session.h │ │ │ │ ├── mal_listing.h │ │ │ │ ├── mal_resolve.h │ │ │ │ ├── mal_runtime.h │ │ │ │ ├── mal_module.h │ │ │ │ └── mal_function.h │ │ │ └── optimizer │ │ │ │ ├── opt_garbageCollector.h │ │ │ │ ├── opt_reorder.h │ │ │ │ ├── opt_dataflow.h │ │ │ │ ├── opt_pushselect.h │ │ │ │ ├── optimizer_private.h │ │ │ │ ├── opt_coercion.h │ │ │ │ ├── opt_constants.h │ │ │ │ ├── opt_profiler.h │ │ │ │ ├── opt_candidates.h │ │ │ │ ├── opt_inline.h │ │ │ │ ├── opt_projectionpath.h │ │ │ │ ├── opt_commonTerms.h │ │ │ │ ├── opt_evaluate.h │ │ │ │ ├── opt_mergetable.h │ │ │ │ ├── opt_deadcode.h │ │ │ │ ├── opt_generator.h │ │ │ │ ├── opt_costModel.h │ │ │ │ ├── opt_mitosis.h │ │ │ │ ├── opt_multiplex.h │ │ │ │ ├── opt_remap.h │ │ │ │ ├── opt_aliases.h │ │ │ │ ├── opt_emptybind.h │ │ │ │ ├── opt_matpack.h │ │ │ │ ├── optimizer.h │ │ │ │ ├── opt_macro.h │ │ │ │ └── opt_pipes.h │ │ ├── embedded │ │ │ ├── undef.h │ │ │ └── inlined_scripts.py │ │ ├── sql │ │ │ ├── storage │ │ │ │ ├── bat │ │ │ │ │ ├── res_table.h │ │ │ │ │ ├── nop_logger.h │ │ │ │ │ ├── bat_table.h │ │ │ │ │ ├── bat_logger.h │ │ │ │ │ ├── bat_utils.h │ │ │ │ │ ├── bat_storage.h │ │ │ │ │ └── nop_logger.c │ │ │ │ ├── store_dependency.h │ │ │ │ └── store_sequence.h │ │ │ ├── scripts │ │ │ │ ├── 41_md5sum.sql │ │ │ │ ├── 11_times.sql │ │ │ │ ├── 10_math.sql │ │ │ │ ├── 18_index.sql │ │ │ │ ├── 27_rejects.sql │ │ │ │ ├── 46_profiler.sql │ │ │ │ ├── 20_vacuum.sql │ │ │ │ ├── 09_like.sql │ │ │ │ ├── 17_temporal.sql │ │ │ │ ├── 16_tracelog.sql │ │ │ │ ├── 22_clients.sql │ │ │ │ ├── 26_sysmon.sql │ │ │ │ ├── 80_statistics.sql │ │ │ │ ├── 13_date.sql │ │ │ │ ├── 99_system.sql │ │ │ │ ├── 39_analytics_hge.sql │ │ │ │ └── 25_debug.sql │ │ │ ├── server │ │ │ │ ├── rel_partition.h │ │ │ │ ├── rel_distribute.h │ │ │ │ ├── rel_planner.h │ │ │ │ ├── rel_xml.h │ │ │ │ ├── rel_trans.h │ │ │ │ ├── rel_sequence.h │ │ │ │ ├── rel_semantic.h │ │ │ │ ├── sql_env.h │ │ │ │ ├── sql_decimal.h │ │ │ │ ├── rel_optimizer.h │ │ │ │ ├── rel_dump.h │ │ │ │ ├── rel_psm.h │ │ │ │ ├── rel_remote.h │ │ │ │ ├── rel_schema.h │ │ │ │ ├── rel_updates.h │ │ │ │ ├── rel_prop.h │ │ │ │ ├── sql_datetime.h │ │ │ │ ├── sql_scan.h │ │ │ │ ├── rel_select.h │ │ │ │ ├── rel_trans.c │ │ │ │ ├── sql_decimal.c │ │ │ │ ├── sql_qc.h │ │ │ │ └── rel_prop.c │ │ │ ├── include │ │ │ │ ├── sql_query.h │ │ │ │ ├── sql_keyword.h │ │ │ │ ├── sql_stack.h │ │ │ │ └── sql_hash.h │ │ │ └── common │ │ │ │ ├── sql_stack.c │ │ │ │ ├── sql_string.h │ │ │ │ ├── sql_hash.c │ │ │ │ └── sql_changeset.c │ │ ├── gdk │ │ │ ├── gdk_storage.h │ │ │ ├── gdk_tm.h │ │ │ ├── gdk_system_private.h │ │ │ ├── gdk_imprints.h │ │ │ ├── gdk_delta.h │ │ │ └── gdk_cand.h │ │ └── common │ │ │ └── mutils.h │ ├── hgimport.sh │ ├── appveyor.yml │ └── tests │ │ ├── readme │ │ └── readme.c │ │ └── sqlitelogic │ │ └── sqllogictest.h └── embeddedr │ ├── mapisplit.h │ ├── mapisplit-r.h │ ├── embeddedr.h │ ├── mapisplit-r.c │ └── mapisplit.c ├── tests ├── testthat │ ├── oldfarm-0.5.0.zip │ ├── oldfarm-0.5.1.zip │ ├── test_07_oldfarm.R │ └── test_03_dbitest.R └── testthat.R ├── .gitignore ├── .Rbuildignore ├── man ├── monetdbRtype.Rd ├── monetdblite_shutdown.Rd ├── ml.Rd ├── sqlitecompat.Rd ├── MonetDBLite.Rd ├── mc.Rd ├── monetdbd.liststatus.Rd ├── dbApply.Rd ├── MonetDB.R.Rd ├── src_monetdb.Rd └── dbSendUpdate.Rd ├── R └── zzz.R ├── NAMESPACE ├── .travis.yml ├── DESCRIPTION └── appveyor.yml /src/.gitignore: -------------------------------------------------------------------------------- 1 | /monetdblite/ 2 | -------------------------------------------------------------------------------- /src/dummy.c: -------------------------------------------------------------------------------- 1 | /* to make R CMD check happier */ 2 | -------------------------------------------------------------------------------- /tests/testthat/oldfarm-0.5.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MonetDB/MonetDBLite-R/HEAD/tests/testthat/oldfarm-0.5.0.zip -------------------------------------------------------------------------------- /tests/testthat/oldfarm-0.5.1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MonetDB/MonetDBLite-R/HEAD/tests/testthat/oldfarm-0.5.1.zip -------------------------------------------------------------------------------- /src/monetdblite/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_store 2 | .project 3 | .cproject 4 | build 5 | *.so 6 | MonetDBLite_*.t* 7 | .settings 8 | *.o 9 | -------------------------------------------------------------------------------- /src/embeddedr/mapisplit.h: -------------------------------------------------------------------------------- 1 | void mapi_unescape(char* in, char* out); 2 | void mapi_line_split(char* line, char** out, size_t ncols); 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_store 2 | .project 3 | .cproject 4 | .pydevproject 5 | build 6 | *.so 7 | MonetDBLite_*.t* 8 | .settings 9 | *.o 10 | -------------------------------------------------------------------------------- /src/embeddedr/mapisplit-r.h: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_EMBEDDED_R 2 | #include 3 | 4 | extern SEXP mapi_split(SEXP mapiLinesVector, SEXP numCols); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | # Sys.setenv("MONETDBLITE_INMEMORY" = "yes") 3 | # test_check("MonetDBLite") 4 | Sys.setenv("MONETDBLITE_INMEMORY" = "no") 5 | test_check("MonetDBLite") 6 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | .*\.hgeol 2 | .*\.travis\.yml 3 | ^hgimport\.sh 4 | ^buildandtest\.sh 5 | ^appveyor\.yml 6 | .*\.git 7 | .*\.sql 8 | .*\.mal 9 | .*\.o 10 | .*sql_parser\.y 11 | ^speed_comparisons\.png 12 | ^src/build 13 | ^src/monetdblite/tests 14 | ^src/monetdblite/Makefile 15 | ^src/monetdblite/src/sql/scripts 16 | .*\.pydevproject 17 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/Mar2018 11 | git status --porcelain | awk '{if ($1=="DU") print $2}' | xargs git rm # && \ 12 | make init 13 | git rm -rf sql/test 14 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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 | -------------------------------------------------------------------------------- /man/monetdbRtype.Rd: -------------------------------------------------------------------------------- 1 | \name{monetdbRtype} 2 | \alias{monetdbRtype} 3 | 4 | \title{ 5 | Get the name of the R data type for a database type. 6 | } 7 | \description{ 8 | For a database data type, get the name of the R data type it is being translated to. 9 | } 10 | \usage{ 11 | monetdbRtype ( dbType ) 12 | } 13 | \arguments{ 14 | \item{dbType}{A database type string such as \code{CHAR} or \code{INTEGER}.} 15 | } 16 | 17 | \value{ 18 | String containing the R data type for the DB data type, e.g. \code{character} or \code{numeric}. 19 | } 20 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/src/mal/optimizer/opt_garbageCollector.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_GARBAGE_ 10 | #define _MAL_GARBAGE_ 11 | #include "opt_support.h" 12 | 13 | mal_export str OPTgarbageCollectorImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /src/monetdblite/src/mal/optimizer/opt_reorder.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_REORDER_ 10 | #define _OPT_REORDER_ 11 | #include "opt_prelude.h" 12 | #include "opt_support.h" 13 | 14 | mal_export str OPTreorderImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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 | -------------------------------------------------------------------------------- /man/monetdblite_shutdown.Rd: -------------------------------------------------------------------------------- 1 | \name{monetdblite_shutdown} 2 | \alias{monetdblite_shutdown} 3 | 4 | \title{ 5 | Shutdown MonetDBLite 6 | } 7 | \description{ 8 | \code{monetdblite_shutdown} terminates the running MonetDBLite instance 9 | } 10 | \usage{ 11 | monetdblite_shutdown() 12 | } 13 | \value{ 14 | Returns \code{TRUE}. 15 | } 16 | \details{ 17 | This provides an alternative to \code{dbDisconnect(con, shutdown=TRUE)} when no connection is available. 18 | } 19 | \examples{ 20 | library(DBI) 21 | con <- dbConnect(MonetDBLite::MonetDBLite()) 22 | MonetDBLite::monetdblite_shutdown() 23 | } 24 | -------------------------------------------------------------------------------- /src/monetdblite/src/mal/optimizer/opt_pushselect.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_PUSHSELECT_H 10 | #define OPT_PUSHSELECT_H 11 | #include "opt_support.h" 12 | #include "opt_prelude.h" 13 | 14 | mal_export str OPTpushselectImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/src/mal/optimizer/opt_profiler.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_PROFILER_ 10 | #define _OPT_PROFILER_ 11 | #include "opt_prelude.h" 12 | #include "opt_support.h" 13 | #include "mal_exception.h" 14 | 15 | mal_export str OPTprofilerImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/src/mal/optimizer/opt_inline.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_INLINE_ 10 | #define _OPT_INLINE_ 11 | #include "opt_prelude.h" 12 | #include "opt_support.h" 13 | #include "mal_interpreter.h" 14 | #include "opt_macro.h" 15 | 16 | mal_export str OPTinlineImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /src/monetdblite/src/mal/optimizer/opt_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 | #include "opt_prelude.h" 12 | #include "opt_support.h" 13 | #include "mal_interpreter.h" 14 | 15 | mal_export str OPTprojectionpathImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /src/monetdblite/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 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | .onLoad <- function(libname, pkgname){ 2 | tryCatch({ 3 | # this is a (dirty) hack so we don't need to depend on dplyr 4 | dplyrMt <- getNamespace("dplyr")$.__S3MethodsTable__. 5 | dplyrMt[["sql_translate_env.MonetDBConnection"]] <- dplyr_sql_translate_env 6 | dplyrMt[["db_analyze.MonetDBConnection"]] <- dplyr_db_analyze 7 | dplyrMt[["db_explain.MonetDBLiteConnection"]] <- dplyr_db_analyze 8 | 9 | dplyrMt[["sample_n.tbl_monetdb"]] <- dplyr_sample_n 10 | dplyrMt[["sample_frac.tbl_monetdb"]] <- dplyr_sample_frac 11 | dplyrMt[["tbl.src_monetdb"]] <- dplyr_tbl_monetdb 12 | }, error = function(e){NA}) 13 | TRUE 14 | } 15 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/src/mal/optimizer/opt_evaluate.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_CX_ 10 | #define _OPT_CX_ 11 | #include "mal_stack.h" 12 | #include "mal_interpreter.h" /* for showErrors() */ 13 | #include "opt_prelude.h" 14 | #include "opt_support.h" 15 | 16 | mal_export str OPTevaluateImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /src/monetdblite/src/mal/optimizer/opt_mergetable.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_MERGETABLE_ 10 | #define _MAL_MERGETABLE_ 11 | #include "opt_prelude.h" 12 | #include "opt_support.h" 13 | #include "mal_interpreter.h" 14 | #include "mal_builder.h" 15 | 16 | mal_export str OPTmergetableImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/src/mal/optimizer/opt_generator.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_GENERATORCODE_ 10 | #define _OPT_GENERATORCODE_ 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 OPTgeneratorImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/src/mal/optimizer/opt_mitosis.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_MITOSIS_ 10 | #define _OPT_MITOSIS_ 11 | #include "opt_prelude.h" 12 | #include "opt_support.h" 13 | 14 | #define MAXSLICES 16 /* to be refined */ 15 | #define MINPARTCNT 100000 /* minimal record count per partition */ 16 | 17 | mal_export str OPTmitosisImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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/monetdblite/src/mal/optimizer/opt_multiplex.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_MULTIPLEX_H_ 10 | #define _OPT_MULTIPLEX_H_ 11 | #include "mal.h" 12 | #include "mal_builder.h" 13 | #include "opt_prelude.h" 14 | #include "opt_support.h" 15 | 16 | mal_export str OPTmultiplexImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 17 | mal_export str OPTmultiplexSimple(Client cntxt, MalBlkPtr mb); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /src/monetdblite/src/mal/optimizer/opt_remap.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_REMAP_ 10 | #define _OPT_REMAP_ 11 | 12 | #include "opt_prelude.h" 13 | #include "opt_support.h" 14 | #include "mal_interpreter.h" 15 | #include "mal_instruction.h" 16 | #include "mal_function.h" 17 | #include "mal_exception.h" 18 | 19 | mal_export str OPTremapImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /man/ml.Rd: -------------------------------------------------------------------------------- 1 | \name{ml} 2 | \alias{ml} 3 | 4 | \title{ 5 | Shorthand connection constructor for embedded MonetDB 6 | } 7 | \description{ 8 | \code{ml(...)} provides a short way of connecting to an embedded MonetDB database. It is equivalent to \code{dbConnect(MonetDBLite(),...)} 9 | } 10 | \usage{ 11 | ml(...) 12 | } 13 | \arguments{ 14 | \item{...}{Parameters passed directly to \code{dbConnect()}} 15 | } 16 | \value{ 17 | Returns a DBI connection to the specified embedded MonetDB database. 18 | } 19 | 20 | \seealso{ 21 | \code{\link[DBI]{dbConnect}} 22 | } 23 | \examples{ 24 | library(DBI) 25 | dbdir <- file.path( tempdir() , "ml" ) 26 | con <- ml(dbdir) 27 | dbDisconnect(con, shutdown = TRUE) 28 | } 29 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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 <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/monetdblite/src/mal/optimizer/opt_macro.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_MACRO_H_ 10 | #define _MAL_MACRO_H_ 11 | 12 | mal_export str MACROprocessor(Client cntxt, MalBlkPtr mb, Symbol t); 13 | mal_export int inlineMALblock(MalBlkPtr mb, int pc, MalBlkPtr mc); 14 | mal_export str OPTmacroImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); 15 | mal_export str OPTorcamImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); 16 | mal_export str OPTmacro(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); 17 | mal_export str OPTorcam(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); 18 | 19 | #endif /* _MAL_MACRO_H_ */ 20 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/src/mal/optimizer/opt_pipes.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_PIPES_ 10 | #define _OPT_PIPES_ 11 | #include "opt_prelude.h" 12 | #include "opt_support.h" 13 | 14 | mal_export str getPipeDefinition(str name); 15 | mal_export str getPipeCatalog(bat *nme, bat *def, bat *stat); 16 | mal_export str addPipeDefinition(Client cntxt, const char *name, const char *pipe); 17 | mal_export int isOptimizerPipe(const char *name); 18 | mal_export str addOptimizerPipe(Client cntxt, MalBlkPtr mb, const char *name); 19 | mal_export str compileOptimizer(Client cntxt, const char *name); 20 | mal_export str compileAllOptimizers(Client cntxt); 21 | mal_export void opt_pipes_reset(void); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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, const char *sname, const char *name, symbol *table_elements_or_subquery, int commit_action, const char *loc, int if_not_exists); 18 | extern sql_rel *rel_list(sql_allocator *sa, sql_rel *l, sql_rel *r); 19 | 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 ); 20 | 21 | #endif /*_REL_SCHEMA_H_*/ 22 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: r 2 | sudo: false 3 | cache: packages 4 | 5 | matrix: 6 | include: 7 | - os: linux 8 | r: oldrel 9 | - os: linux 10 | r: release 11 | - os: linux 12 | r: devel 13 | # - os: linux 14 | # r: devel 15 | # dist: trusty 16 | # env: 17 | # - RVERSION=devel _R_SAN_=TRUE _R_CHECK_FULL_=TRUE 18 | - os: osx 19 | r: release 20 | # - os: osx 21 | # r: devel 22 | 23 | 24 | # r: 25 | # - oldrel 26 | # - release 27 | # - devel 28 | #r_github_packages: 29 | # - r-lib/covr 30 | # - rstats-db/DBI 31 | # - rstats-db/DBItest 32 | # - hadley/testthat 33 | # - hadley/dplyr 34 | # - hadley/dbplyr 35 | 36 | script: 37 | - | 38 | R CMD build . 39 | travis_wait 80 R CMD check MonetDBLite*tar.gz 40 | 41 | addons: 42 | apt_packages: 43 | - pandoc 44 | 45 | # after_success: 46 | # - travis_wait Rscript -e 'covr::codecov()' 47 | 48 | after_failure: 49 | - ./travis-tool.sh dump_logs 50 | 51 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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/embeddedr/embeddedr.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 2008-2015 MonetDB B.V. 7 | */ 8 | 9 | /* 10 | * H. Muehleisen, M. Raasveldt 11 | * Inverse RAPI 12 | */ 13 | #ifndef _EMBEDDED_R_LIB_ 14 | #define _EMBEDDED_R_LIB_ 15 | //#define USE_RINTERNALS 1 16 | 17 | #include 18 | #include 19 | #include "embedded.h" 20 | 21 | SEXP monetdb_query_R(SEXP connsexp, SEXP querysexp, SEXP executesexp, SEXP resultconvertsexp, SEXP progressbarsexp, SEXP int64sexp); 22 | SEXP monetdb_startup_R(SEXP dbdirsexp, SEXP silentsexp, SEXP sequentialsexp); 23 | SEXP monetdb_append_R(SEXP connsexp, SEXP schemaname, SEXP tablename, SEXP tabledata); 24 | SEXP monetdb_connect_R(void); 25 | SEXP monetdb_disconnect_R(SEXP connsexp); 26 | SEXP monetdb_shutdown_R(void); 27 | 28 | void R_init_MonetDBLite(DllInfo *dll); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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 | 19 | b->vtop = 0; 20 | b->q = NULL; 21 | b->mb = NULL; 22 | b->mvc_var = 0; 23 | b->output_format = OFMT_CSV; 24 | return b; 25 | } 26 | 27 | backend * 28 | backend_create(mvc *m, Client c) 29 | { 30 | backend *b = MNEW(backend); 31 | 32 | if( b== NULL) 33 | return NULL; 34 | b->console = isAdministrator(c); 35 | b->mvc = m; 36 | b->client = c; 37 | b->mvc_var = 0; 38 | b->output_format = OFMT_CSV; 39 | return backend_reset(b); 40 | } 41 | 42 | void 43 | backend_destroy(backend *b) 44 | { 45 | _DELETE(b); 46 | } 47 | 48 | -------------------------------------------------------------------------------- /src/monetdblite/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 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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 | -------------------------------------------------------------------------------- /man/mc.Rd: -------------------------------------------------------------------------------- 1 | \name{mc} 2 | \alias{mc} 3 | 4 | \title{ 5 | Shorthand connection constructor for external MonetDB 6 | } 7 | \description{ 8 | \code{mc(...)} provides a short way of connecting to an external MonetDB database. It is equivalent to \code{dbConnect(MonetDB.R(),...)} 9 | } 10 | \usage{ 11 | mc(dbname="demo", user="monetdb", password="monetdb", host="localhost", port=50000, 12 | timeout=60, wait=FALSE,language="sql",...) 13 | } 14 | \arguments{ 15 | \item{dbname}{Database name} 16 | \item{user}{Username for database} 17 | \item{password}{Password for database} 18 | \item{host}{Host name of database server} 19 | \item{port}{TCP Port number of database server} 20 | \item{timeout}{Database connection and query timeout} 21 | \item{wait}{Wait for DB to become available or not} 22 | \item{language}{Database language to be used (probably "sql")} 23 | \item{...}{Unused} 24 | 25 | } 26 | \value{ 27 | Returns a DBI connection to the specified external MonetDB database. 28 | } 29 | 30 | \seealso{ 31 | \code{\link[DBI]{dbConnect}} 32 | } 33 | \examples{ 34 | \dontrun{ 35 | con <- mc(dbname="demo",hostname="localhost") 36 | }} 37 | -------------------------------------------------------------------------------- /src/monetdblite/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 | -------------------------------------------------------------------------------- /tests/testthat/test_07_oldfarm.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | library(DBI) 3 | 4 | versions <- c("0.5.0", "0.5.1") 5 | 6 | test_that("we can upgrade old dbs", { 7 | skip_on_os("windows") 8 | for (v in versions) { 9 | message(v) 10 | dbfile <- sprintf("oldfarm-%s.zip", v) 11 | uf <- file.path(tempdir(), "upgradetestfarm") 12 | unzip(dbfile, exdir=uf) 13 | dbfolder <- list.files(uf, full.names=T)[[1]] 14 | con <- dbConnect(MonetDBLite::MonetDBLite(), dbfolder) 15 | expect_true(dbExistsTable(con, "iris")) 16 | res <- dbReadTable(con, "iris") 17 | res$Species <- as.factor(res$Species) 18 | expect_equal(res, iris) 19 | dbDisconnect(con, shutdown=T) 20 | # start again because it might crash on shutdown 21 | con <- dbConnect(MonetDBLite::MonetDBLite(), dbfolder) 22 | dbDisconnect(con, shutdown=T) 23 | } 24 | }) 25 | 26 | create <- function(v) { 27 | devtools::install_version("MonetDBLite", version = v, repos = "https://cloud.r-project.org/") 28 | con <- dbConnect(MonetDBLite::MonetDBLite(), v) 29 | dbWriteTable(con, "iris", iris) 30 | dbDisconnect(con, shutdown=T) 31 | 32 | dbfile <- sprintf("oldfarm-%s.zip", v) 33 | zip(dbfile, v) 34 | } 35 | -------------------------------------------------------------------------------- /src/monetdblite/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 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: MonetDBLite 2 | Version: 0.6.1 3 | Title: In-Process Version of 'MonetDB' 4 | Authors@R: c( 5 | person("Hannes", "M\u00fchleisen", role = c("aut", "cre"), email = "hannes@cwi.nl", comment = c(ORCID = "0000-0001-8552-0029")), 6 | person("Mark", "Raasveldt", role = "ctb"), 7 | person("Thomas", "Lumley", role = "ctb"), 8 | person("MonetDB B.V.", role = "cph"), 9 | person("The Regents of the University of California", role = "cph"), 10 | person("Kungliga Tekniska Hogskolan", role = "cph"), 11 | person("Free Software Foundation, Inc.", role = "cph")) 12 | Description: An in-process version of 'MonetDB', a SQL database designed for analytical tasks. Similar to 'SQLite', the database runs entirely inside the 'R' shell. 13 | License: MPL (== 2.0) 14 | URL: https://github.com/hannesmuehleisen/MonetDBLite-R 15 | BugReports: https://github.com/hannesmuehleisen/MonetDBLite-R/issues 16 | Depends: R (>= 3.2.0) 17 | Imports: DBI (>= 0.6), digest (>= 0.6.4), methods, codetools 18 | Suggests: assertthat, testthat, survey, nycflights13, RSQLite, dbplyr, dplyr, gdata, callr, devtools, DBItest, bit64 19 | Collate: mapi.R dbi.R dbapply.R dplyr.R control.R embedded.R zzz.R 20 | Encoding: UTF-8 21 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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/monetdblite/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_STACK_H */ 42 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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.sessions() 12 | returns table("user" string, "login" timestamp, "sessiontimeout" bigint, "lastcommand" timestamp, "querytimeout" bigint, "active" bool) 13 | external name sql.sessions; 14 | create view sys.sessions as select * from sys.sessions(); 15 | 16 | create procedure sys.shutdown(delay tinyint) 17 | external name sql.shutdown; 18 | 19 | create procedure sys.shutdown(delay tinyint, force bool) 20 | external name sql.shutdown; 21 | 22 | -- control the query and session time out 23 | create procedure sys.settimeout("query" bigint) 24 | external name clients.settimeout; 25 | create procedure sys.settimeout("query" bigint, "session" bigint) 26 | external name clients.settimeout; 27 | create procedure sys.setsession("timeout" bigint) 28 | external name clients.setsession; 29 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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 | -------------------------------------------------------------------------------- /man/monetdbd.liststatus.Rd: -------------------------------------------------------------------------------- 1 | \name{monetdbd.liststatus} 2 | \alias{monetdbd.liststatus} 3 | \alias{monetdb.liststatus} 4 | 5 | 6 | \title{ 7 | Get list of available databases from external monetdbd 8 | } 9 | \description{ 10 | The \code{monetdbd} daemon can be used to manage multiple MonetDB databases in UNIX-like systems. This function connects to it and retrieves information about the available databases. Please note that \code{monetdbd} has to be configured to allow TCP control connections first. This can be done by setting a passphrase, e.g. "examplepassphrase" (\code{monetdbd set passphrase=examplepassphrase /path/to/dbfarm}) and then switching on remote control (\code{monetdbd set control=true /path/to/dbfarm}). 11 | } 12 | \usage{ 13 | monetdbd.liststatus(passphrase, host="localhost", port=50000L, timeout=86400L) 14 | } 15 | \arguments{ 16 | \item{passphrase}{\code{monetdbd} passphrase, see description} 17 | \item{host}{hostname to connect to} 18 | \item{port}{TCP port where \code{monetdbd} listens} 19 | \item{timeout}{Connection timeout (seconds)} 20 | } 21 | 22 | \value{ 23 | A \code{data.frame} that contains various information about the available databases. 24 | } 25 | \examples{ 26 | \dontrun{ 27 | print(monetdbd.liststatus("mypasshprase")$dbname) 28 | }} 29 | -------------------------------------------------------------------------------- /src/monetdblite/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 | -------------------------------------------------------------------------------- /man/dbApply.Rd: -------------------------------------------------------------------------------- 1 | \name{mdbapply} 2 | \alias{mdbapply} 3 | \alias{mdbapply,MonetDBConnection-method} 4 | 5 | \title{ 6 | Apply a R function to an external MonetDB table. 7 | } 8 | \description{ 9 | \code{dbApply} uses the R UDF facilities in standalone MonetDB to apply the passed function to a table. 10 | 11 | } 12 | \usage{ 13 | mdbapply(conn, table, fun, ...) 14 | } 15 | \arguments{ 16 | \item{conn}{An external MonetDB.R database connection. Created using \code{\link[DBI]{dbConnect}} 17 | with the \code{\link[MonetDBLite]{MonetDB.R}} external database driver.} 18 | \item{table}{An external MonetDB database table. Can also be a view or temporary table.} 19 | \item{fun}{A R function to be run on the external database table. The function gets passed a single \code{data.frame} argument which represents the database table. The function needs to return a single vector (for now).} 20 | \item{...}{Other parameters to be passed to the function} 21 | 22 | } 23 | \value{ 24 | Returns the result of the function applied to the database table. 25 | } 26 | \examples{ 27 | \dontrun{ 28 | library(DBI) 29 | con <- dbConnect(MonetDB.R(), "demo") 30 | data(mtcars) 31 | dbWriteTable(con, "mtcars", mtcars) 32 | 33 | mpgplus42 <- mdbapply(con, "mtcars", "double", function(d) { 34 | d$mpg + 42 35 | }) 36 | }} 37 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # DO NOT CHANGE the "init" and "install" sections below 2 | 3 | # Download script file from GitHub 4 | init: 5 | ps: | 6 | $ErrorActionPreference = "Stop" 7 | Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1" 8 | Import-Module '..\appveyor-tool.ps1' 9 | 10 | install: 11 | - ps: Bootstrap 12 | 13 | environment: 14 | # global: 15 | # WARNINGS_ARE_ERRORS: 1 16 | 17 | matrix: 18 | - R_VERSION: devel 19 | 20 | - R_VERSION: release 21 | 22 | - R_VERSION: devel 23 | WARNINGS_ARE_ERRORS: 1 24 | 25 | - R_VERSION: release 26 | WARNINGS_ARE_ERRORS: 1 27 | 28 | build_script: 29 | - travis-tool.sh install_deps 30 | # - travis-tool.sh github_package rstats-db/DBI 31 | # - travis-tool.sh github_package rstats-db/DBItest 32 | 33 | test_script: 34 | - travis-tool.sh run_tests 35 | 36 | on_failure: 37 | - 7z a failure.zip *.Rcheck\* 38 | - appveyor PushArtifact failure.zip 39 | 40 | artifacts: 41 | - path: '*.Rcheck\**\*.log' 42 | name: Logs 43 | 44 | - path: '*.Rcheck\**\*.out' 45 | name: Logs 46 | 47 | - path: '*.Rcheck\**\*.fail' 48 | name: Logs 49 | 50 | - path: '*.Rcheck\**\*.Rout' 51 | name: Logs 52 | 53 | - path: '\*_*.tar.gz' 54 | name: Bits 55 | 56 | - path: '\*_*.zip' 57 | name: Bits 58 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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 | -------------------------------------------------------------------------------- /tests/testthat/test_03_dbitest.R: -------------------------------------------------------------------------------- 1 | if (Sys.getenv("NOT_CRAN", unset="no") != "no") { 2 | if (Sys.getenv("MONETDBLITE_INMEMORY", unset="no") == "yes") { 3 | dbfolder <- ":memory:" 4 | } else { 5 | dbfolder <- file.path(tempdir(), "dbidir") 6 | } 7 | message("test_03: using ", dbfolder) 8 | 9 | DBItest::make_context(MonetDBLite::MonetDBLite(), dbfolder, tweaks=DBItest::tweaks( 10 | date_cast=function(x) paste0("CAST('", x, "' AS DATE)"), 11 | time_cast=function(x) paste0("CAST('", x, "' AS TIME)"), 12 | timestamp_cast=function(x) paste0("CAST('", x, "' AS TIMESTAMP)"), 13 | omit_blob_tests=TRUE, 14 | strict_identifier=TRUE 15 | )) 16 | 17 | # TODO: get data_64_bit_numeric_warning / data_64_bit_lossless right 18 | # TODO fix NULL IS NULL in SQL parser 19 | # TODO fix roundtrip_time/roundtrip_timestamp/roundtrip_field_types 20 | 21 | skip <- c("package_name", "send_query_only_one_result_set", "send_statement_only_one_result_set", "data_64_bit_numeric_warning", "data_64_bit_lossless", "quote_string_na_is_null", "roundtrip_64_bit_numeric", "roundtrip_64_bit_character", "roundtrip_time", "roundtrip_timestamp", "roundtrip_field_types", "get_info_result", "overwrite_table_missing", "compliance", "get_query_n_bad", "get_query_good_after_bad_n", "data_timestamp", "read_table_row_names_false", "read_table_row_names_default", "roundtrip_numeric_special") 22 | 23 | DBItest::test_all(skip=skip) 24 | 25 | MonetDBLite::monetdblite_shutdown() 26 | warnings() 27 | } 28 | -------------------------------------------------------------------------------- /src/monetdblite/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 b->batDirty field tells you whether a BATs 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/monetdblite/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/monetdblite/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 | -------------------------------------------------------------------------------- /man/MonetDB.R.Rd: -------------------------------------------------------------------------------- 1 | \name{MonetDB.R} 2 | \alias{MonetDB.R} 3 | \alias{MonetDBR} 4 | \alias{MonetDB} 5 | \alias{MonetR} 6 | \alias{RMonetDB} 7 | 8 | \title{ 9 | DBI database connector for external MonetDB database 10 | } 11 | \description{ 12 | \code{MonetDB.R} creates a new DBI driver that can be used to connect and interact with external MonetDB database. 13 | } 14 | \usage{ 15 | MonetDB.R() 16 | } 17 | \value{ 18 | Returns a driver object that can be used in calls to 19 | \code{\link[DBI]{dbConnect}} with an external MonetDB database. 20 | } 21 | \details{ 22 | The \code{MonetDB.R} function creates the R object which can be used to a 23 | call \code{\link[DBI]{dbConnect}} which actually creates the connection. 24 | Since it has no parameters, it is most commonly used inline with the \code{\link[DBI]{dbConnect}} call. 25 | 26 | All of the \code{MonetDBLite::MonetDB.R()} external server connection functions are discouraged in favor of embedded \code{\link[=MonetDBLite]{MonetDBLite::MonetDBLite()}} functions. 27 | 28 | This package aims to provide a reasonably complete implementation of the DBI. 29 | } 30 | \seealso{ 31 | \code{\link[DBI]{dbConnect}} for documentation how to invoke the driver 32 | \code{\link[=control]{monetdb.server.setup}} to set up and start a local MonetDB server from R 33 | } 34 | \examples{ 35 | \dontrun{ 36 | library(DBI) 37 | con <- dbConnect(MonetDBLite::MonetDB.R(), dbname = "demo") 38 | dbWriteTable(con, "iris", iris) 39 | dbListTables(con) 40 | dbGetQuery(con, "SELECT COUNT(*) FROM iris") 41 | d <- dbReadTable(con, "iris") 42 | }} 43 | \keyword{interface} 44 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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/embeddedr/mapisplit-r.c: -------------------------------------------------------------------------------- 1 | #ifdef HAVE_EMBEDDED_R 2 | #include 3 | #include 4 | #include "mapisplit.h" 5 | #include "mapisplit-r.h" 6 | 7 | #include "monetdb_config.h" 8 | 9 | char nullstr[] = "NULL"; 10 | 11 | SEXP mapi_split(SEXP mapiLinesVector, SEXP numCols) { 12 | const int cols = INTEGER_POINTER(AS_INTEGER(numCols))[0]; 13 | const int rows = LENGTH(mapiLinesVector); 14 | SEXP colVec; 15 | int cRow; 16 | int cCol; 17 | char **elems = malloc(sizeof(char*)* cols); 18 | if (!elems) { 19 | error("Memory allocation failure"); 20 | } 21 | 22 | if (!IS_CHARACTER(mapiLinesVector) || rows < 1 || cols < 1) { 23 | error("Invalid input to mapi_split: type=%d, rows=%d, cols=%d", TYPEOF(mapiLinesVector), rows, cols); 24 | } 25 | 26 | PROTECT(colVec = NEW_LIST(cols)); 27 | 28 | for (cRow = 0; cRow < cols; cRow++) { 29 | SEXP colV = PROTECT(NEW_STRING(rows)); 30 | SET_ELEMENT(colVec, cRow, colV); 31 | UNPROTECT(1); 32 | } 33 | 34 | 35 | for (cRow = 0; cRow < rows; cRow++) { 36 | const char *rval = CHAR(STRING_ELT(mapiLinesVector, cRow)); 37 | char *val = strdup(rval); 38 | 39 | cCol = 0; 40 | mapi_line_split(val, elems, cols); 41 | 42 | for (cCol = 0; cCol < cols; cCol++) { 43 | SEXP colV = VECTOR_ELT(colVec, cCol); 44 | size_t tokenLen = strlen(elems[cCol]); 45 | if (tokenLen < 1 || strcmp(elems[cCol], nullstr) == 0) { 46 | SET_STRING_ELT(colV, cRow, NA_STRING); 47 | } 48 | else { 49 | SET_STRING_ELT(colV, cRow, mkCharLen(elems[cCol], tokenLen)); 50 | } 51 | } 52 | free(val); 53 | } 54 | free(elems); 55 | 56 | UNPROTECT(1); 57 | return colVec; 58 | } 59 | #endif 60 | -------------------------------------------------------------------------------- /src/monetdblite/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 | -------------------------------------------------------------------------------- /man/src_monetdb.Rd: -------------------------------------------------------------------------------- 1 | \name{src_monetdb} 2 | \alias{src_monetdb} 3 | \alias{src_monetdblite} 4 | 5 | \title{dplyr integration from MonetDBLite} 6 | \usage{ 7 | src_monetdb(dbname, host = "localhost", port = 50000L, user = "monetdb", 8 | password = "monetdb", con=FALSE, ...) 9 | 10 | src_monetdblite(dbdir = tempdir(), ...) 11 | 12 | } 13 | \arguments{ 14 | \item{dbname}{Database name} 15 | 16 | \item{host,port}{Host name and port number of database (defaults to localhost:50000)} 17 | 18 | \item{user,password}{User name and password (if needed)} 19 | 20 | \item{con}{Existing DBI connection to MonetDB to be re-used} 21 | 22 | \item{...}{for the src, other arguments passed on to the underlying 23 | database connector, \code{dbConnect}.} 24 | 25 | \item{dbdir}{a directory to start MonetDBLite in} 26 | } 27 | \description{ 28 | Use \code{src_monetdb} to connect to an existing MonetDB database, 29 | and \code{tbl} to connect to tables within that database. Please note that the ORDER BY, LIMIT and OFFSET keywords 30 | are not supported in the query when using \code{tbl} on a connection to a MonetDB database. 31 | If you are running a local database, you only need to define the name of the database you want to connect to. 32 | } 33 | 34 | \examples{ 35 | library(dplyr) 36 | # To connect to a database first create a src: 37 | dbdir <- file.path(tempdir(), "dplyrdir") 38 | my_db <- MonetDBLite::src_monetdblite(dbdir) 39 | 40 | # copy some data to DB 41 | my_iris <- copy_to(my_db, iris) 42 | 43 | # create table object 44 | my_iris2 <- tbl(my_db, 'iris') 45 | 46 | # now you can call regular dplyr methods on table object 47 | 48 | # ... 49 | 50 | # shut down the database 51 | MonetDBLite::monetdblite_shutdown() 52 | } 53 | 54 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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 | int console; 35 | char language; /* 'S' or 's' or 'X' */ 36 | mvc *mvc; 37 | stream *out; 38 | ofmt output_format; /* csv, json */ 39 | Client client; 40 | MalBlkPtr mb; /* needed during mal generation */ 41 | int mvc_var; 42 | int vtop; /* top of the variable stack before the current function */ 43 | cq *q; /* pointer to the cached query */ 44 | } backend; 45 | 46 | extern backend *backend_reset(backend *b); 47 | extern backend *backend_create(mvc *m, Client c); 48 | extern void backend_destroy(backend *b); 49 | 50 | #endif /*MAL_BACKEND_H*/ 51 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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 | -------------------------------------------------------------------------------- /man/dbSendUpdate.Rd: -------------------------------------------------------------------------------- 1 | \name{dbSendUpdate} 2 | \alias{dbSendUpdate} 3 | \alias{dbSendUpdateAsync} 4 | \alias{dbSendUpdate,MonetDBConnection,character-method} 5 | \alias{dbSendUpdateAsync,MonetDBConnection,character-method} 6 | 7 | \title{ 8 | Send a data-altering SQL statement to the database. (DEPRECATED) 9 | } 10 | \description{ 11 | Note: This function has been deprecated and will be removed in a future release! 12 | \code{dbSendUpdate} is used to send a data-altering statement to a MonetDB database, 13 | e.g. \code{CREATE TABLE} or \code{INSERT}. As a convenience feature, a placeholder 14 | (\code{?} character) can be used in the SQL statement, and bound to parameters given 15 | in the varargs group before execution. This is especially useful when scripting 16 | database updates, since the parameters will be automatically quoted. 17 | 18 | The \code{dbSendUpdateAsync} function is used when the database update is called from 19 | finalizers, to avoid very esoteric concurrency problems. Here, the update is not guaranteed 20 | to be immediately run. Also, the method returns immediately. 21 | } 22 | \usage{ 23 | dbSendUpdate( conn, statement, ..., async=FALSE ) 24 | } 25 | \arguments{ 26 | \item{conn}{A MonetDBLite database connection. Created using \code{\link[DBI]{dbConnect}} 27 | with the \code{\link[MonetDBLite]{MonetDBLite}} database driver.} 28 | \item{statement}{A SQL statement to be sent to the database, e.g. 'UPDATE' or 'INSERT'.} 29 | \item{...}{Parameters to be bound to '?' characters in the query, similar to JDBC.} 30 | \item{async}{Behave like \code{dbSendUpdateAsync}? Defaults to \code{FALSE}.} 31 | } 32 | \value{ 33 | Returns \code{TRUE} if the update was successful. 34 | } 35 | \seealso{ 36 | \code{\link[DBI]{dbSendQuery}} 37 | } 38 | 39 | \keyword{interface} 40 | -------------------------------------------------------------------------------- /src/embeddedr/mapisplit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "mapisplit.h" 4 | 5 | typedef enum { 6 | INQUOTES, ESCAPED, INTOKEN, INCRAP 7 | } mapi_line_chrstate; 8 | 9 | void mapi_unescape(char* in, char* out) { 10 | char escaped = 0; 11 | size_t i, o = 0; 12 | 13 | for (i=0; i < strlen(in); i++) { 14 | if (!escaped && in[i] == '\\') { 15 | escaped = 1; 16 | continue; 17 | } 18 | out[o++] = in[i]; 19 | escaped = 0; 20 | } 21 | out[o] = '\0'; 22 | } 23 | 24 | void mapi_line_split(char* line, char** out, size_t ncols) { 25 | size_t cCol = 0; 26 | int tokenStart = 2; 27 | int endQuote = 0; 28 | int curPos; 29 | int linelen = (int) strlen(line); 30 | mapi_line_chrstate state = INCRAP; 31 | 32 | // special case: PLAN/EXPLAIN 33 | if (*line == '=') { 34 | out[0] = &line[1]; 35 | return; 36 | } 37 | 38 | (void) ncols; 39 | for (curPos = 2; curPos < linelen - 1; curPos++) { 40 | char chr = line[curPos]; 41 | 42 | switch (state) { 43 | case INCRAP: 44 | if (chr != '\t' && chr != ',' && chr != ' ') { 45 | tokenStart = curPos; 46 | if (chr == '"') { 47 | state = INQUOTES; 48 | tokenStart++; 49 | } else { 50 | state = INTOKEN; 51 | } 52 | } 53 | break; 54 | 55 | case INTOKEN: 56 | if (chr == ',' || curPos == linelen - 2) { 57 | int tokenLen = curPos - tokenStart - endQuote; 58 | line[tokenStart + tokenLen] = '\0'; 59 | out[cCol] = &line[tokenStart]; 60 | cCol++; 61 | endQuote = 0; 62 | state = INCRAP; 63 | } 64 | break; 65 | 66 | case ESCAPED: 67 | state = INQUOTES; 68 | break; 69 | 70 | case INQUOTES: 71 | if (chr == '"') { 72 | state = INTOKEN; 73 | endQuote++; 74 | break; 75 | } 76 | if (chr == '\\') { 77 | state = ESCAPED; 78 | break; 79 | } 80 | break; 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/src/mal/modules/batmmath.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 _BATMATH_H 10 | #define _BATMATH_H 11 | #include "gdk.h" 12 | #include 13 | #include "mal_exception.h" 14 | 15 | #define radians(x) ((x) * 3.14159265358979323846 / 180.0) 16 | #define degrees(x) ((x) * 180.0 / 3.14159265358979323846) 17 | #define radiansf(x) ((flt) radians(x)) 18 | #define degreesf(x) ((flt) degrees(x)) 19 | 20 | 21 | #define scienceDef(X1)\ 22 | mal_export str CMDscience_bat_dbl_##X1(bat *ret, const bat *bid);\ 23 | mal_export str CMDscience_bat_flt_##X1(bat *ret, const bat *bid); 24 | 25 | scienceDef(asin) 26 | scienceDef(acos) 27 | scienceDef(atan) 28 | scienceDef(cos) 29 | scienceDef(sin) 30 | scienceDef(tan) 31 | scienceDef(cosh) 32 | scienceDef(sinh) 33 | scienceDef(tanh) 34 | scienceDef(radians) 35 | scienceDef(degrees) 36 | scienceDef(exp) 37 | scienceDef(log) 38 | scienceDef(log10) 39 | scienceDef(sqrt) 40 | scienceDef(cbrt) 41 | scienceDef(ceil) 42 | scienceDef(fabs) 43 | scienceDef(floor) 44 | 45 | mal_export str CMDscience_bat_cst_atan2_dbl(bat *ret, const bat *bid, const dbl *d); 46 | mal_export str CMDscience_bat_cst_atan2_flt(bat *ret, const bat *bid, const flt *d); 47 | mal_export str CMDscience_cst_bat_atan2_dbl(bat *ret, const dbl *d, const bat *bid); 48 | mal_export str CMDscience_cst_bat_atan2_flt(bat *ret, const flt *d, const bat *bid); 49 | mal_export str CMDscience_bat_cst_pow_dbl(bat *ret, const bat *bid, const dbl *d); 50 | mal_export str CMDscience_bat_cst_pow_flt(bat *ret, const bat *bid, const flt *d); 51 | mal_export str CMDscience_cst_bat_pow_dbl(bat *ret, const dbl *d, const bat *bid); 52 | mal_export str CMDscience_cst_bat_pow_flt(bat *ret, const flt *d, const bat *bid); 53 | #endif /* _BATMATH_H */ 54 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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/monetdblite/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 | -------------------------------------------------------------------------------- /src/monetdblite/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/monetdblite/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/monetdblite/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 | --------------------------------------------------------------------------------