summaryrefslogtreecommitdiffstats
path: root/qlparser/qtbinaryinduce.cc
blob: 9f7b1ba2d668f19eab5d4148b4121ad473aa035c (plain)
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
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
/*
* 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, QtBinaryInduce: $Id: qtbinaryinduce.cc,v 1.47 2003/12/27 20:39:35 rasdev Exp $";

#include "raslib/rmdebug.hh"
#include "debug.hh"

#include "qlparser/qtbinaryinduce.hh"
#include "qlparser/qtatomicdata.hh"
#include "qlparser/qtcomplexdata.hh"
#include "qlparser/qtconst.hh"
#include "qlparser/qtstringdata.hh"

#include "mddmgr/mddobj.hh"

#include "catalogmgr/typefactory.hh"
#include "relcatalogif/mdddomaintype.hh"

#include "tilemgr/tile.hh"

#include <iostream>
#include <string>
#include <vector>
#include <memory>
using namespace std;

const QtNode::QtNodeType QtBinaryInduce::nodeType = QtNode::QT_BINARY_INDUCE;

QtBinaryInduce::QtBinaryInduce( QtOperation* initInput1, QtOperation* initInput2, Ops::OpType initOpType )
  :  QtBinaryOperation( initInput1, initInput2 ),
     opType( initOpType )
{
}



QtData*
QtBinaryInduce::computeOp( QtData* operand1, QtData* operand2 )
{
  RMDBCLASS( "QtBinaryInduce", "computeOp( QtData*, QtData* )", "qlparser", __FILE__, __LINE__ )

  QtData* returnValue = NULL;

  if     ( operand1->getDataType() == QT_MDD &&
           operand2->getDataType() == QT_MDD    )
  {
    QtMDD* mdd1 = (QtMDD*) operand1;
    QtMDD* mdd2 = (QtMDD*) operand2;

    const BaseType* resultBaseType = ((MDDBaseType*)(dataStreamType.getType()))->getBaseType();

    returnValue = computeBinaryMDDOp( mdd1, mdd2, resultBaseType );
  }
  else if( operand1->getDataType() == QT_MDD &&
           operand2->isScalarData()             )
  {
    QtMDD*        mdd    = (QtMDD*)        operand1;
    QtScalarData* scalar = (QtScalarData*) operand2;

    const BaseType* resultBaseType = ((MDDBaseType*)(dataStreamType.getType()))->getBaseType();

    returnValue = computeUnaryMDDOp( mdd, scalar, resultBaseType, 2 );
  }
  else if( operand1->isScalarData() &&
           operand2->getDataType() == QT_MDD  )
  {
    QtMDD*        mdd    = (QtMDD*)        operand2;
    QtScalarData* scalar = (QtScalarData*) operand1;

    const BaseType* resultBaseType = ((MDDBaseType*)(dataStreamType.getType()))->getBaseType();

    returnValue = computeUnaryMDDOp( mdd, scalar, resultBaseType, 1 );
  }
  else if( operand1->isScalarData() &&
           operand2->isScalarData()    )
  {
    QtScalarData* scalar1 = (QtScalarData*) operand1;
    QtScalarData* scalar2 = (QtScalarData*) operand2;

    BaseType* resultBaseType = (BaseType*)(dataStreamType.getType());

    returnValue = computeBinaryOp( scalar1, scalar2, resultBaseType );
  }
  else if( operand1->getDataType() == QT_STRING && operand2->getDataType() == QT_STRING )
  {
    // opType == Ops::OP_EQUAL 
    QtStringData* strObj1 = (QtStringData*) operand1;
    QtStringData* strObj2 = (QtStringData*) operand2;

    bool booleanResult = strObj1->getStringData() == strObj2->getStringData();

    returnValue = new QtAtomicData( booleanResult );
  }

  return returnValue;
}



QtData*
QtBinaryInduce::computeUnaryMDDOp( QtMDD* operand1, QtScalarData* operand2, const BaseType* resultBaseType, int scalarPos )
{
  RMDBCLASS( "QtBinaryInduce", "computeUnaryMDDOp( QtMDD*, QtScalarData*, BaseType*, int )", "qlparser", __FILE__, __LINE__ )

  QtData* returnValue = NULL;

  // get the MDD object
  MDDObj* op = operand1->getMDDObject();

  // create ULong type with QtIntData value
  const BaseType* constBaseType = operand2->getValueType();
  const char*     constValue    = operand2->getValueBuffer();

  //  get the area, where the operation has to be applied
  const r_Minterval &areaOp = operand1->getLoadDomain();

  // contains all tiles of the operand
  vector<Tile*>* allTiles=NULL;

  // iterator for tiles
  vector<Tile*>::iterator tileIt;

  // create MDDObj for result
  MDDDomainType* mddBaseType = new MDDDomainType( "tmp", resultBaseType, areaOp );
  TypeFactory::addTempType( mddBaseType );

  MDDObj* mddres = new MDDObj( mddBaseType, areaOp );

  // get all tiles in relevant area
	allTiles = op->intersect(areaOp);
	tileIt = allTiles->begin();
	//auto_ptr<BinaryOp> myOp(NULL);
	BinaryOp* myOp = NULL;
	if (tileIt != allTiles->end())
		{
		if (scalarPos == 1)
			//myOp.reset(Ops::getBinaryOp(opType, resultBaseType, constBaseType, (*tileIt)->getType()));
			myOp = (Ops::getBinaryOp(opType, resultBaseType, constBaseType, (*tileIt)->getType()));
		else
			//myOp.reset(Ops::getBinaryOp(opType, resultBaseType, (*tileIt)->getType(), constBaseType));
			myOp = (Ops::getBinaryOp(opType, resultBaseType, (*tileIt)->getType(), constBaseType));
		}
  // and iterate over them
  for( ; tileIt != allTiles->end(); tileIt++ )
  {
    // domain of the actual tile
    const r_Minterval &tileDom = (*tileIt)->getDomain();

    // domain of the relevant area of the actual tile
    r_Minterval intersectDom( tileDom.create_intersection( areaOp ) );

    // create tile for result
    Tile* resTile = new Tile( intersectDom, resultBaseType );

    //
    // carry out operation on the relevant area of the tiles
    //

    RMDBGIF( 4, RMDebug::module_qlparser, "QtScale", \
      char* typeStructure = resTile->getType()->getTypeStructure(); \
      RMDBGMIDDLE( 4, RMDebug::module_qlparser, "QtBinaryInduce", "  result tile, area " << intersectDom << \
                   ", type " << resTile->getType()->getTypeName() << \
 		   ", structure " << typeStructure << endl )  \
      free( typeStructure ); typeStructure=NULL; \
      \
      typeStructure = (*tileIt)->getType()->getTypeStructure(); \
      RMDBGMIDDLE( 4, RMDebug::module_qlparser, "QtBinaryInduce", "  operand1 tile, area " << intersectDom << \
                   ", type " << (*tileIt)->getType()->getTypeName() << \
  		   ", structure " << typeStructure << endl ) \
      free( typeStructure ); typeStructure=NULL; \

      typeStructure = constBaseType->getTypeStructure(); \
      RMDBGMIDDLE( 4, RMDebug::module_qlparser, "QtBinaryInduce", "  constant type " << constBaseType->getTypeName() << \
                   ", structure " << typeStructure << \
                   ", value " ) \
      free( typeStructure ); typeStructure=NULL; \
      \
      for( int x=0; x<constBaseType->getSize(); x++ ) \
        RMInit::dbgOut << hex << (int)(constValue[x]); \
      RMInit::dbgOut << dec << endl; \
    )

    RMDBGMIDDLE( 4, RMDebug::module_qlparser, "QtBinaryInduce", "  before execConstOp" << endl )

    resTile->execConstOp( myOp, intersectDom, (*tileIt), intersectDom, constValue, scalarPos );
    //resTile->execConstOp( opType, intersectDom, (*tileIt), intersectDom, constValue, constBaseType, scalarPos );
    RMDBGMIDDLE( 4, RMDebug::module_qlparser, "QtBinaryInduce", "  after execConstOp" << endl )

    // insert Tile in result tile
    mddres->insertTile( resTile );
  }
	delete myOp;
	myOp = NULL;

  // delete tile vector
  delete allTiles;
  allTiles=NULL;

  // create a new QtMDD object as carrier object for the transient MDD object
  returnValue = new QtMDD( (MDDObj*)mddres );

  // The following is now done, when the last reference is deleted.
  // delete the obsolete MDD object
  // delete op;

  return returnValue;
}



QtData*
QtBinaryInduce::computeBinaryMDDOp( QtMDD* operand1, QtMDD* operand2, const BaseType* resultBaseType )
{
  RMDBCLASS( "QtBinaryInduce", "computeBinaryMDDOp( QtMDD*, QtMDD*, BaseType* )", "qlparser", __FILE__, __LINE__ )

  QtData* returnValue = NULL;

  // get the MDD objects
  MDDObj* op1 = operand1->getMDDObject();
  MDDObj* op2 = operand2->getMDDObject();

  //  get the areas, where the operation has to be applied
  const r_Minterval &areaOp1 = operand1->getLoadDomain();
  const r_Minterval &areaOp2 = operand2->getLoadDomain();

  // Check, if the domains are compatible which means that they have the same
  // dimensionality and each dimension has the same number of elements.
  if( areaOp1.get_extent() == areaOp2.get_extent() )
  {
    // contains all tiles of op1
    vector<Tile*>* allTilesOp1=NULL;

    // contains all tiles of op2 which intersect a given op1 Tile in the relevant area.
    vector<Tile*>* intersectTilesOp2=NULL;

    // iterators for tiles of the MDDs
    vector<Tile*>::iterator tileOp1It;
    vector<Tile*>::iterator intersectTileOp2It;

    // intersection of domains in relevant area.
    r_Minterval intersectDom;

    // pointer to generated result tile
    Tile* resTile=NULL;

    // MDDObj for result
    MDDObj* mddres=NULL;

    // translations between the two areas
    r_Point offset12(areaOp1.dimension());
    r_Point offset21(areaOp1.dimension());

    // calculate translations
    r_Point originOp1 = areaOp1.get_origin();
    r_Point originOp2 = areaOp2.get_origin();
    for(r_Dimension i = 0; i<areaOp1.dimension(); i++)
    {
      offset12[i] = originOp2[i] - originOp1[i];
      offset21[i] = originOp1[i] - originOp2[i];
    }

    RMDBGMIDDLE( 4, RMDebug::module_qlparser, "QtBinaryInduce", "  Domain op1 " << areaOp1 << " op2 " << areaOp2 )
    RMDBGMIDDLE( 4, RMDebug::module_qlparser, "QtBinaryInduce", "  Translation vector " << offset12 )

    // create MDDObj for result
    MDDDomainType* mddBaseType = new MDDDomainType( "tmp", resultBaseType, areaOp1 );
    TypeFactory::addTempType( mddBaseType );

    mddres = new MDDObj( mddBaseType, areaOp1 );

    // get all tiles in relevant area of MDD op1
    allTilesOp1 = op1->intersect(areaOp1);

    //    cout << "INTERSECT" << areaOp1 << endl;
    //    for( tileOp1It = allTilesOp1->begin(); tileOp1It !=  allTilesOp1->end(); tileOp1It++ )
    //      cout << (*tileOp1It)->getDomain() << endl;

    // and iterate over them
	auto_ptr<BinaryOp> myOp(Ops::getBinaryOp(opType, mddBaseType->getBaseType(), op1->getCellType(), op2->getCellType()));
    for( tileOp1It = allTilesOp1->begin(); tileOp1It !=  allTilesOp1->end(); tileOp1It++ )
    {
      // domain of the op1 tile
      const r_Minterval &tileOp1Dom = (*tileOp1It)->getDomain();

      // relevant area of op1's domain
      r_Minterval intersectionTileOp1Dom( tileOp1Dom.create_intersection( areaOp1 ) );

      // intersect relevant area of the tile with MDD op2 (including translation)
      intersectTilesOp2 = op2->intersect(intersectionTileOp1Dom.create_translation(offset12));

      // cout << "INTERSECT" << tileOp1Dom.create_translation(offset12) << endl;
      //    for( intersectTileOp2It = intersectTilesOp2->begin();
      //         intersectTileOp2It !=  intersectTilesOp2->end();
      //         intersectTileOp2It++ )
      //      cout << (*intersectTileOp2It)->getDomain() << endl;

      // iterate over intersecting tiles
      for( intersectTileOp2It  = intersectTilesOp2->begin();
           intersectTileOp2It != intersectTilesOp2->end();
           intersectTileOp2It++ )
      {
        const r_Minterval &tileOp2Dom = (*intersectTileOp2It)->getDomain();

        // the relevant domain is the intersection of the
        // domains of the two tiles with the relevant area.
        intersectDom = tileOp1Dom.create_intersection(tileOp2Dom.create_translation(offset21));

        intersectDom.intersection_with(areaOp1);

        // create tile for result
        resTile = new Tile( intersectDom, resultBaseType );

        //
        // carry out operation on the relevant area of the tiles
        //

        RMDBGMIDDLE( 4, RMDebug::module_qlparser, "QtBinaryInduce", "  before execBinaryOp" << endl )
        RMDBGMIDDLE( 4, RMDebug::module_qlparser, "QtBinaryInduce", "  result tile, area " << intersectDom <<
                     ", type " << resTile->getType()->getTypeName() << endl )
        RMDBGMIDDLE( 4, RMDebug::module_qlparser, "QtBinaryInduce", "  operand1 tile, area " << intersectDom <<
                     ", type " << (*tileOp1It)->getType()->getTypeName() << endl )
        RMDBGMIDDLE( 4, RMDebug::module_qlparser, "QtBinaryInduce", "  operand2 tile, type " << (*tileOp1It)->getType()->getTypeName() << endl )
	resTile->execBinaryOp(&(*myOp), intersectDom, (*tileOp1It), intersectDom, (*intersectTileOp2It), intersectDom.create_translation(offset12));
        RMDBGMIDDLE( 4, RMDebug::module_qlparser, "QtBinaryInduce", "  after execBinaryOp" << endl )

        // insert Tile in result mddobj
        mddres->insertTile( resTile );
      }

      delete intersectTilesOp2;
      intersectTilesOp2=NULL;
    }

    delete allTilesOp1;
    allTilesOp1=NULL;

    // create a new QtMDD object as carrier object for the transient MDD object
    returnValue = new QtMDD( (MDDObj*)mddres );
  }
  else
  {
    RMInit::logOut << "Error: QtBinaryInduce::computeBinaryMDDOp() - domains of the operands are incompatible." << endl;
    RMInit::logOut << "areaOp1 " << areaOp1 << " with extent " << areaOp1.get_extent() << endl;
    RMInit::logOut << "areaOp2 " << areaOp2 << " with extent " << areaOp2.get_extent() << endl;
    
    parseInfo.setErrorNo(351);
    throw parseInfo;
  }

  // The following is now done, when the last reference is deleted.
  // delete obsolete MDD objects
  //  delete op1;
  //  delete op2;

  return returnValue;
}



QtData*
QtBinaryInduce::computeBinaryOp( QtScalarData* operand1, QtScalarData* operand2, const BaseType* resultBaseType )
{
  RMDBCLASS( "QtBinaryInduce", "computeBinaryOp( QtScalarData*, QtScalarData*, BaseType*, Ops::OpType )", "qlparser", __FILE__, __LINE__ )

  QtScalarData* scalarDataObj = NULL;

  // allocate memory for the result
  char* resultBuffer = new char[ resultBaseType->getSize() ];

  Ops::execBinaryConstOp( opType, resultBaseType, 
                          operand1->getValueType(),   operand2->getValueType(),
                          resultBuffer, 
                          operand1->getValueBuffer(), operand2->getValueBuffer() );

  if( resultBaseType->getType() == STRUCT )
    scalarDataObj = new QtComplexData();
  else
    scalarDataObj = new QtAtomicData();

  scalarDataObj->setValueType  ( resultBaseType );
  scalarDataObj->setValueBuffer( resultBuffer );

  return scalarDataObj;
}



QtData*
QtBinaryInduce::evaluate( QtDataList* inputList )
{
  QtData* returnValue = NULL;
  QtData* operand1 = NULL;
  QtData* operand2 = NULL;

  if( getOperands( inputList, operand1, operand2 ) )
  {
    returnValue = computeOp( operand1, operand2 );

    // delete the old operands
    if( operand1 ) operand1->deleteRef();
    if( operand2 ) operand2->deleteRef();
  }
  return returnValue;
}



const QtTypeElement&
QtBinaryInduce::checkType( QtTypeTuple* typeTuple )
{
  RMDBCLASS( "QtBinaryInduce", "checkType( QtTypeTuple* )", "qlparser", __FILE__, __LINE__ )

  dataStreamType.setDataType( QT_TYPE_UNKNOWN );  

  // check operand branches
  if( input1 && input2 )
  {

  // get input types
  const QtTypeElement& inputType1 = input1->checkType( typeTuple ); 
  const QtTypeElement& inputType2 = input2->checkType( typeTuple ); 

  RMDBGIF( 1, RMDebug::module_qlparser, "QtBinaryInduce", \
    RMInit::dbgOut << "Operand 1: " << flush; \
    inputType1.printStatus( RMInit::dbgOut ); \
    RMInit::dbgOut << endl; \
    \
    RMInit::dbgOut << "Operand 2: " << flush; \
    inputType2.printStatus( RMInit::dbgOut ); \
    RMInit::dbgOut << endl; \
    \
    RMDBGMIDDLE( 4, RMDebug::module_qlparser, "QtBinaryInduce", "Operation            " << opType ) \
  )

  if( inputType1.getDataType() == QT_MDD && 
      inputType2.getDataType() == QT_MDD    )
  {
    const BaseType* baseType1 = ((MDDBaseType*)(inputType1.getType()))->getBaseType();
    const BaseType* baseType2 = ((MDDBaseType*)(inputType2.getType()))->getBaseType();

    const BaseType* resultBaseType = Ops::getResultType( opType, baseType1, baseType2 );

    if( !resultBaseType )
    {
      RMInit::logOut << "Error: QtBinaryInduce::checkType() - binary induce (MDD + MDD): operand types are incompatible." << endl;
      parseInfo.setErrorNo(363);
      throw parseInfo;
    }

    MDDBaseType* resultMDDType = new MDDBaseType( "tmp", resultBaseType );
    TypeFactory::addTempType( resultMDDType );

    dataStreamType.setType( resultMDDType );    
  }
  else if( inputType1.getDataType() == QT_MDD && 
           inputType2.isBaseType() )
  {
    const BaseType* baseType1 = ((MDDBaseType*)(inputType1.getType()))->getBaseType();
    BaseType* baseType2 = (BaseType*)(inputType2.getType());

    const BaseType* resultBaseType = Ops::getResultType( opType, baseType1, baseType2 );

    if( !resultBaseType )
    {
      RMInit::logOut << "Error: QtBinaryInduce::checkType() - unary induce (MDD + BaseType): operand types are incompatible." << endl;
      parseInfo.setErrorNo(364);
      throw parseInfo;
    }

    MDDBaseType* resultMDDType = new MDDBaseType( "tmp", resultBaseType );
    TypeFactory::addTempType( resultMDDType );

    dataStreamType.setType( resultMDDType );    
  }
  else if( inputType1.isBaseType() &&
           inputType2.getDataType() == QT_MDD )
  {
    BaseType* baseType1 = (BaseType*)(inputType1.getType());
    const BaseType* baseType2 = ((MDDBaseType*)(inputType2.getType()))->getBaseType();

    const BaseType* resultBaseType = Ops::getResultType( opType, baseType1, baseType2 );

    if( !resultBaseType )
    {
      RMInit::logOut << "Error: QtBinaryInduce::checkType() - unary induce (BaseType + MDD): operand types are incompatible." << endl;
      parseInfo.setErrorNo(364);
      throw parseInfo;
    }

    MDDBaseType* resultMDDType = new MDDBaseType( "tmp", resultBaseType );
    TypeFactory::addTempType( resultMDDType );

    dataStreamType.setType( resultMDDType );    
  }
  else if( inputType1.isBaseType() && 
           inputType2.isBaseType() )
  {
    BaseType* baseType1 = (BaseType*)(inputType1.getType());
    BaseType* baseType2 = (BaseType*)(inputType2.getType());

    const BaseType* resultBaseType = Ops::getResultType( opType, baseType1, baseType2 );

    if( !resultBaseType )
    {
      RMInit::logOut << "Error: QtBinaryInduce::checkType() - BaseType + BaseType : operand types are incompatible." << endl;

      parseInfo.setErrorNo(365);
      throw parseInfo;
    }

    dataStreamType.setType( resultBaseType );    
  }
  else if( inputType1.getDataType() == QT_STRING && 
           inputType2.getDataType() == QT_STRING    )
  {
    if( opType != Ops::OP_EQUAL )
    {
      RMInit::logOut << "Error: QtBinaryInduce::checkType() - String + String : operation is not supported on strings." << endl;
      parseInfo.setErrorNo(385);
      throw parseInfo;
    }

    dataStreamType.setDataType( QT_BOOL );
  }
  else
  {
    RMInit::logOut << "Error: QtBinaryInduce::checkType() - operation is not supported on these data types." << endl;
    parseInfo.setErrorNo(403);
    throw parseInfo;
  }
  }
  else
    RMInit::logOut << "Error: QtBinaryInduce::checkType() - operand branch invalid." << endl;

  return dataStreamType;
}



const QtNode::QtNodeType QtPlus::nodeType = QT_PLUS;

QtPlus::QtPlus( QtOperation* initInput1, QtOperation* initInput2 )
  : QtBinaryInduce( initInput1, initInput2, Ops::OP_PLUS )
{
}


/*
void
QtPlus::rewriteOps()
{
  RMDBCLASS( "QtPlus", "rewriteOps()", "qlparser", __FILE__, __LINE__ )

  if( input1 && input2 )
  {
    if( nodeType == input2->getNodeType() )
    {
      // changed from log to debug output -- PB 2003-nov-20
      RMDBGMIDDLE( 1, RMDebug::module_qlparser, "QtPlus", "rewriteOps: rule (left deep tree): A+(B+C) -> (B+C)+A" );

      // more than one equal binary operator, make standard form of the tree

      QtBinaryOperation* nodeR = (QtBinaryOperation*) input2;
      QtOperation* nodeRL = nodeR->getInput1();

      getParent()->setInput( this, nodeR );
      nodeR->setInput1( this );
      this->setInput2( nodeRL );
      nodeR->rewriteOps();
    }
    else
    {
      input1->rewriteOps();
      input2->rewriteOps();
    }
  }
  else
    RMInit::logOut << "Error: QtPlus::rewriteOps() - the operand branch is invalid." << endl;
}
*/

