Line data Source code
1 : /* 2 : * This Source Code Form is subject to the terms of the Mozilla Public 3 : * License, v. 2.0. If a copy of the MPL was not distributed with this 4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 : * 6 : * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V. 7 : */ 8 : 9 : #include "monetdb_config.h" 10 : #include "mal_client.h" 11 : #include "mal_interpreter.h" 12 : 13 : static str 14 259983 : ALGprojectionpath(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) 15 : { 16 : int i; 17 : bat bid; 18 259983 : bat *r = getArgReference_bat(stk, pci, 0); 19 : BAT *b, **joins = NULL; 20 : 21 : (void) mb; 22 : (void) cntxt; 23 : 24 259983 : if(pci->argc <= 1) 25 0 : throw(MAL, "algebra.projectionpath", SQLSTATE(HY013) "INTERNAL ERROR"); 26 259983 : joins = (BAT**)GDKzalloc(pci->argc * sizeof(BAT*)); 27 260065 : if ( joins == NULL) 28 0 : throw(MAL, "algebra.projectionpath", SQLSTATE(HY013) MAL_MALLOC_FAIL); 29 3122510 : for (i = pci->retc; i < pci->argc; i++) { 30 2862560 : bid = *getArgReference_bat(stk, pci, i); 31 2862560 : b = BATdescriptor(bid); 32 2862450 : if (b == NULL || (i + 1 < pci->argc && ATOMtype(b->ttype) != TYPE_oid)) { 33 0 : while (--i >= pci->retc) 34 0 : BBPunfix(joins[i - pci->retc]->batCacheid); 35 0 : GDKfree(joins); 36 0 : throw(MAL, "algebra.projectionpath", "%s", b ? SEMANTIC_TYPE_MISMATCH : INTERNAL_BAT_ACCESS); 37 : } 38 2862450 : joins[i - pci->retc] = b; 39 : } 40 259949 : joins[pci->argc - pci->retc] = NULL; 41 259949 : b = BATprojectchain(joins); 42 3132370 : for (i = pci->retc; i < pci->argc; i++) 43 2872340 : BBPunfix(joins[i - pci->retc]->batCacheid); 44 260030 : GDKfree(joins); 45 260076 : if ( b) 46 260076 : BBPkeepref( *r = b->batCacheid); 47 : else 48 0 : throw(MAL, "algebra.projectionpath", INTERNAL_OBJ_CREATE); 49 260037 : return MAL_SUCCEED; 50 : } 51 : 52 : #include "mel.h" 53 : mel_func projectionpath_init_funcs[] = { 54 : pattern("algebra", "projectionpath", ALGprojectionpath, false, "Routine to handle join paths. The type analysis is rather tricky.", args(1,2, batargany("",0),batvarargany("l",0))), 55 : { .imp=NULL } 56 : }; 57 : #include "mal_import.h" 58 : #ifdef _MSC_VER 59 : #undef read 60 : #pragma section(".CRT$XCU",read) 61 : #endif 62 255 : LIB_STARTUP_FUNC(init_projectionpath_mal) 63 255 : { mal_module("projectionpath", NULL, projectionpath_init_funcs); }