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 : #include "mal_exception.h" 13 : 14 : static str 15 369448 : ALGprojectionpath(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) 16 : { 17 : int i; 18 : bat bid; 19 369448 : bat *r = getArgReference_bat(stk, pci, 0); 20 : BAT *b, **joins = NULL; 21 : 22 : (void) mb; 23 : (void) cntxt; 24 : 25 369448 : if(pci->argc <= 1) 26 0 : throw(MAL, "algebra.projectionpath", SQLSTATE(HY013) "INTERNAL ERROR"); 27 369448 : joins = (BAT**)GDKzalloc(pci->argc * sizeof(BAT*)); 28 369426 : if ( joins == NULL) 29 0 : throw(MAL, "algebra.projectionpath", SQLSTATE(HY013) MAL_MALLOC_FAIL); 30 3617545 : for (i = pci->retc; i < pci->argc; i++) { 31 3248171 : bid = *getArgReference_bat(stk, pci, i); 32 3248171 : b = BATdescriptor(bid); 33 3248119 : if (b == NULL || (i + 1 < pci->argc && ATOMtype(b->ttype) != TYPE_oid && b->ttype != TYPE_msk)) { 34 0 : while (--i >= pci->retc) 35 0 : BBPunfix(joins[i - pci->retc]->batCacheid); 36 0 : GDKfree(joins); 37 0 : if (b) 38 0 : BBPunfix(b->batCacheid); 39 0 : throw(MAL, "algebra.projectionpath", "%s", b ? SEMANTIC_TYPE_MISMATCH : INTERNAL_BAT_ACCESS); 40 : } 41 3248119 : joins[i - pci->retc] = b; 42 : } 43 369374 : joins[pci->argc - pci->retc] = NULL; 44 369374 : b = BATprojectchain(joins); 45 3626558 : for (i = pci->retc; i < pci->argc; i++) 46 3257146 : BBPunfix(joins[i - pci->retc]->batCacheid); 47 369412 : GDKfree(joins); 48 369450 : if ( b) 49 369450 : BBPkeepref( *r = b->batCacheid); 50 : else 51 0 : throw(MAL, "algebra.projectionpath", GDK_EXCEPTION); 52 369399 : return MAL_SUCCEED; 53 : } 54 : 55 : #include "mel.h" 56 : mel_func projectionpath_init_funcs[] = { 57 : pattern("algebra", "projectionpath", ALGprojectionpath, false, "Routine to handle join paths. The type analysis is rather tricky.", args(1,2, batargany("",0),batvarargany("l",0))), 58 : { .imp=NULL } 59 : }; 60 : #include "mal_import.h" 61 : #ifdef _MSC_VER 62 : #undef read 63 : #pragma section(".CRT$XCU",read) 64 : #endif 65 257 : LIB_STARTUP_FUNC(init_projectionpath_mal) 66 257 : { mal_module("projectionpath", NULL, projectionpath_init_funcs); }