/*
void
QtPlus::sortAssociativeOps()
{
  ENTER( "QtPlus::sortAssociativeOps() -- input1 is " << (input1?"not null":"null") << ", input 2 is " << (input2?"not null":"null") );

  if( input1 && input2 )
  {
    if( nodeType == input1->getNodeType() )
    {
      // associative law is applicable

      QtOperation* node = input1->getUniqueOrder( nodeType );

      if( node && node->getSpelling().compare( input2->getSpelling() ) > 0 )
      {
        node->getParent()->setInput( node, input2 );
        setInput2( node );
      }
    }
    else
    {
      bool compare = ( input1->getSpelling().compare( input2->getSpelling() ) > 0 );
      TALK( "QtPlus::sortAssociativeOps(): compare -> " << compare );
      if( compare )
      {
        // changed from log to debug output -- PB 2003-nov-20
        RMDBGMIDDLE( 1, RMDebug::module_qlparser, "QtPlus", "sortAssociativeOps: applying rule 'associativity'" );

        QtOperation* node = input1;

        setInput1( input2 );
        setInput2( node );
      };

    };

    input1->sortAssociativeOps();
  }
  else
    RMInit::logOut << "Error: QtPlus::sortAssociativeOps() - the operand branch is invalid." << endl;

  LEAVE( "QtPlus::sortAssociativeOps()" );
}
*/


