Issue 81214 - ODFF: LOOKUP ForceArray parameters; string vs. number must not match
Summary: ODFF: LOOKUP ForceArray parameters; string vs. number must not match
Status: CLOSED FIXED
Alias: None
Product: Calc
Classification: Application
Component: programming (show other issues)
Version: 680m222
Hardware: All All
: P3 Trivial (vote)
Target Milestone: ---
Assignee: oc
QA Contact: issues@sc
URL:
Keywords:
: 90628 (view as issue list)
Depends on: 102702
Blocks:
  Show dependency tree
 
Reported: 2007-09-03 09:49 UTC by daniel.rentz
Modified: 2017-05-20 11:41 UTC (History)
2 users (show)

See Also:
Issue Type: PATCH
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
patch 1. (3.83 KB, text/plain)
2009-03-12 10:17 UTC, lvyue
no flags Details
patch for modules sc and oox (6.94 KB, patch)
2009-04-29 20:36 UTC, ooo
no flags Details | Diff
testcase Calc .ods (10.46 KB, application/vnd.oasis.opendocument.spreadsheet)
2009-04-29 20:38 UTC, ooo
no flags Details
the same testcase exported to Excel .xls (16.00 KB, application/vnd.ms-excel)
2009-04-29 20:39 UTC, ooo
no flags Details
patch with corrected Excel classification, based on current CWS odff06 (6.94 KB, patch)
2009-04-30 11:50 UTC, ooo
no flags Details | Diff
exported Excel .xls with the corrected parameter classification (no change in display behavior though) (16.00 KB, application/vnd.ms-excel)
2009-04-30 11:53 UTC, ooo
no flags Details
Possible combinations of formula type, param type, token type (13.50 KB, application/vnd.ms-excel)
2009-04-30 13:57 UTC, daniel.rentz
no flags Details
patch without the Excel export bits against the now current CWS odff06 (5.10 KB, patch)
2009-04-30 17:03 UTC, ooo
no flags Details | Diff
based on Eike's latest patch, changed for the third paramater, enable value, string or singleref. (9.99 KB, text/plain)
2009-05-05 09:50 UTC, lvyue
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description daniel.rentz 2007-09-03 09:49:34 UTC
The LOOKUP function cannot handle the following tokens as second parameter
- single cell reference, e.g. =LOOKUP(1;A2)
- constant values, e.g. =LOOKUP(1;1)
- constant arrays, e.g. =LOOKUP(1;{1;2})
Seems that only cell ranges are allowed.
Comment 1 ooo 2007-09-03 11:14:02 UTC
Accepted.
Comment 2 ooo 2008-06-12 16:45:23 UTC
*** Issue 90628 has been marked as a duplicate of this issue. ***
Comment 3 ooo 2008-06-12 16:47:43 UTC
Comment from issue 90628:

ODFF defines the Searched and Results parameters as 'ForceArray'.

Calc doesn't handle for example
=LOOKUP(4; A1:C1*2; A3:C3)

entered in D4, where A1:C1*2 should be evaluated as an array expression, as does
Excel.


Additional note: the array case =LOOKUP(1;{1;2}) was implemented with CWS
odff03. Other cases remain to be done.
Comment 4 ooo 2009-01-21 23:33:00 UTC
Won't make it for 3.1, targeting to 3.2
Comment 5 lvyue 2009-03-12 10:17:29 UTC
Created attachment 60894 [details]
patch 1.
Comment 6 ooo 2009-04-29 20:34:39 UTC
The patch missed to change the parameter classification to ForceArray to make
the example from #desc4 work, also for Excel export. Comparing with Excel
another undocumented subtlety turned out: if the data <= query found is of type
string and the query was numeric, or vice versa, Excel returns #N/A, even if it
is said that a 0-9 < A-Z sorted data is searched. Changed function accordingly.

Other smaller changes:
eDataArray didn't need to be assigned in each case block, once before the switch
and switching on the value suffices.
The result of CollatorWrapper::compareString() is not one of COMPARE_EQUAL,
COMPARE_LESS, ... but values <0, ==0 or >0 instead.

I'll attach my current patch, a test case document and comment on remaining
problems.
Comment 7 ooo 2009-04-29 20:36:19 UTC
Created attachment 61898 [details]
patch for modules sc and oox
Comment 8 ooo 2009-04-29 20:38:33 UTC
Created attachment 61899 [details]
testcase Calc .ods
Comment 9 ooo 2009-04-29 20:39:43 UTC
Created attachment 61900 [details]
the same testcase exported to Excel .xls
Comment 10 ooo 2009-04-29 20:47:45 UTC
@lvyue: with the second patch applied, loading the .ods testcase displays
Err:504 in H2 and H3, these should also work.

