how can you check the data type of a MDX Measure in icCube? - iccube

I am using a project-to-date calculated member in a STATS dimension that aggregates the data. But I am also using string measures (e.g. to display some text).
Now, the string measures show an error when using the PTD view:
"Aggregation SUM is not supported for datatype string".
The solution, is to check on the datatype prior to aggregating it, but how can you do that.
In SSAS MDX, there is the VBA function called "typename()", does something exist for icCube as well?

Since icCube 6.5.1 the following MDX functions are available:
VarTypeName ( arg ) : the type of the MDX argument
ValueTypeName ( arg ) : the type of the MDX argument when evaluated
For example:
VarTypeName ( [Measures].[Amount] ) : "measure"
ValueTypeName ( [Measures].[Amount] ) : "double"
Hope that helps.

Related

Error: The operator '+' isn't defined for the class 'Object'

As a complete Dart beginner coming from python and javascript, I find this behavior quite strange:
var user = {'name': 'John Doe', 'birth_y': 1980};
2021-user['birth_y'] // is 41
But if the operator is on the right.
user['birth_y'] + 41 // error
The error:
Error: The operator '+' isn't defined for the class 'Object'.
- 'Object' is from 'dart:core'.
Try correcting the operator to an existing operator, or defining a '+' operator.
user['birth_y'] + 41;
^
From the error, one guesses that for maps with mixed types, entries have type 'Object', Yet:
user['birth_y'] is int // true
user['birth_y'].runtimeType // int
This behavior is also exhibited by lists of mixed types,
What am I missing?
Dart does a statically analysis of your program before running it. In this analyze phase, it will look at the data type of your variables and see if it is statically safe.
In your case you have this Map:
var user = {'name': 'John Doe', 'birth_y': 1980};
Since your Map contains different types of values, Dart will try to see which data type can be used for all your values. In this case, the only thing String and int shares is the Object type. So user is being analyzed to be of the type Map<String, Object>.
This means that when you get a object from user, the only thing the analyzer can be sure about is it is of the type Object.
So when you do:
user['birth_y'] + 41
The analyzer will assume you get a Object which does not have the + operator.
You should in general not use Map as some kind of object which contains different data types. Instead create a class which makes it possible to write type safe code.

Oracle named parameters

How can I use keywords with Oracle named parameters syntax ? The following gives me 'ORA-00936: missing expression' because of the 'number'-argument:
select b.g3e_fid
, a.g3e_fid
, sdo_nn_distance( 1)
from acn a, b$gc_fitface_s b
where mdsys.sdo_nn ( geometry1 => a.g3e_geometry, geometry2 => b.g3e_geometry, param => 'sdo_num_res=1', number=>1) = 'TRUE' and b.g3e_fid = 57798799;
If I run it without named parameters it is fine.
thanks, Steef
Although you can get around the reserved word issue in your call by enclosing the name in double quotes as #AvrajitRoy suggested, i.e. ... "NUMBER"=>1) = 'TRUE'..., you aren't actually achieving much. Oracle is letting you refer to the parameters by name but it isn't doing anything with that information.
MDSYS.SDO_NN is a spatial operator, not a direct call to a function. There is a function backing it up - you can see from the schema scripts for MDSYS that it's actually calling prtv_idx.nn - but the names of the formal parameters of that function are not relevant. With some digging you can see those are actually called geom, geom2, mask etc., and there isn't one called number (and you can't have a formal parameter called number, even quoting it, as far as I can tell).
The formal parameters to the operator are not named, and are effectively passed through positionally. You can't skip an argument by naming the others, as you can with a function/procedure with arguments that have default values.
So that means you can call the parameters anything you want in your call; changing the names of the first three parameters in your call to something random won't stop it working.
It also means naming them in the call is a bit pointless, but if you're just trying to document the call then you can use some other meaningful name rather than 'number' if you don't want to quote it.
Hello as mentined in you question . There are two ways in which u can eliminate this RESERVED keyword ISSUE.
1) Use "" to use any RESERVED key word for calling. But remember this is not a good coding practice.
Eg >
SELECT b.g3e_fid ,
a.g3e_fid ,
sdo_nn_distance( 1)
FROM acn a,
b$gc_fitface_s b
WHERE mdsys.sdo_nn
( geometry1 => a.g3e_geometry,
geometry2 => b.g3e_geometry,
"param" => 'sdo_num_res=1',
"NUMBER"=>1) = 'TRUE'
AND b.g3e_fid = 57798799;
2) Secondly you can just call the function without using "=>" as shown below
Eg >
SELECT b.g3e_fid ,
a.g3e_fid ,
sdo_nn_distance( 1)
FROM acn a,
b$gc_fitface_s b
WHERE mdsys.sdo_nn
( a.g3e_geometry,
b.g3e_geometry,
'sdo_num_res=1',
1) = 'TRUE'
AND b.g3e_fid = 57798799;