QtOperation*
QtPlus::getUniqueOrder( const QtNode::QtNodeType ID )
{
  RMDBCLASS( "QtPlus", "getUniqueOrder( const QtNode::QtNodeType )", "qlparser", __FILE__, __LINE__ )

  QtOperation* returnValue = NULL;

  if( nodeType == ID )
  {
    QtOperation* node = input1->getUniqueOrder( nodeType );

    if( node )
    {
      if( ( node->getSpelling().compare( input2->getSpelling() ) ) > 0 )
        returnValue = node;
      else
        returnValue = input2;
    }
    else
      RMInit::logOut << "Error: QtMult::getUniqueOrder(): Query tree invalid" << endl;
  }
  else
    returnValue = this;

  return returnValue;
}



void
QtPlus::printTree( int tab, ostream& s, QtChildType mode )
{
  s << SPACE_STR(tab).c_str() << "QtPlus Object " << getNodeType() << endl;

  QtBinaryInduce::printTree( tab, s, mode );
}



void
QtPlus::printAlgebraicExpression( ostream& s )
{
  s << "(";

  if( input1 )
    input1->printAlgebraicExpression( s );
  else
    s << "<nn>";

  s << " + ";

  if( input2 )
    input2->printAlgebraicExpression( s );
  else
    s << "<nn>";

  s << ")";
}



