Qlik Community

Qlik Server Side Extensions Discussions

Discussion Board for collaboration on Server-Side Extensions and Advanced Analytics Integration.

stevenkoppens
New Contributor III

Using other datatypes in fullscriptsupport_pandas example

I'm struggling to use other datatypes than numeric in the SSE example fullscriptsupport_pandas, I've modified the example slightly. So, this first part works where I'm just sending the first column 3 times (which is numeric):

Table1:

LOAD * INLINE [

ID, String, Mixed

0, "a", 10

1, "b", "ten"

2, "c", "eleven"

3, "d", 11

];

SET vScript = '

tableDescription = True          # tableDescription must be set to True if it should be sent to Qlik

table.name = "SSETableLoad"      # Set the table name, note that it is overridden in a table name is specified in the Load Script

table.fields.add(name="Id1",dataType=1)

table.fields.add(name="Id2",dataType=1)

table.fields.add(name="Id3",dataType=1)

qResult=q.values                  # Return the same values as retrieved';

Load * Extension ScriptPandas.ScriptEval('$(vScript)', Table1{ID as Id1,ID as Id2,ID as Id3});

        exit script



But if I slightly modify the script and try to include the String column, I get a an error:


Table1:

LOAD * INLINE [

ID, String, Mixed

0, "a", 10

1, "b", "ten"

2, "c", "eleven"

3, "d", 11

];

SET vScript = '

tableDescription = True           # tableDescription must be set to True if it should be sent to Qlik

table.name = "SSETableLoad"       # Set the table name, note that it is overridden in a table name is specified in the Load Script

table.fields.add(name="Id1",dataType=1)

table.fields.add(name="String1",dataType=0)

table.fields.add(name="Id3",dataType=1)

qResult=q.values                  # Return the same values as retrieved';

Load * Extension ScriptPandas.ScriptEval('$(vScript)', Table1{ID as Id1,String as String1,ID as Id3});

exit script

The following error occurred:

Connector reply error: grpc:Smiley FrustratedtatusCode::UNKNOWN: 'Exception iterating responses: 'a' has type <class 'str'>, but expected one of: ((<class 'numbers.Real'>,),) for field Dual.numData'

Could anyone explain to me what I'm missing?

Thanks!

Steven


Labels (1)
1 Solution

Accepted Solutions
ost
New Contributor III

Re: Using other datatypes in fullscriptsupport_pandas example

Hi Steven!

Thank you for reaching out. When I reproduced the issue you're describing I noticed it's a bug in the plugin. The tableDescription should use the dataTypes in the tableDescription over the returnType of the function, which it doesn't right now. You can see that in the get_duals method in scripteval.py file. We are assuming all columns have the same returnType which is determined by the function. The latter explains why you could only return strings when using the ScriptEvalStr and numerics when using ScriptEval

I managed to write a quick fix for it, but I need to clean it up a bit before updating the code on GitHub. I'll update you when I've fixed it. I believe I can have it updated at the beginning of next week!

Kind regards,

Josefine

3 Replies
stevenkoppens
New Contributor III

Re: Using other datatypes in fullscriptsupport_pandas example

I managed to get it working by using ScriptEvalStr. But in this case, I can only use strings, is anyone aware of a method in which you can return both strings & numbers?

Table1:

LOAD * INLINE [

ID, String, Mixed

0, "a", 10

1, "b", "ten"

2, "c", "eleven"

3, "d", 11

];

SET vScript = '

tableDescription = True          # tableDescription must be set to True if it should be sent to Qlik

table.name = "SSETableLoad"      # Set the table name, note that it is overridden in a table name is specified in the Load Script

table.fields.add(name="String1",dataType=0)

table.fields.add(name="String2",dataType=0)

table.fields.add(name="String3",dataType=0)

qResult=q.values                  # Return the same values as retrieved';

Load * Extension ScriptPandas.ScriptEvalStr('$(vScript)', Table1{String as String1,String as String2,String as String3});

exit script

ost
New Contributor III

Re: Using other datatypes in fullscriptsupport_pandas example

Hi Steven!

Thank you for reaching out. When I reproduced the issue you're describing I noticed it's a bug in the plugin. The tableDescription should use the dataTypes in the tableDescription over the returnType of the function, which it doesn't right now. You can see that in the get_duals method in scripteval.py file. We are assuming all columns have the same returnType which is determined by the function. The latter explains why you could only return strings when using the ScriptEvalStr and numerics when using ScriptEval

I managed to write a quick fix for it, but I need to clean it up a bit before updating the code on GitHub. I'll update you when I've fixed it. I believe I can have it updated at the beginning of next week!

Kind regards,

Josefine

ost
New Contributor III

Re: Using other datatypes in fullscriptsupport_pandas example

Hi Steven!

The fix is merged into the master branch in the server-side-extension GitHub repo now. You can find the pull request here: https://github.com/qlik-oss/server-side-extension/pull/29

Kind regards,

Josefine

Community Browser