webdataconnector icon indicating copy to clipboard operation
webdataconnector copied to clipboard

Errors loading schemas

Open gilbert-n opened this issue 10 years ago • 6 comments

I noticed this error and I wanted to see if you know where it might be coming from.

A bit of background: I have a web api that I hit and returns data, variables and classifications (codes) in a json format. So, my connector expects to load multiple tables. I have implemented a web connector which works correctly on the simulator. When run on tableau desktop (version 10.0.1, trial), I get the following errors:

Either invalid data are present or required fields are empty for class TableInfo. Required fields and respective data types are: { (Name : 'id', Type : QString, IsRequired : true), (Name : 'columns', Type : QVariantList, IsRequired : true), (Name : 'alias', Type : QString, IsRequired : false), (Name : 'description', Type : QString, IsRequired : false), (Name : 'incrementColumnId', Type : QString, IsRequired : false) }.

The error is thrown as "Reporting data source exception. Type='WDCInvalidData' message='...'

This seems to happen only when I am loading more than 2 tables. If I have just one table or 2 I don't get any error and everything works fine. The error I am getting isn't really that descriptive/ helpful. For what I can gather, this error is thrown by Tableau desktop when it's putting the table schemas in place.

Given the fact that my connector works just fine for any number of tables on the simulator and works correctly on Tableau desktop for two tables max, I wonder if this might be a tableau limitation for trial versions.

gilbert-n avatar Oct 04 '16 19:10 gilbert-n

Hey @gilbert-n, do you notice that it works for any combination of two tables? I.e. can you load tables A+B, and also B+C, but not A+B+C?

There wouldn't be any limitation because the version is a trial version.

Apologies for the unhelpful error message. Usually what this means is there is some sort of data type incompatibility or illegal name in the schema. Can you share your getSchema method?

lbrendanl avatar Oct 04 '16 23:10 lbrendanl

Hi @lbrendanl,

yes, I tried those cases: A+B, B+C works, but A+B+C+... does not work.

I am including my getSchema method. I will also include a sample json result I get from my API and also the schema json I wrap into the schemaCallback.

Method:

myConnector.getSchema = function (schemaCallback) { //this block prapares the url's referencing the API that will return the variables/ classifications etc
// *********************************************************************************** var fullQuery = $("#full_query").val(); var map = parseInputQuery(fullQuery); var studyUrl = map["studyUrl"]; var varUrl = map["varUrl"];
tableau.log("Getting schema from " + varUrl); //don't worry about this block. Assume that we have 2 valid urls: studyUrl and varUrl //***********************************************************************************

    var cols = [];  //main variable table columns
    var classes = [];  //this is an array of arrays of tableInfo containing classifications

    $.get(varUrl, function(result){
        if(result == null){
            tableau.log("No results were found.");
            tableau.abortWithError("No results were found.");
        }

        tableau.log("API result: " + JSON.stringify(result));

        var variables = result.variables;
        var classif = result.classifications;
        var metadata = result.metadata;

        if(variables == null){
            tableau.log("No variables were found. Trying to look under metadata");

            if(metadata == null){
                tableau.log("No metadata available from the result.");
                tableau.abortWithError("No metadata available from the result");
            }

            variables = metadata.variables;
            if(variables == null){
                tableau.log("No variables were found under metadata. Throwing exception and return");
                tableau.abortWithError("No variables were found.");
            }

            classif = metadata.classifications;
            if(classif == null){
                tableau.log("No classifications were found under metadata.");
            }
        }


        //tableau.log(variables);       
        var resources = variables.resources;
        if(resources == null){
            tableau.log("No resources were found.");
            tableau.abortWithError("No resources were found.");
        }
        //tableau.log(resources);

        for(var idx = 0; idx < resources.length; idx++){
            var variableObj = resources[idx];
            var _id             = variableObj.id;
            var _alias      = variableObj.name;
            var _dataType   = getDataType(variableObj.storageType);
            var _description = variableObj.label;
            cols.push({id:_id, alias: _alias, dataType: _dataType, description:_description});
            tableau.log(cols[idx].id);
        }


        //Get all classifications
        if(classif != null){
            resources = classif.resources;
            if(resources == null) tableau.log("there is no resources property under classification");
            else{
                var col1 = {id:"value", alias:"Value", dataType:tableau.dataTypeEnum.int, description:"value"};
                var col2 = {id:"label", alias:"Label", dataType:tableau.dataTypeEnum.string, description:"Label"};
                var classCols = [];
                classCols.push(col1); classCols.push(col2);
                for(var idx = 0; idx < resources.length; idx++){
                    var classObj = resources[idx];
                    var _id = classObj.id;
                    var codes = classObj.codes != null? classObj.codes : "";
                    var codesVal = JSON.stringify(codes);                       
                    var classInfo = {id:_id, alias:"class_" + _id, columns:classCols, description:codesVal};
                    classes.push(classInfo);
                    tableau.log("Classification: " + JSON.stringify(classInfo));
                }
            }
        }

        var tableInfo = {id:studyUrl, alias:"study", columns:cols};

        $.get(studyUrl, function(result){
            if(result == null){
                tableau.log("Couldn't get the studyInfo. Now using generic info");

                var tables = [tableInfo];
                for(var idx = 0; idx < classes.length; idx++){
                    tables.push(classes[idx]);
                    //if(idx >= 0) break; //when we have more than two tables it's not working
                }

                tableau.log("Resulting schema: " + JSON.stringify(tables));
                schemaCallback(tables);
                return;
            }

            var _id = result.id;
            var _alias = result.name;
            if(_id != null) tableInfo.id = _id;
            if(_alias != null) tableInfo.alias = _alias;

            var tables = [tableInfo]; 
            for(var idx = 0; idx < classes.length; idx++){
                tables.push(classes[idx]);
                //if(idx >= 0) break; //when we have more than two tables it's not working
            }

            tableau.log("Resulting schema: " + JSON.stringify(tables));
            schemaCallback(tables);

        });

    });     

};

You can see the sample result from my API at http://jsonformatter.org/852ba9 You can see the sample schema array at http://jsonformatter.org/c6e6b2

Click on the "Format/ Beautify" button to format those objects.

Thanks.

gilbert-n avatar Oct 05 '16 16:10 gilbert-n

@sdesmond46 any ideas here? I can't think of anything that would cause getSchema to fail when it has many tables but work for each of those tables independently.

lbrendanl avatar Oct 06 '16 17:10 lbrendanl

I do have one idea. Sometimes when trying to marshal data from the javascript layer over to the C++ layer, we have issues if the same object is referenced more than once in the payload going from javascript to native (this is a component we unfortunately cannot modify).

Could you modify your code which is adding more tables to the tables array (tables.push(classes[idx]);) to serialize and deserialize the table before adding them to the array? This will create all new object for us to send back to the native code. The js code would look like this:

       for(var idx = 0; idx < classes.length; idx++){
            var tableCopy = JSON.parse(JSON.stringify(classes[idx]));
            tables.push(tableCopy);
            // if(idx >= 0) break; //when we have more than two tables it's not working
        }

sdesmond46 avatar Oct 17 '16 22:10 sdesmond46

+1 I had a similar issue in my first WDC and that work-around fixed it

jagreene avatar Oct 17 '16 22:10 jagreene

Tried. It works. Thank you

gilbert-n avatar Oct 24 '16 21:10 gilbert-n