const QtNode::QtNodeType QtMinus::nodeType = QT_MINUS;

QtMinus::QtMinus( QtOperation* initInput1, QtOperation* initInput2 )
  :  QtBinaryInduce( initInput1, initInput2, Ops::OP_MINUS )
{
}



bool
QtMinus::isCommutative() const
{
  return false; // NOT commutative
}



void
QtMinus::printTree( int tab, ostream& s, QtChildType mode )
{
  s << SPACE_STR(tab).c_str() << "QtMinus Object " << getNodeType() << endl;

  QtBinaryInduce::printTree( tab, s, mode );
}



void
QtMinus::printAlgebraicExpression( ostream& s )
{
  s << "(";

  if( input1 )
    input1->printAlgebraicExpression( s );
  else
    s << "<nn>";

  s << " - ";

  if( input2 )
    input2->printAlgebraicExpression( s );
  else
    s << "<nn>";

  s << ")";
}




const QtNode::QtNodeType QtMult::nodeType = QT_MULT;

QtMult::QtMult( QtOperation* initInput1, QtOperation* initInput2 )
  :  QtBinaryInduce( initInput1, initInput2, Ops::OP_MULT )
{
}


/*
void
QtMult::rewriteOps()
{
  RMDBCLASS( "QtMult", "rewriteOps()", "qlparser", __FILE__, __LINE__ )

  if( input1 && input2 )
  {
    if( nodeType == input2->getNodeType() )
    {
      RMInit::logOut << "> rule (left deep tree): A*(B*C) -> (B*C)*A" << endl;

      // more than one equal binary operator, make standard form of the tree

      QtBinaryOperation* nodeR = (QtBinaryOperation*) input2;
      QtOperation* nodeRL = nodeR->getInput1();

      getParent()->setInput( this, nodeR );
      nodeR->setInput1( this );
      this->setInput2( nodeRL );
      nodeR->rewriteOps();
    }
    else
    {
      input1->rewriteOps();
      input2->rewriteOps();
    }
  }
  else
    RMInit::logOut << "Error: QtMult::rewriteOps() - the operand branch is invalid." << endl;
}
*/