Distinct-Nodes taking too long in BaseX (XQuery)

I am trying to get all distinct start element /products/p:category/start nodes of a big file. I have written a query which is given below. It is taking to long to get the result. I am attaching the query info and the XML file.
After Running couple of minutes, I stopped the execution.
The query is trying to get all the distinct start elements. There are 3 lac category elements.
declare namespace functx = "http://www.functx.com";
declare namespace p="a:b:c";
declare function functx:is-node-in-sequence(
$node as node()? ,
$seq as node()*
) as xs:boolean {
some $nodeInSeq in $seq satisfies deep-equal($nodeInSeq,$node)
};
declare function functx:distinct-nodes(
$nodes as node()*
) as node()* {
for $seq in (1 to count($nodes))
return $nodes[$seq]
[not(functx:is-node-in-sequence(.,$nodes[position() < $seq]))]} ;
let $diff_starts := functx:distinct-nodes(/products/p:category/start)
return $diff_starts
Please let me know if you require further details.
xml file
Comparing a rather large number of nodes with the function provided by FunctX is very expensive, and far beyond costs linear with the number of items.
FunctX is generally a neat library, but often does not scale very well for larger data as you have it (although XML databases can very well handle data much larger without problems).
In this query, I first fetch all distinct values in linear time (in the number of node lookups; for getting distinct values BaseX uses a hashtable ), and another linear scan over all nodes to retrieve the first result node for each of those values. Total execution time on my laptop was about 700ms.
declare namespace p="a:b:c";
for $date in distinct-values(/products/p:category/start)
return (/products/p:category/start[. eq $date])[1]

idl: pass keyword dynamically to isa function to test structure read by read_csv

