LCOV - code coverage report
Current view: top level - monetdb5/optimizer - opt_json.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 49 0.0 %
Date: 2021-10-13 02:24:04 Functions: 0 1 0.0 %

          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             : /*
      10             :  * This simple module replaces the SQL rendering with a JSON rendering
      11             :  * Can be called after dataflow optimizer. The result appears as a string
      12             :  * in the calling environment.
      13             :  */
      14             : #include "monetdb_config.h"
      15             : #include "mal_builder.h"
      16             : #include "opt_json.h"
      17             : 
      18             : str
      19           0 : OPTjsonImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
      20             : {
      21             :         int i, j, limit, slimit;
      22             :         int bu = 0, br = 0, bj = 0;
      23             :         str nme;
      24             :         InstrPtr p,q;
      25             :         int actions = 0;
      26             :         InstrPtr *old;
      27             :         str msg = MAL_SUCCEED;
      28             : 
      29             :         (void) cntxt;
      30             :         (void) stk;             /* to fool compilers */
      31           0 :         old= mb->stmt;
      32           0 :         limit= mb->stop;
      33           0 :         slimit = mb->ssize;
      34           0 :         if ( newMalBlkStmt(mb,mb->stop) < 0)
      35           0 :                 throw(MAL,"optimizer.json", SQLSTATE(HY013) MAL_MALLOC_FAIL);
      36             : 
      37           0 :         for (i = 0; i < limit; i++) {
      38           0 :                 p = old[i];
      39           0 :                 if( getModuleId(p) == sqlRef  && getFunctionId(p) == affectedRowsRef) {
      40           0 :                         q = newInstruction(0, jsonRef, resultSetRef);
      41           0 :                         q = addArgument(mb, q, bu);
      42           0 :                         q = addArgument(mb, q, br);
      43           0 :                         q = addArgument(mb, q, bj);
      44           0 :                         pushInstruction(mb,q);
      45           0 :                         j = getArg(q,0);
      46           0 :                         p= getInstrPtr(mb,0);
      47           0 :                         setDestVar(q, newTmpVariable(mb, TYPE_str));
      48           0 :                         pushInstruction(mb,p);
      49           0 :                         q = newInstruction(0, NULL, NULL);
      50           0 :                         q->barrier = RETURNsymbol;
      51           0 :                         getArg(q,0)= getArg(p,0);
      52           0 :                         q = addArgument(mb,q,j);
      53           0 :                         pushInstruction(mb,q);
      54           0 :                         actions++;
      55           0 :                         continue;
      56             :                 }
      57           0 :                 if( getModuleId(p) == sqlRef  && getFunctionId(p) == rsColumnRef) {
      58           0 :                         nme = getVarConstant(mb,getArg(p,4)).val.sval;
      59           0 :                         if (strcmp(nme,"uuid")==0)
      60           0 :                                 bu = getArg(p,7);
      61           0 :                         if (strcmp(nme,"lng")==0)
      62           0 :                                 br = getArg(p,7);
      63           0 :                         if (strcmp(nme,"json")==0)
      64           0 :                                 bj = getArg(p,7);
      65           0 :                         freeInstruction(p);
      66           0 :                         actions++;
      67           0 :                         continue;
      68             :                 }
      69           0 :                 pushInstruction(mb,p);
      70             :         }
      71           0 :         for(; i<slimit; i++)
      72           0 :                 if (old[i])
      73           0 :                         pushInstruction(mb, old[i]);
      74           0 :         GDKfree(old);
      75             :         /* Defense line against incorrect plans */
      76           0 :         if( actions > 0){
      77           0 :                 msg = chkTypes(cntxt->usermodule, mb, FALSE);
      78           0 :                 if (!msg)
      79           0 :                         msg = chkFlow(mb);
      80           0 :                 if (!msg)
      81           0 :                         msg = chkDeclarations(mb);
      82             :         }
      83             :         /* keep actions taken as a fake argument*/
      84           0 :         (void) pushInt(mb, pci, actions);
      85           0 :         return msg;
      86             : }

Generated by: LCOV version 1.14