/*
void
QtMult::sortAssociativeOps()
{
  RMDBCLASS( "QtMult", "sortAssociativeOps()", "qlparser", __FILE__, __LINE__ )

  if( input1 && input2 )
  {
    if( nodeType == input1->getNodeType() )
    {
      // associative law is applicable

      QtOperation* node = input1->getUniqueOrder( nodeType );

      if( node && node->getSpelling().compare( input2->getSpelling() ) > 0 )
      {
        node->getParent()->setInput( node, input2 );
        setInput2( node );
      };
    }
    else
    {
      if( input1->getSpelling().compare( input2->getSpelling() ) > 0 )
      {
        RMDBGMIDDLE( 1, RMDebug::module_qlparser, "QtMult", "sortAssociativeOps: rule (associativity): A * B -> B * A" );

        QtOperation* node = input1;

        setInput1( input2 );
        setInput2( node );
      };
    }

    input1->sortAssociativeOps();
  }
  else
    RMInit::logOut << "Error: QtMult::sortAssociativeOps() - the operand branch is invalid." << endl;
}
*/


QtOperation*
QtMult::getUniqueOrder( const QtNode::QtNodeType ID )
{
  RMDBCLASS( "QtMult", "getUniqueOrder( const string )", "qlparser", __FILE__, __LINE__ )

  QtOperation* returnValue = NULL;

  if( nodeType == ID )
  {
    QtOperation* node = input1->getUniqueOrder( nodeType );

    if( node )
    {
      if( node->getSpelling().compare( input2->getSpelling() ) > 0 )
        returnValue = node;
      else
        returnValue = input2;
    }
    else
      RMInit::logOut << "Error: QtMult::getUniqueOrder(): Query tree invalid" << endl;
  }
  else
    returnValue = this;

  return returnValue;
}



