simple udf code generation

dev
Bill 2 years ago
parent ece2a6cc9f
commit 5b1bbf0f99

5
.gitignore vendored

@ -18,6 +18,9 @@ out.k
k k
*.so *.so
*.pdf *.pdf
**/*.cmake
**/Debug
**/Release
test*.c* test*.c*
*.csv *.csv
!test.csv !test.csv
@ -38,3 +41,5 @@ test*.c*
*.shm *.shm
server/packages/** server/packages/**
*.ipynb *.ipynb
*.cmake
*.stackdump

@ -4,9 +4,14 @@ MonetDB_LIB =
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
OS_SUPPORT += server/winhelper.cpp OS_SUPPORT += server/winhelper.cpp
MonetDB_LIB += -Imonetdb/msvc msc-plugin/monetdbe.dll MonetDB_LIB += -Imonetdb/msvc msc-plugin/monetdbe.dll
else
MonetDB_LIB += -lmonetdbe
endif endif
$(info $(OS_SUPPORT))
info:
$(info $(OS_SUPPORT))
$(info $(OS))
$(info "test")
server.bin: server.bin:
$(CXX) server/server.cpp $(OS_SUPPORT) --std=c++1z -O3 -march=native -o server.bin $(CXX) server/server.cpp $(OS_SUPPORT) --std=c++1z -O3 -march=native -o server.bin
server.so: server.so:

@ -0,0 +1,222 @@
{
"stmts": {
"udf": {
"fname": "covariances2",
"params": ["x", "y", "w"],
"stmt": [{
"assignment": {
"var": "xmeans",
"op": ":=",
"expr": 0.0
}
}, {
"assignment": {
"var": "ymeans",
"op": ":=",
"expr": 0.0
}
}, {
"assignment": {
"var": "l",
"op": ":=",
"expr": "_builtin_len"
}
}, {
"if": {
"cond": {
"gt": ["w", "l"]
},
"assignment": {
"var": "w",
"op": ":=",
"expr": "l"
},
"elif": [{
"cond": {
"gt": ["w", {
"add": ["l", 2]
}]
},
"stmt": [{
"assignment": {
"var": "l",
"op": ":=",
"expr": 3
}
}, {
"assignment": {
"var": "w",
"op": ":=",
"expr": 4
}
}]
}, {
"cond": {
"lt": ["w", 99]
},
"stmt": {
"assignment": {
"var": "l",
"op": ":=",
"expr": 8
}
}
}, {
"cond": {
"lt": ["w", 999]
},
"assignment": {
"var": "w",
"op": ":=",
"expr": 6
}
}],
"else": {
"assignment": {
"var": "l",
"op": ":=",
"expr": {
"div": ["l", 2]
}
}
}
}
}, {
"for": {
"defs": {
"var": ["i", "j"],
"op": [":=", ":="],
"expr": [0, 0]
},
"cond": {
"lt": ["i", "w"]
},
"tail": {
"var": "i",
"op": ":=",
"expr": {
"add": ["i", 1]
}
},
"stmt": [{
"assignment": {
"var": "xmeans",
"op": "+=",
"expr": {
"get": ["x", "i"]
}
}
}, {
"assignment": {
"var": "ymeans",
"op": "+=",
"expr": {
"get": ["y", "i"]
}
}
}, {
"assignment": {
"var": {
"get": ["_builtin_ret", "i"]
},
"op": ":=",
"expr": {
"avg": {
"mul": [{
"sub": [{
"x": [{
"sub": ["l", "w"]
}, "l"]
}, "xmeans"]
}, {
"sub": [{
"y": [{
"sub": ["l", "w"]
}, "l"]
}, "ymeans"]
}]
}
}
}
}]
}
}, {
"for": {
"defs": {
"var": "i",
"op": ":=",
"expr": 0
},
"cond": {
"lt": ["i", "l"]
},
"tail": {
"var": "i",
"op": "+=",
"expr": 1
},
"stmt": [{
"assignment": {
"var": "xmeans",
"op": "+=",
"expr": {
"div": [{
"sub": [{
"get": ["x", "i"]
}, {
"get": ["x", {
"sub": ["i", "w"]
}]
}]
}, "w"]
}
}
}, {
"assignment": {
"var": "ymeans",
"op": "+=",
"expr": {
"div": [{
"sub": [{
"get": ["y", "i"]
}, {
"get": ["y", {
"sub": ["i", "w"]
}]
}]
}, "w"]
}
}
}, {
"assignment": {
"var": {
"get": ["_builtin_ret", "i"]
},
"op": ":=",
"expr": {
"avg": {
"mul": [{
"sub": [{
"x": [{
"sub": ["l", "w"]
}, "l"]
}, "xmeans"]
}, {
"sub": [{
"y": [{
"sub": ["l", "w"]
}, "l"]
}, "ymeans"]
}]
}
}
}
}]
}
}],
"ret": {
"null": {}
}
}
}
}

@ -1,30 +1,32 @@
# put environment specific configuration here # put environment specific configuration here
import os import os
# os.environ['CXX'] = 'C:/Program Files/LLVM/bin/clang.exe' # os.environ['CXX'] = 'C:/Program Files/LLVM/bin/clang.exe'
add_path_to_ldpath = True add_path_to_ldpath = True
rebuild_backend = False
os_platform = 'unkown' run_backend = False
import sys os_platform = 'unkown'
if os.name == 'nt': import sys
if sys.platform == 'win32':
os_platform = 'win' if os.name == 'nt':
elif sys.platform == 'cygwin' or sys.platform == 'msys': if sys.platform == 'win32':
os_platform = 'cygwin' os_platform = 'win'
elif os.name == 'posix': elif sys.platform == 'cygwin' or sys.platform == 'msys':
if sys.platform == 'darwin': os_platform = 'cygwin'
os_platform = 'mac' elif os.name == 'posix':
elif 'linux' in sys.platform: if sys.platform == 'darwin':
os_platform = 'linux' os_platform = 'mac'
elif 'bsd' in sys.platform: elif 'linux' in sys.platform:
os_platform = 'bsd' os_platform = 'linux'
elif 'bsd' in sys.platform:
os_platform = 'bsd'
# deal with msys dependencies:
if os_platform == 'win':
os.add_dll_directory('c:/msys64/usr/bin') # deal with msys dependencies:
os.add_dll_directory(os.path.abspath('./msc-plugin')) if os_platform == 'win':
os.add_dll_directory('c:/msys64/usr/bin')
os.add_dll_directory(os.path.abspath('./msc-plugin'))
print("adding path") print("adding path")

@ -34,6 +34,7 @@ FETCH = keyword("fetch").suppress()
FROM = keyword("from").suppress() FROM = keyword("from").suppress()
FULL = keyword("full") FULL = keyword("full")
FUNCTION = keyword("function").suppress() FUNCTION = keyword("function").suppress()
AGGREGATION = keyword("aggregation").suppress()
GROUP = keyword("group").suppress() GROUP = keyword("group").suppress()
HAVING = keyword("having").suppress() HAVING = keyword("having").suppress()
INNER = keyword("inner") INNER = keyword("inner")
@ -73,6 +74,11 @@ RECURSIVE = keyword("recursive").suppress()
VALUES = keyword("values").suppress() VALUES = keyword("values").suppress()
WINDOW = keyword("window") WINDOW = keyword("window")
INTO = keyword("into").suppress() INTO = keyword("into").suppress()
IF = keyword("if").suppress()
STATIC = keyword("static").suppress()
ELIF = keyword("elif").suppress()
ELSE = keyword("else").suppress()
FOR = keyword("for").suppress()
PRIMARY_KEY = Group(PRIMARY + KEY).set_parser_name("primary_key") PRIMARY_KEY = Group(PRIMARY + KEY).set_parser_name("primary_key")
FOREIGN_KEY = Group(FOREIGN + KEY).set_parser_name("foreign_key") FOREIGN_KEY = Group(FOREIGN + KEY).set_parser_name("foreign_key")
@ -112,8 +118,14 @@ INDF = (
keyword("is not distinct from").set_parser_name("ne!") keyword("is not distinct from").set_parser_name("ne!")
) )
FASSIGN = Literal(":=").set_parser_name("fassign") # Assignment in UDFs FASSIGN = Literal(":=").set_parser_name("fassign") # Assignment in UDFs
PASSIGN = Literal("+=").set_parser_name("passign")
MASSIGN = Literal("-=").set_parser_name("massign")
MULASSIGN = Literal("*=").set_parser_name("mulassign")
DASSIGN = Literal("/=").set_parser_name("dassign")
COLON = Literal(":").set_parser_name("colon")
NEQ = (Literal("!=") | Literal("<>")).set_parser_name("neq") NEQ = (Literal("!=") | Literal("<>")).set_parser_name("neq")
LAMBDA = Literal("->").set_parser_name("lambda") LAMBDA = Literal("->").set_parser_name("lambda")
DOT = Literal(".").set_parser_name("dot")
AND = keyword("and") AND = keyword("and")
BETWEEN = keyword("between") BETWEEN = keyword("between")
@ -233,6 +245,8 @@ L_INLINE = Literal("<k>").suppress()
R_INLINE = Literal("</k>").suppress() R_INLINE = Literal("</k>").suppress()
LBRACE = Literal("{").suppress() LBRACE = Literal("{").suppress()
RBRACE = Literal("}").suppress() RBRACE = Literal("}").suppress()
LSB = Literal("[").suppress()
RSB = Literal("]").suppress()
LB = Literal("(").suppress() LB = Literal("(").suppress()
RB = Literal(")").suppress() RB = Literal(")").suppress()
EQ = Char("=").suppress() EQ = Char("=").suppress()

@ -235,6 +235,8 @@ def parser(literal_string, ident, sqlserver=False):
scale_function = ((real_num | int_num) + call_function) / scale scale_function = ((real_num | int_num) + call_function) / scale
scale_ident = ((real_num | int_num) + ident) / scale scale_ident = ((real_num | int_num) + ident) / scale
compound = ( compound = (
NULL NULL
| TRUE | TRUE
@ -329,13 +331,40 @@ def parser(literal_string, ident, sqlserver=False):
+ Group(var_name("name") + AS + over_clause("value"))("join") + Group(var_name("name") + AS + over_clause("value"))("join")
) )
) / to_join_call ) / to_join_call
fassign = Group(var_name("var") + Suppress(FASSIGN) + expr("expr") + Suppress(";"))("assignment")
fassigns = fassign + ZeroOrMore(fassign, Whitespace(white=" \t"))
fbody = (Optional(fassigns) + expr("ret"))
definable_name = Forward()
dindex = definable_name("l") + LSB + expr("idx") + RSB
definable_name << var_name | dindex
# lname = Forward()
# ptr = (lname("l") + LAMBDA + var_name("r"))
# member = (lname("l") + DOT + var_name("r"))
# idx = (expr | COLON)
# index = (lname("l") + LSB + expr("lidx") + "," + idx("ridx") + RSB)
# lname << var_name | ptr | member | index
assignment = expr("var") + (FASSIGN|PASSIGN|MASSIGN|MULASSIGN|DASSIGN)("op") + expr("expr")
declaration = definable_name("var") + Optional(Suppress(FASSIGN) + expr("expr"))
fassign = Group(assignment + Suppress(";"))("assignment")
static_decl = Group(STATIC + delimited_list(declaration))("static_decl")
stmt = Forward()
elifstmt = Group(ELIF + LB + expr("cond") + RB + stmt)("elif")
elsestmt = Group(ELSE + stmt)("else")
ifstmt = Group(IF + LB + expr("cond") + RB + stmt +
ZeroOrMore(elifstmt) + Optional(elsestmt))("if")
forstmt = Group(FOR + LB + ( delimited_list(assignment)("defs")
+ Suppress(";") + expr("cond") +
Suppress(";") + delimited_list(assignment)("tail"))
+ RB + stmt)("for")
block = Forward()
stmt << (fassign|ifstmt|forstmt|block|Suppress(";"))
stmts = (ZeroOrMore(stmt("stmt"), Whitespace()))
block << (LBRACE + Optional(stmts) + RBRACE)("code_block")
fbody = (Optional(static_decl) + Optional(stmts) + expr("ret"))
udf = ( udf = (
Optional(AGGREGATION("Agg")) +
FUNCTION FUNCTION
+ var_name("fname") + var_name("fname")
+ LB + LB

@ -1,15 +1,15 @@
## Windows ## Windows
- clang-msvc: - clang-msvc:
- "%CXX%" -D_CRT_SECURE_NO_WARNINGS -shared server/server.cpp server/winhelper.cpp server/monetdb_conn.cpp -Imonetdb/msvc -Lmonetdb/msvc -lmonetdbe.lib --std=c++2a -o server.so - "%CXX%" -D_CRT_SECURE_NO_WARNINGS -shared server/server.cpp server/winhelper.cpp server/monetdb_conn.cpp -Imonetdb/msvc -Lmonetdb/msvc -lmonetdbe.lib --std=c++2a -o server.so
- os.add_dll_directory(os.path.abspath('./monetdb/msvc')) - os.add_dll_directory(os.path.abspath('./monetdb/msvc'))
- gcc-mingw (link w/ msvc monetdb): - gcc-mingw (link w/ msvc monetdb):
- "%CXX%" -shared -fPIC server/server.cpp server/winhelper.cpp server/monetdb_conn.cpp -Imonetdb/msvc msc-plugin/monetdbe.dll --std=c++2a -o server.so - "%CXX%" -shared -fPIC server/server.cpp server/winhelper.cpp server/monetdb_conn.cpp -Imonetdb/msvc msc-plugin/monetdbe.dll --std=c++2a -o server.so
- os.add_dll_directory('c:/msys64/usr/bin') - os.add_dll_directory('c:/msys64/usr/bin')
- os.add_dll_directory(os.path.abspath('./monetdb/msvc')) - os.add_dll_directory(os.path.abspath('./monetdb/msvc'))
- gcc-mingw (link w/ mingw monetdb, can only load under mingw python): - gcc-mingw (link w/ mingw monetdb, can only load under mingw python):
- $(CXX) server/server.cpp server/monetdb_conn.cpp -fPIC -shared $(OS_SUPPORT) --std=c++1z -O3 -march=native -o server.so -I./monetdb/msys64 -L./lib -lmonetdbe - $(CXX) server/server.cpp server/monetdb_conn.cpp -fPIC -shared $(OS_SUPPORT) --std=c++1z -O3 -march=native -o server.so -I./monetdb/msys64 -L./lib -lmonetdbe
- os.add_dll_directory('c:/msys64/usr/bin') - os.add_dll_directory('c:/msys64/usr/bin')
- os.add_dll_directory(os.path.abspath('./lib')) - os.add_dll_directory(os.path.abspath('./lib'))
- msvc: - msvc:
- D:\gg\vs22\MSBuild\Current\Bin\msbuild "d:\gg\AQuery++\server\server.vcxproj" /p:configuration=Release /p:platform=x64 - D:\gg\vs22\MSBuild\Current\Bin\msbuild "d:\gg\AQuery++\server\server.vcxproj" /p:configuration=Release /p:platform=x64
- os.add_dll_directory(os.path.abspath('./monetdb/msvc')) - os.add_dll_directory(os.path.abspath('./monetdb/msvc'))

@ -79,6 +79,10 @@ LongT = Types(4, name = 'int64', sqlname = 'BIGINT', fp_type = DoubleT)
ByteT = Types(1, name = 'int8', sqlname = 'TINYINT', long_type=LongT, fp_type=FloatT) ByteT = Types(1, name = 'int8', sqlname = 'TINYINT', long_type=LongT, fp_type=FloatT)
ShortT = Types(2, name = 'int16', sqlname='SMALLINT', long_type=LongT, fp_type=FloatT) ShortT = Types(2, name = 'int16', sqlname='SMALLINT', long_type=LongT, fp_type=FloatT)
IntT = Types(3, name = 'int', cname = 'int', long_type=LongT, fp_type=FloatT) IntT = Types(3, name = 'int', cname = 'int', long_type=LongT, fp_type=FloatT)
ULongT = Types(8, name = 'uint64', sqlname = 'UINT64', fp_type=DoubleT)
UIntT = Types(7, name = 'uint32', sqlname = 'UINT32', long_type=ULongT, fp_type=FloatT)
UShortT = Types(6, name = 'uint16', sqlname = 'UINT16', long_type=ULongT, fp_type=FloatT)
UByteT = Types(5, name = 'uint8', sqlname = 'UINT8', long_type=ULongT, fp_type=FloatT)
StrT = Types(200, name = 'str', cname = 'const char*', sqlname='VARCHAR', ctype_name = 'types::STRING') StrT = Types(200, name = 'str', cname = 'const char*', sqlname='VARCHAR', ctype_name = 'types::STRING')
def _ty_make_dict(fn : str, *ty : Types): def _ty_make_dict(fn : str, *ty : Types):
return {eval(fn):t for t in ty} return {eval(fn):t for t in ty}
@ -214,6 +218,11 @@ spnull = OperatorBase('missing', 1, logical, cname = "", sqlname = "", call = is
# cstdlib # cstdlib
fnsqrt = OperatorBase('sqrt', 1, lambda *_ : DoubleT, cname = 'sqrt', sqlname = 'SQRT', call = fn_behavior) fnsqrt = OperatorBase('sqrt', 1, lambda *_ : DoubleT, cname = 'sqrt', sqlname = 'SQRT', call = fn_behavior)
fnlog = OperatorBase('log', 2, lambda *_ : DoubleT, cname = 'log', sqlname = 'LOG', call = fn_behavior)
fnsin = OperatorBase('sin', 1, lambda *_ : DoubleT, cname = 'sin', sqlname = 'SIN', call = fn_behavior)
fncos = OperatorBase('cos', 1, lambda *_ : DoubleT, cname = 'cos', sqlname = 'COS', call = fn_behavior)
fntan = OperatorBase('tan', 1, lambda *_ : DoubleT, cname = 'tan', sqlname = 'TAN', call = fn_behavior)
fnpow = OperatorBase('pow', 2, lambda *_ : DoubleT, cname = 'pow', sqlname = 'POW', call = fn_behavior)
# type collections # type collections
def _op_make_dict(*items : OperatorBase): def _op_make_dict(*items : OperatorBase):
@ -223,8 +232,8 @@ builtin_binary_logical = _op_make_dict(opand, opor, opxor, opgt, oplt, opge, opl
builtin_unary_logical = _op_make_dict(opnot) builtin_unary_logical = _op_make_dict(opnot)
builtin_unary_arith = _op_make_dict(opneg) builtin_unary_arith = _op_make_dict(opneg)
builtin_unary_special = _op_make_dict(spnull) builtin_unary_special = _op_make_dict(spnull)
builtin_cstdlib = _op_make_dict(fnsqrt) builtin_cstdlib = _op_make_dict(fnsqrt, fnlog, fnsin, fncos, fntan, fnpow)
builtin_func = _op_make_dict(fnmax, fnmin, fnsum, fnavg, fnmaxs, fnmins, fnsums, fnavgs, fncnt) builtin_func = _op_make_dict(fnmax, fnmin, fnsum, fnavg, fnmaxs, fnmins, fnsums, fnavgs, fncnt)
builtin_operators : dict[str, OperatorBase] = {**builtin_binary_arith, **builtin_binary_logical, builtin_operators : Dict[str, OperatorBase] = {**builtin_binary_arith, **builtin_binary_logical,
**builtin_unary_arith, **builtin_unary_logical, **builtin_unary_special, **builtin_func, **builtin_cstdlib} **builtin_unary_arith, **builtin_unary_logical, **builtin_unary_special, **builtin_func, **builtin_cstdlib}

@ -1,19 +1,23 @@
import uuid import uuid
base62alp = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' lower_alp = 'abcdefghijklmnopqrstuvwxyz'
upper_alp = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
nums = '0123456789' nums = '0123456789'
base62alp = nums + lower_alp + upper_alp
reserved_monet = ['month'] reserved_monet = ['month']
def base62uuid(crop=8): def base62uuid(crop=8):
id = uuid.uuid4().int _id = uuid.uuid4().int
ret = '' ret = ''
while id: while _id:
ret = base62alp[id % 62] + ret ret = base62alp[_id % 62] + ret
id //= 62 _id //= 62
return ret[:crop] if len(ret) else '0' return ret[:crop] if len(ret) else '0'
def get_leagl_name(name, lower = True): def get_legal_name(name, lower = True):
if name is not None: if name is not None:
if lower: if lower:
name = name.lower() name = name.lower()
@ -26,7 +30,7 @@ def get_leagl_name(name, lower = True):
return name return name
def check_leagl_name(name): def check_legal_name(name):
all_underscores = True all_underscores = True
for c in name: for c in name:
if c not in base62alp and c != '_': if c not in base62alp and c != '_':
@ -53,4 +57,17 @@ def has_other(a, b):
return False return False
def defval(val, default): def defval(val, default):
return default if val is None else val return default if val is None else val
# escape must be readonly
from typing import Set
def remove_last(pattern : str, string : str, escape : Set[str] = set()) -> str:
idx = string.rfind(pattern)
if idx == -1:
return string
else:
if set(string[idx:]).difference(escape):
return string
else:
return string[:idx] + string[idx+1:]

@ -1,24 +1,35 @@
FUNCTION covariance (x , y ) { FUNCTION covariance (x , y ) {
xmean := avg (x) ; xmean := avg (x) ;
ymean := avg (y) ; ymean := avg (y) ;
avg (( x - xmean ) * (y - ymean )) avg (( x - xmean ) * (y - ymean ))
} }
FUNCTION sd ( x) {
sqrt ( covariance (x , x) ) FUNCTION sd ( x) {
} sqrt ( covariance (x , x) )
}
FUNCTION pairCorr (x , y ) {
covariance (x , y ) / ( sd (x) * sd (y )) AGGREGATION FUNCTION covariances(x, y, w){
} static xmeans := 0, ymeans := 0, cnt := 0;
if (cnt < w) { xmeans += x; }
CREATE TABLE test1(a INT, b INT, c INT, d INT) else {
xmeans += (x - x.vec[cnt - w]) / w;
LOAD DATA INFILE "test.csv" ymeans += (y - y.vec[cnt - w]) / w;
INTO TABLE test1 }
FIELDS TERMINATED BY "," avg (( x.vec(x.len-w, x.len) - xmean ) * (y.vec(y.len - w, y.len) - ymean ))
}
SELECT pairCorr(c, b) * d, sum(a), b
FROM test1 FUNCTION pairCorr (x , y ) {
group by c,b,d covariance (x , y ) / ( sd (x) * sd (y ))
}
CREATE TABLE test1(a INT, b INT, c INT, d INT)
LOAD DATA INFILE "test.csv"
INTO TABLE test1
FIELDS TERMINATED BY ","
SELECT pairCorr(c, b) * d, sum(a), b
FROM test1
group by c,b,d
order by b ASC order by b ASC

@ -1,34 +1,34 @@
FUNCTION covariance (x , y ) { FUNCTION covariance (x , y ) {
xmean := avg (x) ; xmean := avg (x) ;
ymean := avg (y) ; ymean := avg (y) ;
avg (( x - xmean ) * (y - ymean )) avg (( x - xmean ) * (y - ymean ))
} }
FUNCTION sd ( x) { FUNCTION sd ( x) {
sqrt ( covariance (x , x) ) sqrt ( covariance (x , x) )
} }
FUNCTION pairCorr (x , y ) { FUNCTION pairCorr (x , y ) {
covariance (x , y ) / ( sd (x) * sd (y )) covariance (x , y ) / ( sd (x) * sd (y ))
} }
-- FUNCTION covariances (w, x , y ) { -- FUNCTION covariances (w, x , y ) {
-- xmean := avgs (w, x) ; -- xmean := avgs (w, x) ;
-- ymean := avgs (y) ; -- ymean := avgs (y) ;
-- avg (( x - xmean ) * (y - ymean )) -- avg (( x - xmean ) * (y - ymean ))
-- } -- }
CREATE TABLE tt(a INT, b INT, c INT, d INT) CREATE TABLE tt(a INT, b INT, c INT, d INT)
LOAD DATA INFILE "test.csv" LOAD DATA INFILE "test.csv"
INTO TABLE tt INTO TABLE tt
FIELDS TERMINATED BY "," FIELDS TERMINATED BY ","
CREATE TABLE sale(Mont INT, sales INT) CREATE TABLE sale(Mont INT, sales INT)
LOAD DATA INFILE "moving_avg.csv" LOAD DATA INFILE "moving_avg.csv"
INTO TABLE sale INTO TABLE sale
FIELDS TERMINATED BY "," FIELDS TERMINATED BY ","
select sd(a) + sales from tt, sale where tt.a = sale.Mont select sd(a) + sales from tt, sale where tt.a = sale.Mont

@ -1,98 +0,0 @@
# Generated by CMake
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.6)
message(FATAL_ERROR "CMake >= 2.6.0 required")
endif()
cmake_policy(PUSH)
cmake_policy(VERSION 2.6...3.21)
#----------------------------------------------------------------
# Generated CMake target import file.
#----------------------------------------------------------------
# Commands may need to know the format version.
set(CMAKE_IMPORT_FILE_VERSION 1)
# Protect against multiple inclusion, which would fail when already imported targets are added once more.
set(_targetsDefined)
set(_targetsNotDefined)
set(_expectedTargets)
foreach(_expectedTarget MonetDB::monetdb_config_header)
list(APPEND _expectedTargets ${_expectedTarget})
if(NOT TARGET ${_expectedTarget})
list(APPEND _targetsNotDefined ${_expectedTarget})
endif()
if(TARGET ${_expectedTarget})
list(APPEND _targetsDefined ${_expectedTarget})
endif()
endforeach()
if("${_targetsDefined}" STREQUAL "${_expectedTargets}")
unset(_targetsDefined)
unset(_targetsNotDefined)
unset(_expectedTargets)
set(CMAKE_IMPORT_FILE_VERSION)
cmake_policy(POP)
return()
endif()
if(NOT "${_targetsDefined}" STREQUAL "")
message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_targetsDefined}\nTargets not yet defined: ${_targetsNotDefined}\n")
endif()
unset(_targetsDefined)
unset(_targetsNotDefined)
unset(_expectedTargets)
# Compute the installation prefix relative to this file.
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
if(_IMPORT_PREFIX STREQUAL "/")
set(_IMPORT_PREFIX "")
endif()
# Create imported target MonetDB::monetdb_config_header
add_library(MonetDB::monetdb_config_header INTERFACE IMPORTED)
set_target_properties(MonetDB::monetdb_config_header PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include/monetdb"
)
if(CMAKE_VERSION VERSION_LESS 3.0.0)
message(FATAL_ERROR "This file relies on consumers using CMake 3.0.0 or greater.")
endif()
# Load information for each installed configuration.
get_filename_component(_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
file(GLOB CONFIG_FILES "${_DIR}/monetdb_config_headerTargets-*.cmake")
foreach(f ${CONFIG_FILES})
include(${f})
endforeach()
# Cleanup temporary variables.
set(_IMPORT_PREFIX)
# Loop over all imported files and verify that they actually exist
foreach(target ${_IMPORT_CHECK_TARGETS} )
foreach(file ${_IMPORT_CHECK_FILES_FOR_${target}} )
if(NOT EXISTS "${file}" )
message(FATAL_ERROR "The imported target \"${target}\" references the file
\"${file}\"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
\"${CMAKE_CURRENT_LIST_FILE}\"
but not all the files it references.
")
endif()
endforeach()
unset(_IMPORT_CHECK_FILES_FOR_${target})
endforeach()
unset(_IMPORT_CHECK_TARGETS)
# This file does not depend on other imported targets which have
# been exported from the same project but in a separate export set.
# Commands beyond this point should not need to know the version.
set(CMAKE_IMPORT_FILE_VERSION)
cmake_policy(POP)

@ -0,0 +1,4 @@
LOAD MODULE FROM "test.so"
FUNCTIONS (div(a:int, b:int) -> double,
mulvec(a:int, b:vecfloat) -> vecfloat
);

@ -1,466 +1,466 @@
/* /*
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
* *
* Copyright 1997 - July 2008 CWI, August 2008 - 2022 MonetDB B.V. * Copyright 1997 - July 2008 CWI, August 2008 - 2022 MonetDB B.V.
*/ */
/* monetdb_config.h.in. Generated from CMakeLists.txt */ /* monetdb_config.h.in. Generated from CMakeLists.txt */
#ifndef MT_SEEN_MONETDB_CONFIG_H #ifndef MT_SEEN_MONETDB_CONFIG_H
#define MT_SEEN_MONETDB_CONFIG_H 1 #define MT_SEEN_MONETDB_CONFIG_H 1
#ifdef _MSC_VER #ifdef _MSC_VER
#if _MSC_VER < 1900 #if _MSC_VER < 1900
#error Versions below Visual Studio 2015 are no longer supported #error Versions below Visual Studio 2015 are no longer supported
#endif #endif
/* Prevent pollution through excessive inclusion of include files by Windows.h. */ /* Prevent pollution through excessive inclusion of include files by Windows.h. */
#ifndef WIN32_LEAN_AND_MEAN #ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1 #define WIN32_LEAN_AND_MEAN 1
#endif #endif
/* Visual Studio 8 has deprecated lots of stuff: suppress warnings */ /* Visual Studio 8 has deprecated lots of stuff: suppress warnings */
#ifndef _CRT_SECURE_NO_DEPRECATE #ifndef _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_DEPRECATE 1 #define _CRT_SECURE_NO_DEPRECATE 1
#endif #endif
#define _CRT_RAND_S /* for Windows rand_s, before stdlib.h */ #define _CRT_RAND_S /* for Windows rand_s, before stdlib.h */
#define HAVE_RAND_S 1 #define HAVE_RAND_S 1
#endif #endif
#if !defined(_XOPEN_SOURCE) && defined(__CYGWIN__) #if !defined(_XOPEN_SOURCE) && defined(__CYGWIN__)
#define _XOPEN_SOURCE 700 #define _XOPEN_SOURCE 700
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#if defined(_MSC_VER) && defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC) #if defined(_MSC_VER) && defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
/* In this case, malloc and friends are redefined in crtdbg.h to debug /* In this case, malloc and friends are redefined in crtdbg.h to debug
* versions. We need to include stdlib.h first or else we get * versions. We need to include stdlib.h first or else we get
* conflicting declarations. */ * conflicting declarations. */
#include <crtdbg.h> #include <crtdbg.h>
#endif #endif
#define HAVE_SYS_TYPES_H 1 #define HAVE_SYS_TYPES_H 1
#ifdef HAVE_SYS_TYPES_H #ifdef HAVE_SYS_TYPES_H
# include <sys/types.h> # include <sys/types.h>
#endif #endif
/* standard C-99 include files */ /* standard C-99 include files */
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#ifdef _MSC_VER #ifdef _MSC_VER
/* Windows include files */ /* Windows include files */
#include <process.h> #include <process.h>
#include <windows.h> #include <windows.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
/* indicate to sqltypes.h that windows.h has already been included and /* indicate to sqltypes.h that windows.h has already been included and
that it doesn't have to define Windows constants */ that it doesn't have to define Windows constants */
#define ALREADY_HAVE_WINDOWS_TYPE 1 #define ALREADY_HAVE_WINDOWS_TYPE 1
#define NATIVE_WIN32 1 #define NATIVE_WIN32 1
#endif /* _MSC_VER */ #endif /* _MSC_VER */
#if !defined(WIN32) && (defined(__CYGWIN__) || defined(__MINGW32__)) #if !defined(WIN32) && (defined(__CYGWIN__) || defined(__MINGW32__))
#define WIN32 1 #define WIN32 1
#endif #endif
// Section: monetdb configure defines // Section: monetdb configure defines
/* #undef HAVE_DISPATCH_DISPATCH_H */ /* #undef HAVE_DISPATCH_DISPATCH_H */
/* #undef HAVE_DLFCN_H */ /* #undef HAVE_DLFCN_H */
#define HAVE_FCNTL_H 1 #define HAVE_FCNTL_H 1
#define HAVE_IO_H 1 #define HAVE_IO_H 1
/* #undef HAVE_KVM_H */ /* #undef HAVE_KVM_H */
/* #undef HAVE_LIBGEN_H */ /* #undef HAVE_LIBGEN_H */
/* #undef HAVE_LIBINTL_H */ /* #undef HAVE_LIBINTL_H */
/* #undef HAVE_MACH_MACH_INIT_H */ /* #undef HAVE_MACH_MACH_INIT_H */
/* #undef HAVE_MACH_TASK_H */ /* #undef HAVE_MACH_TASK_H */
/* #undef HAVE_MACH_O_DYLD_H */ /* #undef HAVE_MACH_O_DYLD_H */
/* #undef HAVE_NETDB_H */ /* #undef HAVE_NETDB_H */
/* #undef HAVE_NETINET_IN_H */ /* #undef HAVE_NETINET_IN_H */
/* #undef HAVE_POLL_H */ /* #undef HAVE_POLL_H */
/* #undef HAVE_PROCFS_H */ /* #undef HAVE_PROCFS_H */
/* #undef HAVE_PWD_H */ /* #undef HAVE_PWD_H */
/* #undef HAVE_STRINGS_H */ /* #undef HAVE_STRINGS_H */
/* #undef HAVE_STROPTS_H */ /* #undef HAVE_STROPTS_H */
/* #undef HAVE_SYS_FILE_H */ /* #undef HAVE_SYS_FILE_H */
/* #undef HAVE_SYS_IOCTL_H */ /* #undef HAVE_SYS_IOCTL_H */
/* #undef HAVE_SYS_SYSCTL_H */ /* #undef HAVE_SYS_SYSCTL_H */
/* #undef HAVE_SYS_MMAN_H */ /* #undef HAVE_SYS_MMAN_H */
/* #undef HAVE_SYS_PARAM_H */ /* #undef HAVE_SYS_PARAM_H */
/* #undef HAVE_SYS_RANDOM_H */ /* #undef HAVE_SYS_RANDOM_H */
/* #undef HAVE_SYS_RESOURCE_H */ /* #undef HAVE_SYS_RESOURCE_H */
/* #undef HAVE_SYS_TIME_H */ /* #undef HAVE_SYS_TIME_H */
/* #undef HAVE_SYS_TIMES_H */ /* #undef HAVE_SYS_TIMES_H */
/* #undef HAVE_SYS_UIO_H */ /* #undef HAVE_SYS_UIO_H */
/* #undef HAVE_SYS_UN_H */ /* #undef HAVE_SYS_UN_H */
/* #undef HAVE_SYS_WAIT_H */ /* #undef HAVE_SYS_WAIT_H */
/* #undef HAVE_TERMIOS_H */ /* #undef HAVE_TERMIOS_H */
/* #undef HAVE_UNISTD_H */ /* #undef HAVE_UNISTD_H */
/* #undef HAVE_UUID_UUID_H */ /* #undef HAVE_UUID_UUID_H */
#define HAVE_WINSOCK_H 1 #define HAVE_WINSOCK_H 1
/* #undef HAVE_SEMAPHORE_H */ /* #undef HAVE_SEMAPHORE_H */
#define HAVE_GETOPT_H 1 #define HAVE_GETOPT_H 1
/* #undef HAVE_STDATOMIC_H */ /* #undef HAVE_STDATOMIC_H */
/* #undef HAVE_DIRENT_H */ /* #undef HAVE_DIRENT_H */
/* #undef HAVE_SYS_SOCKET_H */ /* #undef HAVE_SYS_SOCKET_H */
/* #undef HAVE_GETTIMEOFDAY */ /* #undef HAVE_GETTIMEOFDAY */
#define HAVE_SYS_STAT_H 1 #define HAVE_SYS_STAT_H 1
/* #undef HAVE_FDATASYNC */ /* #undef HAVE_FDATASYNC */
/* #undef HAVE_ACCEPT4 */ /* #undef HAVE_ACCEPT4 */
/* #undef HAVE_ASCTIME_R */ /* #undef HAVE_ASCTIME_R */
/* #undef HAVE_CLOCK_GETTIME */ /* #undef HAVE_CLOCK_GETTIME */
/* #undef HAVE_CTIME_R */ /* #undef HAVE_CTIME_R */
/* #undef HAVE_DISPATCH_SEMAPHORE_CREATE */ /* #undef HAVE_DISPATCH_SEMAPHORE_CREATE */
/* #undef HAVE_FALLOCATE */ /* #undef HAVE_FALLOCATE */
/* #undef HAVE_FCNTL */ /* #undef HAVE_FCNTL */
/* #undef HAVE_FORK */ /* #undef HAVE_FORK */
/* #undef HAVE_FSYNC */ /* #undef HAVE_FSYNC */
#define HAVE_FTIME 1 #define HAVE_FTIME 1
/* #undef HAVE_GETENTROPY */ /* #undef HAVE_GETENTROPY */
/* #undef HAVE_GETEXECNAME */ /* #undef HAVE_GETEXECNAME */
/* #undef HAVE_GETLOGIN */ /* #undef HAVE_GETLOGIN */
#define HAVE_GETOPT_LONG 1 #define HAVE_GETOPT_LONG 1
/* #undef HAVE_GETRLIMIT */ /* #undef HAVE_GETRLIMIT */
/* #undef HAVE_GETTIMEOFDAY */ /* #undef HAVE_GETTIMEOFDAY */
/* #undef HAVE_GETUID */ /* #undef HAVE_GETUID */
/* #undef HAVE_GMTIME_R */ /* #undef HAVE_GMTIME_R */
/* #undef HAVE_LOCALTIME_R */ /* #undef HAVE_LOCALTIME_R */
/* #undef HAVE_STRERROR_R */ /* #undef HAVE_STRERROR_R */
/* #undef HAVE_LOCKF */ /* #undef HAVE_LOCKF */
/* #undef HAVE_MADVISE */ /* #undef HAVE_MADVISE */
/* #undef HAVE_MREMAP */ /* #undef HAVE_MREMAP */
/* #undef HAVE_NANOSLEEP */ /* #undef HAVE_NANOSLEEP */
/* #undef HAVE_NL_LANGINFO */ /* #undef HAVE_NL_LANGINFO */
/* #undef HAVE__NSGETEXECUTABLEPATH */ /* #undef HAVE__NSGETEXECUTABLEPATH */
/* #undef HAVE_PIPE2 */ /* #undef HAVE_PIPE2 */
/* #undef HAVE_POLL */ /* #undef HAVE_POLL */
/* #undef HAVE_POPEN */ /* #undef HAVE_POPEN */
/* #undef HAVE_POSIX_FADVISE */ /* #undef HAVE_POSIX_FADVISE */
/* #undef HAVE_POSIX_FALLOCATE */ /* #undef HAVE_POSIX_FALLOCATE */
/* #undef HAVE_POSIX_MADVISE */ /* #undef HAVE_POSIX_MADVISE */
#define HAVE_PUTENV 1 #define HAVE_PUTENV 1
/* #undef HAVE_SETSID */ /* #undef HAVE_SETSID */
#define HAVE_SHUTDOWN 1 #define HAVE_SHUTDOWN 1
/* #undef HAVE_SIGACTION */ /* #undef HAVE_SIGACTION */
/* #undef HAVE_STPCPY */ /* #undef HAVE_STPCPY */
/* #undef HAVE_STRCASESTR */ /* #undef HAVE_STRCASESTR */
/* #undef HAVE_STRNCASECMP */ /* #undef HAVE_STRNCASECMP */
/* #undef HAVE_STRPTIME */ /* #undef HAVE_STRPTIME */
/* #undef HAVE_STRSIGNAL */ /* #undef HAVE_STRSIGNAL */
/* #undef HAVE_SYSCONF */ /* #undef HAVE_SYSCONF */
/* #undef HAVE_TASK_INFO */ /* #undef HAVE_TASK_INFO */
/* #undef HAVE_TIMES */ /* #undef HAVE_TIMES */
/* #undef HAVE_UNAME */ /* #undef HAVE_UNAME */
/* #undef HAVE_SEMTIMEDOP */ /* #undef HAVE_SEMTIMEDOP */
/* #undef HAVE_PTHREAD_KILL */ /* #undef HAVE_PTHREAD_KILL */
/* #undef HAVE_PTHREAD_SIGMASK */ /* #undef HAVE_PTHREAD_SIGMASK */
#define HAVE_GETOPT 1 #define HAVE_GETOPT 1
#define ICONV_CONST #define ICONV_CONST
#define FLEXIBLE_ARRAY_MEMBER #define FLEXIBLE_ARRAY_MEMBER
#define ENABLE_MAPI 1 #define ENABLE_MAPI 1
#define HAVE_MAPI 1 #define HAVE_MAPI 1
// End Section: monetdb configure defines // End Section: monetdb configure defines
// Section: monetdb macro variables // Section: monetdb macro variables
#define HAVE_ICONV 1 #define HAVE_ICONV 1
/* #undef HAVE_PTHREAD_H */ /* #undef HAVE_PTHREAD_H */
#define HAVE_LIBPCRE 1 #define HAVE_LIBPCRE 1
#define HAVE_LIBBZ2 1 #define HAVE_LIBBZ2 1
/* #undef HAVE_CURL */ /* #undef HAVE_CURL */
#define HAVE_LIBLZMA 1 #define HAVE_LIBLZMA 1
#define HAVE_LIBXML 1 #define HAVE_LIBXML 1
#define HAVE_LIBZ 1 #define HAVE_LIBZ 1
#define HAVE_LIBLZ4 1 #define HAVE_LIBLZ4 1
/* #undef HAVE_PROJ */ /* #undef HAVE_PROJ */
/* #undef HAVE_SNAPPY */ /* #undef HAVE_SNAPPY */
/* #undef HAVE_FITS */ /* #undef HAVE_FITS */
/* #undef HAVE_UUID */ /* #undef HAVE_UUID */
/* #undef HAVE_VALGRIND */ /* #undef HAVE_VALGRIND */
/* #undef HAVE_NETCDF */ /* #undef HAVE_NETCDF */
/* #undef HAVE_READLINE */ /* #undef HAVE_READLINE */
/* #undef HAVE_LIBR */ /* #undef HAVE_LIBR */
#define RHOME "/registry" #define RHOME "/registry"
#define HAVE_GEOM 1 #define HAVE_GEOM 1
/* #undef HAVE_SHP */ /* #undef HAVE_SHP */
#define HAVE_LIBPY3 1 #define HAVE_LIBPY3 1
// #define SOCKET_LIBRARIES // #define SOCKET_LIBRARIES
#define HAVE_GETADDRINFO 1 #define HAVE_GETADDRINFO 1
/* #undef HAVE_CUDF */ /* #undef HAVE_CUDF */
#define MAPI_PORT 50000 #define MAPI_PORT 50000
#define MAPI_PORT_STR "50000" #define MAPI_PORT_STR "50000"
#ifdef _MSC_VER #ifdef _MSC_VER
#define DIR_SEP '\\' #define DIR_SEP '\\'
#define PATH_SEP ';' #define PATH_SEP ';'
#define DIR_SEP_STR "\\" #define DIR_SEP_STR "\\"
#define SO_PREFIX "" #define SO_PREFIX ""
#else #else
#define DIR_SEP '/' #define DIR_SEP '/'
#define PATH_SEP ':' #define PATH_SEP ':'
#define DIR_SEP_STR "/" #define DIR_SEP_STR "/"
/* #undef SO_PREFIX */ /* #undef SO_PREFIX */
#endif #endif
#define SO_EXT ".dll" #define SO_EXT ".dll"
#define BINDIR "C:/cygwin64/home/monet/x86_64/install/bin" #define BINDIR "C:/cygwin64/home/monet/x86_64/install/bin"
#define LIBDIR "C:/cygwin64/home/monet/x86_64/install/lib" #define LIBDIR "C:/cygwin64/home/monet/x86_64/install/lib"
#define LOCALSTATEDIR "C:/cygwin64/home/monet/x86_64/install/var" #define LOCALSTATEDIR "C:/cygwin64/home/monet/x86_64/install/var"
// End Section: monetdb macro variables // End Section: monetdb macro variables
// Section: monetdb configure misc // Section: monetdb configure misc
#define MONETDB_RELEASE "Jan2022-SP3" #define MONETDB_RELEASE "Jan2022-SP3"
#define MONETDB_VERSION "11.43.15" #define MONETDB_VERSION "11.43.15"
#define MONETDB_VERSION_MAJOR 11 #define MONETDB_VERSION_MAJOR 11
#define MONETDB_VERSION_MINOR 43 #define MONETDB_VERSION_MINOR 43
#define MONETDB_VERSION_PATCH 15 #define MONETDB_VERSION_PATCH 15
#define GDK_VERSION "25.1.0" #define GDK_VERSION "25.1.0"
#define GDK_VERSION_MAJOR 25 #define GDK_VERSION_MAJOR 25
#define GDK_VERSION_MINOR 1 #define GDK_VERSION_MINOR 1
#define GDK_VERSION_PATCH 0 #define GDK_VERSION_PATCH 0
#define MAPI_VERSION "14.0.2" #define MAPI_VERSION "14.0.2"
#define MAPI_VERSION_MAJOR 14 #define MAPI_VERSION_MAJOR 14
#define MAPI_VERSION_MINOR 0 #define MAPI_VERSION_MINOR 0
#define MAPI_VERSION_PATCH 2 #define MAPI_VERSION_PATCH 2
#define MONETDB5_VERSION "32.0.6" #define MONETDB5_VERSION "32.0.6"
#define MONETDB5_VERSION_MAJOR 32 #define MONETDB5_VERSION_MAJOR 32
#define MONETDB5_VERSION_MINOR 0 #define MONETDB5_VERSION_MINOR 0
#define MONETDB5_VERSION_PATCH 6 #define MONETDB5_VERSION_PATCH 6
#define MONETDBE_VERSION "3.0.2" #define MONETDBE_VERSION "3.0.2"
#define MONETDBE_VERSION_MAJOR 3 #define MONETDBE_VERSION_MAJOR 3
#define MONETDBE_VERSION_MINOR 0 #define MONETDBE_VERSION_MINOR 0
#define MONETDBE_VERSION_PATCH 2 #define MONETDBE_VERSION_PATCH 2
#define STREAM_VERSION "16.0.1" #define STREAM_VERSION "16.0.1"
#define STREAM_VERSION_MAJOR 16 #define STREAM_VERSION_MAJOR 16
#define STREAM_VERSION_MINOR 0 #define STREAM_VERSION_MINOR 0
#define STREAM_VERSION_PATCH 1 #define STREAM_VERSION_PATCH 1
#define SQL_VERSION "12.0.5" #define SQL_VERSION "12.0.5"
#define SQL_VERSION_MAJOR 12 #define SQL_VERSION_MAJOR 12
#define SQL_VERSION_MINOR 0 #define SQL_VERSION_MINOR 0
#define SQL_VERSION_PATCH 5 #define SQL_VERSION_PATCH 5
/* Host identifier */ /* Host identifier */
#define HOST "amd64-pc-windows-msvc" #define HOST "amd64-pc-windows-msvc"
/* The used password hash algorithm */ /* The used password hash algorithm */
#define MONETDB5_PASSWDHASH "SHA512" #define MONETDB5_PASSWDHASH "SHA512"
/* The used password hash algorithm */ /* The used password hash algorithm */
#define MONETDB5_PASSWDHASH_TOKEN SHA512 #define MONETDB5_PASSWDHASH_TOKEN SHA512
#ifndef _Noreturn #ifndef _Noreturn
#define _Noreturn __declspec(noreturn) #define _Noreturn __declspec(noreturn)
#endif #endif
#ifndef __cplusplus #ifndef __cplusplus
/* Does your compiler support `inline' keyword? (C99 feature) */ /* Does your compiler support `inline' keyword? (C99 feature) */
#ifndef inline #ifndef inline
#define inline __inline #define inline __inline
#endif #endif
/* Does your compiler support `__restrict__' keyword? (C99 feature) */ /* Does your compiler support `__restrict__' keyword? (C99 feature) */
#ifndef __restrict__ #ifndef __restrict__
#define __restrict__ restrict #define __restrict__ restrict
#endif #endif
#endif #endif
#ifdef _MSC_VER #ifdef _MSC_VER
#ifndef __restrict__ #ifndef __restrict__
#define __restrict__ __restrict #define __restrict__ __restrict
#endif #endif
#endif #endif
// End Section: monetdb configure misc // End Section: monetdb configure misc
// Section: monetdb configure sizes // Section: monetdb configure sizes
#define SIZEOF_SIZE_T 8 #define SIZEOF_SIZE_T 8
/* The size of `void *', as computed by sizeof. */ /* The size of `void *', as computed by sizeof. */
#define SIZEOF_VOID_P 8 #define SIZEOF_VOID_P 8
#define SIZEOF_CHAR 1 #define SIZEOF_CHAR 1
#define SIZEOF_SHORT 2 #define SIZEOF_SHORT 2
#define SIZEOF_INT 4 #define SIZEOF_INT 4
#define SIZEOF_LONG 4 #define SIZEOF_LONG 4
#define SIZEOF_LONG_LONG 8 #define SIZEOF_LONG_LONG 8
#define SIZEOF_DOUBLE 8 #define SIZEOF_DOUBLE 8
#define SIZEOF_WCHAR_T 2 #define SIZEOF_WCHAR_T 2
#define HAVE_LONG_LONG 1 /* for ODBC include files */ #define HAVE_LONG_LONG 1 /* for ODBC include files */
#ifdef _MSC_VER #ifdef _MSC_VER
#ifdef _WIN64 #ifdef _WIN64
#define LENP_OR_POINTER_T SQLLEN * #define LENP_OR_POINTER_T SQLLEN *
#else #else
#define LENP_OR_POINTER_T SQLPOINTER #define LENP_OR_POINTER_T SQLPOINTER
#endif #endif
#else #else
#define LENP_OR_POINTER_T SQLLEN * #define LENP_OR_POINTER_T SQLLEN *
#endif #endif
#define SIZEOF_SQLWCHAR 2 #define SIZEOF_SQLWCHAR 2
/* #undef WORDS_BIGENDIAN */ /* #undef WORDS_BIGENDIAN */
/* Does your compiler support `ssize_t' type? (Posix type) */ /* Does your compiler support `ssize_t' type? (Posix type) */
#ifndef ssize_t #ifndef ssize_t
#define ssize_t int64_t #define ssize_t int64_t
#endif #endif
/* The size of `__int128', as computed by sizeof. */ /* The size of `__int128', as computed by sizeof. */
/* #undef SIZEOF___INT128 */ /* #undef SIZEOF___INT128 */
/* The size of `__int128_t', as computed by sizeof. */ /* The size of `__int128_t', as computed by sizeof. */
/* #undef SIZEOF___INT128_T */ /* #undef SIZEOF___INT128_T */
/* The size of `__uint128_t', as computed by sizeof. */ /* The size of `__uint128_t', as computed by sizeof. */
/* #undef SIZEOF___UINT128_T */ /* #undef SIZEOF___UINT128_T */
#ifdef SIZEOF___INT128 #ifdef SIZEOF___INT128
typedef __int128 hge; typedef __int128 hge;
typedef unsigned __int128 uhge; typedef unsigned __int128 uhge;
#define HAVE_HGE 1 #define HAVE_HGE 1
#define SIZEOF_HGE SIZEOF___INT128 #define SIZEOF_HGE SIZEOF___INT128
#elif defined(SIZEOF___INT128_T) && defined(SIZEOF___UINT128_T) #elif defined(SIZEOF___INT128_T) && defined(SIZEOF___UINT128_T)
typedef __int128_t hge; typedef __int128_t hge;
typedef __uint128_t uhge; typedef __uint128_t uhge;
#define HAVE_HGE 1 #define HAVE_HGE 1
#define SIZEOF_HGE SIZEOF___INT128_T #define SIZEOF_HGE SIZEOF___INT128_T
#endif #endif
// End Section: monetdb configure sizes // End Section: monetdb configure sizes
/* Does your compiler support `__attribute__' extension? */ /* Does your compiler support `__attribute__' extension? */
#if !defined(__GNUC__) && !defined(__clang__) && !defined(__attribute__) #if !defined(__GNUC__) && !defined(__clang__) && !defined(__attribute__)
#define __attribute__(a) #define __attribute__(a)
#endif #endif
#if !defined(__cplusplus) || __cplusplus < 201103L #if !defined(__cplusplus) || __cplusplus < 201103L
#ifndef static_assert #ifndef static_assert
/* static_assert is a C11/C++11 feature, defined in assert.h which also exists /* static_assert is a C11/C++11 feature, defined in assert.h which also exists
* in many other compilers we ignore it if the compiler doesn't support it * in many other compilers we ignore it if the compiler doesn't support it
* However in C11 static_assert is a macro, while on C++11 is a keyword */ * However in C11 static_assert is a macro, while on C++11 is a keyword */
#define static_assert(expr, mesg) ((void) 0) #define static_assert(expr, mesg) ((void) 0)
#endif #endif
#endif #endif
#ifdef HAVE_STRINGS_H #ifdef HAVE_STRINGS_H
#include <strings.h> /* strcasecmp */ #include <strings.h> /* strcasecmp */
#endif #endif
#ifdef _MSC_VER #ifdef _MSC_VER
#define strdup(s) _strdup(s) #define strdup(s) _strdup(s)
#ifndef strcasecmp #ifndef strcasecmp
#define strcasecmp(x,y) _stricmp(x,y) #define strcasecmp(x,y) _stricmp(x,y)
#endif #endif
/* Define to 1 if you have the `strncasecmp' function. */ /* Define to 1 if you have the `strncasecmp' function. */
#define HAVE_STRNCASECMP 1 #define HAVE_STRNCASECMP 1
#ifndef strncasecmp #ifndef strncasecmp
#define strncasecmp(x,y,z) _strnicmp(x,y,z) #define strncasecmp(x,y,z) _strnicmp(x,y,z)
#endif #endif
#include <sys/stat.h> #include <sys/stat.h>
#ifdef lstat #ifdef lstat
#undef lstat #undef lstat
#endif #endif
#define lstat _stat64 #define lstat _stat64
#ifdef stat #ifdef stat
#undef stat #undef stat
#endif #endif
#define stat _stat64 #define stat _stat64
#ifdef fstat #ifdef fstat
#undef fstat #undef fstat
#endif #endif
#define fstat _fstat64 #define fstat _fstat64
static inline char * static inline char *
stpcpy(char *__restrict__ dst, const char *__restrict__ src) stpcpy(char *__restrict__ dst, const char *__restrict__ src)
{ {
size_t i; size_t i;
for (i = 0; src[i]; i++) for (i = 0; src[i]; i++)
dst[i] = src[i]; dst[i] = src[i];
dst[i] = 0; dst[i] = 0;
return dst + i; return dst + i;
} }
/* Define to 1 if the system has the type `socklen_t'. */ /* Define to 1 if the system has the type `socklen_t'. */
#define HAVE_SOCKLEN_T 1 #define HAVE_SOCKLEN_T 1
/* type used by connect */ /* type used by connect */
#define socklen_t int #define socklen_t int
#define strtok_r(t,d,c) strtok_s(t,d,c) #define strtok_r(t,d,c) strtok_s(t,d,c)
#define HAVE_GETOPT_LONG 1 #define HAVE_GETOPT_LONG 1
/* there is something very similar to localtime_r on Windows: */ /* there is something very similar to localtime_r on Windows: */
#include <time.h> #include <time.h>
#define HAVE_LOCALTIME_R 1 #define HAVE_LOCALTIME_R 1
static inline struct tm * static inline struct tm *
localtime_r(const time_t *__restrict__ timep, struct tm *__restrict__ result) localtime_r(const time_t *__restrict__ timep, struct tm *__restrict__ result)
{ {
return localtime_s(result, timep) == 0 ? result : NULL; return localtime_s(result, timep) == 0 ? result : NULL;
} }
#define HAVE_GMTIME_R 1 #define HAVE_GMTIME_R 1
static inline struct tm * static inline struct tm *
gmtime_r(const time_t *__restrict__ timep, struct tm *__restrict__ result) gmtime_r(const time_t *__restrict__ timep, struct tm *__restrict__ result)
{ {
return gmtime_s(result, timep) == 0 ? result : NULL; return gmtime_s(result, timep) == 0 ? result : NULL;
} }
/* Define if you have ctime_r(time_t*,char *buf,size_t s) */ /* Define if you have ctime_r(time_t*,char *buf,size_t s) */
#define HAVE_CTIME_R 1 #define HAVE_CTIME_R 1
#define HAVE_CTIME_R3 1 #define HAVE_CTIME_R3 1
/* there is something very similar to ctime_r on Windows: */ /* there is something very similar to ctime_r on Windows: */
#define ctime_r(t,b,s) (ctime_s(b,s,t) ? NULL : (b)) #define ctime_r(t,b,s) (ctime_s(b,s,t) ? NULL : (b))
#endif /* _MSC_VER */ #endif /* _MSC_VER */
#define HAVE_SOCKLEN_T 1 #define HAVE_SOCKLEN_T 1
#ifndef _MSC_VER #ifndef _MSC_VER
#define SOCKET int #define SOCKET int
#define closesocket close #define closesocket close
#endif #endif
#ifndef _In_z_ #ifndef _In_z_
#define _In_z_ #define _In_z_
#endif #endif
#ifndef _Printf_format_string_ #ifndef _Printf_format_string_
#define _Printf_format_string_ #define _Printf_format_string_
#endif #endif
#ifdef _MSC_VER #ifdef _MSC_VER
#define _LIB_STARTUP_FUNC_(f,q) \ #define _LIB_STARTUP_FUNC_(f,q) \
static void f(void); \ static void f(void); \
__declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \ __declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \
__pragma(comment(linker,"/include:" q #f "_")) \ __pragma(comment(linker,"/include:" q #f "_")) \
static void f(void) static void f(void)
#ifdef _WIN64 #ifdef _WIN64
#define LIB_STARTUP_FUNC(f) _LIB_STARTUP_FUNC_(f,"") #define LIB_STARTUP_FUNC(f) _LIB_STARTUP_FUNC_(f,"")
#else #else
#define LIB_STARTUP_FUNC(f) _LIB_STARTUP_FUNC_(f,"_") #define LIB_STARTUP_FUNC(f) _LIB_STARTUP_FUNC_(f,"_")
#endif #endif
#else #else
#define LIB_STARTUP_FUNC(f) \ #define LIB_STARTUP_FUNC(f) \
static void f(void) __attribute__((__constructor__)); \ static void f(void) __attribute__((__constructor__)); \
static void f(void) static void f(void)
#endif #endif
#endif /* MT_SEEN_MONETDB_CONFIG_H */ #endif /* MT_SEEN_MONETDB_CONFIG_H */

@ -1,473 +1,473 @@
/* /*
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
* *
* Copyright 1997 - July 2008 CWI, August 2008 - 2022 MonetDB B.V. * Copyright 1997 - July 2008 CWI, August 2008 - 2022 MonetDB B.V.
*/ */
/* monetdb_config.h.in. Generated from CMakeLists.txt */ /* monetdb_config.h.in. Generated from CMakeLists.txt */
#ifndef MT_SEEN_MONETDB_CONFIG_H #ifndef MT_SEEN_MONETDB_CONFIG_H
#define MT_SEEN_MONETDB_CONFIG_H 1 #define MT_SEEN_MONETDB_CONFIG_H 1
#ifdef _MSC_VER #ifdef _MSC_VER
#if _MSC_VER < 1900 #if _MSC_VER < 1900
#error Versions below Visual Studio 2015 are no longer supported #error Versions below Visual Studio 2015 are no longer supported
#endif #endif
/* Prevent pollution through excessive inclusion of include files by Windows.h. */ /* Prevent pollution through excessive inclusion of include files by Windows.h. */
#ifndef WIN32_LEAN_AND_MEAN #ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1 #define WIN32_LEAN_AND_MEAN 1
#endif #endif
/* Visual Studio 8 has deprecated lots of stuff: suppress warnings */ /* Visual Studio 8 has deprecated lots of stuff: suppress warnings */
#ifndef _CRT_SECURE_NO_DEPRECATE #ifndef _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_DEPRECATE 1 #define _CRT_SECURE_NO_DEPRECATE 1
#endif #endif
#define _CRT_RAND_S /* for Windows rand_s, before stdlib.h */ #define _CRT_RAND_S /* for Windows rand_s, before stdlib.h */
#define HAVE_RAND_S 1 #define HAVE_RAND_S 1
#endif #endif
#if !defined(_XOPEN_SOURCE) && defined(__CYGWIN__) #if !defined(_XOPEN_SOURCE) && defined(__CYGWIN__)
#define _XOPEN_SOURCE 700 #define _XOPEN_SOURCE 700
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#if defined(_MSC_VER) && defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC) #if defined(_MSC_VER) && defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
/* In this case, malloc and friends are redefined in crtdbg.h to debug /* In this case, malloc and friends are redefined in crtdbg.h to debug
* versions. We need to include stdlib.h first or else we get * versions. We need to include stdlib.h first or else we get
* conflicting declarations. */ * conflicting declarations. */
#include <crtdbg.h> #include <crtdbg.h>
#endif #endif
#define HAVE_SYS_TYPES_H 1 #define HAVE_SYS_TYPES_H 1
#ifdef HAVE_SYS_TYPES_H #ifdef HAVE_SYS_TYPES_H
# include <sys/types.h> # include <sys/types.h>
#endif #endif
/* standard C-99 include files */ /* standard C-99 include files */
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#ifdef _MSC_VER #ifdef _MSC_VER
/* Windows include files */ /* Windows include files */
#include <process.h> #include <process.h>
#include <windows.h> #include <windows.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
/* indicate to sqltypes.h that windows.h has already been included and /* indicate to sqltypes.h that windows.h has already been included and
that it doesn't have to define Windows constants */ that it doesn't have to define Windows constants */
#define ALREADY_HAVE_WINDOWS_TYPE 1 #define ALREADY_HAVE_WINDOWS_TYPE 1
#define NATIVE_WIN32 1 #define NATIVE_WIN32 1
#endif /* _MSC_VER */ #endif /* _MSC_VER */
#if !defined(WIN32) && (defined(__CYGWIN__)||defined(__MINGW32__)) #if !defined(WIN32) && (defined(__CYGWIN__)||defined(__MINGW32__))
#define WIN32 1 #define WIN32 1
#endif #endif
// Section: monetdb configure defines // Section: monetdb configure defines
/* #undef HAVE_DISPATCH_DISPATCH_H */ /* #undef HAVE_DISPATCH_DISPATCH_H */
#define HAVE_DLFCN_H 1 #define HAVE_DLFCN_H 1
#define HAVE_FCNTL_H 1 #define HAVE_FCNTL_H 1
#define HAVE_IO_H 1 #define HAVE_IO_H 1
/* #undef HAVE_KVM_H */ /* #undef HAVE_KVM_H */
#define HAVE_LIBGEN_H 1 #define HAVE_LIBGEN_H 1
/* #undef HAVE_LIBINTL_H */ /* #undef HAVE_LIBINTL_H */
/* #undef HAVE_MACH_MACH_INIT_H */ /* #undef HAVE_MACH_MACH_INIT_H */
/* #undef HAVE_MACH_TASK_H */ /* #undef HAVE_MACH_TASK_H */
/* #undef HAVE_MACH_O_DYLD_H */ /* #undef HAVE_MACH_O_DYLD_H */
#define HAVE_NETDB_H 1 #define HAVE_NETDB_H 1
#define HAVE_NETINET_IN_H 1 #define HAVE_NETINET_IN_H 1
#define HAVE_POLL_H 1 #define HAVE_POLL_H 1
/* #undef HAVE_PROCFS_H */ /* #undef HAVE_PROCFS_H */
#define HAVE_PWD_H 1 #define HAVE_PWD_H 1
#define HAVE_STRINGS_H 1 #define HAVE_STRINGS_H 1
/* #undef HAVE_STROPTS_H */ /* #undef HAVE_STROPTS_H */
#define HAVE_SYS_FILE_H 1 #define HAVE_SYS_FILE_H 1
#define HAVE_SYS_IOCTL_H 1 #define HAVE_SYS_IOCTL_H 1
/* #undef HAVE_SYS_SYSCTL_H */ /* #undef HAVE_SYS_SYSCTL_H */
#define HAVE_SYS_MMAN_H 1 #define HAVE_SYS_MMAN_H 1
#define HAVE_SYS_PARAM_H 1 #define HAVE_SYS_PARAM_H 1
#define HAVE_SYS_RANDOM_H 1 #define HAVE_SYS_RANDOM_H 1
#define HAVE_SYS_RESOURCE_H 1 #define HAVE_SYS_RESOURCE_H 1
#define HAVE_SYS_TIME_H 1 #define HAVE_SYS_TIME_H 1
#define HAVE_SYS_TIMES_H 1 #define HAVE_SYS_TIMES_H 1
#define HAVE_SYS_UIO_H 1 #define HAVE_SYS_UIO_H 1
#define HAVE_SYS_UN_H 1 #define HAVE_SYS_UN_H 1
#define HAVE_SYS_WAIT_H 1 #define HAVE_SYS_WAIT_H 1
#define HAVE_TERMIOS_H 1 #define HAVE_TERMIOS_H 1
#define HAVE_UNISTD_H 1 #define HAVE_UNISTD_H 1
#define HAVE_WINSOCK_H 1 #define HAVE_WINSOCK_H 1
#define HAVE_SEMAPHORE_H 1 #define HAVE_SEMAPHORE_H 1
#define HAVE_GETOPT_H 1 #define HAVE_GETOPT_H 1
#define HAVE_STDATOMIC_H 1 #define HAVE_STDATOMIC_H 1
#define HAVE_DIRENT_H 1 #define HAVE_DIRENT_H 1
#define HAVE_SYS_SOCKET_H 1 #define HAVE_SYS_SOCKET_H 1
#define HAVE_GETTIMEOFDAY 1 #define HAVE_GETTIMEOFDAY 1
#define HAVE_SYS_STAT_H 1 #define HAVE_SYS_STAT_H 1
#define HAVE_FDATASYNC 1 #define HAVE_FDATASYNC 1
#define HAVE_ACCEPT4 1 #define HAVE_ACCEPT4 1
#define HAVE_ASCTIME_R 1 #define HAVE_ASCTIME_R 1
#define HAVE_CLOCK_GETTIME 1 #define HAVE_CLOCK_GETTIME 1
#define HAVE_CTIME_R 1 #define HAVE_CTIME_R 1
/* #undef HAVE_DISPATCH_SEMAPHORE_CREATE */ /* #undef HAVE_DISPATCH_SEMAPHORE_CREATE */
/* #undef HAVE_FALLOCATE */ /* #undef HAVE_FALLOCATE */
#define HAVE_FCNTL 1 #define HAVE_FCNTL 1
#define HAVE_FORK 1 #define HAVE_FORK 1
#define HAVE_FSYNC 1 #define HAVE_FSYNC 1
#define HAVE_FTIME 1 #define HAVE_FTIME 1
#define HAVE_GETENTROPY 1 #define HAVE_GETENTROPY 1
/* #undef HAVE_GETEXECNAME */ /* #undef HAVE_GETEXECNAME */
#define HAVE_GETLOGIN 1 #define HAVE_GETLOGIN 1
#define HAVE_GETOPT_LONG 1 #define HAVE_GETOPT_LONG 1
#define HAVE_GETRLIMIT 1 #define HAVE_GETRLIMIT 1
#define HAVE_GETTIMEOFDAY 1 #define HAVE_GETTIMEOFDAY 1
#define HAVE_GETUID 1 #define HAVE_GETUID 1
#define HAVE_GMTIME_R 1 #define HAVE_GMTIME_R 1
#define HAVE_LOCALTIME_R 1 #define HAVE_LOCALTIME_R 1
#define HAVE_STRERROR_R 1 #define HAVE_STRERROR_R 1
#define HAVE_LOCKF 1 #define HAVE_LOCKF 1
#define HAVE_MADVISE 1 #define HAVE_MADVISE 1
/* #undef HAVE_MREMAP */ /* #undef HAVE_MREMAP */
#define HAVE_NANOSLEEP 1 #define HAVE_NANOSLEEP 1
#define HAVE_NL_LANGINFO 1 #define HAVE_NL_LANGINFO 1
/* #undef HAVE__NSGETEXECUTABLEPATH */ /* #undef HAVE__NSGETEXECUTABLEPATH */
/* #undef HAVE_PIPE2 */ /* #undef HAVE_PIPE2 */
#define HAVE_POLL 1 #define HAVE_POLL 1
#define HAVE_POPEN 1 #define HAVE_POPEN 1
#define HAVE_POSIX_FADVISE 1 #define HAVE_POSIX_FADVISE 1
#define HAVE_POSIX_FALLOCATE 1 #define HAVE_POSIX_FALLOCATE 1
#define HAVE_POSIX_MADVISE 1 #define HAVE_POSIX_MADVISE 1
#define HAVE_PUTENV 1 #define HAVE_PUTENV 1
#define HAVE_SETSID 1 #define HAVE_SETSID 1
#define HAVE_SHUTDOWN 1 #define HAVE_SHUTDOWN 1
#define HAVE_SIGACTION 1 #define HAVE_SIGACTION 1
#define HAVE_STPCPY 1 #define HAVE_STPCPY 1
#define HAVE_STRCASESTR 1 #define HAVE_STRCASESTR 1
#define HAVE_STRNCASECMP 1 #define HAVE_STRNCASECMP 1
#define HAVE_STRPTIME 1 #define HAVE_STRPTIME 1
#define HAVE_STRSIGNAL 1 #define HAVE_STRSIGNAL 1
#define HAVE_SYSCONF 1 #define HAVE_SYSCONF 1
/* #undef HAVE_TASK_INFO */ /* #undef HAVE_TASK_INFO */
#define HAVE_TIMES 1 #define HAVE_TIMES 1
#define HAVE_UNAME 1 #define HAVE_UNAME 1
/* #undef HAVE_SEMTIMEDOP */ /* #undef HAVE_SEMTIMEDOP */
#define HAVE_PTHREAD_KILL 1 #define HAVE_PTHREAD_KILL 1
#define HAVE_PTHREAD_SIGMASK 1 #define HAVE_PTHREAD_SIGMASK 1
#define HAVE_GETOPT 1 #define HAVE_GETOPT 1
#define ICONV_CONST #define ICONV_CONST
#define FLEXIBLE_ARRAY_MEMBER #define FLEXIBLE_ARRAY_MEMBER
#define ENABLE_MAPI 1 #define ENABLE_MAPI 1
#define HAVE_MAPI 1 #define HAVE_MAPI 1
// End Section: monetdb configure defines // End Section: monetdb configure defines
// Section: monetdb macro variables // Section: monetdb macro variables
/* #undef HAVE_ICONV */ /* #undef HAVE_ICONV */
#define HAVE_PTHREAD_H 1 #define HAVE_PTHREAD_H 1
/* #undef HAVE_LIBPCRE */ /* #undef HAVE_LIBPCRE */
/* #undef HAVE_LIBBZ2 */ /* #undef HAVE_LIBBZ2 */
/* #undef HAVE_CURL */ /* #undef HAVE_CURL */
/* #undef HAVE_LIBLZMA */ /* #undef HAVE_LIBLZMA */
/* #undef HAVE_LIBXML */ /* #undef HAVE_LIBXML */
/* #undef HAVE_LIBZ */ /* #undef HAVE_LIBZ */
/* #undef HAVE_LIBLZ4 */ /* #undef HAVE_LIBLZ4 */
/* #undef HAVE_PROJ */ /* #undef HAVE_PROJ */
/* #undef HAVE_SNAPPY */ /* #undef HAVE_SNAPPY */
/* #undef HAVE_FITS */ /* #undef HAVE_FITS */
/* #undef HAVE_VALGRIND */ /* #undef HAVE_VALGRIND */
/* #undef HAVE_NETCDF */ /* #undef HAVE_NETCDF */
/* #undef HAVE_READLINE */ /* #undef HAVE_READLINE */
/* #undef HAVE_LIBR */ /* #undef HAVE_LIBR */
#define RHOME "/registry" #define RHOME "/registry"
/* #undef HAVE_GEOM */ /* #undef HAVE_GEOM */
/* #undef HAVE_SHP */ /* #undef HAVE_SHP */
/* #undef HAVE_LIBPY3 */ /* #undef HAVE_LIBPY3 */
// #define SOCKET_LIBRARIES // #define SOCKET_LIBRARIES
#define HAVE_GETADDRINFO 1 #define HAVE_GETADDRINFO 1
/* #undef HAVE_CUDF */ /* #undef HAVE_CUDF */
#define MAPI_PORT 50000 #define MAPI_PORT 50000
#define MAPI_PORT_STR "50000" #define MAPI_PORT_STR "50000"
#ifdef _MSC_VER #ifdef _MSC_VER
#define DIR_SEP '\\' #define DIR_SEP '\\'
#define PATH_SEP ';' #define PATH_SEP ';'
#define DIR_SEP_STR "\\" #define DIR_SEP_STR "\\"
#define SO_PREFIX "" #define SO_PREFIX ""
#else #else
#define DIR_SEP '/' #define DIR_SEP '/'
#define PATH_SEP ':' #define PATH_SEP ':'
#define DIR_SEP_STR "/" #define DIR_SEP_STR "/"
#define SO_PREFIX "lib" #define SO_PREFIX "lib"
#endif #endif
#define SO_EXT ".dll" #define SO_EXT ".dll"
#define BINDIR "C:/Program Files (x86)/MonetDB/bin" #define BINDIR "C:/Program Files (x86)/MonetDB/bin"
#define LIBDIR "C:/Program Files (x86)/MonetDB/lib" #define LIBDIR "C:/Program Files (x86)/MonetDB/lib"
#define LOCALSTATEDIR "C:/Program Files (x86)/MonetDB/var" #define LOCALSTATEDIR "C:/Program Files (x86)/MonetDB/var"
// End Section: monetdb macro variables // End Section: monetdb macro variables
// Section: monetdb configure misc // Section: monetdb configure misc
#define MONETDB_RELEASE "unreleased" #define MONETDB_RELEASE "unreleased"
#define MONETDB_VERSION "11.44.0" #define MONETDB_VERSION "11.44.0"
#define MONETDB_VERSION_MAJOR 11 #define MONETDB_VERSION_MAJOR 11
#define MONETDB_VERSION_MINOR 44 #define MONETDB_VERSION_MINOR 44
#define MONETDB_VERSION_PATCH 0 #define MONETDB_VERSION_PATCH 0
#define GDK_VERSION "25.1.0" #define GDK_VERSION "25.1.0"
#define GDK_VERSION_MAJOR 25 #define GDK_VERSION_MAJOR 25
#define GDK_VERSION_MINOR 1 #define GDK_VERSION_MINOR 1
#define GDK_VERSION_PATCH 0 #define GDK_VERSION_PATCH 0
#define MAPI_VERSION "14.0.2" #define MAPI_VERSION "14.0.2"
#define MAPI_VERSION_MAJOR 14 #define MAPI_VERSION_MAJOR 14
#define MAPI_VERSION_MINOR 0 #define MAPI_VERSION_MINOR 0
#define MAPI_VERSION_PATCH 2 #define MAPI_VERSION_PATCH 2
#define MONETDB5_VERSION "32.0.6" #define MONETDB5_VERSION "32.0.6"
#define MONETDB5_VERSION_MAJOR 32 #define MONETDB5_VERSION_MAJOR 32
#define MONETDB5_VERSION_MINOR 0 #define MONETDB5_VERSION_MINOR 0
#define MONETDB5_VERSION_PATCH 6 #define MONETDB5_VERSION_PATCH 6
#define MONETDBE_VERSION "3.0.2" #define MONETDBE_VERSION "3.0.2"
#define MONETDBE_VERSION_MAJOR 3 #define MONETDBE_VERSION_MAJOR 3
#define MONETDBE_VERSION_MINOR 0 #define MONETDBE_VERSION_MINOR 0
#define MONETDBE_VERSION_PATCH 2 #define MONETDBE_VERSION_PATCH 2
#define STREAM_VERSION "16.0.1" #define STREAM_VERSION "16.0.1"
#define STREAM_VERSION_MAJOR 16 #define STREAM_VERSION_MAJOR 16
#define STREAM_VERSION_MINOR 0 #define STREAM_VERSION_MINOR 0
#define STREAM_VERSION_PATCH 1 #define STREAM_VERSION_PATCH 1
#define SQL_VERSION "12.0.5" #define SQL_VERSION "12.0.5"
#define SQL_VERSION_MAJOR 12 #define SQL_VERSION_MAJOR 12
#define SQL_VERSION_MINOR 0 #define SQL_VERSION_MINOR 0
#define SQL_VERSION_PATCH 5 #define SQL_VERSION_PATCH 5
/* Host identifier */ /* Host identifier */
#define HOST "amd64-pc-windows-gnu" #define HOST "amd64-pc-windows-gnu"
/* The used password hash algorithm */ /* The used password hash algorithm */
#define MONETDB5_PASSWDHASH "SHA512" #define MONETDB5_PASSWDHASH "SHA512"
/* The used password hash algorithm */ /* The used password hash algorithm */
#define MONETDB5_PASSWDHASH_TOKEN SHA512 #define MONETDB5_PASSWDHASH_TOKEN SHA512
#ifndef _Noreturn #ifndef _Noreturn
#ifdef __cplusplus #ifdef __cplusplus
#define _Noreturn #define _Noreturn
#else #else
/* #undef _Noreturn */ /* #undef _Noreturn */
#endif #endif
#endif #endif
/* Does your compiler support `inline' keyword? (C99 feature) */ /* Does your compiler support `inline' keyword? (C99 feature) */
#ifndef inline #ifndef inline
#ifdef __cplusplus #ifdef __cplusplus
#define inline #define inline
#else #else
/* #undef inline */ /* #undef inline */
#endif #endif
#endif #endif
/* Does your compiler support `restrict' keyword? (C99 feature) */ /* Does your compiler support `restrict' keyword? (C99 feature) */
#ifndef restrict #ifndef restrict
#ifdef __cplusplus #ifdef __cplusplus
#define restrict #define restrict
#else #else
/* #undef restrict */ /* #undef restrict */
#endif #endif
#endif #endif
// End Section: monetdb configure misc // End Section: monetdb configure misc
// Section: monetdb configure sizes // Section: monetdb configure sizes
#define SIZEOF_SIZE_T 8 #define SIZEOF_SIZE_T 8
/* The size of `void *', as computed by sizeof. */ /* The size of `void *', as computed by sizeof. */
#define SIZEOF_VOID_P 8 #define SIZEOF_VOID_P 8
#define SIZEOF_CHAR 1 #define SIZEOF_CHAR 1
#define SIZEOF_SHORT 2 #define SIZEOF_SHORT 2
#define SIZEOF_INT 4 #define SIZEOF_INT 4
#define SIZEOF_LONG 8 #define SIZEOF_LONG 8
#define SIZEOF_LONG_LONG 8 #define SIZEOF_LONG_LONG 8
#define SIZEOF_DOUBLE 8 #define SIZEOF_DOUBLE 8
#define SIZEOF_WCHAR_T 2 #define SIZEOF_WCHAR_T 2
#define HAVE_LONG_LONG 1 /* for ODBC include files */ #define HAVE_LONG_LONG 1 /* for ODBC include files */
#ifdef _MSC_VER #ifdef _MSC_VER
#ifdef _WIN64 #ifdef _WIN64
#define LENP_OR_POINTER_T SQLLEN * #define LENP_OR_POINTER_T SQLLEN *
#else #else
#define LENP_OR_POINTER_T SQLPOINTER #define LENP_OR_POINTER_T SQLPOINTER
#endif #endif
#else #else
/* #undef LENP_OR_POINTER_T */ /* #undef LENP_OR_POINTER_T */
#endif #endif
/* #undef SIZEOF_SQLWCHAR */ /* #undef SIZEOF_SQLWCHAR */
/* #undef WORDS_BIGENDIAN */ /* #undef WORDS_BIGENDIAN */
/* Does your compiler support `ssize_t' type? (Posix type) */ /* Does your compiler support `ssize_t' type? (Posix type) */
#ifndef ssize_t #ifndef ssize_t
/* #undef ssize_t */ /* #undef ssize_t */
#endif #endif
/* The size of `__int128', as computed by sizeof. */ /* The size of `__int128', as computed by sizeof. */
#define SIZEOF___INT128 16 #define SIZEOF___INT128 16
/* The size of `__int128_t', as computed by sizeof. */ /* The size of `__int128_t', as computed by sizeof. */
#define SIZEOF___INT128_T 16 #define SIZEOF___INT128_T 16
/* The size of `__uint128_t', as computed by sizeof. */ /* The size of `__uint128_t', as computed by sizeof. */
#define SIZEOF___UINT128_T 16 #define SIZEOF___UINT128_T 16
#define HAVE___INT128 1 #define HAVE___INT128 1
#define HAVE___INT128_T 1 #define HAVE___INT128_T 1
#define HAVE___UINT128_T 1 #define HAVE___UINT128_T 1
/* #undef HAVE_HGE */ /* #undef HAVE_HGE */
#ifdef HAVE_HGE #ifdef HAVE_HGE
#ifdef HAVE___INT128 #ifdef HAVE___INT128
typedef __int128 hge; typedef __int128 hge;
typedef unsigned __int128 uhge; typedef unsigned __int128 uhge;
#define SIZEOF_HGE SIZEOF___INT128 #define SIZEOF_HGE SIZEOF___INT128
#elif defined(HAVE___INT128_T) && defined(HAVE___UINT128_T) #elif defined(HAVE___INT128_T) && defined(HAVE___UINT128_T)
typedef __int128_t hge; typedef __int128_t hge;
typedef __uint128_t uhge; typedef __uint128_t uhge;
#define SIZEOF_HGE SIZEOF___INT128_T #define SIZEOF_HGE SIZEOF___INT128_T
#endif #endif
#endif #endif
// End Section: monetdb configure sizes // End Section: monetdb configure sizes
/* Does your compiler support `__attribute__' extension? */ /* Does your compiler support `__attribute__' extension? */
#if !defined(__GNUC__) && !defined(__clang__) && !defined(__attribute__) #if !defined(__GNUC__) && !defined(__clang__) && !defined(__attribute__)
#define __attribute__(a) #define __attribute__(a)
#endif #endif
#if !defined(__cplusplus) || __cplusplus < 201103L #if !defined(__cplusplus) || __cplusplus < 201103L
#ifndef static_assert #ifndef static_assert
/* static_assert is a C11/C++11 feature, defined in assert.h which also exists /* static_assert is a C11/C++11 feature, defined in assert.h which also exists
* in many other compilers we ignore it if the compiler doesn't support it * in many other compilers we ignore it if the compiler doesn't support it
* However in C11 static_assert is a macro, while on C++11 is a keyword */ * However in C11 static_assert is a macro, while on C++11 is a keyword */
#define static_assert(expr, mesg) ((void) 0) #define static_assert(expr, mesg) ((void) 0)
#endif #endif
#endif #endif
#ifdef HAVE_STRINGS_H #ifdef HAVE_STRINGS_H
#include <strings.h> /* strcasecmp */ #include <strings.h> /* strcasecmp */
#endif #endif
#ifdef _MSC_VER #ifdef _MSC_VER
#define strdup(s) _strdup(s) #define strdup(s) _strdup(s)
#ifndef strcasecmp #ifndef strcasecmp
#define strcasecmp(x,y) _stricmp(x,y) #define strcasecmp(x,y) _stricmp(x,y)
#endif #endif
/* Define to 1 if you have the `strncasecmp' function. */ /* Define to 1 if you have the `strncasecmp' function. */
#define HAVE_STRNCASECMP 1 #define HAVE_STRNCASECMP 1
#ifndef strncasecmp #ifndef strncasecmp
#define strncasecmp(x,y,z) _strnicmp(x,y,z) #define strncasecmp(x,y,z) _strnicmp(x,y,z)
#endif #endif
#include <sys/stat.h> #include <sys/stat.h>
#ifdef lstat #ifdef lstat
#undef lstat #undef lstat
#endif #endif
#define lstat _stat64 #define lstat _stat64
#ifdef stat #ifdef stat
#undef stat #undef stat
#endif #endif
#define stat _stat64 #define stat _stat64
#ifdef fstat #ifdef fstat
#undef fstat #undef fstat
#endif #endif
#define fstat _fstat64 #define fstat _fstat64
static inline char * static inline char *
stpcpy(char *restrict dst, const char *restrict src) stpcpy(char *restrict dst, const char *restrict src)
{ {
size_t i; size_t i;
for (i = 0; src[i]; i++) for (i = 0; src[i]; i++)
dst[i] = src[i]; dst[i] = src[i];
dst[i] = 0; dst[i] = 0;
return dst + i; return dst + i;
} }
/* Define to 1 if the system has the type `socklen_t'. */ /* Define to 1 if the system has the type `socklen_t'. */
#define HAVE_SOCKLEN_T 1 #define HAVE_SOCKLEN_T 1
/* type used by connect */ /* type used by connect */
#define socklen_t int #define socklen_t int
#define strtok_r(t,d,c) strtok_s(t,d,c) #define strtok_r(t,d,c) strtok_s(t,d,c)
#define HAVE_GETOPT_LONG 1 #define HAVE_GETOPT_LONG 1
/* there is something very similar to localtime_r on Windows: */ /* there is something very similar to localtime_r on Windows: */
#include <time.h> #include <time.h>
#define HAVE_LOCALTIME_R 1 #define HAVE_LOCALTIME_R 1
static inline struct tm * static inline struct tm *
localtime_r(const time_t *restrict timep, struct tm *restrict result) localtime_r(const time_t *restrict timep, struct tm *restrict result)
{ {
return localtime_s(result, timep) == 0 ? result : NULL; return localtime_s(result, timep) == 0 ? result : NULL;
} }
#define HAVE_GMTIME_R 1 #define HAVE_GMTIME_R 1
static inline struct tm * static inline struct tm *
gmtime_r(const time_t *restrict timep, struct tm *restrict result) gmtime_r(const time_t *restrict timep, struct tm *restrict result)
{ {
return gmtime_s(result, timep) == 0 ? result : NULL; return gmtime_s(result, timep) == 0 ? result : NULL;
} }
/* Define if you have ctime_r(time_t*,char *buf,size_t s) */ /* Define if you have ctime_r(time_t*,char *buf,size_t s) */
#define HAVE_CTIME_R 1 #define HAVE_CTIME_R 1
#define HAVE_CTIME_R3 1 #define HAVE_CTIME_R3 1
/* there is something very similar to ctime_r on Windows: */ /* there is something very similar to ctime_r on Windows: */
#define ctime_r(t,b,s) (ctime_s(b,s,t) ? NULL : (b)) #define ctime_r(t,b,s) (ctime_s(b,s,t) ? NULL : (b))
#endif /* _MSC_VER */ #endif /* _MSC_VER */
/* #undef HAVE_SOCKLEN_T */ /* #undef HAVE_SOCKLEN_T */
#ifndef _MSC_VER #ifndef _MSC_VER
#define SOCKET int #define SOCKET int
#define closesocket close #define closesocket close
#endif #endif
#ifndef _In_z_ #ifndef _In_z_
#define _In_z_ #define _In_z_
#endif #endif
#ifndef _Printf_format_string_ #ifndef _Printf_format_string_
#define _Printf_format_string_ #define _Printf_format_string_
#endif #endif
#ifdef _MSC_VER #ifdef _MSC_VER
#define _LIB_STARTUP_FUNC_(f,q) \ #define _LIB_STARTUP_FUNC_(f,q) \
static void f(void); \ static void f(void); \
__declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \ __declspec(allocate(".CRT$XCU")) void (*f##_)(void) = f; \
__pragma(comment(linker,"/include:" q #f "_")) \ __pragma(comment(linker,"/include:" q #f "_")) \
static void f(void) static void f(void)
#ifdef _WIN64 #ifdef _WIN64
#define LIB_STARTUP_FUNC(f) _LIB_STARTUP_FUNC_(f,"") #define LIB_STARTUP_FUNC(f) _LIB_STARTUP_FUNC_(f,"")
#else #else
#define LIB_STARTUP_FUNC(f) _LIB_STARTUP_FUNC_(f,"_") #define LIB_STARTUP_FUNC(f) _LIB_STARTUP_FUNC_(f,"_")
#endif #endif
#else #else
#define LIB_STARTUP_FUNC(f) \ #define LIB_STARTUP_FUNC(f) \
static void f(void) __attribute__((__constructor__)); \ static void f(void) __attribute__((__constructor__)); \
static void f(void) static void f(void)
#endif #endif
#endif /* MT_SEEN_MONETDB_CONFIG_H */ #endif /* MT_SEEN_MONETDB_CONFIG_H */

@ -1,190 +1,190 @@
/* /*
* This Source Code Form is subject to the terms of the Mozilla Public * 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 * 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/. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
* *
* Copyright 1997 - July 2008 CWI, August 2008 - 2022 MonetDB B.V. * Copyright 1997 - July 2008 CWI, August 2008 - 2022 MonetDB B.V.
*/ */
#ifndef _MONETDBE_LIB_ #ifndef _MONETDBE_LIB_
#define _MONETDBE_LIB_ #define _MONETDBE_LIB_
#include "monetdb_config.h" #include "monetdb_config.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include <stdint.h> #include <stdint.h>
#ifdef WIN32 #ifdef WIN32
#ifndef LIBMONETDBE #ifndef LIBMONETDBE
#define monetdbe_export extern __declspec(dllimport) #define monetdbe_export extern __declspec(dllimport)
#else #else
#define monetdbe_export extern __declspec(dllexport) #define monetdbe_export extern __declspec(dllexport)
#endif #endif
#else #else
#define monetdbe_export extern #define monetdbe_export extern
#endif #endif
typedef int64_t monetdbe_cnt; typedef int64_t monetdbe_cnt;
typedef struct { typedef struct {
unsigned char day; unsigned char day;
unsigned char month; unsigned char month;
short year; short year;
} monetdbe_data_date; } monetdbe_data_date;
typedef struct { typedef struct {
unsigned int ms; unsigned int ms;
unsigned char seconds; unsigned char seconds;
unsigned char minutes; unsigned char minutes;
unsigned char hours; unsigned char hours;
} monetdbe_data_time; } monetdbe_data_time;
typedef struct { typedef struct {
monetdbe_data_date date; monetdbe_data_date date;
monetdbe_data_time time; monetdbe_data_time time;
} monetdbe_data_timestamp; } monetdbe_data_timestamp;
typedef struct { typedef struct {
size_t size; size_t size;
char* data; char* data;
} monetdbe_data_blob; } monetdbe_data_blob;
typedef enum { typedef enum {
monetdbe_bool, monetdbe_int8_t, monetdbe_int16_t, monetdbe_int32_t, monetdbe_int64_t, monetdbe_bool, monetdbe_int8_t, monetdbe_int16_t, monetdbe_int32_t, monetdbe_int64_t,
#ifdef HAVE_HGE #ifdef HAVE_HGE
monetdbe_int128_t, monetdbe_int128_t,
#endif #endif
monetdbe_size_t, monetdbe_float, monetdbe_double, monetdbe_size_t, monetdbe_float, monetdbe_double,
monetdbe_str, monetdbe_blob, monetdbe_str, monetdbe_blob,
monetdbe_date, monetdbe_time, monetdbe_timestamp, monetdbe_date, monetdbe_time, monetdbe_timestamp,
// should be last: // should be last:
monetdbe_type_unknown monetdbe_type_unknown
} monetdbe_types; } monetdbe_types;
typedef struct { typedef struct {
char* name; char* name;
unsigned int scale; unsigned int scale;
unsigned int digits; unsigned int digits;
} monetdbe_sql_type; } monetdbe_sql_type;
typedef struct { typedef struct {
monetdbe_types type; monetdbe_types type;
monetdbe_sql_type sql_type; monetdbe_sql_type sql_type;
void *data; void *data;
size_t count; size_t count;
char* name; char* name;
} monetdbe_column; } monetdbe_column;
typedef struct { typedef struct {
size_t nparam; size_t nparam;
monetdbe_types *type; monetdbe_types *type;
} monetdbe_statement; } monetdbe_statement;
typedef struct { typedef struct {
monetdbe_cnt nrows; monetdbe_cnt nrows;
size_t ncols; size_t ncols;
char *name; char *name;
monetdbe_cnt last_id; /* last auto incremented id */ monetdbe_cnt last_id; /* last auto incremented id */
} monetdbe_result; } monetdbe_result;
typedef void* monetdbe_database; typedef void* monetdbe_database;
typedef struct { typedef struct {
const char *host; const char *host;
int port; int port;
const char *database; const char *database;
const char *username; const char *username;
const char *password; const char *password;
const char *lang; const char *lang;
} monetdbe_remote; } monetdbe_remote;
typedef struct { typedef struct {
const char *host; const char *host;
const char* port; const char* port;
const char* usock; const char* usock;
} monetdbe_mapi_server; } monetdbe_mapi_server;
typedef struct { typedef struct {
int memorylimit; // top off the amount of RAM to be used, in MB int memorylimit; // top off the amount of RAM to be used, in MB
int querytimeout; // graceful terminate query after a few seconds int querytimeout; // graceful terminate query after a few seconds
int sessiontimeout; // graceful terminate the session after a few seconds int sessiontimeout; // graceful terminate the session after a few seconds
int nr_threads; // maximum number of worker treads, limits level of parallelism int nr_threads; // maximum number of worker treads, limits level of parallelism
monetdbe_remote* remote; monetdbe_remote* remote;
monetdbe_mapi_server* mapi_server; monetdbe_mapi_server* mapi_server;
const char *trace_file; // file to which log output should be written const char *trace_file; // file to which log output should be written
} monetdbe_options; } monetdbe_options;
#define DEFAULT_STRUCT_DEFINITION(ctype, typename) \ #define DEFAULT_STRUCT_DEFINITION(ctype, typename) \
typedef struct \ typedef struct \
{ \ { \
monetdbe_types type; \ monetdbe_types type; \
monetdbe_sql_type sql_type; \ monetdbe_sql_type sql_type; \
ctype *data; \ ctype *data; \
size_t count; \ size_t count; \
char *name; \ char *name; \
ctype null_value; \ ctype null_value; \
double scale; \ double scale; \
int (*is_null)(ctype *value); \ int (*is_null)(ctype *value); \
} monetdbe_column_##typename } monetdbe_column_##typename
DEFAULT_STRUCT_DEFINITION(int8_t, bool); DEFAULT_STRUCT_DEFINITION(int8_t, bool);
DEFAULT_STRUCT_DEFINITION(int8_t, int8_t); DEFAULT_STRUCT_DEFINITION(int8_t, int8_t);
DEFAULT_STRUCT_DEFINITION(int16_t, int16_t); DEFAULT_STRUCT_DEFINITION(int16_t, int16_t);
DEFAULT_STRUCT_DEFINITION(int32_t, int32_t); DEFAULT_STRUCT_DEFINITION(int32_t, int32_t);
DEFAULT_STRUCT_DEFINITION(int64_t, int64_t); DEFAULT_STRUCT_DEFINITION(int64_t, int64_t);
#ifdef HAVE_HGE #ifdef HAVE_HGE
DEFAULT_STRUCT_DEFINITION(__int128, int128_t); DEFAULT_STRUCT_DEFINITION(__int128, int128_t);
#endif #endif
DEFAULT_STRUCT_DEFINITION(size_t, size_t); DEFAULT_STRUCT_DEFINITION(size_t, size_t);
DEFAULT_STRUCT_DEFINITION(float, float); DEFAULT_STRUCT_DEFINITION(float, float);
DEFAULT_STRUCT_DEFINITION(double, double); DEFAULT_STRUCT_DEFINITION(double, double);
DEFAULT_STRUCT_DEFINITION(char *, str); DEFAULT_STRUCT_DEFINITION(char *, str);
DEFAULT_STRUCT_DEFINITION(monetdbe_data_blob, blob); DEFAULT_STRUCT_DEFINITION(monetdbe_data_blob, blob);
DEFAULT_STRUCT_DEFINITION(monetdbe_data_date, date); DEFAULT_STRUCT_DEFINITION(monetdbe_data_date, date);
DEFAULT_STRUCT_DEFINITION(monetdbe_data_time, time); DEFAULT_STRUCT_DEFINITION(monetdbe_data_time, time);
DEFAULT_STRUCT_DEFINITION(monetdbe_data_timestamp, timestamp); DEFAULT_STRUCT_DEFINITION(monetdbe_data_timestamp, timestamp);
// UUID, INET, XML ? // UUID, INET, XML ?
monetdbe_export const char *monetdbe_version(void); monetdbe_export const char *monetdbe_version(void);
monetdbe_export int monetdbe_open(monetdbe_database *db, char *url, monetdbe_options *opts); monetdbe_export int monetdbe_open(monetdbe_database *db, char *url, monetdbe_options *opts);
/* 0 ok, -1 (allocation failed), -2 error in db */ /* 0 ok, -1 (allocation failed), -2 error in db */
monetdbe_export int monetdbe_close(monetdbe_database db); monetdbe_export int monetdbe_close(monetdbe_database db);
monetdbe_export char* monetdbe_error(monetdbe_database db); monetdbe_export char* monetdbe_error(monetdbe_database db);
monetdbe_export char* monetdbe_get_autocommit(monetdbe_database dbhdl, int* result); monetdbe_export char* monetdbe_get_autocommit(monetdbe_database dbhdl, int* result);
monetdbe_export char* monetdbe_set_autocommit(monetdbe_database dbhdl, int value); monetdbe_export char* monetdbe_set_autocommit(monetdbe_database dbhdl, int value);
monetdbe_export int monetdbe_in_transaction(monetdbe_database dbhdl); monetdbe_export int monetdbe_in_transaction(monetdbe_database dbhdl);
monetdbe_export char* monetdbe_query(monetdbe_database dbhdl, char* query, monetdbe_result** result, monetdbe_cnt* affected_rows); monetdbe_export char* monetdbe_query(monetdbe_database dbhdl, char* query, monetdbe_result** result, monetdbe_cnt* affected_rows);
monetdbe_export char* monetdbe_result_fetch(monetdbe_result *mres, monetdbe_column** res, size_t column_index); monetdbe_export char* monetdbe_result_fetch(monetdbe_result *mres, monetdbe_column** res, size_t column_index);
monetdbe_export char* monetdbe_cleanup_result(monetdbe_database dbhdl, monetdbe_result* result); monetdbe_export char* monetdbe_cleanup_result(monetdbe_database dbhdl, monetdbe_result* result);
monetdbe_export char* monetdbe_prepare(monetdbe_database dbhdl, char *query, monetdbe_statement **stmt, monetdbe_result** result); monetdbe_export char* monetdbe_prepare(monetdbe_database dbhdl, char *query, monetdbe_statement **stmt, monetdbe_result** result);
monetdbe_export char* monetdbe_bind(monetdbe_statement *stmt, void *data, size_t parameter_nr); monetdbe_export char* monetdbe_bind(monetdbe_statement *stmt, void *data, size_t parameter_nr);
monetdbe_export char* monetdbe_execute(monetdbe_statement *stmt, monetdbe_result **result, monetdbe_cnt* affected_rows); monetdbe_export char* monetdbe_execute(monetdbe_statement *stmt, monetdbe_result **result, monetdbe_cnt* affected_rows);
monetdbe_export char* monetdbe_cleanup_statement(monetdbe_database dbhdl, monetdbe_statement *stmt); monetdbe_export char* monetdbe_cleanup_statement(monetdbe_database dbhdl, monetdbe_statement *stmt);
monetdbe_export char* monetdbe_append(monetdbe_database dbhdl, const char* schema, const char* table, monetdbe_column **input, size_t column_count); monetdbe_export char* monetdbe_append(monetdbe_database dbhdl, const char* schema, const char* table, monetdbe_column **input, size_t column_count);
monetdbe_export const void* monetdbe_null(monetdbe_database dbhdl, monetdbe_types t); monetdbe_export const void* monetdbe_null(monetdbe_database dbhdl, monetdbe_types t);
monetdbe_export char* monetdbe_get_columns(monetdbe_database dbhdl, const char* schema_name, const char *table_name, size_t *column_count, monetdbe_column **columns); monetdbe_export char* monetdbe_get_columns(monetdbe_database dbhdl, const char* schema_name, const char *table_name, size_t *column_count, monetdbe_column **columns);
monetdbe_export char* monetdbe_dump_database(monetdbe_database dbhdl, const char *backupfile); monetdbe_export char* monetdbe_dump_database(monetdbe_database dbhdl, const char *backupfile);
monetdbe_export char* monetdbe_dump_table(monetdbe_database dbhdl, const char *schema_name, const char *table_name, const char *backupfile); monetdbe_export char* monetdbe_dump_table(monetdbe_database dbhdl, const char *schema_name, const char *table_name, const char *backupfile);
monetdbe_export const char* monetdbe_get_mapi_port(void); monetdbe_export const char* monetdbe_get_mapi_port(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif

Binary file not shown.

@ -1,21 +1,31 @@
#include "./server/libaquery.h" #include "./server/aggregations.h"
#include "./udf.hpp" #include "./udf.hpp"
#include "./server/hasher.h"
#include <unordered_map>
#include "./server/monetdb_conn.h" #include "./server/monetdb_conn.h"
#include "./server/aggregations.h" #include "./server/libaquery.h"
extern "C" int __DLLEXPORT__ dllmain(Context* cxt) { extern "C" int __DLLEXPORT__ dllmain(Context* cxt) {
using namespace std; using namespace std;
using namespace types; using namespace types;
auto server = static_cast<Server*>(cxt->alt_server); auto server = static_cast<Server*>(cxt->alt_server);
auto len_6WMRXO = server->cnt; auto len_4fxytV = server->cnt;
auto suma_6BP = ColRef<int64_t>(len_6WMRXO, server->getCol(0)); auto b_3pr = ColRef<int>(len_4fxytV, server->getCol(0));
auto b_5Yb = ColRef<int>(len_6WMRXO, server->getCol(1)); auto a_65L = ColRef<int>(len_4fxytV, server->getCol(1));
auto c_2Vh = ColRef<int>(len_6WMRXO, server->getCol(2)); auto out_2UnEpP = new TableInfo<value_type<decays<decltype(covariances2_gettype(a_65L, b_3pr, 4))>>>("out_2UnEpP");
auto d_1Ma = ColRef<int>(len_6WMRXO, server->getCol(3)); auto col_C9QF0Z = out_2UnEpP->get_col<0>();
auto out_2URo7p = new TableInfo<value_type<decays<decltype((paircorr(c_2Vh, b_5Yb) * d_1Ma))>>,int64_t,int>("out_2URo7p"); for (uint32_t i41 = 0; i41 < t1K4f4I0.size; ++i41){
out_2URo7p->get_col<0>() = (paircorr(c_2Vh, b_5Yb) * d_1Ma); g1zdpLFa[forward_as_tuple(t1K4f4I0[i41])].emplace_back(i41);
out_2URo7p->get_col<1>().initfrom(suma_6BP); }
out_2URo7p->get_col<2>().initfrom(b_5Yb); for (const auto& i40 : g1zdpLFa){
print(*out_2URo7p); auto &len_5NTOM6m = val_2423Z8E.size;
auto &key_6fZPUDS = i4O.first;
auto &val_2423Z8E = i4O.second;
col_C9QF0Z.emplace_back({len_5NTOM6m});
covariances2(a_65L[val_2423Z8E], b_3pr[val_2423Z8E], 4, len_5NTOM6m, col_C9QF0Z.back());
}
print(*out_2UnEpP);
return 0; return 0;
} }

@ -34,13 +34,17 @@ server_mode = RunType.Threaded
server_bin = 'server.bin' if server_mode == RunType.IPC else 'server.so' server_bin = 'server.bin' if server_mode == RunType.IPC else 'server.so'
try:
os.remove(server_bin)
except Exception as e:
print(type(e), e)
nullstream = open(os.devnull, 'w') nullstream = open(os.devnull, 'w')
subprocess.call(['make', server_bin], stdout=nullstream)
if aquery_config.rebuild_backend:
try:
os.remove(server_bin)
except Exception as e:
print(type(e), e)
subprocess.call(['make', server_bin], stdout=nullstream)
cleanup = True cleanup = True
def rm(): def rm():
@ -157,12 +161,12 @@ def init_threaded():
else: else:
os.environ['PATH'] = os.environ['PATH'] + os.pathsep + os.path.abspath('.') os.environ['PATH'] = os.environ['PATH'] + os.pathsep + os.path.abspath('.')
os.environ['PATH'] = os.environ['PATH'] + os.pathsep + os.path.abspath('./lib') os.environ['PATH'] = os.environ['PATH'] + os.pathsep + os.path.abspath('./lib')
if aquery_config.run_backend:
server_so = ctypes.CDLL('./'+server_bin) server_so = ctypes.CDLL('./'+server_bin)
global cfg, th, send global cfg, th, send
send = server_so['receive_args'] send = server_so['receive_args']
th = threading.Thread(target=server_so['main'], args=(-1, ctypes.POINTER(ctypes.c_char_p)(cfg.c)), daemon=True) th = threading.Thread(target=server_so['main'], args=(-1, ctypes.POINTER(ctypes.c_char_p)(cfg.c)), daemon=True)
th.start() th.start()
if server_mode == RunType.IPC: if server_mode == RunType.IPC:
atexit.register(rm) atexit.register(rm)
@ -180,8 +184,11 @@ else:
global cfg global cfg
cfg.new_query = 1 cfg.new_query = 1
set_ready = __set_ready set_ready = __set_ready
get_ready = lambda:cfg.new_query get_ready = lambda: aquery_config.run_backend and cfg.new_query
server_status = lambda : not th.is_alive() if aquery_config.run_backend:
server_status = lambda : not th.is_alive()
else:
server_status = lambda : True
init() init()
test_parser = True test_parser = True
@ -221,7 +228,10 @@ while test_parser:
qs = [ctypes.c_char_p(bytes(q, 'utf-8')) for q in sqls if len(q)] qs = [ctypes.c_char_p(bytes(q, 'utf-8')) for q in sqls if len(q)]
sz = len(qs) sz = len(qs)
payload = (ctypes.c_char_p*sz)(*qs) payload = (ctypes.c_char_p*sz)(*qs)
send(sz, payload) try:
send(sz, payload)
except TypeError as e:
print(e)
if cxt.udf is not None: if cxt.udf is not None:
with open('udf.hpp', 'wb') as outfile: with open('udf.hpp', 'wb') as outfile:
outfile.write(cxt.udf.encode('utf-8')) outfile.write(cxt.udf.encode('utf-8'))
@ -237,19 +247,18 @@ while test_parser:
continue continue
elif q == 'dbg': elif q == 'dbg':
import code import code
var = globals().copy() from copy import deepcopy
var.update(locals()) var = {**globals(), **locals()}
sh = code.InteractiveConsole(var) sh = code.InteractiveConsole(var)
try: try:
code.interact() sh.interact(banner = 'debugging session began.', exitmsg = 'debugging session ended.')
except BaseException as e: except BaseException as e:
# don't care about anything happened in interactive console # don't care about anything happened in interactive console
pass print(e.with_traceback())
elif q.startswith('log'): elif q.startswith('log'):
qs = re.split(' |\t', q) qs = re.split(r'[ \t]', q)
if len(qs) > 1: if len(qs) > 1:
cxt.log_level = qs[1] cxt.log_level = qs[1]
else: else:
@ -276,7 +285,7 @@ while test_parser:
set_ready() set_ready()
continue continue
elif q.startswith('save'): elif q.startswith('save'):
filename = re.split(' |\t', q) filename = re.split(r'[ \t]', q)
if (len(filename) > 1): if (len(filename) > 1):
filename = filename[1] filename = filename[1]
else: else:

@ -1,32 +0,0 @@
Exception: STATUS_ACCESS_VIOLATION at rip=005A43E1EE8
rax=000000080016C970 rbx=00000000FFFFC2E0 rcx=0000000000000015
rdx=00000000FFFFCE00 rsi=0000000000000000 rdi=0000000000000002
r8 =00000000000000A8 r9 =000000080016C970 r10=0000000000005150
r11=000000080016C970 r12=00000000FFFFFFFF r13=0000000000000000
r14=00006FFFFFEBA2F8 r15=00000000FFFFC380
rbp=00000000FFFFC210 rsp=00000000FFFFC160
program=C:\msys64\usr\bin\python3.exe, pid 821, thread main
cs=0033 ds=002B es=002B fs=0053 gs=002B ss=002B
Stack trace:
Frame Function Args
000FFFFC210 005A43E1EE8 (00000000000, 0057B699D00, 00000000050, 000FFFFC2A0)
000FFFFC210 00487B249A1 (0000000000A, 000FFFFC2F0, 00000000002, 000FFFFC3A0)
000FFFFC2A0 00487B245EE (000FFFC68F0, 00000000002, 6FFFFFEBA2F8, 00000000000)
000FFFFC3A0 00487B247B2 (004484CACEA, 00800187A50, 004484CACDA, 000FFFFC2D0)
000FFFFC3A0 004484CAE74 (0057B4D31A2, 00500001101, 00000000000, 00800187A50)
00000000000 004484C476D (6FFFFFF97DF0, 00000000000, 0057B539C7B, 6FFFFFE9AF40)
004484C4660 0057B509F6F (6FFFFFFC68F0, 6FFFFFEA2330, 0057B547BA7, 00000000000)
00800048F80 0057B6910D9 (0080016ABE0, 6FFF00000000, 0057B68A0EA, 0057B72B2E0)
00000000000 0057B5D0C61 (6FFFFFE9F190, 000FFFFC7F0, 0057B5E3A05, 00000000000)
6FFFFFF30220 0057B5D0FD1 (0080016ABF0, 6FFFFFF93D30, 0057B618338, 6FFFFFF34D00)
6FFFFFF30220 0057B60C6B0 (6FFFFFE9A0B0, 0080004A920, 6FFFFFE9F190, 6FFFFFEE2610)
6FFFFFF30220 0057B60C8B4 (0057B50A49A, 00000000000, 0057B539B2F, 000FFFFCAB8)
6FFFFFF30220 0057B60EE21 (00000000000, 000FFFFCAB8, 00000000001, 0057B731792)
0057B699678 0057B60F0B6 (0057B618804, 000FFFFCD30, 0057B604F54, 00800049350)
000FFFFCD30 0057B60FA20 (00000000000, 000FFFFC968, 000FFFFCD30, 00000000001)
000FFFFCD30 0057B62ABDD (001004016D0, 001004016D0, 00000000000, 000FFFFCD30)
000FFFFCD30 0057B62AE9D (00180049B25, 00180048A40, 00000000002, 00180326FE0)
000FFFFCD30 00180049B91 (00000000000, 00000000000, 00000000000, 00000000000)
000FFFFFFF0 00180047716 (00000000000, 00000000000, 00000000000, 00000000000)
000FFFFFFF0 001800477C4 (00000000000, 00000000000, 00000000000, 00000000000)
End of stack trace

@ -0,0 +1,11 @@
# TODO:
## 1. double scans in projections
- first for special aggrigations and singular columns
- Then in group by node decide if we have special group by aggregations
- If sp_gb_agg exists, the entire groupby aggregation is done in C plugin
- If not, group by is done in SQL
## 2. ColRef supports multiple objects
- A.a = B.b then in projection A.a B.b will refer to same projection
- Colref::ProjEq(ColRef v) => this == v or v in this.proj_eqs

@ -1,7 +1,9 @@
from re import T from copy import deepcopy
from typing import Set, Tuple from dataclasses import dataclass
from enum import Enum, auto
from typing import Set, Tuple, Dict, Union, List, Optional
from engine.types import * from engine.types import *
from engine.utils import enlist, base62uuid, base62alp, get_leagl_name from engine.utils import enlist, base62uuid, base62alp, get_legal_name
from reconstruct.storage import Context, TableInfo, ColRef from reconstruct.storage import Context, TableInfo, ColRef
class ast_node: class ast_node:
@ -9,11 +11,14 @@ class ast_node:
types = dict() types = dict()
first_order = False first_order = False
def __init__(self, parent:"ast_node", node, context:Context = None): def __init__(self, parent:Optional["ast_node"], node, context:Optional[Context] = None):
self.context = parent.context if context is None else context self.context = parent.context if context is None else context
self.parent = parent self.parent = parent
self.sql = '' self.sql = ''
self.datasource = None if hasattr(parent, 'datasource'):
self.datasource = parent.datasource
else:
self.datasource = None
self.init(node) self.init(node)
self.produce(node) self.produce(node)
self.spawn(node) self.spawn(node)
@ -38,7 +43,7 @@ class ast_node:
self.emit(self.sql+';\n') self.emit(self.sql+';\n')
from reconstruct.expr import expr from reconstruct.expr import expr, fastscan
class projection(ast_node): class projection(ast_node):
@ -70,10 +75,6 @@ class projection(ast_node):
else: else:
self.where = None self.where = None
if 'groupby' in node:
self.group_node = groupby(self, node['groupby'])
else:
self.group_node = None
def consume(self, node): def consume(self, node):
# deal with projections # deal with projections
@ -82,9 +83,9 @@ class projection(ast_node):
col_ext : Set[ColRef]= set() col_ext : Set[ColRef]= set()
col_exprs : List[Tuple[str, Types]] = [] col_exprs : List[Tuple[str, Types]] = []
proj_map = dict() proj_map : Dict[int, List[Union[Types, int, str, expr]]]= dict()
var_table = dict() var_table = dict()
self.sp_refs = set()
for i, proj in enumerate(self.projections): for i, proj in enumerate(self.projections):
compound = False compound = False
self.datasource.rec = set() self.datasource.rec = set()
@ -102,25 +103,26 @@ class projection(ast_node):
name = eval('f\'' + name + '\'') name = eval('f\'' + name + '\'')
if name not in var_table: if name not in var_table:
var_table[name] = len(col_exprs) var_table[name] = len(col_exprs)
proj_map[i] = [this_type, len(col_exprs)] proj_map[i] = [this_type, len(col_exprs), proj_expr]
col_exprs.append((name, proj_expr.type)) col_exprs.append((name, proj_expr.type))
else: else:
self.context.headers.add('"./server/aggregations.h"') self.context.headers.add('"./server/aggregations.h"')
if self.datasource.rec is not None: if self.datasource.rec is not None:
col_ext = col_ext.union(self.datasource.rec) col_ext = col_ext.union(self.datasource.rec) # TODO: make this one var?
proj_map[i] = [this_type, proj_expr.sql] self.sp_refs = self.sp_refs.union(self.datasource.rec)
proj_map[i] = [this_type, proj_expr.sql, proj_expr]
if 'name' in proj: # renaming column by AS keyword if 'name' in proj: # renaming column by AS keyword
name += ' AS ' + proj['name'] name += ' AS ' + proj['name']
if not proj_expr.is_special: if not proj_expr.is_special:
var_table[proj['name']] = len(col_exprs) var_table[proj['name']] = len(col_exprs)
disp_name = get_leagl_name(name) disp_name = get_legal_name(name)
elif type(proj) is str: elif type(proj) is str:
col = self.datasource.get_col(proj) col = self.datasource.get_col(proj)
this_type = col.type this_type = col.type
name = col.name # name = col.name
self.datasource.rec = None self.datasource.rec = None
# TODO: Type deduction in Python # TODO: Type deduction in Python
cols.append(ColRef(this_type, self.out_table, None, disp_name, i, compound=compound)) cols.append(ColRef(this_type, self.out_table, None, disp_name, i, compound=compound))
@ -133,13 +135,17 @@ class projection(ast_node):
if col not in var_table: if col not in var_table:
var_table[col] = i + _base_offset var_table[col] = i + _base_offset
def finialize(astnode:ast_node): def finialize(astnode:ast_node):
if(astnode is not None): if(astnode is not None):
self.add(astnode.sql) self.add(astnode.sql)
self.add('FROM') self.add('FROM')
finialize(self.datasource) finialize(self.datasource)
finialize(self.where) finialize(self.where)
finialize(self.group_node) if 'groupby' in node:
self.group_node = groupby(self, node['groupby'])
else:
self.group_node = None
if 'orderby' in node: if 'orderby' in node:
self.add(orderby(self, node['orderby']).sql) self.add(orderby(self, node['orderby']).sql)
if 'outfile' in node: if 'outfile' in node:
@ -149,6 +155,8 @@ class projection(ast_node):
else: else:
# TODO: subquery, name create tmp-table from subquery w/ alias as name # TODO: subquery, name create tmp-table from subquery w/ alias as name
pass pass
# cpp module codegen # cpp module codegen
self.context.has_dll = True self.context.has_dll = True
# extract typed-columns from result-set # extract typed-columns from result-set
@ -159,44 +167,59 @@ class projection(ast_node):
self.context.emitc(f'auto {length_name} = server->cnt;') self.context.emitc(f'auto {length_name} = server->cnt;')
for v, idx in var_table.items(): for v, idx in var_table.items():
vname = get_leagl_name(v) + '_' + base62uuid(3) vname = get_legal_name(v) + '_' + base62uuid(3)
pyname2cname[v] = vname pyname2cname[v] = vname
self.context.emitc(f'auto {vname} = ColRef<{typenames[idx].cname}>({length_name}, server->getCol({idx}));') self.context.emitc(f'auto {vname} = ColRef<{typenames[idx].cname}>({length_name}, server->getCol({idx}));')
vid2cname[idx] = vname vid2cname[idx] = vname
# Create table into context # Create table into context
outtable_name = 'out_' + base62uuid(6) outtable_name = 'out_' + base62uuid(6)
out_typenames = [None] * len(proj_map) out_typenames = [None] * len(proj_map)
for key, val in proj_map.items(): for key, val in proj_map.items():
if type(val[1]) is str: if type(val[1]) is str:
x = True x = True
y = lambda t: pyname2cname[t] y = lambda t: pyname2cname[t]
val[1] = eval('f\'' + val[1] + '\'') val[1] = val[2].eval(x, y, gettype=True)
if callable(val[1]):
val[1] = val[1](True)
decltypestring = val[1]
if val[0] == LazyT: if val[0] == LazyT:
out_typenames[key] = f'value_type<decays<decltype({val[1]})>>' out_typenames[key] = f'value_type<decays<decltype({decltypestring})>>'
else: else:
out_typenames[key] = val[0].cname out_typenames[key] = val[0].cname
# out_typenames = [v[0].cname for v in proj_map.values()] # out_typenames = [v[0].cname for v in proj_map.values()]
self.context.emitc(f'auto {outtable_name} = new TableInfo<{",".join(out_typenames)}>("{outtable_name}");') self.context.emitc(f'auto {outtable_name} = new TableInfo<{",".join(out_typenames)}>("{outtable_name}");')
# TODO: Inject custom group by code here and flag them in proj_map
for key, val in proj_map.items(): # Type of UDFs? Complex UDFs, ones with static vars?
if type(val[1]) is int: if self.group_node is not None:
self.context.emitc(f'{outtable_name}->get_col<{key}>().initfrom({vid2cname[val[1]]});') gb_vartable : Dict[str, Union[str, int]] = deepcopy(pyname2cname)
else: gb_cexprs : List[str] = []
# for funcs evaluate f_i(x, ...)
self.context.emitc(f'{outtable_name}->get_col<{key}>() = {val[1]};') for key, val in proj_map.items():
col_name = 'col_' + base62uuid(6)
self.context.emitc(f'auto {col_name} = {outtable_name}->get_col<{key}>();')
gb_cexprs.append((col_name, val[2]))
self.group_node.finalize(gb_cexprs, gb_vartable)
else:
for key, val in proj_map.items():
if type(val[1]) is int:
self.context.emitc(f'{outtable_name}->get_col<{key}>().initfrom({vid2cname[val[1]]});')
else:
# for funcs evaluate f_i(x, ...)
self.context.emitc(f'{outtable_name}->get_col<{key}>() = {val[1]};')
# print out col_is # print out col_is
self.context.emitc(f'print(*{outtable_name});') self.context.emitc(f'print(*{outtable_name});')
class orderby(ast_node): class orderby(ast_node):
name = 'order by' name = 'order by'
def produce(self, node): def produce(self, node):
if node is None: if node is None:
self.sql = '' self.sql = ''
return return
elif type(node) is not list:
node = [node]
node = enlist(node)
o_list = [] o_list = []
for o in node: for o in node:
@ -206,11 +229,172 @@ class orderby(ast_node):
o_list.append(o_str) o_list.append(o_str)
self.add(', '.join(o_list)) self.add(', '.join(o_list))
class scan(ast_node):
name = 'scan'
def __init__(self, parent: "ast_node", node, loop_style = 'for', context: Context = None, const = False):
self.const = "const " if const else ""
self.loop_style = loop_style
super().__init__(parent, node, context)
def init(self, _):
self.datasource = self.context.datasource
self.initializers = ''
self.start = ''
self.front = ''
self.body = ''
self.end = '}'
scan_vars = set(s.it_var for s in self.context.scans)
self.it_ver = 'i' + base62uuid(2)
while(self.it_ver in scan_vars):
self.it_ver = 'i' + base62uuid(6)
self.parent.context.scans.append(self)
def produce(self, node):
if self.loop_style == 'for_each':
self.colref = node
self.start += f'for ({self.const}auto& {self.it_ver} : {node.cobj}) {{\n'
else:
self.start += f"for (uint32_t {self.it_ver} = 0; {self.it_ver} < {node}; ++{self.it_ver}){{\n"
def add(self, stmt, position = "body"):
if position == "body":
self.body += stmt + '\n'
elif position == "init":
self.initializers += stmt + '\n'
else:
self.front += stmt + '\n'
class groupby(orderby): def finalize(self):
name = 'group by' self.context.remove_scan(self, self.initializers + self.start + self.front + self.body + self.end)
class groupby_c(ast_node):
name = '_groupby'
def produce(self, node : List[Tuple[expr, Set[ColRef]]]):
self.context.headers.add('"./server/hasher.h"')
self.context.headers.add('unordered_map')
self.group = 'g' + base62uuid(7)
self.group_type = 'record_type' + base62uuid(7)
self.datasource = self.parent.datasource
self.scanner = None
self.datasource.rec = set()
g_contents = ''
g_contents_list = []
first_col = ''
for g in node:
e = g[0]
g_str = e.eval(c_code = True)
# if v is compound expr, create tmp cols
if e.is_ColExpr:
tmpcol = 't' + base62uuid(7)
self.emit(f'auto {tmpcol} = {g_str};')
e = tmpcol
g_contents_list.append(e)
first_col = g_contents_list[0]
g_contents_decltype = [f'decays<decltype({c})>' for c in g_contents_list]
g_contents = ','.join(g_contents_list)
self.emit(f'typedef record<{",".join(g_contents_decltype)}> {self.group_type};')
self.emit(f'unordered_map<{self.group_type}, vector_type<uint32_t>, '
f'transTypes<{self.group_type}, hasher>> {self.group};')
self.n_grps = len(node)
self.scanner = scan(self, first_col + '.size')
self.scanner.add(f'{self.group}[forward_as_tuple({g_contents}[{self.scanner.it_ver}])].emplace_back({self.scanner.it_ver});')
def consume(self, _):
self.scanner.finalize()
# def deal_with_assumptions(self, assumption:assumption, out:TableInfo):
# gscanner = scan(self, self.group)
# val_var = 'val_'+base62uuid(7)
# gscanner.add(f'auto &{val_var} = {gscanner.it_ver}.second;')
# gscanner.add(f'{self.datasource.cxt_name}->order_by<{assumption.result()}>(&{val_var});')
# gscanner.finalize()
def finalize(self, cexprs : List[Tuple[str, expr]], var_table : Dict[str, Union[str, int]]):
gscanner = scan(self, self.group)
key_var = 'key_'+base62uuid(7)
val_var = 'val_'+base62uuid(7)
gscanner.add(f'auto &{key_var} = {gscanner.it_ver}.first;')
gscanner.add(f'auto &{val_var} = {gscanner.it_ver}.second;')
len_var = None
def define_len_var():
nonlocal len_var
if len_var is None:
len_var = 'len_'+base62uuid(7)
gscanner.add(f'auto &{len_var} = {val_var}.size;', position = 'front')
def get_var_names (varname : str):
var = var_table[varname]
if type(var) is str:
return f'{var}[{val_var}]'
else:
return f'get<{var}>({key_var})'
for ce in cexprs:
ex = ce[1]
materialize_builtin = {}
if type(ex.udf) is udf:
if '_builtin_len' in ex.udf.builtin_used:
define_len_var()
materialize_builtin['_builtin_len'] = len_var
if '_builtin_ret' in ex.udf.builtin_used:
define_len_var()
gscanner.add(f'{ce[0]}.emplace_back({{{len_var}}});\n')
materialize_builtin['_builtin_ret'] = f'{ce[0]}.back()'
gscanner.add(f'{ex.eval(c_code = True, y=get_var_names, materialize_builtin = materialize_builtin)};\n')
continue
gscanner.add(f'{ce[0]}.emplace_back({ex.eval(c_code = True, y=get_var_names, materialize_builtin = materialize_builtin)});\n')
gscanner.finalize()
self.datasource.groupinfo = None
class groupby(ast_node):
name = 'group by'
@property
def use_sp_gb (self):
return len(self.sp_refs) > 0
def produce(self, node):
if type(self.parent) is not projection:
raise ValueError('groupby can only be used in projection')
sp_refs = self.parent.sp_refs
node = enlist(node)
o_list = []
self.dedicated_glist = []
self.refs : Set[ColRef] = set()
self.sp_refs : Set[ColRef] = set()
for g in node:
self.datasource.rec = set()
g_expr = expr(self, g['value'])
refs : Set[ColRef] = self.datasource.rec
self.datasource.rec = None
this_sp_ref = refs.difference(sp_refs)
this_ref = refs.intersection(this_sp_ref)
# TODO: simplify this
self.refs = self.refs.union(this_ref)
self.sp_refs = self.sp_refs.union(this_sp_ref)
self.dedicated_glist.append((g_expr, refs))
g_str = g_expr.eval(c_code = False)
if 'sort' in g and f'{g["sort"]}'.lower() == 'desc':
g_str = g_str + ' ' + 'DESC'
o_list.append(g_str)
if not self.use_sp_gb:
self.dedicated_gb = None
self.add(', '.join(o_list))
def finalize(self, cexprs : List[Tuple[str, expr]], var_table : Dict[str, Union[str, int]]):
if self.use_sp_gb:
self.dedicated_gb = groupby_c(self.parent, self.dedicated_glist)
self.dedicated_gb.finalize(cexprs, var_table)
class join(ast_node): class join(ast_node):
name = 'join' name = 'join'
def init(self, _): def init(self, _):
@ -233,7 +417,7 @@ class join(ast_node):
self.tables_dir[tbls.table_name] = tbls self.tables_dir[tbls.table_name] = tbls
for a in tbls.alias: for a in tbls.alias:
self.tables_dir[a] = tbls self.tables_dir[a] = tbls
elif type(tbls) is projection: elif type(tbls) is projection:
self.joins.append(alias(tbls.finalize())) self.joins.append(alias(tbls.finalize()))
@ -257,7 +441,6 @@ class join(ast_node):
tbl = self.context.tables_byname[table_name] tbl = self.context.tables_byname[table_name]
if 'name' in node: if 'name' in node:
tbl.add_alias(node['name']) tbl.add_alias(node['name'])
self.append(tbl, alias) self.append(tbl, alias)
else: else:
keys = node.keys() keys = node.keys()
@ -271,7 +454,10 @@ class join(ast_node):
self.tables_dir = {**self.tables_dir, **j.tables_dir} self.tables_dir = {**self.tables_dir, **j.tables_dir}
elif type(node) is str: elif type(node) is str:
self.append(self.context.tables_byname[node]) if node in self.context.tables_byname:
self.append(self.context.tables_byname[node])
else:
print(f'Error: table {node} not found.')
def get_cols(self, colExpr: str) -> ColRef: def get_cols(self, colExpr: str) -> ColRef:
for t in self.tables: for t in self.tables:
@ -324,9 +510,7 @@ class create_table(ast_node):
self.sql += ')' self.sql += ')'
if self.context.use_columnstore: if self.context.use_columnstore:
self.sql += ' engine=ColumnStore' self.sql += ' engine=ColumnStore'
class insert(ast_node): class insert(ast_node):
name = 'insert' name = 'insert'
first_order = name first_order = name
@ -405,56 +589,261 @@ class outfile(ast_node):
class udf(ast_node): class udf(ast_node):
name = 'udf' name = 'udf'
first_order = name first_order = name
@dataclass
class builtin_var:
enabled : bool = False
_type : Types = AnyT
all = ('_builtin_len', '_builtin_ret')
def decltypecall(self, c_code = False, *args):
from engine.types import fn_behavior
class dummy:
def __init__(self, name):
self.cname = name + '_gettype'
self.sqlname = self.cname
return fn_behavior(dummy(self.cname), c_code, *args)
def __call__(self, c_code = False, *args): def __call__(self, c_code = False, *args):
from engine.types import fn_behavior from engine.types import fn_behavior
return fn_behavior(self, c_code, *args) builtin_args = [f'{{{n}()}}' for n, v in self.builtin.items() if v.enabled]
return fn_behavior(self, c_code, *args, *builtin_args)
def return_type(self, *_ : Types): def return_type(self, *_ : Types):
return LazyT return LazyT
def init(self, node):
def init(self, _):
self.builtin : Dict[str, udf.builtin_var] = {
'_builtin_len' : udf.builtin_var(False, UIntT),
'_builtin_ret' : udf.builtin_var(False, Types(
255, name = 'generic_ref', cname = 'auto&'
))
}
self.var_table = {} self.var_table = {}
self.args = [] self.args = []
if self.context.udf is None: if self.context.udf is None:
self.context.udf = Context.udf_head self.context.udf = Context.udf_head
self.context.headers.add('\"./udf.hpp\"') self.context.headers.add('\"./udf.hpp\"')
self.vecs = set()
self.code_list = []
self.builtin_used = None
def add(self, *code):
ccode = ''
for c in code:
if type(c) is str:
ccode += c
else:
self.code_list.append(ccode)
self.code_list.append(c)
ccode = ''
if ccode:
self.code_list.append(ccode)
def produce(self, node): def produce(self, node):
from engine.utils import get_leagl_name, check_leagl_name from engine.utils import get_legal_name, check_legal_name
node = node[self.name] node = node[self.name]
# register udf # register udf
self.cname = get_leagl_name(node['fname']) self.agg = 'Agg' in node
self.cname = get_legal_name(node['fname'])
self.sqlname = self.cname self.sqlname = self.cname
self.context.udf_map[self.cname] = self self.context.udf_map[self.cname] = self
self.ccode = f'auto {self.cname} = [](' if self.agg:
self.context.udf_agg_map[self.cname] = self
self.add(f'auto {self.cname} = [](')
def get_block(self, ind, node):
if 'stmt' in node:
old_ind = ind
ind += '\t'
next_stmt = enlist(node['stmt'])
if len(next_stmt) > 1:
self.add(f' {{\n')
self.get_stmt(ind ,next_stmt)
self.add(f'{old_ind}}}\n')
else:
self.get_stmt(ind, next_stmt)
def get_cname(self, x:str):
return self.var_table[x]
def get_assignment(self, ind, node, *, types = 'auto', sep = ';\n'):
var_ex = expr(self, node['var'], c_code=True, supress_undefined = True)
ex = expr(self, node['expr'], c_code=True)
var = var_ex.eval(y=self.get_cname)
if var in self.var_table or hasattr(var_ex, 'builtin_var'):
op = '='
if 'op' in node and node['op'] != ':=':
op = node['op']
e = ex.eval(y=self.get_cname)
def assign_behavior(decltypestr = False):
nonlocal ind, var, op, e, sep
v = var(decltypestr) if callable(var) else var
_e = e(decltypestr) if callable(e) else e
if v == '_builtin_ret':
return f'{ind}return {_e}{sep}'
elif '_builtin_ret' not in _e:
return f'{ind}{v} {op} {_e}{sep}'
else:
return ''
self.add(assign_behavior)
else:
cvar = get_legal_name(var)
self.var_table[var] = cvar
self.add(f'{ind}{types} {cvar} = ', ex.eval(y=self.get_cname), sep)
def get_stmt(self, ind, node):
node = enlist(node)
for n in node:
if 'if' in n:
_ifnode = n['if']
self.add(f'{ind}if(', expr(self, _ifnode["cond"]).eval(y=self.get_cname), ')')
if 'stmt' in _ifnode:
self.get_block(ind, _ifnode)
else:
self.add('\n')
self.get_stmt(ind + '\t', _ifnode)
if 'elif' in _ifnode:
for e in n['elif']:
self.add(f'{ind}else if(', expr(self, e["cond"]).eval(y=self.get_cname), ')')
self.get_block(ind, e)
if 'else' in _ifnode:
self.add(f'{ind}else ')
self.get_block(ind, _ifnode['else'])
elif 'for' in n:
_fornode = n['for']
defs = _fornode['defs']
self.add(f'{ind}for({"auto " if len(enlist(defs["op"])) != 0 else ";"}')
def get_inline_assignments(node, end = '; '):
var = enlist(node['var'])
op = enlist(node['op'])
expr = enlist(node['expr'])
len_node = len(enlist(op))
for i, (v, o, e) in enumerate(zip(var, op, expr)):
self.get_assignment('', {'var' : v, 'op' : o, 'expr' : e}, types = '', sep = ', ' if i != len_node - 1 else end)
get_inline_assignments(defs)
self.add(expr(self, _fornode["cond"]).eval(y=self.get_cname), '; ')
get_inline_assignments(_fornode['tail'], ') ')
if 'stmt' in _fornode:
self.get_block(ind, _fornode)
else:
self.add('\n')
self.get_stmt(ind + '\t', _fornode)
elif 'assignment' in n:
assign = n['assignment']
self.get_assignment(ind, assign)
def consume(self, node): def consume(self, node):
from engine.utils import get_leagl_name, check_leagl_name from engine.utils import get_legal_name, check_legal_name
node = node[self.name] node = node[self.name]
if 'params' in node: if 'params' in node:
for args in node['params']: for args in node['params']:
cname = get_leagl_name(args) cname = get_legal_name(args)
self.var_table[args] = cname self.var_table[args] = cname
self.args.append(cname) self.args.append(cname)
self.ccode += ', '.join([f'auto {a}' for a in self.args]) + ') {\n' front = [*self.code_list, ', '.join([f'auto {a}' for a in self.args])]
self.code_list = []
if 'assignment' in node:
for assign in node['assignment']: self.with_storage = False
var = assign['var'] self.with_statics = False
ex = expr(self, assign['expr'], c_code=True) self.static_decl : Optional[List[str]] = None
if var in self.var_table: ind = '\t'
self.ccode += f'\t{var} = {ex.eval()};\n' if 'static_decl' in node:
else: self.add(') {\n')
cvar = get_leagl_name(var) curr = node['static_decl']
self.var_table[var] = cvar self.with_statics = True
self.ccode += f'\tauto {cvar} = {ex.eval()};\n' if 'var' in curr and 'expr' in curr:
if len(curr['var']) != len(curr['expr']):
print("Error: every static variable must be initialized.")
self.static_decl = []
for v, e in zip(curr['var'], curr['expr']):
cname = get_legal_name(v)
self.var_table[v] = cname
self.static_decl.append(f'{cname} = ', expr(self, e, c_code=True).eval(self.get_cname))
self.add(f'{ind}static auto {"; static auto ".join(self.static_decl)};\n')
self.add(f'{ind}auto reset = [=]() {{ {"; ".join(self.static_decl)}; }};\n')
self.add(f'{ind}auto call = []({", ".join([f"decltype({a}) {a}" for a in self.args])}')
ind = '\t\t'
front = [*front, *self.code_list]
self.code_list = []
if 'stmt' in node:
self.get_stmt(ind, node['stmt'])
# first scan to determine vec types
# if self.agg:
# for assign in node['assignment']:
# var = fastscan(assign['var'])
# ex = fastscan(assign['expr'])
# self.vecs.union(var.vec_vars)
# self.vecs.union(var.requested_lens)
# self.vecs.union(ex.vec_vars)
# self.vecs.union(ex.requested_lens)
# if len(self.vecs) != 0:
# self.idx_var = 'idx_' + base62uuid(5)
# self.ccode += f'{ind}auto {self.idx_var} = 0;\n'
ret = node['ret'] ret = node['ret']
self.ccode += f'\treturn {expr(self, ret, c_code=True).eval()};' def return_call(decltypestr = False):
self.ccode += '\n};\n' if (decltypestr):
print(self.ccode) return ''
ret = ''
for r in self.return_call:
if callable(r):
ret += r(False)
else:
ret += r
return ret
self.return_call = (f'{ind}return ', expr(self, ret, c_code=True).eval(self.get_cname), ';\n')
self.add(return_call)
if self.with_statics:
self.add('\t};\n')
self.add('\treturn std::make_pair(reset, call);\n')
self.add('};\n')
self.context.udf += self.ccode + '\n' #print(self.ccode)
self.builtin_args = [(name, var._type.cname) for name, var in self.builtin.items() if var.enabled]
# self.context.udf += front + builtin_argstr + self.ccode + '\n'
self.finalize(front)
def finalize(self, front):
builtin_argstr = ', ' if len(self.builtin_args) and len(self.args) else ''
builtin_argstr += ', '.join([f'{t} {n}' for (n, t) in self.builtin_args])
self.builtin_used = [b for b, v in self.builtin.items() if v.enabled]
ccode = ''
def process_recursion(l, decltypestr = False):
nonlocal ccode
for c in l:
if type(c) is str:
ccode += c
elif callable(c):
ccode += c(decltypestr) # a callback function
else:
raise ValueError(f'Illegal operation in udf code generation: {c}')
process_recursion(front)
ccode += builtin_argstr + ') {\n'
process_recursion(self.code_list)
self.context.udf += ccode + '\n'
ccode = ''
if self.return_pattern == udf.ReturnPattern.elemental_return:
ccode += f'auto {self.cname}_gettype = []('
process_recursion(front[1:], True)
ccode += ') {\n\tuint32_t _builtin_len = 0;\n'
process_recursion(self.code_list, True)
self.context.udf += ccode + '\n'
class ReturnPattern(Enum):
bulk_return = auto()
elemental_return = auto()
@property
def return_pattern(self):
if '_builtin_ret' in self.builtin_used:
return udf.ReturnPattern.elemental_return
else:
return udf.ReturnPattern.bulk_return
def include(objs): def include(objs):
import inspect import inspect
for _, cls in inspect.getmembers(objs): for _, cls in inspect.getmembers(objs):

@ -1,26 +1,59 @@
from typing import Optional
from reconstruct.ast import ast_node from reconstruct.ast import ast_node
from reconstruct.storage import ColRef from reconstruct.storage import ColRef, Context
from engine.types import * from engine.types import *
# TODO: Decouple expr and upgrade architecture
# C_CODE : get ccode/sql code?
# projections : C/SQL/decltype string
# orderby/joins/where : SQL only
# assumption/groupby : C/sql
# is_udfexpr: C only
class expr(ast_node): class expr(ast_node):
name='expr' name='expr'
@property
def __init__(self, parent, node, *, c_code = None): def udf_decltypecall(self):
from reconstruct.ast import projection return self._udf_decltypecall if self._udf_decltypecall else self.sql
@udf_decltypecall.setter
def udf_decltypecall(self, val):
self._udf_decltypecall = val
@property
def need_decltypestr(self):
return self._udf_decltypecall is not None
def __init__(self, parent, node, *, c_code = None, supress_undefined = False):
from reconstruct.ast import projection, udf
self.type = None self.type = None
self.raw_col = None self.raw_col = None
self.udf : Optional[udf] = None
self.inside_agg = False self.inside_agg = False
self.is_special = False self.is_special = False
self.is_ColExpr = False
self.is_recursive_call_inudf = False
self.codlets : list = []
self.codebuf : Optional[str] = None
self._udf_decltypecall = None
self.supress_undefined = supress_undefined
if(type(parent) is expr): if(type(parent) is expr):
self.inside_agg = parent.inside_agg self.inside_agg = parent.inside_agg
if(type(parent) is not expr): self.is_udfexpr = parent.is_udfexpr
self.root = self self.root : expr = parent.root
self.c_code = type(parent) is projection
else:
self.root = parent.root
self.c_code = parent.c_code self.c_code = parent.c_code
self.builtin_vars = parent.builtin_vars
else:
self.is_udfexpr = type(parent) is udf
self.root : expr = self
self.c_code = self.is_udfexpr or type(parent) is projection
if self.is_udfexpr:
self.udf : udf = parent
self.builtin_vars = self.udf.builtin.keys()
else:
self.builtin_vars = []
if type(c_code) is bool: if type(c_code) is bool:
self.c_code = c_code self.c_code = c_code
@ -38,8 +71,11 @@ class expr(ast_node):
self.udf_map = parent.context.udf_map self.udf_map = parent.context.udf_map
self.func_maps = {**builtin_func, **self.udf_map} self.func_maps = {**builtin_func, **self.udf_map}
self.operators = {**builtin_operators, **self.udf_map} self.operators = {**builtin_operators, **self.udf_map}
def produce(self, node): def produce(self, node):
from engine.utils import enlist from engine.utils import enlist
from reconstruct.ast import udf
if type(node) is dict: if type(node) is dict:
for key, val in node.items(): for key, val in node.items():
if key in self.operators: if key in self.operators:
@ -49,35 +85,114 @@ class expr(ast_node):
exp_vals = [expr(self, v, c_code = self.c_code) for v in val] exp_vals = [expr(self, v, c_code = self.c_code) for v in val]
str_vals = [e.sql for e in exp_vals] str_vals = [e.sql for e in exp_vals]
type_vals = [e.type for e in exp_vals] type_vals = [e.type for e in exp_vals]
try:
self.type = op.return_type(*type_vals) self.type = op.return_type(*type_vals)
except AttributeError as e:
if type(self.root) is not udf:
print(f'alert: {e}')
self.type = AnyT
self.sql = op(self.c_code, *str_vals) self.sql = op(self.c_code, *str_vals)
special_func = [*self.context.udf_map.keys(), "maxs", "mins", "avgs", "sums"] special_func = [*self.context.udf_map.keys(), "maxs", "mins", "avgs", "sums"]
if key in special_func and not self.is_special: if key in special_func and not self.is_special:
self.is_special = True self.is_special = True
if key in self.context.udf_map:
self.root.udf = self.context.udf_map[key]
if key == self.root.udf.name:
self.root.is_recursive_call_inudf = True
p = self.parent p = self.parent
while type(p) is expr and not p.is_special: while type(p) is expr and not p.is_special:
p.is_special = True p.is_special = True
p = p.parent p = p.parent
need_decltypestr = any([e.need_decltypestr for e in exp_vals])
if need_decltypestr or (self.udf and type(op) is udf):
decltypestr_vals = [e.udf_decltypecall for e in exp_vals]
self.udf_decltypecall = op(self.c_code, *decltypestr_vals)
if self.udf and type(op) is udf:
self.udf_decltypecall = op.decltypecall(self.c_code, *decltypestr_vals)
elif self.is_udfexpr:
var_table = self.root.udf.var_table
vec = key.split('.')
_vars = [*var_table, *self.builtin_vars]
def get_vname (node):
if node in self.builtin_vars:
self.root.udf.builtin[node].enabled = True
self.builtin_var = node
return node
else:
return var_table[node]
if vec[0] not in _vars:
print(f'Use of undefined variable {vec[0]}')
else:
vname = get_vname(vec[0])
val = enlist(val)
if(len(val) > 2):
print('Warning: more than 2 indexes found for subvec operator.')
ex = [expr(self, v, c_code = self.c_code) for v in val]
idxs = ', '.join([e.sql for e in ex])
self.sql = f'{vname}.subvec({idxs})'
if any([e.need_decltypestr for e in ex]):
self.udf_decltypecall = f'{vname}.subvec({[", ".join([e.udf_decltypecall for e in ex])]})'
if key == 'get' and len(val) > 1:
ex_vname = expr(self, val[0], c_code=self.c_code)
self.sql = f'{ex_vname.sql}[{expr(self, val[1], c_code=self.c_code).sql}]'
if hasattr(ex_vname, 'builtin_var'):
if not hasattr(self, 'builtin_var'):
self.builtin_var = []
self.builtin_var = [*self.builtin_var, *ex_vname.builtin_var]
self.udf_decltypecall = ex_vname.sql
else: else:
print(f'Undefined expr: {key}{val}') print(f'Undefined expr: {key}{val}')
elif type(node) is str: elif type(node) is str:
p = self.parent if self.is_udfexpr:
while type(p) is expr and not p.isvector: curr_udf : udf = self.root.udf
p.isvector = True var_table = curr_udf.var_table
p = p.parent split = node.split('.')
if self.datasource is not None: if split[0] in var_table:
self.raw_col = self.datasource.parse_col_names(node) varname = var_table[split[0]]
self.raw_col = self.raw_col if type(self.raw_col) is ColRef else None if curr_udf.agg and varname in curr_udf.vecs:
if self.raw_col is not None: if len(split) > 1:
self.sql = self.raw_col.name if split[1] == 'vec':
self.type = self.raw_col.type self.sql += varname
elif split[1] == 'len':
self.sql += f'{varname}.size'
else:
print(f'no member {split[1]} in object {varname}')
else:
self.sql += f'{varname}[{curr_udf.idx_var}]'
else:
self.sql += varname
elif self.supress_undefined or split[0] in self.builtin_vars:
self.sql += node
if split[0] in self.builtin_vars:
curr_udf.builtin[split[0]].enabled = True
self.builtin_var = split[0]
else:
print(f'Undefined varname: {split[0]}')
# get the column from the datasource in SQL context
else: else:
self.sql = node p = self.parent
self.type = StrT while type(p) is expr and not p.isvector:
if self.c_code and self.datasource is not None: p.isvector = True
self.sql = f'{{y(\"{self.sql}\")}}' p = p.parent
if self.datasource is not None:
self.raw_col = self.datasource.parse_col_names(node)
self.raw_col = self.raw_col if type(self.raw_col) is ColRef else None
if self.raw_col is not None:
self.is_ColExpr = True
self.sql = self.raw_col.name
self.type = self.raw_col.type
else:
self.sql = node
self.type = StrT
if self.c_code and self.datasource is not None:
self.sql = f'{{y(\"{self.sql}\")}}'
elif type(node) is bool: elif type(node) is bool:
self.type = IntT self.type = IntT
if self.c_code: if self.c_code:
@ -91,18 +206,109 @@ class expr(ast_node):
elif type(node) is float: elif type(node) is float:
self.type = DoubleT self.type = DoubleT
def finalize(self, y): def finalize(self, override = False):
if self.c_code: from reconstruct.ast import udf
x = self.is_special if self.codebuf is None or override:
self.sql = eval('f\'' + self.sql + '\'') self.codebuf = ''
for c in self.codlets:
if type(c) is str:
self.codebuf += c
elif type(c) is udf:
self.codebuf += c()
elif type(c) is expr:
self.codebuf += c.finalize(override=override)
return self.codebuf
def __str__(self): def __str__(self):
return self.sql return self.sql
def __repr__(self): def __repr__(self):
return self.__str__() return self.__str__()
def eval(self):
x = self.c_code # builtins is readonly, so it's okay to set default value as an object
y = lambda x: x # eval is only called at root expr.
return eval('f\'' + self.sql + '\'') def eval(self, c_code = None, y = lambda t: t, materialize_builtin = False, _decltypestr = False, *, gettype = False):
assert(self.is_root)
def call(decltypestr = False) -> str:
nonlocal c_code, y, materialize_builtin
if self.udf is not None:
loc = locals()
builtin_vars = self.udf.builtin_used
for b in self.udf.builtin_var.all:
exec(f'loc["{b}"] = lambda: "{{{b}()}}"')
if builtin_vars:
if type(materialize_builtin) is dict:
for b in builtin_vars:
exec(f'loc["{b}"] = lambda: "{materialize_builtin[b]}"')
elif self.is_recursive_call_inudf:
for b in builtin_vars:
exec(f'loc["{b}"] = lambda : "{b}"')
x = self.c_code if c_code is None else c_code
if decltypestr:
return eval('f\'' + self.udf_decltypecall + '\'')
return eval('f\'' + self.sql + '\'')
if self.is_recursive_call_inudf or (self.need_decltypestr and self.is_udfexpr) or gettype:
return call
else:
return call(_decltypestr)
@property
def is_root(self):
return self.root == self
# For UDFs: first check if agg variable is used as vector
# if not, then check if its length is used
class fastscan(expr):
name = 'fastscan'
def init(self, _):
self.vec_vars = set()
self.requested_lens = set()
super().init(self, _)
def process(self, key : str):
segs = key.split('.')
var_table = self.root.udf.var_table
if segs[0] in var_table and len(segs) > 1:
if segs[1] == 'vec':
self.vec_vars.add(segs[0])
elif segs[1] == 'len':
self.requested_lens.add(segs[0])
def produce(self, node):
from engine.utils import enlist
if type(node) is dict:
for key, val in node.items():
if key in self.operators:
val = enlist(val)
elif self.is_udfexpr:
self.process(key)
[fastscan(self, v, c_code = self.c_code) for v in val]
elif type(node) is str:
self.process(node)
import engine.expr as cexpr
class getrefs(expr):
name = 'getrefs'
def init(self, _):
self.datasource.rec = set()
self.rec = None
def produce(self, node):
from engine.utils import enlist
if type(node) is dict:
for key, val in node.items():
if key in self.operators:
val = enlist(val)
[getrefs(self, v, c_code = self.c_code) for v in val]
elif type(node) is str:
self.datasource.parse_col_names(node)
def consume(self, _):
if self.root == self:
self.rec = self.datasource.rec
self.datasource.rec = None

@ -86,6 +86,7 @@ class Context:
self.sql = '' self.sql = ''
self.finalized = False self.finalized = False
self.udf = None self.udf = None
self.scans = []
def __init__(self): def __init__(self):
self.tables_byname = dict() self.tables_byname = dict()
@ -94,6 +95,7 @@ class Context:
self.cols = [] self.cols = []
self.datasource = None self.datasource = None
self.udf_map = dict() self.udf_map = dict()
self.udf_agg_map = dict()
self.use_columnstore = False self.use_columnstore = False
self.print = print self.print = print
self.has_dll = False self.has_dll = False
@ -110,7 +112,10 @@ class Context:
tbl = TableInfo(table_name, cols, self) tbl = TableInfo(table_name, cols, self)
self.tables.append(tbl) self.tables.append(tbl)
return tbl return tbl
def remove_scan(self, scan, str_scan):
self.emitc(str_scan)
self.scans.remove(scan)
function_head = ''' function_head = '''
extern "C" int __DLLEXPORT__ dllmain(Context* cxt) { extern "C" int __DLLEXPORT__ dllmain(Context* cxt) {
using namespace std; using namespace std;

@ -2,4 +2,5 @@ mo-future
mo-dots==8.20.21357 mo-dots==8.20.21357
mo-parsing mo-parsing
mo-imports mo-imports
readline; sys_platform != 'win32' readline; sys_platform != 'win32'
numpy

@ -0,0 +1,12 @@
#include "../server/libaquery.h"
extern void* Aalloc(size_t sz);
extern int Afree(void * mem);
template <typename T>
size_t register_memory(T* ptr){
[](void* m){ auto _m = static_cast<T*>(m); delete _m; };
}
#define EXPORT __DLLEXPORT__

@ -0,0 +1,5 @@
#include "aquery.h"
#include <memory>
#include <stdlib>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -1,2 +0,0 @@
#TargetFrameworkVersion=:PlatformToolSet=v141:EnableManagedIncrementalBuild=false:VCToolArchitecture=Native32Bit:WindowsTargetPlatformVersion=10.0.19041.0
Release|Win32|d:\gg\AQuery++\server\|

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -14,11 +14,26 @@ const char* monetdbe_type_str[] = {
// should be last: // should be last:
"monetdbe_type_unknown" "monetdbe_type_unknown"
} ; } ;
const unsigned char monetdbe_type_szs[] = {
sizeof(monetdbe_column_bool::null_value), sizeof(monetdbe_column_int8_t::null_value),
sizeof(monetdbe_column_int16_t::null_value), sizeof(monetdbe_column_int32_t::null_value),
sizeof(monetdbe_column_int64_t::null_value),
#ifdef HAVE_HGE
sizeof(monetdbe_column_int128_t::null_value),
#endif
sizeof(monetdbe_column_size_t::null_value), sizeof(monetdbe_column_float::null_value),
sizeof(monetdbe_column_double::null_value),
sizeof(monetdbe_column_str::null_value), sizeof(monetdbe_column_blob::null_value),
sizeof(monetdbe_data_date), sizeof(monetdbe_data_time), sizeof(monetdbe_data_timestamp),
// should be last:
1
};
Server::Server(Context* cxt){ Server::Server(Context* cxt){
if (cxt){ if (cxt){
connect(cxt); connect(cxt);
} }
} }
void Server::connect(Context *cxt){ void Server::connect(Context *cxt){

@ -1,4 +1,8 @@
#include "monetdbe.h" #ifdef _WIN32
#include "monetdbe.h"
#else
#include "monetdb/monetdbe.h"
#endif
struct Context; struct Context;

@ -111,49 +111,50 @@ int dll_main(int argc, char** argv, Context* cxt){
return 0; return 0;
} }
//
extern "C" int __DLLEXPORT__ main(int argc, char** argv) { //extern "C" int __DLLEXPORT__ main(int argc, char** argv) {
puts("running"); //
Context* cxt = new Context(); // puts("running");
cxt->log("%d %s\n", argc, argv[1]); // Context* cxt = new Context();
// cxt->log("%d %s\n", argc, argv[1]);
const char* shmname; //
if (argc < 0) // const char* shmname;
return dll_main(argc, argv, cxt); // if (argc < 0)
else if (argc <= 1) // return dll_main(argc, argv, cxt);
return test_main(); // else if (argc <= 1)
else // return test_main();
shmname = argv[1]; // else
SharedMemory shm = SharedMemory(shmname); // shmname = argv[1];
if (!shm.pData) // SharedMemory shm = SharedMemory(shmname);
return 1; // if (!shm.pData)
bool &running = static_cast<bool*>(shm.pData)[0], // return 1;
&ready = static_cast<bool*>(shm.pData)[1]; // bool &running = static_cast<bool*>(shm.pData)[0],
using namespace std::chrono_literals; // &ready = static_cast<bool*>(shm.pData)[1];
cxt->log("running: %s\n", running? "true":"false"); // using namespace std::chrono_literals;
cxt->log("ready: %s\n", ready? "true":"false"); // cxt->log("running: %s\n", running? "true":"false");
while (running) { // cxt->log("ready: %s\n", ready? "true":"false");
std::this_thread::sleep_for(1ms); // while (running) {
if(ready){ // std::this_thread::sleep_for(1ms);
cxt->log("running: %s\n", running? "true":"false"); // if(ready){
cxt->log("ready: %s\n", ready? "true":"false"); // cxt->log("running: %s\n", running? "true":"false");
void* handle = dlopen("./dll.so", RTLD_LAZY); // cxt->log("ready: %s\n", ready? "true":"false");
cxt->log("handle: %lx\n", handle); // void* handle = dlopen("./dll.so", RTLD_LAZY);
if (handle) { // cxt->log("handle: %lx\n", handle);
cxt->log("inner\n"); // if (handle) {
code_snippet c = reinterpret_cast<code_snippet>(dlsym(handle, "dllmain")); // cxt->log("inner\n");
cxt->log("routine: %lx\n", c); // code_snippet c = reinterpret_cast<code_snippet>(dlsym(handle, "dllmain"));
if (c) { // cxt->log("routine: %lx\n", c);
cxt->log("inner\n"); // if (c) {
cxt->err("return: %d\n", c(cxt)); // cxt->log("inner\n");
} // cxt->err("return: %d\n", c(cxt));
} // }
ready = false; // }
} // ready = false;
} // }
shm.FreeMemoryMap(); // }
return 0; // shm.FreeMemoryMap();
} // return 0;
//}
#include "utils.h" #include "utils.h"
int test_main() int test_main()
{ {

@ -62,6 +62,9 @@ public:
ColRef(const char* name, types::Type_t ty) : name(name), ty(ty) {} ColRef(const char* name, types::Type_t ty) : name(name), ty(ty) {}
using vector_type<_Ty>::operator[]; using vector_type<_Ty>::operator[];
using vector_type<_Ty>::operator=; using vector_type<_Ty>::operator=;
using vector_type<_Ty>::subvec;
using vector_type<_Ty>::subvec_view;
using vector_type<_Ty>::subvec_deep;
ColView<_Ty> operator [](const vector_type<uint32_t>&idxs) const { ColView<_Ty> operator [](const vector_type<uint32_t>&idxs) const {
return ColView<_Ty>(*this, idxs); return ColView<_Ty>(*this, idxs);
} }
@ -132,6 +135,14 @@ public:
ret[i] = orig[idxs[i]]; ret[i] = orig[idxs[i]];
return ret; return ret;
} }
ColRef<_Ty> subvec_deep(uint32_t start, uint32_t end) {
uint32_t len = end - start;
ColRef<_Ty> subvec(len);
for (uint32_t i = 0; i < len; ++i)
subvec[i] = operator[](i);
return subvec;
}
inline ColRef<_Ty> subvec_deep(uint32_t start = 0) { return subvec_deep(start, size); }
}; };
template <template <class...> class VT, class T> template <template <class...> class VT, class T>
std::ostream& operator<<(std::ostream& os, const VT<T>& v) std::ostream& operator<<(std::ostream& os, const VT<T>& v)
@ -431,84 +442,84 @@ inline void TableInfo<Types...>::print(const char* __restrict sep, const char* _
} }
template <class T1, class T2, template<typename ...> class VT, template<typename ...> class VT2> template <class T1, class T2, template<typename ...> class VT, template<typename ...> class VT2>
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator -(const VT<T1>& lhs, const VT2<T2>& rhs) { decayed_t<VT, typename types::Coercion<T1, T2>::type> operator -(const VT<T1>& lhs, const VT2<T2>& rhs) {
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size, ""); auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size);
for (int i = 0; i < lhs.size; ++i) for (int i = 0; i < lhs.size; ++i)
ret[i] = lhs[i] - rhs[i]; ret[i] = lhs[i] - rhs[i];
return ret; return ret;
} }
template <class T1, class T2, template<typename ...> class VT> template <class T1, class T2, template<typename ...> class VT>
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator -(const VT<T1>& lhs, const T2& rhs) { decayed_t<VT, typename types::Coercion<T1, T2>::type> operator -(const VT<T1>& lhs, const T2& rhs) {
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size, ""); auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size);
for (int i = 0; i < lhs.size; ++i) for (int i = 0; i < lhs.size; ++i)
ret[i] = lhs[i] - rhs; ret[i] = lhs[i] - rhs;
return ret; return ret;
} }
template <class T1, class T2, template<typename ...> class VT> template <class T1, class T2, template<typename ...> class VT>
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator -(const T2& lhs, const VT<T1>& rhs) { decayed_t<VT, typename types::Coercion<T1, T2>::type> operator -(const T2& lhs, const VT<T1>& rhs) {
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(rhs.size, ""); auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(rhs.size);
for (int i = 0; i < rhs.size; ++i) for (int i = 0; i < rhs.size; ++i)
ret[i] = lhs - rhs[i]; ret[i] = lhs - rhs[i];
return ret; return ret;
} }
template <class T1, class T2, template<typename ...> class VT, template<typename ...> class VT2> template <class T1, class T2, template<typename ...> class VT, template<typename ...> class VT2>
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator +(const VT<T1>& lhs, const VT2<T2>& rhs) { decayed_t<VT, typename types::Coercion<T1, T2>::type> operator +(const VT<T1>& lhs, const VT2<T2>& rhs) {
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size, ""); auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size);
for (int i = 0; i < lhs.size; ++i) for (int i = 0; i < lhs.size; ++i)
ret[i] = lhs[i] + rhs[i]; ret[i] = lhs[i] + rhs[i];
return ret; return ret;
} }
template <class T1, class T2, template<typename ...> class VT> template <class T1, class T2, template<typename ...> class VT>
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator +(const VT<T1>& lhs, const T2& rhs) { decayed_t<VT, typename types::Coercion<T1, T2>::type> operator +(const VT<T1>& lhs, const T2& rhs) {
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size, ""); auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size);
for (int i = 0; i < lhs.size; ++i) for (int i = 0; i < lhs.size; ++i)
ret[i] = lhs[i] + rhs; ret[i] = lhs[i] + rhs;
return ret; return ret;
} }
template <class T1, class T2, template<typename ...> class VT> template <class T1, class T2, template<typename ...> class VT>
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator +(const T2& lhs, const VT<T1>& rhs) { decayed_t<VT, typename types::Coercion<T1, T2>::type> operator +(const T2& lhs, const VT<T1>& rhs) {
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(rhs.size, ""); auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(rhs.size);
for (int i = 0; i < rhs.size; ++i) for (int i = 0; i < rhs.size; ++i)
ret[i] = lhs + rhs[i]; ret[i] = lhs + rhs[i];
return ret; return ret;
} }
template <class T1, class T2, template<typename ...> class VT, template<typename ...> class VT2> template <class T1, class T2, template<typename ...> class VT, template<typename ...> class VT2>
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator *(const VT<T1>& lhs, const VT2<T2>& rhs) { decayed_t<VT, typename types::Coercion<T1, T2>::type> operator *(const VT<T1>& lhs, const VT2<T2>& rhs) {
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size, ""); auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size);
for (int i = 0; i < lhs.size; ++i) for (int i = 0; i < lhs.size; ++i)
ret[i] = lhs[i] * rhs[i]; ret[i] = lhs[i] * rhs[i];
return ret; return ret;
} }
template <class T1, class T2, template<typename ...> class VT> template <class T1, class T2, template<typename ...> class VT>
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator *(const VT<T1>& lhs, const T2& rhs) { decayed_t<VT, typename types::Coercion<T1, T2>::type> operator *(const VT<T1>& lhs, const T2& rhs) {
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size, ""); auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(lhs.size);
for (int i = 0; i < lhs.size; ++i) for (int i = 0; i < lhs.size; ++i)
ret[i] = lhs[i] * rhs; ret[i] = lhs[i] * rhs;
return ret; return ret;
} }
template <class T1, class T2, template<typename ...> class VT> template <class T1, class T2, template<typename ...> class VT>
decayed_t<VT, typename types::Coercion<T1, T2>::type> operator *(const T2& lhs, const VT<T1>& rhs) { decayed_t<VT, typename types::Coercion<T1, T2>::type> operator *(const T2& lhs, const VT<T1>& rhs) {
auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(rhs.size, ""); auto ret = decayed_t<VT, typename types::Coercion<T1, T2>::type>(rhs.size);
for (int i = 0; i < rhs.size; ++i) for (int i = 0; i < rhs.size; ++i)
ret[i] = lhs * rhs[i]; ret[i] = lhs * rhs[i];
return ret; return ret;
} }
template <class T1, class T2, template<typename ...> class VT, template<typename ...> class VT2> template <class T1, class T2, template<typename ...> class VT, template<typename ...> class VT2>
decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>> operator /(const VT<T1>& lhs, const VT2<T2>& rhs) { decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>> operator /(const VT<T1>& lhs, const VT2<T2>& rhs) {
auto ret = decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>>(lhs.size, ""); auto ret = decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>>(lhs.size);
for (int i = 0; i < lhs.size; ++i) for (int i = 0; i < lhs.size; ++i)
ret[i] = lhs[i] / rhs[i]; ret[i] = lhs[i] / rhs[i];
return ret; return ret;
} }
template <class T1, class T2, template<typename ...> class VT> template <class T1, class T2, template<typename ...> class VT>
decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>> operator /(const VT<T1>& lhs, const T2& rhs) { decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>> operator /(const VT<T1>& lhs, const T2& rhs) {
auto ret = decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>>(lhs.size, ""); auto ret = decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>>(lhs.size);
for (int i = 0; i < lhs.size; ++i) for (int i = 0; i < lhs.size; ++i)
ret[i] = lhs[i] / rhs; ret[i] = lhs[i] / rhs;
return ret; return ret;
} }
template <class T1, class T2, template<typename ...> class VT> template <class T1, class T2, template<typename ...> class VT>
decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>> operator /(const T2& lhs, const VT<T1>& rhs) { decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>> operator /(const T2& lhs, const VT<T1>& rhs) {
auto ret = decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>>(rhs.size, ""); auto ret = decayed_t<VT, types::GetFPType<typename types::Coercion<T1, T2>::type>>(rhs.size);
for (int i = 0; i < rhs.size; ++i) for (int i = 0; i < rhs.size; ++i)
ret[i] = lhs / rhs[i]; ret[i] = lhs / rhs[i];
return ret; return ret;

@ -47,6 +47,7 @@ public:
_Ty* container; _Ty* container;
uint32_t size, capacity; uint32_t size, capacity;
typedef _Ty* iterator_t; typedef _Ty* iterator_t;
typedef _Ty value_t;
vector_type(const uint32_t& size) : size(size), capacity(size) { vector_type(const uint32_t& size) : size(size), capacity(size) {
container = (_Ty*)malloc(size * sizeof(_Ty)); container = (_Ty*)malloc(size * sizeof(_Ty));
} }
@ -58,6 +59,7 @@ public:
} }
} }
constexpr vector_type() noexcept : size(0), capacity(0), container(0) {}; constexpr vector_type() noexcept : size(0), capacity(0), container(0) {};
constexpr vector_type(_Ty* container, uint32_t len) noexcept : size(len), capacity(0), container(container) {};
constexpr vector_type(const vector_type<_Ty>& vt) noexcept : capacity(0) { constexpr vector_type(const vector_type<_Ty>& vt) noexcept : capacity(0) {
_copy(vt); _copy(vt);
} }
@ -107,11 +109,13 @@ public:
} }
void emplace_back(_Ty _val) { void emplace_back(_Ty _val) {
if (size >= capacity) { // geometric growth if (size >= capacity) { // geometric growth
capacity += 1 + (capacity >> 1); uint32_t new_capacity = size + 1 + (size >> 1);
_Ty* n_container = (_Ty*)malloc(capacity * sizeof(_Ty)); _Ty* n_container = (_Ty*)malloc(new_capacity * sizeof(_Ty));
memcpy(n_container, container, sizeof(_Ty) * size); memcpy(n_container, container, sizeof(_Ty) * size);
free(container); if (capacity)
free(container);
container = n_container; container = n_container;
capacity = new_capacity;
} }
container[size++] = _val; container[size++] = _val;
} }
@ -208,6 +212,25 @@ public:
size = this->size + dist; size = this->size + dist;
} }
void out(uint32_t n = 4, const char* sep = " ") const; void out(uint32_t n = 4, const char* sep = " ") const;
vector_type<_Ty> subvec(uint32_t start, uint32_t end) {
vector_type<_Ty> subvec(end - start);
memcpy(subvec.container, container + start, sizeof(_Ty) * (end - start));
return subvec;
}
inline vector_type<_Ty> subvec_view(uint32_t start, uint32_t end) {
return subvec(container + start, end - start);
}
vector_type<_Ty> subvec_deep(uint32_t start, uint32_t end) {
uint32_t len = end - start;
vector_type<_Ty> subvec(len);
for (uint32_t i = 0; i < len; ++i)
subvec[i] = container[i];
return subvec;
}
inline vector_type<_Ty> subvec(uint32_t start = 0) { return subvec(start, size); }
inline vector_type<_Ty> subvec_view(uint32_t start = 0) { return subvec_view(start, size); }
inline vector_type<_Ty> subvec_deep(uint32_t start = 0) { return subvec_deep(start, size); }
~vector_type() { ~vector_type() {
if (capacity > 0) free(container); if (capacity > 0) free(container);
container = 0; size = capacity = 0; container = 0; size = capacity = 0;
@ -285,6 +308,12 @@ public:
void operator[](const uint32_t& i) { void operator[](const uint32_t& i) {
} }
vector_type<void> subvec(uint32_t, uint32_t);
vector_type<void> subvec_view(uint32_t, uint32_t);
vector_type<void> subvec_deep(uint32_t, uint32_t);
vector_type<void> subvec(uint32_t);
vector_type<void> subvec_view(uint32_t);
vector_type<void> subvec_deep(uint32_t);
}; };
#pragma pack(pop) #pragma pack(pop)
#endif #endif

