1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
|
/*
* This file is part of rasdaman community.
*
* Rasdaman community is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rasdaman community is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
rasdaman GmbH.
*
* For more information please see <http://www.rasdaman.org>
* or contact Peter Baumann via <baumann@rasdaman.com>.
*/
/*************************************************************
*
*
* PURPOSE:
*
*
* COMMENTS:
*
************************************************************/
static const char rcsid[] = "@(#)qlparser, QtCondenseOp: $Header: /home/rasdev/CVS-repository/rasdaman/qlparser/qtcondenseop.cc,v 1.18 2003/12/27 20:51:28 rasdev Exp $";
#include "raslib/rmdebug.hh"
#include "qlparser/qtcondenseop.hh"
#include "qlparser/qtdata.hh"
#include "qlparser/qtmdd.hh"
#include "qlparser/qtpointdata.hh"
#include "qlparser/qtmintervaldata.hh"
#include "qlparser/qtatomicdata.hh"
#include "qlparser/qtcomplexdata.hh"
#include "mddmgr/mddobj.hh"
#include "catalogmgr/typefactory.hh"
#include "catalogmgr/algebraops.hh"
#include <iostream>
#ifndef CPPSTDLIB
#include <ospace/string.h> // STL<ToolKit>
#else
#include <string>
using namespace std;
#endif
const QtNode::QtNodeType QtCondenseOp::nodeType = QT_CONDENSEOP;
QtCondenseOp::QtCondenseOp( Ops::OpType newOperation,
const string &initIteratorName,
QtOperation* mintervalExp,
QtOperation* cellExp,
QtOperation* condExp )
: operation( newOperation ),
iteratorName( initIteratorName ),
QtBinaryOperation( mintervalExp, cellExp ),
condOp( condExp )
{
}
QtCondenseOp::~QtCondenseOp()
{
if( condOp )
{
delete condOp;
condOp=NULL;
}
}
QtNode::QtNodeList*
QtCondenseOp::getChilds( QtChildType flag )
{
RMDBCLASS( "QtCondenseOp", "getChilds( QtChildType )", "qlparser", __FILE__, __LINE__ )
QtNodeList* resultList;
resultList = QtBinaryOperation::getChilds( flag );
if( condOp )
{
if( flag == QT_LEAF_NODES || flag == QT_ALL_NODES )
{
QtNodeList* subList=NULL;
subList = condOp->getChilds( flag );
// remove all elements in subList and insert them at the beginning in resultList
resultList->splice( resultList->begin(), *subList );
// delete temporary subList
delete subList;
subList=NULL;
}
// add the nodes of the current level
if( flag == QT_DIRECT_CHILDS || flag == QT_ALL_NODES )
resultList->push_back( condOp );
}
return resultList;
}
bool
QtCondenseOp::equalMeaning( QtNode* node )
{
RMDBCLASS( "QtCondenseOp", "equalMeaning( QtNode* )", "qlparser", __FILE__, __LINE__ )
bool result = false;
if( nodeType == node->getNodeType() )
{
QtCondenseOp* condNode;
condNode = (QtCondenseOp*) node; // by force
// check domain and cell expression
result = QtBinaryOperation::equalMeaning( condNode );
// check condition expression
result &= ( !condOp && !condNode->getCondOp() ) ||
condOp->equalMeaning( condNode->getCondOp() );
};
return ( result );
}
string
QtCondenseOp::getSpelling()
{
char tempStr[20];
sprintf(tempStr, "%ud", (unsigned long)getNodeType());
string result = string(tempStr);
result.append( "(" );
result.append( QtBinaryOperation::getSpelling() );
result.append( "," );
if( condOp )
result.append( condOp->getSpelling() );
else
result.append( "<nn>" );
result.append( ")" );
return result;
}
void
QtCondenseOp::setInput( QtOperation* inputOld, QtOperation* inputNew )
{
QtBinaryOperation::setInput( inputOld, inputNew );
if( condOp == inputOld )
{
condOp = inputNew;
if( inputNew )
inputNew->setParent( this );
}
};
void
QtCondenseOp::optimizeLoad( QtTrimList* trimList )
{
RMDBCLASS( "QtCondenseOp", "optimizeLoad( QtTrimList* )", "qlparser", __FILE__, __LINE__ )
// delete the trimList and optimize subtrees
// release( trimList->begin(), trimList->end() );
for( QtNode::QtTrimList::iterator iter=trimList->begin(); iter!=trimList->end(); iter++ )
{
delete *iter;
*iter=NULL;
}
delete trimList;
trimList=NULL;
QtBinaryOperation::optimizeLoad( new QtNode::QtTrimList() );
if( condOp )
condOp->optimizeLoad( new QtNode::QtTrimList() );
}
void
QtCondenseOp::simplify()
{
RMDBCLASS( "QtCondenseOp", "simplify()", "qlparser", __FILE__, __LINE__ )
RMDBGMIDDLE(1, RMDebug::module_qlparser, "QtCondenseOp", "simplify() warning: QtCondenseOp itself is not simplified yet")
// Default method for all classes that have no implementation.
// Method is used bottom up.
QtNodeList* resultList=NULL;
QtNodeList::iterator iter;
resultList = getChilds( QT_DIRECT_CHILDS );
for( iter=resultList->begin(); iter!=resultList->end(); iter++ )
(*iter)->simplify();
delete resultList;
resultList=NULL;
}
bool
QtCondenseOp::isCommutative() const
{
return false; // NOT commutative
}
QtData*
QtCondenseOp::evaluate( QtDataList* inputList )
{
RMDBCLASS( "QtCondenseOp", "evaluate( QtDataList* )", "qlparser", __FILE__, __LINE__ )
QtData* returnValue = NULL;
QtData* operand1 = NULL;
if( getOperand( inputList, operand1, 1 ) )
{
#ifdef QT_RUNTIME_TYPE_CHECK
if( operand1->getDataType() != QT_MINTERVAL )
RMInit::logOut << "Internal error in QtMarrayOp::evaluate() - "
<< "runtime type checking failed (Minterval)." << endl;
// delete old operand
if( operand1 ) operand1->deleteRef();
return 0;
}
#endif
r_Minterval domain = ((QtMintervalData*)operand1)->getMintervalData();
RMDBGMIDDLE(1, RMDebug::module_qlparser, "QtCondenseOp", "Marray domain " << domain)
// determine aggregation type
BaseType* cellType = (BaseType*) input2->getDataStreamType().getType();
// get operation object
BinaryOp* cellBinOp = Ops::getBinaryOp( operation, cellType, cellType, cellType );
// create execution object QLCondenseOp
QLCondenseOp* qlCondenseOp = new QLCondenseOp( input2, condOp, inputList, iteratorName,
cellType, 0, cellBinOp );
// result buffer
char* result=NULL;
try
{
// execute query engine marray operation
result = Tile::execGenCondenseOp( qlCondenseOp, domain );
}
catch(...)
{
// free ressources
delete qlCondenseOp;
qlCondenseOp=NULL;
delete cellBinOp;
cellBinOp=NULL;
if( operand1 ) operand1->deleteRef();
throw;
}
// allocate cell buffer
char* resultBuffer = new char[ cellType->getSize() ];
// copy cell content
memcpy( (void*)resultBuffer, (void*)result, cellType->getSize() );
delete qlCondenseOp;
qlCondenseOp=NULL;
delete cellBinOp;
cellBinOp=NULL;
// create data object for the cell
QtScalarData* scalarDataObj = NULL;
if( cellType->getType() == STRUCT )
scalarDataObj = new QtComplexData();
else
scalarDataObj = new QtAtomicData();
scalarDataObj->setValueType ( cellType );
scalarDataObj->setValueBuffer( resultBuffer );
// set return data object
returnValue = scalarDataObj;
// delete old operands
if( operand1 ) operand1->deleteRef();
}
return returnValue;
}
void
QtCondenseOp::printTree( int tab, ostream& s, QtChildType mode )
{
s << SPACE_STR(tab).c_str() << "QtCondenseOp Object " << getNodeType() << endl;
s << SPACE_STR(tab).c_str() << "Iterator Name: " << iteratorName.c_str() << endl;
QtBinaryOperation::printTree( tab, s, mode );
}
void
QtCondenseOp::printAlgebraicExpression( ostream& s )
{
s << "(";
s << iteratorName.c_str() << ",";
if( input1 )
input1->printAlgebraicExpression( s );
else
s << "<nn>";
s << ",";
if( input2 )
input2->printAlgebraicExpression( s );
else
s << "<nn>";
s << ")";
}
const QtTypeElement&
QtCondenseOp::checkType( QtTypeTuple* typeTuple )
{
RMDBCLASS( "QtCondenseOp", "checkType( QtTypeTuple* )", "qlparser", __FILE__, __LINE__ )
dataStreamType.setDataType( QT_TYPE_UNKNOWN );
// check operand branches
if( input1 && input2 )
{
// check domain expression
const QtTypeElement& domainExp = input1->checkType( typeTuple );
if( domainExp.getDataType() != QT_MINTERVAL )
{
RMInit::logOut << "Error: QtMarrayOp::checkType() - Can not evaluate domain expression to an minterval" << endl;
parseInfo.setErrorNo(401);
throw parseInfo;
}
// add domain iterator to the list of bounded variables
bool newList = false;
if( !typeTuple )
{
typeTuple = new QtTypeTuple();
newList = true;
}
typeTuple->tuple.push_back( QtTypeElement( QT_POINT, iteratorName.c_str() ) );
//
// check value expression
//
// get value expression type
const QtTypeElement& valueExp = input2->checkType( typeTuple );
// check type
if( valueExp.getDataType() != QT_BOOL && valueExp.getDataType() != QT_COMPLEX &&
valueExp.getDataType() != QT_CHAR && valueExp.getDataType() != QT_OCTET &&
valueExp.getDataType() != QT_USHORT && valueExp.getDataType() != QT_SHORT &&
valueExp.getDataType() != QT_ULONG && valueExp.getDataType() != QT_LONG &&
valueExp.getDataType() != QT_FLOAT && valueExp.getDataType() != QT_DOUBLE )
{
RMInit::logOut << "Error: QtMarrayOp::checkType() - Value expression must be either of type atomic or complex" << endl;
parseInfo.setErrorNo(412);
throw parseInfo;
}
dataStreamType = valueExp;
//
// check condition expression
//
if( condOp )
{
// get value expression type
const QtTypeElement& condExp = condOp->checkType( typeTuple );
// check type
if( condExp.getDataType() != QT_BOOL )
{
RMInit::logOut << "Error: QtMarrayOp::checkType() - Condition expression must be of type boolean" << endl;
parseInfo.setErrorNo(413);
throw parseInfo;
}
}
// remove iterator again
typeTuple->tuple.pop_back();
if( newList )
{
delete typeTuple;
typeTuple = NULL;
}
}
else
RMInit::logOut << "Error: QtCondenseOp::checkType() - operand branch invalid." << endl;
return dataStreamType;
}
|