@dr: with the second patch applied, testcase exported to .xls and loaded in
Excel it displays #VALUE! in cells E19:H28, see also attached .xls file.
Pressing F2 and enter on each then displays the expected value. The formulas are
not different from those in A19:D28, except of different cells referred. I don't
see a reason why this should be.. please investigate.

Thanks
  Eike
Comment 11 daniel.rentz 2009-04-30 10:05:24 UTC
dr->er: Seems that there is another type of token class in Excel which is
neither exactly ref-type nor array-type. 

First, please do not change the first parameter, it must remain value-type.
For the second parameter, Excel seems to handle it as array-type in cell
formulas (value-type context) and as ref-type in other formula types, e.g.
defined names and array formula cells (ref-type and array-type contexts).

I have checked handling of ref-type parameters (e.g. SUM) and array-type
parameters (e.g. SUMPRODUCT) in all formula types. The export filter works
correctly for all types of formulas there. So I need to extend the formula
compiler for this new parameter type.
Comment 12 ooo 2009-04-30 11:06:50 UTC
@dr:
> First, please do not change the first parameter, it must remain value-type.
Argh, sure, that was in error, bad me.. I'll attach a corrected patch.

> So I need to extend the formula compiler for this new parameter type.
Question remains whether there are other functions using this type yet
undiscovered. And if it has any influence on our internal
classification.
Comment 13 ooo 2009-04-30 11:50:36 UTC
Created attachment 61912 [details]
patch with corrected Excel classification, based on current CWS odff06
Comment 14 ooo 2009-04-30 11:53:28 UTC
Created attachment 61913 [details]
exported Excel .xls with the corrected parameter classification (no change in display behavior though)
Comment 15 daniel.rentz 2009-04-30 12:46:08 UTC
Yes, what about the [HV]LOOKUP functions? I am currently thinking about a
generic testcase to be able to distinguish these cases.
Comment 16 daniel.rentz 2009-04-30 13:51:43 UTC
I think all functions should be tested that contain an R parameter type in the
Excel filter function list, except functions that do not accept anything but
real references (e.g. the ROW() function).

The functions should be used in a cell formula receiving a value-type parameter
(e.g. "PI()"), and a (value-type*ref-type) parameter (e.g. "A1*PI()") as argument.
If Excel writes the function parameter as array-type, this function needs to be
changed to the new parameter type.

I will add the new functionality in the Excel filter to CWS odff06, and I will
check the functions.
Comment 17 daniel.rentz 2009-04-30 13:55:18 UTC
@er: please remove the changed parameter type in the Excel filter from the
patch, to not run into confusion :-)
Comment 18 daniel.rentz 2009-04-30 13:57:20 UTC
Created attachment 61926 [details]
Possible combinations of formula type, param type, token type
Comment 19 ooo 2009-04-30 17:03:12 UTC
Created attachment 61933 [details]
patch without the Excel export bits against the now current CWS odff06
Comment 20 ooo 2009-04-30 17:03:56 UTC
All 3 LOOKUP results in that i81214_paramtypes.xls are #N/A with the current patch.
Comment 21 lvyue 2009-05-05 09:50:39 UTC
Created attachment 61995 [details]
based on Eike's latest patch, changed for the third paramater, enable value, string or singleref.
Comment 22 daniel.rentz 2009-06-12 09:34:21 UTC
The Excel export problem is now covered by issue 102702.
Comment 23 ooo 2009-06-25 12:27:31 UTC
Another detail: a non-range lookup must return #N/A if the query was string and
the search vector is numbers or vice versa, an automatic conversion must not be
applied. For example, a query "3" must not match 3, a query 3 must not match "3".
Comment 24 ooo 2009-08-14 17:19:35 UTC
In cws odff06:

revision 275000
sc/source/core/inc/parclass.hxx
sc/source/core/tool/interpr1.cxx
sc/source/core/tool/interpr4.cxx
sc/source/core/tool/parclass.cxx

Changed implementation of the patch to use PushCellResultToken() wherever
possible for inherited emptiness, that was broken. For this, introduced a new
parameter classification ReferenceOrForcedArray to be able to distinguish
between references passed that don't need to be unnecessarily converted to
arrays, and arguments that need to be converted to array in the parameter chain.
Comment 25 ooo 2009-08-14 21:38:55 UTC
Submitted separate issue 104241 for the "string query should not return match
for last numeric value if no string <= query was found" problem, as it affects
LOOKUP, MATCH, VLOOKUP and HLOOKUP.
Comment 26 ooo 2009-09-03 17:06:10 UTC
Reassigning to QA for verification.

Note: Exporting i81214_LOOKUP.ods to .xls and loading in Excel, the following
ranges differ and produce #N/A in Excel (instead of a value found in Calc)
because of issue 104241:

F13:I13
I13:I16
E37:E39
Comment 27 oc 2009-09-11 08:39:19 UTC
verified in internal build cws_odff06