@ -2,17 +2,55 @@
#include "./server/libaquery.h" #include "./server/libaquery.h"
#include "./server/aggregations.h" #include "./server/aggregations.h"
auto covariance = [](auto x, auto y) { auto covariances2 = [](auto x, auto y, auto w, uint32_t _builtin_len, auto& _builtin_ret) {
auto xmean = avg(x); auto xmeans = 0.0;
auto ymean = avg(y); auto ymeans = 0.0;
return avg(((x - xmean) * (y - ymean))); auto l = _builtin_len;
if((l > 0)) {
xmeans = x[0];
ymeans = y[0];
_builtin_ret[0] = 0.0;
}
if((w > l))
w = l;
for(auto i = 1, j = 0; (i < w); i = (i + 1)) {
xmeans += x[i];
ymeans += y[i];
_builtin_ret[i] = avg(((x.subvec(0, i) - (xmeans / i)) * (y.subvec(0, i) - (ymeans / i))));
}
xmeans /= w;
ymeans /= w;
for(auto i = w; (i < l); i += 1) {
xmeans += ((x[i] - x[(i - w)]) / w);
ymeans += ((y[i] - y[(i - w)]) / w);
_builtin_ret[i] = avg(((x.subvec((i - w), i) - xmeans) * (y.subvec((i - w), i) - ymeans)));
}
return ;
}; };
auto sd = [](auto x) { auto covariances2_gettype = [](auto x, auto y, auto w) {
return sqrt(covariance(x, x)); uint32_t _builtin_len = 0;
}; auto xmeans = 0.0;
auto ymeans = 0.0;
auto paircorr = [](auto x, auto y) { auto l = _builtin_len;
return (covariance(x, y) / (sd(x) * sd(y))); if((l > 0)) {
xmeans = x[0];
ymeans = y[0];
return 0.0;
}
if((w > l))
w = l;
for(auto i = 1, j = 0; (i < w); i = (i + 1)) {
xmeans += x[i];
ymeans += y[i];
return avg(((x.subvec(0, i) - (xmeans / i)) * (y.subvec(0, i) - (ymeans / i))));
}
xmeans /= w;
ymeans /= w;
for(auto i = w; (i < l); i += 1) {
xmeans += ((x[i] - x[(i - w)]) / w);
ymeans += ((y[i] - y[(i - w)]) / w);
return avg(((x.subvec((i - w), i) - xmeans) * (y.subvec((i - w), i) - ymeans)));
}
}; };