I am using IDL 8.4. I want to use isa() function to determine input type read by read_csv(). I want to use /number, /integer, /float and /string as some field I want to make sure float, other to be integer and other I don't care. I can do like this, but it is not very readable to human eye.
str = read_csv(filename, header=inheader)
; TODO check header
if not isa(str.(0), /integer) then stop
if not isa(str.(1), /number) then stop
if not isa(str.(2), /float) then stop
I am hoping I can do something like
expected_header = ['id', 'x', 'val']
expected_type = ['/integer', '/number', '/float']
str = read_csv(filename, header=inheader)
if not array_equal(strlowcase(inheader), expected_header) then stop
for i=0l,n_elements(expected_type) do
if not isa(str.(i), expected_type[i]) then stop
endfor
the above doesn't work, as '/integer' is taken literally and I guess isa() is looking for named structure. How can you do something similar?
Ideally I want to pick expected type based on header read from file, so that script still works as long as header specifies expected field.
EDIT:
my tentative solution is to write a wrapper for ISA(). Not very pretty, but does what I wanted... if there is cleaner solution , please let me know.
Also, read_csv is defined to return only one of long, long64, double and string, so I could write function to test with this limitation. but I just wanted to make it to work in general so that I can reuse them for other similar cases.
function isa_generic,var,typ
; calls isa() http://www.exelisvis.com/docs/ISA.html with keyword
; if 'n', test /number
; if 'i', test /integer
; if 'f', test /float
; if 's', test /string
if typ eq 'n' then return, isa(var, /number)
if typ eq 'i' then then return, isa(var, /integer)
if typ eq 'f' then then return, isa(var, /float)
if typ eq 's' then then return, isa(var, /string)
print, 'unexpected typename: ', typ
stop
end
IDL has some limited reflection abilities, which will do exactly what you want:
expected_types = ['integer', 'number', 'float']
expected_header = ['id', 'x', 'val']
str = read_csv(filename, header=inheader)
if ~array_equal(strlowcase(inheader), expected_header) then stop
foreach type, expected_types, index do begin
if ~isa(str.(index), _extra=create_struct(type, 1)) then stop
endforeach
It's debatable if this is really "easier to read" in your case, since there are only three cases to test. If there were 500 cases, it would be a lot cleaner than writing 500 slightly different lines.
This snipped used some rather esoteric IDL features, so let me explain what's happening a bit:
expected_types is just a list of (string) keyword names in the order they should be used.
The foreach part iterates over expected_types, putting the keyword string into the type variable and the iteration count into index.
This is equivalent to using for index = 0, n_elements(expected_types) - 1 do and then using expected_types[index] instead of type, but the foreach loop is easier to read IMHO. Reference here.
_extra is a special keyword that can pass a structure as if it were a set of keywords. Each of the structure's tags is interpreted as a keyword. Reference here.
The create_struct function takes one or more pairs of (string) tag names and (any type) values, then returns a structure with those tag names and values. Reference here.
Finally, I replaced not (bitwise not) with ~ (logical not). This step, like foreach vs for, is not necessary in this instance, but can avoid headache when debugging some types of code, where the distinction matters.
--
Reflective abilities like these can do an awful lot, and come in super handy. They're work-horses in other languages, but IDL programmers don't seem to use them as much. Here's a quick list of common reflective features I use in IDL, with links to the documentation for each:
create_struct - Create a structure from (string) tag names and values.
n_tags - Get the number of tags in a structure.
_extra, _strict_extra, and _ref_extra - Pass keywords by structure or reference.
call_function - Call a function by its (string) name.
call_procedure - Call a procedure by its (string) name.
call_method - Call a method (of an object) by its (string) name.
execute - Run complete IDL commands stored in a string.
Note: Be very careful using the execute function. It will blindly execute any IDL statement you (or a user, file, web form, etc.) feed it. Never ever feed untrusted or web user input to the IDL execute function.
You can't access the keywords quite like that, but there is a typename parameter to ISA that might be useful. This is untested, but should work:
expected_header = ['id', 'x', 'val']
expected_type = ['int', 'long', 'float']
str = read_cv(filename, header=inheader)
if not array_equal(strlowcase(inheader), expected_header) then stop
for i = 0L, n_elemented(expected_type) - 1L do begin
if not isa(str.(i), expected_type[i]) then stop
endfor

R equivalent of Java map

I would like to pass a key/value pair from my R code to a java function.
My java function has argument Map<String,String > .
How can I write R function which calls my Java function and pass values to map ??
EDIT :
config <- list(Portname="PORT.H.2",MktValue="8000000",WtScheme="Closed")
createPortfolio<-function(config)
{
m <- .jnew("java/util/HashMap")
for( key in names(config)){
m$put( key, config[key])
}
m
getting
Error in FUN(X[[2L]], ...) :
Sorry, parameter type `NA' is ambiguous or not supported.
How about trying something like this?
m <- .jnew("java/util/HashMap")
m$put( "key", "value" )
I think you meant
for (key in names(config)) m$put(key, config[[key]])
since you want to pass string as value to put and not a list.
(Consider asking on the rJava mailing list stats-rosuda-devel to get a more prompt answer)
For people, like myself, who had this issue and don't have access to the Java code, it seems to be possible to make a HashMap, and cast it to a Map, like this:
m <- .jnew("java/util/HashMap")
m$put( "key", "value" )
map <- .jcast(m, "java/util/Map")

Resources