Assumption, outfile, bugfixes on type deduction

dev
Bill 2 years ago
parent 6490aab558
commit 70f29e028d

2
.gitignore vendored

@ -43,3 +43,5 @@ server/packages/**
*.ipynb
*.cmake
*.stackdump
saves
*.exe

BIN
a.exe

Binary file not shown.

BIN
a.exp

Binary file not shown.

BIN
a.lib

Binary file not shown.

@ -31,3 +31,6 @@ if os_platform == 'win':
os.add_dll_directory('c:/msys64/usr/bin')
os.add_dll_directory(os.path.abspath('./msc-plugin'))
print("adding path")
else:
import readline

@ -132,3 +132,4 @@ class expr(ast_node):
self.cexpr = expr.toCExpr(self._expr)
def __str__(self):
return self.cexpr

@ -74,6 +74,7 @@ type_table = dict()
AnyT = Types(0)
LazyT = Types(240, name = 'Lazy', cname = '', sqlname = '', ctype_name = '')
DoubleT = Types(17, name = 'double', cname='double', sqlname = 'DOUBLE', is_fp = True)
LDoubleT = Types(18, name = 'long double', cname='long double', sqlname = 'LDOUBLE', is_fp = True)
FloatT = Types(16, name = 'float', cname = 'float', sqlname = 'REAL',
long_type = DoubleT, is_fp = True)
HgeT = Types(9, name = 'int128',cname='__int128_t', sqlname = 'HUGEINT', fp_type = DoubleT)
@ -87,13 +88,33 @@ UIntT = Types(7, name = 'uint32', sqlname = 'UINT32', long_type=ULongT, fp_type=
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')
def _ty_make_dict(fn : str, *ty : Types):
return {eval(fn):t for t in ty}
int_types : Dict[str, Types] = _ty_make_dict('t.sqlname.lower()', LongT, ByteT, ShortT, IntT)
uint_types : Dict[str, Types] = _ty_make_dict('t.sqlname.lower()', ULongT, UByteT, UShortT, UIntT)
fp_types : Dict[str, Types] = _ty_make_dict('t.sqlname.lower()', FloatT, DoubleT)
builtin_types : Dict[str, Types] = {**_ty_make_dict('t.sqlname.lower()', AnyT, StrT), **int_types, **fp_types}
def get_int128_support():
for t in int_types.values():
t.long_type = HgeT
for t in uint_types.values():
t.long_type = UHgeT
int_types['int128'] = HgeT
uint_types['uint128'] = UHgeT
def revert_int128_support():
for t in int_types.values():
t.long_type = LongT
for t in uint_types.values():
t.long_type = ULongT
int_types.pop('int128', None)
uint_types.pop('uint128', None)
type_bylength : Dict[int, TypeCollection] = {}
type_bylength[1] = TypeCollection(1, ByteT)
type_bylength[2] = TypeCollection(2, ShortT)

@ -1,19 +0,0 @@
<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage" lang="zh-CN"><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title><script nonce="Gwv7h0bXsTxPbUPNEbU73Q">(function(){window.google={kEI:'6SlvYryXC8qH-Aa284e4Dg',kEXPI:'0,1302536,56873,6059,206,4804,2316,383,246,5,1354,4013,1238,1122515,1197738,380753,16114,28684,893,16679,4858,1362,9291,3029,17579,4998,13228,3847,4192,6430,7432,14680,629,2370,4304,1279,2742,149,1103,840,1986,210,4101,109,4011,2023,1777,522,6341,8327,3227,2845,7,17450,7540,8780,4465,3783,9359,3,576,6459,149,13975,4,1528,2304,32112,2658,7357,13658,4437,16786,5824,2533,4094,17,4035,3,3541,1,36574,5580,2,15953,5589,744,5852,9865,1758,5679,1021,2380,2719,11305,6955,2,6,7755,4568,6258,3014,3,3706,16695,1249,5838,14967,1555,2778,4677,1412,1395,445,2,2,1,1509,22318,799,152,1417,1,8591,2566,2558,5,1272,181,799,189,2259,511,84,858,10779,7341,2621,29,3421,2,1,10310,770,264,847,829,4829,1630,22,588,23,879,4222,335,1,1427,789,2155,350,537,163,4633,3,131,76,4,486,4,2912,151,1573,395,1662,1520,633,1206,2516,130,843,9,733,1126,488,3,435,128,44,646,606,482,3,1022,157,808,855,168,8,5432026,355,126,103,8796585,1326,3,1877,1,2562,1,748,141,795,6164,6751,155,17,13,72,139,4,2,20,2,169,13,19,46,5,39,644,29,2,2,1,2,1,2,2,7,4,1,2,2,2,2,2,2,1052,1,1,158,3,2,2,2,2,2,4,2,3,3,2011,1002,312,222,8,8,277,8,4,3,85,3,3,3,1,1,1,1,4,17,2,2,3,3,6,4,2,11,4,9,4,2,8,6,5,5,13,2,7,7,23950912,4041690,3,450,4899,159,1358,4726,3,2664,422,3302,1103,3406,492,112,1481',kBL:'WaFM'};google.sn='webhp';google.kHL='zh-CN';})();(function(){
var f=this||self;var h,k=[];function l(a){for(var b;a&&(!a.getAttribute||!(b=a.getAttribute("eid")));)a=a.parentNode;return b||h}function m(a){for(var b=null;a&&(!a.getAttribute||!(b=a.getAttribute("leid")));)a=a.parentNode;return b}
function n(a,b,c,d,g){var e="";c||-1!==b.search("&ei=")||(e="&ei="+l(d),-1===b.search("&lei=")&&(d=m(d))&&(e+="&lei="+d));d="";!c&&f._cshid&&-1===b.search("&cshid=")&&"slh"!==a&&(d="&cshid="+f._cshid);c=c||"/"+(g||"gen_204")+"?atyp=i&ct="+a+"&cad="+b+e+"&zx="+Date.now()+d;/^http:/i.test(c)&&"https:"===window.location.protocol&&(google.ml&&google.ml(Error("a"),!1,{src:c,glmm:1}),c="");return c};h=google.kEI;google.getEI=l;google.getLEI=m;google.ml=function(){return null};google.log=function(a,b,c,d,g){if(c=n(a,b,c,d,g)){a=new Image;var e=k.length;k[e]=a;a.onerror=a.onload=a.onabort=function(){delete k[e]};a.src=c}};google.logUrl=n;}).call(this);(function(){
google.y={};google.sy=[];google.x=function(a,b){if(a)var c=a.id;else{do c=Math.random();while(google.y[c])}google.y[c]=[a,b];return!1};google.sx=function(a){google.sy.push(a)};google.lm=[];google.plm=function(a){google.lm.push.apply(google.lm,a)};google.lq=[];google.load=function(a,b,c){google.lq.push([[a],b,c])};google.loadAll=function(a,b){google.lq.push([a,b])};google.bx=!1;google.lx=function(){};}).call(this);google.f={};(function(){
document.documentElement.addEventListener("submit",function(b){var a;if(a=b.target){var c=a.getAttribute("data-submitfalse");a="1"===c||"q"===c&&!a.elements.q.value?!0:!1}else a=!1;a&&(b.preventDefault(),b.stopPropagation())},!0);document.documentElement.addEventListener("click",function(b){var a;a:{for(a=b.target;a&&a!==document.documentElement;a=a.parentElement)if("A"===a.tagName){a="1"===a.getAttribute("data-nohref");break a}a=!1}a&&b.preventDefault()},!0);}).call(this);</script><style>#gbar,#guser{font-size:13px;padding-top:1px !important;}#gbar{height:22px}#guser{padding-bottom:7px !important;text-align:right}.gbh,.gbd{border-top:1px solid #c9d7f1;font-size:1px}.gbh{height:0;position:absolute;top:24px;width:100%}@media all{.gb1{height:22px;margin-right:.5em;vertical-align:top}#gbar{float:left}}a.gb1,a.gb4{text-decoration:underline !important}a.gb1,a.gb4{color:#00c !important}.gbi .gb4{color:#dd8e27 !important}.gbf .gb4{color:#900 !important}
</style><style>body,td,a,p,.h{font-family:arial,sans-serif}body{margin:0;overflow-y:scroll}#gog{padding:3px 8px 0}td{line-height:.8em}.gac_m td{line-height:17px}form{margin-bottom:20px}.h{color:#1558d6}em{color:#c5221f;font-style:normal;font-weight:normal}a em{text-decoration:underline}.lst{height:25px;width:496px}.gsfi,.lst{font:18px arial,sans-serif}.gsfs{font:17px arial,sans-serif}.ds{display:inline-box;display:inline-block;margin:3px 0 4px;margin-left:4px}input{font-family:inherit}body{background:#fff;color:#000}a{color:#4b11a8;text-decoration:none}a:hover,a:active{text-decoration:underline}.fl a{color:#1558d6}a:visited{color:#4b11a8}.sblc{padding-top:5px}.sblc a{display:block;margin:2px 0;margin-left:13px;font-size:11px}.lsbb{background:#f8f9fa;border:solid 1px;border-color:#dadce0 #70757a #70757a #dadce0;height:30px}.lsbb{display:block}#WqQANb a{display:inline-block;margin:0 12px}.lsb{background:url(/images/nav_logo229.png) 0 -261px repeat-x;border:none;color:#000;cursor:pointer;height:30px;margin:0;outline:0;font:15px arial,sans-serif;vertical-align:top}.lsb:active{background:#dadce0}.lst:focus{outline:none}</style><script nonce="Gwv7h0bXsTxPbUPNEbU73Q">(function(){window.google.erd={jsr:1,bv:1576,de:true};
var f=this||self;var g,h=null!=(g=f.mei)?g:1,m,n=null!=(m=f.sdo)?m:!0,p=0,q,r=google.erd,u=r.jsr;google.ml=function(a,b,d,k,c){c=void 0===c?2:c;b&&(q=a&&a.message);if(google.dl)return google.dl(a,c,d),null;if(0>u){window.console&&console.error(a,d);if(-2===u)throw a;b=!1}else b=!a||!a.message||"Error loading script"===a.message||p>=h&&!k?!1:!0;if(!b)return null;p++;d=d||{};var e=c;c=encodeURIComponent;b="/gen_204?atyp=i&ei="+c(google.kEI);google.kEXPI&&(b+="&jexpid="+c(google.kEXPI));b+="&srcpg="+c(google.sn)+"&jsr="+c(r.jsr)+"&bver="+c(r.bv)+("&jsel="+e);e=a.lineNumber;void 0!==e&&(b+="&line="+
e);var l=a.fileName;l&&(b+="&script="+c(l),e&&l===window.location.href&&(e=document.documentElement.outerHTML.split("\n")[e],b+="&cad="+c(e?e.substring(0,300):"No script found.")));for(var t in d)b+="&",b+=c(t),b+="=",b+=c(d[t]);b=b+"&emsg="+c(a.name+": "+a.message);b=b+"&jsst="+c(a.stack||"N/A");12288<=b.length&&(b=b.substr(0,12288));a=b;k||google.log(0,"",a);return a};window.onerror=function(a,b,d,k,c){q!==a&&(a=c instanceof Error?c:Error(a),void 0===d||"lineNumber"in a||(a.lineNumber=d),void 0===b||"fileName"in a||(a.fileName=b),google.ml(a,!1,void 0,!1,"SyntaxError"===a.name||"SyntaxError"===a.message.substring(0,11)?2:0));q=null;n&&p>=h&&(window.onerror=null)};})();</script></head><body bgcolor="#fff"><script nonce="Gwv7h0bXsTxPbUPNEbU73Q">(function(){var src='/images/nav_logo229.png';var iesg=false;document.body.onload = function(){window.n && window.n();if (document.images){new Image().src=src;}
if (!iesg){document.f&&document.f.q.focus();document.gbqf&&document.gbqf.q.focus();}
}
})();</script><div id="mngb"><div id=gbar><nobr><b class=gb1>搜索</b> <a class=gb1 href="http://www.google.cn/imghp?hl=zh-CN&tab=wi">图片</a> <a class=gb1 href="http://ditu.google.cn/maps?hl=zh-CN&tab=wl">地图</a> <a class=gb1 href="https://play.google.com/?hl=zh-CN&tab=w8">Play</a> <a class=gb1 href="https://news.google.com/?tab=wn">新闻</a> <a class=gb1 href="https://drive.google.com/?tab=wo">云端硬盘</a> <a class=gb1 href="https://calendar.google.com/calendar?tab=wc">日历</a> <a class=gb1 href="https://translate.google.cn/?hl=zh-CN&tab=wT">翻译</a> <a class=gb1 style="text-decoration:none" href="https://www.google.cn/intl/zh-CN/about/products?tab=wh"><u>更多</u> &raquo;</a></nobr></div><div id=guser width=100%><nobr><span id=gbn class=gbi></span><span id=gbf class=gbf></span><span id=gbe></span><a href="http://www.google.cn/history/optout?hl=zh-CN" class=gb4>网络历史记录</a> | <a href="/preferences?hl=zh-CN" class=gb4>设置</a> | <a target=_top id=gb_70 href="https://accounts.google.com/ServiceLogin?hl=zh-CN&passive=true&continue=http://www.google.com.hk/&ec=GAZAAQ" class=gb4>登录</a></nobr></div><div class=gbh style=left:0></div><div class=gbh style=right:0></div></div><center><br clear="all" id="lgpd"><div id="lga"><img alt="Google" height="92" src="/images/branding/googlelogo/1x/googlelogo_white_background_color_272x92dp.png" style="padding:28px 0 14px" width="272" id="hplogo"><br><br></div><form action="/search" name="f"><table cellpadding="0" cellspacing="0"><tr valign="top"><td width="25%">&nbsp;</td><td align="center" nowrap=""><input name="ie" value="GB2312" type="hidden"><input value="zh-CN" name="hl" type="hidden"><input name="source" type="hidden" value="hp"><input name="biw" type="hidden"><input name="bih" type="hidden"><div class="ds" style="height:32px;margin:4px 0"><input class="lst" style="margin:0;padding:5px 8px 0 6px;vertical-align:top;color:#000" autocomplete="off" value="" title="Google 搜索" maxlength="2048" name="q" size="57"></div><br style="line-height:0"><span class="ds"><span class="lsbb"><input class="lsb" value="Google 搜索" name="btnG" type="submit"></span></span><span class="ds"><span class="lsbb"><input class="lsb" id="tsuid1" value="&nbsp;手气不错&nbsp;" name="btnI" type="submit"><script nonce="Gwv7h0bXsTxPbUPNEbU73Q">(function(){var id='tsuid1';document.getElementById(id).onclick = function(){if (this.form.q.value){this.checked = 1;if (this.form.iflsig)this.form.iflsig.disabled = false;}
else top.location='/doodles/';};})();</script><input value="AJiK0e8AAAAAYm83-cz7iLpxWfOf4MXVhR41bEjV0J4S" name="iflsig" type="hidden"></span></span></td><td class="fl sblc" align="left" nowrap="" width="25%"><a href="/advanced_search?hl=zh-CN&amp;authuser=0">高级搜索</a></td></tr></table><input id="gbv" name="gbv" type="hidden" value="1"><script nonce="Gwv7h0bXsTxPbUPNEbU73Q">(function(){
var a,b="1";if(document&&document.getElementById)if("undefined"!=typeof XMLHttpRequest)b="2";else if("undefined"!=typeof ActiveXObject){var c,d,e=["MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];for(c=0;d=e[c++];)try{new ActiveXObject(d),b="2"}catch(h){}}a=b;if("2"==a&&-1==location.search.indexOf("&gbv=2")){var f=google.gbvu,g=document.getElementById("gbv");g&&(g.value=a);f&&window.setTimeout(function(){location.href=f},0)};}).call(this);</script></form><div id="gac_scont"></div><div style="font-size:83%;min-height:3.5em"><br></div><span id="footer"><div style="font-size:10pt"><div style="margin:19px auto;text-align:center" id="WqQANb"><a href="/intl/zh-CN/ads/">加入营销计划</a><a href="/intl/zh-CN/about.html">Google 大全</a><a href="http://www.google.com.hk/setprefdomain?prefdom=US&amp;sig=K_5xGLaVXPJ9E6BAv_UFwF6QuXCsk%3D" id="fehl">Google.com</a></div></div><p style="font-size:8pt;color:#70757a">&copy; 2022 - <a href="/intl/zh-CN/policies/privacy/">隐私权</a> - <a href="/intl/zh-CN/policies/terms/">条款</a></p></span></center><script nonce="Gwv7h0bXsTxPbUPNEbU73Q">(function(){window.google.cdo={height:757,width:1440};(function(){
var a=window.innerWidth,b=window.innerHeight;if(!a||!b){var c=window.document,d="CSS1Compat"==c.compatMode?c.documentElement:c.body;a=d.clientWidth;b=d.clientHeight}a&&b&&(a!=google.cdo.width||b!=google.cdo.height)&&google.log("","","/client_204?&atyp=i&biw="+a+"&bih="+b+"&ei="+google.kEI);}).call(this);})();</script> <script nonce="Gwv7h0bXsTxPbUPNEbU73Q">(function(){google.xjs={ck:'',cs:'',excm:[]};})();</script> <script nonce="Gwv7h0bXsTxPbUPNEbU73Q">(function(){var u='/xjs/_/js/k\x3dxjs.hp.en.j3jfXaQeWvI.O/am\x3dAOAJAEACkA/d\x3d1/ed\x3d1/esmo\x3d1/rs\x3dACT90oG3H1KdGSCGx9JeWfQKPi1zGOmoVQ/m\x3dsb_he,d';
var d=this||self,e=function(a){return a};var g;var l=function(a,b){this.g=b===h?a:""};l.prototype.toString=function(){return this.g+""};var h={};
function n(){var a=u;google.lx=function(){p(a);google.lx=function(){}};google.bx||google.lx()}
function p(a){google.timers&&google.timers.load&&google.tick&&google.tick("load","xjsls");var b=document;var c="SCRIPT";"application/xhtml+xml"===b.contentType&&(c=c.toLowerCase());c=b.createElement(c);if(void 0===g){b=null;var k=d.trustedTypes;if(k&&k.createPolicy){try{b=k.createPolicy("goog#html",{createHTML:e,createScript:e,createScriptURL:e})}catch(q){d.console&&d.console.error(q.message)}g=b}else g=b}a=(b=g)?b.createScriptURL(a):a;a=new l(a,h);c.src=a instanceof l&&a.constructor===l?a.g:"type_error:TrustedResourceUrl";var f,m;(f=(a=null==(m=(f=(c.ownerDocument&&c.ownerDocument.defaultView||window).document).querySelector)?void 0:m.call(f,"script[nonce]"))?a.nonce||a.getAttribute("nonce")||"":"")&&c.setAttribute("nonce",f);document.body.appendChild(c);google.psa=!0};google.xjsu=u;setTimeout(function(){n()},0);})();function _DumpException(e){throw e;}
function _F_installCss(c){}
(function(){google.jl={attn:false,blt:'none',chnk:0,dw:false,dwu:true,emtn:0,end:0,ine:false,injs:'none',injt:0,lls:'default',pdt:0,rep:0,snet:true,strt:0,ubm:false,uwp:true};})();(function(){var pmc='{\x22d\x22:{},\x22sb_he\x22:{\x22agen\x22:true,\x22cgen\x22:true,\x22client\x22:\x22heirloom-hp\x22,\x22dh\x22:true,\x22dhqt\x22:true,\x22ds\x22:\x22\x22,\x22ffql\x22:\x22zh-CN\x22,\x22fl\x22:true,\x22host\x22:\x22google.com.hk\x22,\x22isbh\x22:28,\x22jsonp\x22:true,\x22msgs\x22:{\x22cibl\x22:\x22清除搜索\x22,\x22dym\x22:\x22您是不是要找\x22,\x22lcky\x22:\x22\\u0026nbsp;手气不错\\u0026nbsp;\x22,\x22lml\x22:\x22了解详情\x22,\x22oskt\x22:\x22输入工具\x22,\x22psrc\x22:\x22该搜索记录已从您的\\u003Ca href\x3d\\\x22/history\\\x22\\u003E网络历史记录\\u003C/a\\u003E中移除\x22,\x22psrl\x22:\x22删除\x22,\x22sbit\x22:\x22按图片搜索\x22,\x22srch\x22:\x22Google 搜索\x22},\x22ovr\x22:{},\x22pq\x22:\x22\x22,\x22refpd\x22:true,\x22rfs\x22:[],\x22sbas\x22:\x220 3px 8px 0 rgba(0,0,0,0.2),0 0 0 1px rgba(0,0,0,0.08)\x22,\x22sbpl\x22:16,\x22sbpr\x22:16,\x22scd\x22:10,\x22stok\x22:\x22OShBkbRb_Q7vaenlYCLCbBOyK0I\x22,\x22uhde\x22:false}}';google.pmc=JSON.parse(pmc);})();</script> </body></html>

@ -10,5 +10,5 @@ FROM sale
INTO OUTFILE "moving_avg_output.csv"
FIELDS TERMINATED BY ";"
select Mont, mins(2,sales) from sale assuming desc Mont group by sales
into outfile "flatten.csv"
-- select Mont, mins(2,sales) from sale assuming desc Mont group by sales
-- into outfile "flatten.csv"

@ -1,17 +1,19 @@
#include "./udf.hpp"
#include "./server/monetdb_conn.h"
#include "./server/aggregations.h"
#include "./server/libaquery.h"
#include "./server/monetdb_conn.h"
extern "C" int __DLLEXPORT__ dllmain(Context* cxt) {
using namespace std;
using namespace types;
auto server = static_cast<Server*>(cxt->alt_server);
auto len_6SzLPm = server->cnt;
auto sales_5fe = ColRef<int>(len_6SzLPm, server->getCol(0));
auto a_yJz = ColRef<int>(len_6SzLPm, server->getCol(1));
auto out_4UoFb5 = new TableInfo<value_type<decays<decltype((sd(a_yJz) + sales_5fe))>>>("out_4UoFb5");
out_4UoFb5->get_col<0>() = (sd(a_yJz) + sales_5fe);
print(*out_4UoFb5);
auto len_5sGusn = server->cnt;
auto sumc_5IN = ColRef<__int128_t>(len_5sGusn, server->getCol(0));
auto b_79y = ColRef<int>(len_5sGusn, server->getCol(1));
auto d_4yS = ColRef<int>(len_5sGusn, server->getCol(2));
auto out_kio0QJ = new TableInfo<__int128_t,int,int>("out_kio0QJ");
out_kio0QJ->get_col<0>().initfrom(sumc_5IN);
out_kio0QJ->get_col<1>().initfrom(b_79y);
out_kio0QJ->get_col<2>().initfrom(d_4yS);
print(*out_kio0QJ);
puts("done.");
return 0;
}

@ -74,7 +74,6 @@ def init_ipc():
global shm, server, basecmd, mm
shm = base62uuid()
if sys.platform != 'win32':
import readline
shm += '.shm'
basecmd = ['bash', '-c', 'rlwrap k']
mm = None
@ -166,6 +165,9 @@ def init_threaded():
global cfg, th, send
send = server_so['receive_args']
aquery_config.have_hge = server_so['have_hge']()
if aquery_config.have_hge:
from engine.types import get_int128_support
get_int128_support()
th = threading.Thread(target=server_so['main'], args=(-1, ctypes.POINTER(ctypes.c_char_p)(cfg.c)), daemon=True)
th.start()
@ -258,6 +260,7 @@ while test_parser:
except BaseException as e:
# don't care about anything happened in interactive console
print(e)
continue
elif q.startswith('log'):
qs = re.split(r'[ \t]', q)
if len(qs) > 1:
@ -270,6 +273,28 @@ while test_parser:
continue
elif q == 'print':
cxt.print(stmts)
continue
elif q.startswith('save'):
savecmd = re.split(r'[ \t]', q)
if len(savecmd) > 1:
fname = savecmd[1]
else:
tm = time.gmtime()
fname = f'{tm.tm_year}{tm.tm_mon}_{tm.tm_mday}_{tm.tm_hour}:{tm.tm_min}:{tm.tm_sec}'
if cxt:
def savefile(attr:str, desc:str):
if hasattr(cxt, attr):
attr : str = getattr(cxt, attr)
if attr:
ext = '.' + desc
name = fname if fname.endswith(ext) else fname + ext
with open('saves/' + name, 'wb') as cfile:
cfile.write(attr.encode('utf-8'))
print(f'saved {desc} code as {name}')
savefile('ccode', 'cpp')
savefile('udf', 'udf')
savefile('sql', 'sql')
continue
elif q == 'keep':
keep = not keep
@ -285,7 +310,7 @@ while test_parser:
elif q == 'rr': # run
set_ready()
continue
elif q.startswith('save'):
elif q.startswith('save2'):
filename = re.split(r'[ \t]', q)
if (len(filename) > 1):
filename = filename[1]

@ -15,6 +15,7 @@ class ast_node:
self.context = parent.context if context is None else context
self.parent = parent
self.sql = ''
self.ccode = ''
if hasattr(parent, 'datasource'):
self.datasource = parent.datasource
else:
@ -28,6 +29,8 @@ class ast_node:
self.context.emit(code)
def add(self, code):
self.sql += code + ' '
def addc(self, code):
self.ccode += code + '\n'
name = 'null'
@ -64,7 +67,8 @@ class projection(ast_node):
self.datasource = join(self, from_clause)
if 'assumptions' in from_clause:
self.assumptions = enlist(from_clause['assumptions'])
else:
self.assumptions = []
if self.datasource is not None:
self.datasource_changed = True
self.prev_datasource = self.context.datasource
@ -98,6 +102,7 @@ class projection(ast_node):
this_type = proj_expr.type
name = proj_expr.sql
compound = True # compound column
proj_expr.cols_mentioned = self.datasource.rec
if not proj_expr.is_special:
y = lambda x:x
name = eval('f\'' + name + '\'')
@ -110,7 +115,6 @@ class projection(ast_node):
if self.datasource.rec is not None:
self.col_ext = self.col_ext.union(self.datasource.rec)
proj_map[i] = [this_type, proj_expr.sql, proj_expr]
if 'name' in proj: # renaming column by AS keyword
name += ' AS ' + proj['name']
if not proj_expr.is_special:
@ -147,12 +151,25 @@ class projection(ast_node):
self.add('FROM')
finialize(self.datasource)
finialize(self.where)
finialize(self.group_node)
if self.group_node and not self.group_node.use_sp_gb:
self.add(self.group_node.sql)
if self.col_ext or self.group_node and self.group_node.use_sp_gb:
self.use_postproc = True
o = self.assumptions
if 'orderby' in node:
self.add(orderby(self, node['orderby']).sql)
o.extend(enlist(node['orderby']))
if o:
self.add(orderby(self, o).sql)
if 'outfile' in node:
self.sql = outfile(self, node['outfile'], sql = self.sql).sql
self.outfile = outfile(self, node['outfile'], sql = self.sql)
if not self.use_postproc:
self.sql += self.outfile.sql
else:
self.outfile = None
if self.parent is None:
self.emit(self.sql+';\n')
else:
@ -175,7 +192,7 @@ class projection(ast_node):
self.context.emitc(f'auto {vname} = ColRef<{typenames[idx].cname}>({length_name}, server->getCol({idx}));')
vid2cname[idx] = vname
# Create table into context
outtable_name = 'out_' + base62uuid(6)
self.outtable_name = 'out_' + base62uuid(6)
out_typenames = [None] * len(proj_map)
for key, val in proj_map.items():
@ -189,15 +206,20 @@ class projection(ast_node):
if val[0] == LazyT:
decltypestring = f'value_type<decays<decltype({decltypestring})>>'
if type(val[2].udf) is udf and val[2].udf.return_pattern == udf.ReturnPattern.elemental_return:
out_typenames[key] = f'ColRef<{decltypestring}>'
else:
out_typenames[key] = decltypestring
else:
out_typenames[key] = val[0].cname
if (type(val[2].udf_called) is udf and
val[2].udf_called.return_pattern == udf.ReturnPattern.elemental_return
or
self.group_node and self.group_node.use_sp_gb and
val[2].cols_mentioned.intersection(
self.datasource.all_cols.difference(self.group_node.refs))
):
out_typenames[key] = f'ColRef<{out_typenames[key]}>'
# 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 {self.outtable_name} = new TableInfo<{",".join(out_typenames)}>("{self.outtable_name}");')
# TODO: Inject custom group by code here and flag them in proj_map
# Type of UDFs? Complex UDFs, ones with static vars?
if self.group_node is not None and self.group_node.use_sp_gb:
@ -206,18 +228,22 @@ class projection(ast_node):
for key, val in proj_map.items():
col_name = 'col_' + base62uuid(6)
self.context.emitc(f'decltype(auto) {col_name} = {outtable_name}->get_col<{key}>();')
self.context.emitc(f'decltype(auto) {col_name} = {self.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]]});')
self.context.emitc(f'{self.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]};')
self.context.emitc(f'{self.outtable_name}->get_col<{key}>() = {val[1]};')
# print out col_is
self.context.emitc(f'print(*{outtable_name});')
self.context.emitc(f'print(*{self.outtable_name});')
if self.outfile:
self.outfile.finalize()
self.context.emitc(f'puts("done.");')
class orderby(ast_node):
name = 'order by'
@ -357,11 +383,11 @@ class groupby_c(ast_node):
for ce in cexprs:
ex = ce[1]
materialize_builtin = {}
if type(ex.udf) is udf:
if '_builtin_len' in ex.udf.builtin_used:
if type(ex.udf_called) is udf:
if '_builtin_len' in ex.udf_called.builtin_used:
define_len_var()
materialize_builtin['_builtin_len'] = len_var
if '_builtin_ret' in ex.udf.builtin_used:
if '_builtin_ret' in ex.udf_called.builtin_used:
define_len_var()
gscanner.add(f'{ce[0]}.emplace_back({{{len_var}}});\n')
materialize_builtin['_builtin_ret'] = f'{ce[0]}.back()'
@ -382,6 +408,7 @@ class groupby(ast_node):
node = enlist(node)
o_list = []
self.refs = set()
self.dedicated_glist : List[Tuple[expr, Set[ColRef]]] = []
self.use_sp_gb = False
for g in node:
@ -392,7 +419,7 @@ class groupby(ast_node):
if self.parent.col_ext:
this_sp_ref = refs.difference(self.parent.col_ext)
self.use_sp_gb = self.use_sp_gb or len(this_sp_ref) > 0
self.refs.update(refs)
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':
@ -418,7 +445,7 @@ class join(ast_node):
name = 'join'
def init(self, _):
self.joins:list = []
self.tables = []
self.tables : List[TableInfo] = []
self.tables_dir = dict()
self.rec = None
# self.tmp_name = 'join_' + base62uuid(4)
@ -496,7 +523,9 @@ class join(ast_node):
raise ValueError(f'Table name/alias not defined{parsedColExpr[0]}')
else:
return datasource.parse_col_names(parsedColExpr[1])
@property
def all_cols(self):
return set([c for t in self.tables for c in t.columns])
def consume(self, _):
self.sql = ', '.join(self.joins)
return super().consume(_)
@ -581,13 +610,19 @@ class load(ast_node):
class outfile(ast_node):
name="_outfile"
def __init__(self, parent, node, context = None, *, sql = None):
self.node = node
super().__init__(parent, node, context)
self.sql = sql
self.sql = sql if sql else ''
def init(self, _):
assert(type(self.parent) is projection)
if not self.parent.use_postproc:
if self.context.dialect == 'MonetDB':
self.produce = self.produce_monetdb
else:
self.produce = self.produce_aq
return super().init(_)
def produce_aq(self, node):
filename = node['loc']['literal'] if 'loc' in node else node['literal']
self.sql += f'INTO OUTFILE "{filename}"'
@ -605,6 +640,15 @@ class outfile(ast_node):
d = node['term']['literal']
self.sql += f' delimiters \'{d}\', \'{e}\''
def finalize(self):
filename = self.node['loc']['literal'] if 'loc' in self.node else self.node['literal']
sep = ',' if 'term' not in self.node else self.node['term']['literal']
file_pointer = 'fp_' + base62uuid(6)
self.addc(f'FILE* {file_pointer} = fopen("{filename}", "w");')
self.addc(f'{self.parent.outtable_name}->printall("{sep}", "\\n", nullptr, {file_pointer});')
self.addc(f'fclose({file_pointer});')
self.context.ccode += self.ccode
class udf(ast_node):
name = 'udf'
first_order = name
@ -863,6 +907,7 @@ class udf(ast_node):
else:
return udf.ReturnPattern.bulk_return
def include(objs):
import inspect
for _, cls in inspect.getmembers(objs):

@ -57,6 +57,8 @@ class expr(ast_node):
if type(c_code) is bool:
self.c_code = c_code
self.udf_called = None
self.cols_mentioned : Optional[set[ColRef]] = None
ast_node.__init__(self, parent, node, None)
def init(self, _):
@ -97,20 +99,25 @@ class expr(ast_node):
if key in special_func and not self.is_special:
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.udf_called = self.context.udf_map[key]
if self.is_udfexpr and key == self.root.udf.name:
self.root.is_recursive_call_inudf = True
# TODO: make udf_called a set!
p = self.parent
while type(p) is expr and not p.udf_called:
p.udf_called = self.udf_called
p = p.parent
p = self.parent
while type(p) is expr and not p.is_special:
p.is_special = True
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):
if need_decltypestr or (self.udf_called 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:
if self.udf_called and type(op) is udf:
self.udf_decltypecall = op.decltypecall(self.c_code, *decltypestr_vals)
elif self.is_udfexpr:
@ -230,10 +237,10 @@ class expr(ast_node):
assert(self.is_root)
def call(decltypestr = False) -> str:
nonlocal c_code, y, materialize_builtin
if self.udf is not None:
if self.udf_called is not None:
loc = locals()
builtin_vars = self.udf.builtin_used
for b in self.udf.builtin_var.all:
builtin_vars = self.udf_called.builtin_used
for b in self.udf_called.builtin_var.all:
exec(f'loc["{b}"] = lambda: "{{{b}()}}"')
if builtin_vars:
if type(materialize_builtin) is dict:

@ -101,7 +101,8 @@ class Context:
self.has_dll = False
self.dialect = 'MonetDB'
self.have_hge = False
self.Info = lambda *_: None
self.Info = lambda *_: None
self.new()

@ -5,8 +5,15 @@ extern void* Aalloc(size_t sz);
extern int Afree(void * mem);
template <typename T>
size_t register_memory(T* ptr){
size_t register_memory(T* ptr, void(dealloc)(void*)){
[](void* m){ auto _m = static_cast<T*>(m); delete _m; };
}
struct Session{
struct Statistic{
size_t total_active;
size_t cnt_object;
size_t total_alloc;
};
void* memory_map;
};
#define EXPORT __DLLEXPORT__

@ -2,4 +2,18 @@
#include <memory>
#include <stdlib>
#include <unordered_set>
Session* session;
void* Aalloc(size_t sz){
void mem = malloc(sz);
auto memmap = (std::unordered_set<void*>*) session->memory_map;
memmap->insert(mem);
return mem;
}
int Afree(void* mem){
auto memmap = (std::unordered_set<void*>*) session->memory_map;
memmap->erase(mem);
return free(mem);
}

@ -320,7 +320,6 @@ struct TableInfo {
std::string printf_string =
generate_printf_string<typename std::tuple_element<cols, tuple_type>::type ...>(sep, end);
std::string header_string = std::string();
constexpr static int a_cols[] = { cols... };
for(int i = 0; i < sizeof...(cols); ++i)

@ -24,7 +24,7 @@ namespace types {
AINT32, AFLOAT, ASTR, ADOUBLE, ALDOUBLE, AINT64, AINT128, AINT16, ADATE, ATIME, AINT8,
AUINT32, AUINT64, AUINT128, AUINT16, AUINT8, VECTOR, NONE, ERROR
};
static constexpr const char* printf_str[] = { "%d", "%f", "%s", "%lf", "%llf", "%ld", "%s", "%hi", "%s", "%s", "%c",
static constexpr const char* printf_str[] = { "%d", "%f", "%s", "%lf", "%Lf", "%ld", "%s", "%hi", "%s", "%s", "%c",
"%u", "%lu", "%s", "%hu", "%hhu", "Vector<%s>", "NULL", "ERROR" };
// TODO: deal with data/time <=> str/uint conversion
struct date_t {
@ -96,13 +96,13 @@ namespace types {
#define __Eq(x) (sizeof(T) == sizeof(x))
template<class T>
struct GetFPTypeImpl {
using type = Cond(__Eq(float), float, Cond(__Eq(double), double, long double));
using type = Cond(__Eq(float), float, Cond(__Eq(double), double, double));
};
template<class T>
using GetFPType = typename GetFPTypeImpl<typename std::decay<T>::type>::type;
template<class T>
struct GetLongTypeImpl {
using type = Cond(__U(T), ULL_Type, Cond(Fp(T), long double, LL_Type));
using type = Cond(__U(T), ULL_Type, Cond(Fp(T), double, LL_Type));
};
template<class T>
using GetLongType = typename GetLongTypeImpl<typename std::decay<T>::type>::type;

@ -21,12 +21,12 @@ INSERT INTO stocks VALUES(16,5)
-- SELECT max(price-min(timestamp)) FROM stocks
/*<k> "q2" </k>*/
SELECT max(price-mins(price)) FROM stocks
-- SELECT max(price-mins(price)) FROM stocks
/*<k> "q3"</k>*/
SELECT price, timestamp FROM stocks where price - timestamp > 1 and not (price*timestamp<100)
/*<k> "q4"</k>*/
SELECT max(price-mins(price))
FROM stocks
ASSUMING DESC timestamp
-- SELECT max(price-mins(price))
-- FROM stocks
-- ASSUMING DESC timestamp

Binary file not shown.
Loading…
Cancel
Save