void
QtMult::printTree( int tab, ostream& s, QtChildType mode )
{
  s << SPACE_STR(tab).c_str() << "QtMult Object " << getNodeType() << endl;

  QtBinaryInduce::printTree( tab, s, mode );
}



void
QtMult::printAlgebraicExpression( ostream& s )
{
  s << "(";

  if( input1 )
    input1->printAlgebraicExpression( s );
  else
    s << "<nn>";

  s << " * ";

  if( input2 )
    input2->printAlgebraicExpression( s );
  else
    s << "<nn>";

  s << ")";
}



const QtNode::QtNodeType QtDiv::nodeType = QT_DIV;

QtDiv::QtDiv( QtOperation* initInput1, QtOperation* initInput2 )
  :  QtBinaryInduce( initInput1, initInput2, Ops::OP_DIV )
{
}



bool
QtDiv::isCommutative() const
{
  return false; // NOT commutative
}



void
QtDiv::printTree( int tab, ostream& s, QtChildType mode )
{
  s << SPACE_STR(tab).c_str() << "QtDiv Object " << getNodeType() << endl;

  QtBinaryInduce::printTree( tab, s, mode );
}



void
QtDiv::printAlgebraicExpression( ostream& s )
{
  s << "(";

  if( input1 )
    input1->printAlgebraicExpression( s );
  else
    s << "<nn>";

  s << " / ";

  if( input2 )
    input2->printAlgebraicExpression( s );
  else
    s << "<nn>";

  s << ")";
}