Opened 8 years ago

Closed 6 years ago

Last modified 6 years ago

#1563 closed defect (fixed)

problem with type assignment while outputting to csv/json from a switch/case query with varying data types in each case

Reported by: bbell Owned by: Dimitar Misev
Priority: major Milestone: 9.7
Component: qlparser Version: development
Keywords: Cc: Dimitar Misev, Vlad Merticariu
Complexity: Medium

Description (last modified by bbell)

in the wcps query:

for c in (test_mr) return encode(switch case c>0 return log(c) default return (char)0,"csv")

the default case outputs something slightly different from, but arbitrarily close to, 0.

Change History (11)

comment:1 by bbell, 8 years ago

Description: modified (diff)

comment:2 by Dimitar Misev, 8 years ago

Milestone: 9.4

Please try to set the milestone in new tickets.

comment:3 by Dimitar Misev, 7 years ago

Milestone: 9.49.7

comment:4 by bbell, 6 years ago

Just to clarify, the resulting rasql query would be:

SELECT encode(CASE WHEN ( c > 0 ) THEN ( log( c ) ) ELSE ( (octet) 0 ) END, "csv" ) FROM test_mr AS c

comment:5 by bbell, 6 years ago

Owner: changed from bbell to dkamov
Status: newassigned

comment:6 by bbell, 6 years ago

This seems to work for me now. We should add a test in test_select to enforce consistency of this behavior for future patches, and close this ticket.

comment:7 by Dimitar Misev, 6 years ago

There's a memory error currently, because the scalar value is in a buffer of size 1, but the result is floats (so size 4), case tries to copy 4 bytes from the scalar value.. so it randomly results in a random output.

The correct way to fix this issue is to throw an exception that the types in the THEN/ELSE clauses do not match in checkType. They should all be of the same base type.

Request: 'select encode((case when(c > 0) then (log(c)) else (0f) end)[75:85,75:85], "csv") from test_grey as c'... parsing... checking semantics... evaluating... cell count: 0
=================================================================
==19981==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000007d74 at pc 0x7f67b4fad6c2 bp 0x7ffe68d938a0 sp 0x7ffe68d93050
READ of size 8 at 0x602000007d74 thread T0
    #0 0x7f67b4fad6c1  (/usr/lib/x86_64-linux-gnu/libasan.so.4+0x766c1)
    #1 0x5647d09030c7 in Tile::setCell(unsigned long, char const*) tilemgr/tile.cc:1018
    #2 0x5647d0a7a417 in QtCaseOp::evaluateInducedOp(std::vector<QtData*, std::allocator<QtData*> >*) qlparser/qtcaseop.cc:347
    #3 0x5647d0a7ae59 in QtCaseOp::evaluate(std::vector<QtData*, std::allocator<QtData*> >*) qlparser/qtcaseop.cc:464
    #4 0x5647d0ae1618 in QtDomainOperation::evaluate(std::vector<QtData*, std::allocator<QtData*> >*) qlparser/qtdomainoperation.cc:508
    #5 0x5647d0ace4db in QtConversion::evaluate(std::vector<QtData*, std::allocator<QtData*> >*) qlparser/qtconversion.cc:192
    #6 0x5647d0b459ff in QtOperationIterator::next() qlparser/qtoperationiterator.cc:253
    #7 0x5647d0ba4bb8 in QueryTree::evaluateRetrieval() qlparser/querytree.cc:174
    #8 0x5647d09572b1 in ServerComm::executeQuery(unsigned long, char const*, ExecuteQueryRes&) servercomm/servercomm2.cc:1662
    #9 0x5647d05ad707 in doStuff() applications/directql/directql.cc:1125
    #10 0x5647d05ae427 in main applications/directql/directql.cc:1194
    #11 0x7f67b15a4a86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21a86)
    #12 0x5647d05a6209 in _start (/home/dimitar/rasdaman/community/src-install/bin/directql+0xa2b209)

0x602000007d74 is located 0 bytes to the right of 4-byte region [0x602000007d70,0x602000007d74)
allocated by thread T0 here:
    #0 0x7f67b50124e0 in operator new[](unsigned long) (/usr/lib/x86_64-linux-gnu/libasan.so.4+0xdb4e0)
    #1 0x5647d0a51f57 in QtAtomicData::QtAtomicData(double, unsigned short) qlparser/qtatomicdata.cc:148
    #2 0x5647d0a107ef in yyparse(void*) build/qlparser/oql.yy:3832
    #3 0x5647d09570cd in ServerComm::executeQuery(unsigned long, char const*, ExecuteQueryRes&) servercomm/servercomm2.cc:1639
    #4 0x5647d05ad707 in doStuff() applications/directql/directql.cc:1125
    #5 0x5647d05ae427 in main applications/directql/directql.cc:1194
    #6 0x7f67b15a4a86 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21a86)

comment:8 by Dimitar Misev, 6 years ago

Cc: Vlad Merticariu added

comment:9 by Dimitar Misev, 6 years ago

Owner: changed from dkamov to Dimitar Misev

comment:10 by Dimitar Misev, 6 years ago

Resolution: fixed
Status: assignedclosed

comment:11 by Dimitar Misev, 6 years ago

You get a nice error now that such a query is not allowed. You need to cast the 0 to double in this case to match the type of log().

Note: See TracTickets for help on using tickets.