Binary file not shown.

@ -0,0 +1,14 @@
AGGREGATION FUNCTION covariances(x, y, w){
static xmeans := 0., ymeans := 0., cnt := 0;
if (cnt < w)
{
xmeans += x;
ymeans += y;
cnt+=1;
}
else {
xmeans += (x - x.vec[cnt - w]) / w;
ymeans += (y - y.vec[cnt - w]) / w;
}
avg (( x.vec(x.len-w, x.len) - xmeans ) * (y.vec(y.len - w, y.len) - ymeans ))
}

@ -0,0 +1,41 @@
AGGREGATION FUNCTION add(a, b){
a+b
}
AGGREGATION FUNCTION covariances2(x, y, w){
xmeans := 0.;
ymeans := 0.;
l := _builtin_len;
if (l > 0)
{
xmeans := x[0];
ymeans := y[0];
_builtin_ret[0] := 0.;
}
if (w > l)
w := l;
for (i := 1, j:= 0; i < w; i := i+1) {
xmeans += x[i];
ymeans += y[i];
_builtin_ret[i] := avg (( x(0, i) - xmeans/i ) * (y(0, i) - ymeans/i ));
}
xmeans /= w;
ymeans /= w;
for (i := w; i < l; i += 1)
{
xmeans += (x[i] - x[i - w]) / w;
ymeans += (y[i] - y[i - w]) / w;
_builtin_ret[i] := avg (( x(i-w, i) - xmeans ) * (y(i - w, i) - ymeans ));
}
Null
}
CREATE TABLE test(a INT, b INT, c INT, d INT)
LOAD DATA INFILE "test.csv"
INTO TABLE test
FIELDS TERMINATED BY ","
select covariances2(a, b, 4) from test group by c;

