Opened 5 years ago

Closed 5 years ago

#2172 closed defect (fixed)

overlay of scalar and array causes segfault

Reported by: Dimitar Misev Owned by: apercov
Priority: major Milestone: 10.0
Component: qlparser Version: 9.8
Keywords: Cc:
Complexity: Medium

Description

To reproduce:

rasql -q 'SELECT { 13c, 115c, 212c } overlay <[0:1] true, false>' --out file

stacktrace:

 [1] ??:0
 [2] relcatalogif/type.C:102 in Type::getType() const
     > 102:     return myType;
 [3] catalogmgr/ops.cc:298 in Ops::getBinaryOp(Ops::OpType, BaseType const*, BaseType const*, BaseType const*, unsigned long, unsigned long, unsigned long, bool)
     > 298:     const auto typeRes = resType->getType();
 [4] catalogmgr/ops.cc:923 in Ops::isApplicable(Ops::OpType, BaseType const*, BaseType const*)
     > 923:         myBinaryOp = getBinaryOp(op, resType, const_cast<BaseType *>(op1Type), const_cast<BaseType *>(op2Type));
 [5] catalogmgr/ops.cc:1358 in Ops::isApplicableOnStructConst(Ops::OpType, BaseType const*, BaseType const*)
     > 1358:         if (!isApplicable(op, myStructType->getElemType(i), op2Type))
 [6] catalogmgr/ops.cc:670 in Ops::getBinaryOp(Ops::OpType, BaseType const*, BaseType const*, BaseType const*, unsigned long, unsigned long, unsigned long, bool)
     > 670:             if (op >= OP_MINUS && op <= OP_CONSTRUCT_COMPLEX && isApplicableOnStructConst(op, op2Type, op1Type))
 [7] qlparser/qtbinaryinduce.cc:186 in QtBinaryInduce::computeUnaryMDDOp(QtMDD*, QtScalarData*, BaseType const*, int)
     > 186:         myOp = (Ops::getBinaryOp(opType, resultBaseType, op->getCellType(), constBaseType));
 [8] qlparser/qtbinaryinduce.cc:92 in QtBinaryInduce::computeOp(QtData*, QtData*)
     > 92:             returnValue = computeUnaryMDDOp(mdd, scalar, resultBaseType, 2);
 [9] qlparser/qtbinaryinduce.cc:496 in QtBinaryInduce::evaluate(std::vector<QtData*, std::allocator<QtData*> >*)
     > 496:         returnValue = computeOp(operand1, operand2);
[10] qlparser/qtoperationiterator.cc:252 in QtOperationIterator::next()
     > 252:                     (*resultList)[pos] = op->evaluate(nextTuple.get());
[11] qlparser/querytree.cc:168 in QueryTree::evaluateRetrieval()
     > 168:             while ((dataList = oncRootNode->next()))
...

Change History (9)

comment:1 by Dimitar Misev, 5 years ago

Another segfault: SELECT not 3.1415927f

comment:2 by apercov, 5 years ago

Status: newaccepted

comment:3 by apercov, 5 years ago

I checked the problem. It seems that the segmentation fault is received because we do not return result type in ops, and later try to access it. We receive 0 as result type, when we are trying to find because the code attempts to do overlay while counting op1Type as Bool and op2Type as CHAR, however they are not compatible to each other (only Char and Bool are (this order)). In that case code returns structResultType. However, none of the ops is struct.

if (op == OP_OVERLAY)
    {
        if (op1->compatibleWith(op2))
        {
            return op1;
        }
        else
        {
            return getStructResultType(op, op1, op2);
        }
    }

You can see the code above. What would be the correct behavior?

comment:4 by Dimitar Misev, 5 years ago

In this case, the scalar (operand on the left) should be considered as an array technically with same sdom as the array on the right. I.e. that query should be equivalent to

rasql -q 'SELECT marray i in [0:1] values { 13c, 115c, 212c } 
                 overlay 
                 <[0:1] true, false>' --out file

comment:5 by Dimitar Misev, 5 years ago

It should work like other induced operations basically, e.g. with * you can multiply a scalar and an array.

in reply to:  4 comment:6 by apercov, 5 years ago

Replying to dmisev:

In this case, the scalar (operand on the left) should be considered as an array technically with same sdom as the array on the right. I.e. that query should be equivalent to

rasql -q 'SELECT marray i in [0:1] values { 13c, 115c, 212c } 
                 overlay 
                 <[0:1] true, false>' --out file

The output of this query is

rasdaman error 412: Execution error 412 in line 0, column 0, near token : Value expression must be either of type atomic or complex.

comment:7 by apercov, 5 years ago

Okey I checked it further. There was a problem with oql.yy and overlay. For some reason second operand was entered in place of first and vice versa for the first one. That resolved the segmentation fault. Now we receive next error:

rasdaman error 364: Execution error 364 in line 1, column 28, near token overlay: Cell base type and scalar type of binary induce operation are incompatible

However, according to this comment overlay between char and booltype is not defined:

 // overlay between composite types defined only on identical types
    if (op == OP_OVERLAY)
    {

In order to test it this is written:

if (op1->compatibleWith(op2))
        {
            return op1;
        }

I see next three solutions:
1) keep it like this
2) modify compatibleWith
3) change the if clause so we use more local check instead of compatibleWith?

comment:8 by Dimitar Misev, 5 years ago

Okey I checked it further. There was a problem with oql.yy and overlay. For some reason second operand was entered in place of first and vice versa for the first one. That resolved the segmentation fault.

Wait, that doesn't sound like a way to fix this problem, you're changing the semantics of the overlay operator! Please read the documentation on what this operator does first of all.

comment:9 by apercov, 5 years ago

Resolution: fixed
Status: acceptedclosed
Note: See TracTickets for help on using tickets.