googleads / googleads/googleads-php-lib

Error in PublisherQueryLanguageContextError.UNEXECUTABLE

Open
#795 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
676
Forks
754
PR merge metrics
No merged PRs in 30d

Description

Hello everyone i am getting this error how to solve this?
[PublisherQueryLanguageContextError.UNEXECUTABLE @ Only constant values and bound values are allowed in the haystack of IN.].

i am using this code :

$statementBuilder = (new StatementBuilder())
->where('AD_UNIT_ID IN ('.$excluded.')');

$reportQuery->setStatement($statementBuilder->toStatement());
$reportQuery->setAdUnitView(ReportQueryAdUnitView::HIERARCHICAL);

$reportQuery->setDateRangeType(DateRangeType::TODAY);

$reportJob = new ReportJob();
$reportJob->setReportQuery($reportQuery);

        $reportJob = $reportService->runReportJob($reportJob);
        $exportFormat = 'CSV_DUMP';
        $reportJobId = $reportJob->getId();
        $reportDownloader = new ReportDownloader($reportService, $reportJobId);

if ($reportDownloader->waitForReportToFinish()) {
// set download option
$options = new ReportDownloadOptions();
$options->setExportFormat($exportFormat);
$options->setUseGzipCompression(FALSE);

        $downloadUrl = $reportService->getReportDownloadUrlWithOptions($reportJobId, $options);


        $filePath = dirname(dirname(__DIR__)).'/webroot/adxreports/'.rand().'-admanager-Native-report.csv';

        file_put_contents($filePath, fopen($downloadUrl, 'rb'));
        $file = fopen($filePath, 'r');
         $admanagerRecords = array();
         $row = 1;
        while (($line = fgetcsv($file)) !== FALSE) {


          if($row == 1){ $row++; continue; }
          $ad_unit_id = $line[0];
          $ad_unit_name = $line[1];
          $COUNTRY_NAME = $line[2];
          $criteria_id = $line[3];
          $click = $line[4];
          $impression = $line[5];
          $revenue = $line[6];
          $request = $line[7];
          $unmatch = $line[8];
          // $request = 0;
          // $unmatch = 0;

              $key  = array_search($line[0],$adunits);
              $ckey  = array_search($criteria_id,$cids);
              $appID = $records[$key]['application_id'];
              $countryId = $countryList[$ckey]['id'];

              $ctr = (($click > 0 && $impression > 0)?($click / $impression)*100 : 0);
              $revenueINR = ($revenue / 1000000);
              $cpc = ($revenueINR>0 && $click>0)?($revenueINR/$click):0;
              $ctrvalue =  number_format($ctr,2);
              $cpcvalue =  number_format($cpc,2);

              if($impression > 0 && $revenueINR > 0 && $criteria_id > 0){

                if(isset($dateRange) && $dateRange=='LASTWEEK'){
                  $admanagerRecords[] = array('report_flag'=>$hour,'application_id'=>$appID,'adunit_id'=>$ad_unit_id,'adunit_name'=>$ad_unit_name,'campaign_type'=>'Native',
                  'country_id'=>$countryId,'revenue'=>$revenueINR,'impressions'=>$impression,'clicks'=>$click,'ctr'=>$ctrvalue,'cpc'=>$cpcvalue,'created'=>$insertDate);
                }elseif(isset($dateRange) && $dateRange!='TODAY'){
                $admanagerRecords[] = array('report_flag'=>$YDflag,'application_id'=>$appID,'adunit_id'=>$ad_unit_id,'adunit_name'=>$ad_unit_name,'campaign_type'=>'Native',
                'country_id'=>$countryId,'clicks'=>$click,'impressions'=>$impression,'revenue'=>$revenueINR,'ctr'=>$ctrvalue,'cpc'=>$cpcvalue,'created'=>$insertDate,'total_requests'=>$request,'unmatched_requests'=>$unmatch);
              }elseif(isset($dateRange) && $dateRange=='CUSTOM'){
                $admanagerRecords[] = array('application_id'=>$appID,'adunit_id'=>$ad_unit_id,'adunit_name'=>$ad_unit_name,'campaign_type'=>'Native',
                'country_id'=>$countryId,'clicks'=>$click,'impressions'=>$impression,'revenue'=>$revenueINR,'ctr'=>$ctrvalue,'cpc'=>$cpcvalue,'created'=>$insertDate,'total_requests'=>$request,'unmatched_requests'=>$unmatch);
              }else{
               $admanagerRecords[] = array('report_flag'=>$hour,'application_id'=>$appID,'adunit_id'=>$ad_unit_id,'adunit_name'=>$ad_unit_name,'campaign_type'=>'Native',
               'country_id'=>$countryId,'clicks'=>$click,'impressions'=>$impression,'revenue'=>$revenueINR,'ctr'=>$ctrvalue,'cpc'=>$cpcvalue,'created'=>$insertDate,'total_requests'=>$request,'unmatched_requests'=>$unmatch);
             }

           }

         }

         if(isset($dateRange) && $dateRange=='LASTWEEK'){
           $reports  = TableRegistry::getTableLocator()->get('WeeklyAdxReport');
           $entities = $reports->newEntities($admanagerRecords);
           $result   = $reports->saveMany($entities);
           unlink($filePath);
         }elseif(isset($dateRange) && $dateRange=='CUSTOM'){
            $reports  = TableRegistry::getTableLocator()->get('AdxReport');
            $entities = $reports->newEntities($admanagerRecords);
            $result   = $reports->saveMany($entities);
            unlink($filePath);
          }else{
            $reports  = TableRegistry::getTableLocator()->get('TodayAdxReport');
            $entities = $reports->newEntities($admanagerRecords);
            $result   = $reports->saveMany($entities);
            unlink($filePath);

          }

    }else {
      echo 'failed';
      exit;
    }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue provides only an inline PHP example using StatementBuilder and ReportQuery, with no repository file or test named. Start by reproducing the report query around the AD_UNIT_ID IN clause and determine the expected input and successful report-job behavior; done means the query runs without the UNEXECUTABLE error.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.