Changeset: bdcd02833b9b for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=bdcd02833b9b Added Files: sql/backends/monet5/sample/80_sample.sql sql/backends/monet5/sample/Makefile.ag sql/backends/monet5/sample/Tests/All sql/backends/monet5/sample/Tests/weightedsample.sql sql/backends/monet5/sample/sample.c sql/backends/monet5/sample/sample.h Modified Files: sql/server/sql_parser.y Branch: stratified_sampling Log Message:
Add missing sampling files. diffs (183 lines): diff --git a/sql/backends/monet5/sample/80_sample.sql b/sql/backends/monet5/sample/80_sample.sql new file mode 100644 --- /dev/null +++ b/sql/backends/monet5/sample/80_sample.sql @@ -0,0 +1,13 @@ +-- This Source Code Form is subject to the terms of the Mozilla Public +-- License, v. 2.0. If a copy of the MPL was not distributed with this +-- file, You can obtain one at http://mozilla.org/MPL/2.0/. +-- +-- Copyright 1997 - July 2008 CWI, August 2008 - 2016 MonetDB B.V. + +-- add function signatures to SQL catalog + + +-- Reverse a string +create function weighted_sample(src double, cnt bigint) +returns boolean external name libsample.weighted_sample;--TODO possibly nolibsample + diff --git a/sql/backends/monet5/sample/Makefile.ag b/sql/backends/monet5/sample/Makefile.ag new file mode 100644 --- /dev/null +++ b/sql/backends/monet5/sample/Makefile.ag @@ -0,0 +1,36 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Copyright 1997 - July 2008 CWI, August 2008 - 2016 MonetDB B.V. + +INCLUDES = .. \ + ../../../include \ + ../../../common \ + ../../../storage \ + ../../../server \ + ../../../../monetdb5/modules/atoms \ + ../../../../monetdb5/modules/kernel \ + ../../../../monetdb5/mal \ + ../../../../monetdb5/modules/mal \ + ../../../../monetdb5/optimizer \ + ../../../../common/options \ + ../../../../common/stream \ + ../../../../gdk + +lib__sample = { + MODULE + DIR = libdir/monetdb5 + SOURCES = sample.c sample.h sample_impl.h + LIBS = ../../../../monetdb5/tools/libmonetdb5 \ + ../../../../gdk/libbat +} + +headers_sql = { + HEADERS = sql + DIR = libdir/monetdb5/createdb + SOURCES = 80_sample.sql +} + +EXTRA_DIST_DIR = Tests + diff --git a/sql/backends/monet5/sample/Tests/All b/sql/backends/monet5/sample/Tests/All new file mode 100644 --- /dev/null +++ b/sql/backends/monet5/sample/Tests/All @@ -0,0 +1,1 @@ +weightedsample diff --git a/sql/backends/monet5/sample/Tests/weightedsample.sql b/sql/backends/monet5/sample/Tests/weightedsample.sql new file mode 100644 --- /dev/null +++ b/sql/backends/monet5/sample/Tests/weightedsample.sql @@ -0,0 +1,9 @@ +set optimizer = 'sequential_pipe'; +-- ADD FLAG TO DISALLOW PARALLELIZATION (MITOSIS) FOR weighted_sample +CREATE TABLE wsample (i INTEGER, weights DOUBLE); +INSERT INTO wsample VALUES (1, 1), (2, 1), (3, 1), (4, 1), (5, 1); + + +explain SELECT i FROM wsample WHERE weighted_sample(weights, 2); +SELECT i FROM wsample WHERE weighted_sample(weights, 2); + diff --git a/sql/backends/monet5/sample/sample.c b/sql/backends/monet5/sample/sample.c new file mode 100644 --- /dev/null +++ b/sql/backends/monet5/sample/sample.c @@ -0,0 +1,47 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 1997 - July 2008 CWI, August 2008 - 2016 MonetDB B.V. + */ + +/* monetdb_config.h must be the first include in each .c file */ + +#include "monetdb_config.h" +#include "sample.h" + +#ifdef notdefined //!!!TODO + +/* MAL wrapper */ +char * +UDFBATweightedsample(bat *ret, const bat *arg, const lng *cnt) +{//bat = identifier, BAT is actual bat, BATdescriptor turns ID into BAT + BAT *res = NULL, *src = NULL; + char *msg = NULL; + + /* assert calling sanity */ + assert(ret != NULL && arg != NULL); + + /* bat-id -> BAT-descriptor */ + if ((src = BATdescriptor(*arg)) == NULL) + throw(MAL, "batudf.reverse", RUNTIME_OBJECT_MISSING); + printf("Count: %lld\n", *cnt); + + //TODO Type checking + /* do the work */ + //msg = UDFBATreverse_ ( &res, src );//TODO + throw(MAL, "batudf.reverse", "LOLFAIL");//TODO + res = _BATsample(arg, *cnt, BAT *cdf) + + /* release input BAT-descriptor */ + //BBPunfix(src->batCacheid); + + //if (msg == MAL_SUCCEED) { + /* register result BAT in buffer pool */ + // BBPkeepref((*ret = res->batCacheid)); + //} + return msg; +} + +#endif diff --git a/sql/backends/monet5/sample/sample.h b/sql/backends/monet5/sample/sample.h new file mode 100644 --- /dev/null +++ b/sql/backends/monet5/sample/sample.h @@ -0,0 +1,20 @@ +/* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright 1997 - July 2008 CWI, August 2008 - 2016 MonetDB B.V. + */ + +/* In your own module, replace "UDF" & "udf" by your module's name */ + +#ifndef _SQL_WEIGHTEDSAMPLE_H_ +#define _SQL_WEIGHTEDSAMPLE_H_ +#include "sql.h" + +/* export MAL wrapper functions */ + +extern char * UDFBATweightedsample(bat *ret, const bat *arg, const lng *cnt); + +#endif + diff --git a/sql/server/sql_parser.y b/sql/server/sql_parser.y --- a/sql/server/sql_parser.y +++ b/sql/server/sql_parser.y @@ -4664,15 +4664,21 @@ literal: | sqlDBL { sql_subtype *t= sql_bind_localtype("dbl"); + double val; + char *p = $1; + errno = 0; - $$ = _newAtomNode( atom_float(SA, t, strtod($1,NULL))); + val = strtod($1,&p); if(errno) { char *msg = sql_message("\b22003!double value could not be parsed (%s)", $1); - errno = 0; + yyerror(m, msg); _DELETE(msg); + $$ = NULL; YYABORT; } + + $$ = _newAtomNode( atom_float(SA, t, val)); } ; _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list