@ -0,0 +1,32 @@
AGGREGATION FUNCTION covariances2(x, y, w){
xmeans := 0.;
ymeans := 0.;
l := _builtin_len;
if (w > l)
w := l;
elif (w > l + 2)
{
l := 3;
w := 4;
}
elif(w < 99){
l := 8;
}
elif(w<999)
w := 6;
else
l := l / 2;
for (i := 0, j:= 0; i < w; i := i+1) {
xmeans += x[i];
ymeans += y[i];
_builtin_ret[i] := avg (( x(l-w, l) - xmeans ) * (y(l - w, l) - ymeans ));
}
for (i := 0; i < l; i += 1)
{
xmeans += (x[i] - x[i - w]) / w;
ymeans += (y[i] - y[i - w]) / w;
_builtin_ret[i] := avg (( x(l-w, l) - xmeans ) * (y(l - w, l) - ymeans ));
}
Null
}

@ -0,0 +1,19 @@
#pragma once
#include "./server/libaquery.h"
#include "./server/aggregations.h"
auto covariances = [](auto x, auto y, auto w) {
static auto xmeans=0.0;static auto ymeans=0.0; static auto cnt=0;
auto reset = [=]() { xmeans=0.0, ymeans=0.0, cnt=0; };
auto call = [](decltype(x) x, decltype(y) y, decltype(w) w){
if((cnt < w)) {
xmeans += x;
ymeans += y;
cnt += 1;
}
y = (x - xmeans);
return avg(((x.subvec((x - w), x) - xmeans) * (y.subvec((y - w), y) - ymeans)));
};
return std::make_pair(reset, call);
};

@ -0,0 +1,14 @@
#include "udf.hpp"
int main(){
vector_type _a{1,2,3,4};
vector_type _b{2,3,3,5};
ColRef<int> a("a");
ColRef<int> b("b");
a.initfrom(_a, "a");
b.initfrom(_b, "b");
ColRef<decltype(covariances2_gettype(a,b,0))> ret{4};
covariances2(a,b,2,4,ret);
print(ret);
}

@ -0,0 +1,5 @@
#include "udf.hpp"
int main(){
}
Loading…
Cancel
Save