Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Getting DataSource record count without fetching all records?

    We want to decide what action to take (e.g. which type of report to run) based on how many records would be involved (e.g. switch to a summary report in our reporting software if there will be too many points for the every point report).

    Is there a way to ask a DataSource how many records match a filter criteria (or how many rows without any criteria) without fetching all of the records?

    Since one of the things we are testing for is cases where a huge amount of data would be included we would rather not have to fetch every point in order to get the total count.

    Thank you in advance for any help on this.
    Patrick

    #2
    Yes, whether client or server-side, you can set startRow:0 endRow:1 on your dsRequest and you will only fetch one record, and the totalRows will be set to the total.

    Comment


      #3
      Hello,

      We implemented this solution a while back, with SmartGWTPower
      -2.5_NB_20120102, and it worked great. However, we recently upgraded to SmartGWT 3.0, and now the DSResponse.getTotalRows() always returns 1 (or 0 if there are no records), regardless of how many rows actually exist in the data set.

      SmartClient v8.2p_2012-05-11/EVAL Deployment
      Firefox 3.6.23

      Here is the code we are using - are we doing something wrong?

      Code:
      Criteria reportCriteria = new AdvancedCriteria(OperatorId.AND,
          new Criterion[] {
          new Criterion(PRODUCT_TYPE_ID_FIELD, 
            OperatorId.EQUALS, theTrendParameters.getID()), 
          new Criterion(START_TIMESTAMP_FIELD, 
            OperatorId.GREATER_OR_EQUAL, 
            theStartTimespanSelector.getValueAsDate()),
          new Criterion(END_TIMESTAMP_FIELD, 
            OperatorId.LESS_OR_EQUAL, 
            theEndTimespanSelector.getValueAsDate()) 
          });
      
      DSRequest request= new DSRequest();
      request.setStartRow(0);
      request.setEndRow(1);
      
      DSCallback callback= new DSCallback() {
      
               @Override
               public void execute(DSResponse aResponse,
                                   Object aRawData,
                                   DSRequest aRequest)
               {
                  int recordCount = aResponse.getTotalRows();
               }
            };
      
      DataSource ds = DataSource.get("datasource");
      ds.fetchData(criteria, callback, request);
      Thanks in advance!

      Comment


        #4
        This seems very odd - if totalRows is broken in 8.2p, it would affect every user and we would have seen many reports of it by now. That said, an engineer has been assigned to look into it - we'll get back to you.

        Comment


          #5
          Aha, I found the problem. There was a type error in my .ds.xml file. A TIMESTAMP field was listed as a TEXT field. Apparently that didn't cause any problems with 2.5, which is why we didn't catch it before.

          Comment


            #6
            Hmm, On the server side, in SmartClient Version: v13.0p_2024-01-20/PowerEdition Deployment (built 2024-01-20) response.getTotalRows() appears to be giving me the number of rows returned in the response + 20.

            In case my grouping details matter, here is what I'm doing

            Code:
                       DSRequest taDsRequest = new DSRequest("TestAttributeNamesBenchView", "fetch");
                        taDsRequest.setTextMatchStyle("exactCase");
                        taDsRequest.setAdvancedCriteria(crit);
                        String[] fieldNames = {"PK_Test_Attribute_Names", "Name", "Parent1_Name", "Parent2_Name", "Parent3_Name", "NestedName", "Type", "BenchName", "ParentJSONArray"};
                        taDsRequest.setOutputs(Arrays.asList(fieldNames));
                        taDsRequest.setGroupBy(fieldNames); 
                        taDsRequest.setStartRow(0).setEndRow(1);
                        DSResponse resp = taDsRequest.execute();
            
            long eslookSize1 = resp.getTotalRows();     // this comes back as 21 !  I'm expecting 320,000 
                        int esCnt1 = ((List<?>)resp.getData()).size();  // this is 1, as expected
            
            
                        taDsRequest.setStartRow(0).setEndRow(100);
                        resp = taDsRequest.execute();
            long eslookSize2 = resp.getTotalRows();    //  I'm getting 120 here !
                        List<?> t2a2 = (List<?>)resp.getData();
                        int esCntr = ((List<?>)resp.getData()).size();   // 100 as expected

            Comment


              #7
              You have progressiveLoading enabled.

              https://smartclient.com/smartclient-...ressiveLoading

              You can turn it off on a per-DSRequest basis (dsRequest.progressiveLoading) if you need the true count.

              Comment

              Working...
              X