Ejemplo n.º 1
0
 function queryBigQuery($sql, $dataset, $table_name)
 {
     $queryConfig = new Google_Service_Bigquery_JobConfigurationQuery();
     $queryConfig->setDestinationTable($this->createDestinationTable($dataset, $table_name));
     $queryConfig->setQuery($sql);
     $config = new Google_Service_Bigquery_JobConfiguration();
     $config->setDryRun(false);
     $config->setQuery($queryConfig);
     $job = new Google_Service_Bigquery_Job();
     $job->setConfiguration($config);
     print "<PRE>";
     print_r($job);
     exit;
     $job = $this->service->jobs->insert($this->project_id, $job);
     return $job;
 }
Ejemplo n.º 2
0
function asyncQuery(Google_Service_Bigquery $bigquery, $projectId, $queryString, $batch = false)
{
    $query = new Google_Service_Bigquery_JobConfigurationQuery();
    $query->setQuery($queryString);
    $query->setPriority($batch ? 'BATCH' : 'INTERACTIVE');
    $config = new Google_Service_Bigquery_JobConfiguration();
    $config->setQuery($query);
    $job = new Google_Service_Bigquery_Job();
    $job->setConfiguration($config);
    return $bigquery->jobs->insert($projectId, $job);
}
Ejemplo n.º 3
0
 /**
  * @param $project_id
  * @param $dataSet
  * @param $tableId
  * @param $csvPath
  * @param $skipLeadingRows
  * @return array|\Exception
  */
 public function bigQueryLoadDataExistingTable($project_id, $dataSet, $tableId, $csvPath, $skipLeadingRows = 1)
 {
     // Information about the destination table
     $destination_table = new \Google_Service_Bigquery_TableReference();
     $destination_table->setProjectId($project_id);
     $destination_table->setDatasetId($dataSet);
     $destination_table->setTableId($tableId);
     // Set the load configuration, including source file(s) and schema
     $load_configuration = new \Google_Service_Bigquery_JobConfigurationLoad();
     //'gs://YOUR_GOOGLE_CLOUD_STORAGE_BUCKET/file.csv'
     $load_configuration->setSourceUris(array($csvPath));
     $load_configuration->setDestinationTable($destination_table);
     $load_configuration->skipLeadingRows = $skipLeadingRows;
     $load_configuration->sourceFormat = 'CSV';
     $load_configuration->setwriteDisposition('WRITE_APPEND');
     $job_configuration = new \Google_Service_Bigquery_JobConfiguration();
     $job_configuration->setLoad($load_configuration);
     $job = new \Google_Service_Bigquery_Job();
     $job->setKind('load');
     $job->setConfiguration($job_configuration);
     $jobs = $this->bigqueryService->jobs;
     $response = $jobs->insert($project_id, $job);
     $jobStatus = new \Google_Service_Bigquery_JobStatus();
     $status = $response->getStatus();
     if ($jobStatus->count() != 0) {
         $err_res = $jobStatus->getErrorResult();
         return $err_res->getMessage();
     }
     $jr = $response->getJobReference();
     $jobId = $jr['jobId'];
     $state = $status['state'];
     return array('JOBID' => $jobId, 'STATUS' => $state);
 }