Last active
April 20, 2020 08:14
-
-
Save showsky/90f48027b040ecf454493b41f8558c18 to your computer and use it in GitHub Desktop.
BigQuery Dump
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $job_type = "QUERY"; | |
| $save_folder_path = './feebee_bigquery_log'; | |
| $start_timestamp = '1583370000000'; | |
| $end_timestamp = '1583391600000'; | |
| $size = 1000; | |
| $bg_ls_command = sprintf( | |
| '/usr/local/bin/bq ls -j -a --format=json --min_creation_time=%s --max_creation_time=%s --message_type=INFO -n %s', | |
| $start_timestamp, | |
| $end_timestamp, | |
| $size | |
| ); | |
| date_default_timezone_set("Asia/Taipei"); | |
| $result = shell_exec($bg_ls_command); | |
| $json = json_decode($result, TRUE); | |
| var_dump($bg_ls_command); | |
| echo PHP_EOL; | |
| echo 'Data count: ' . count($json); | |
| echo PHP_EOL; | |
| if ( ! file_exists($save_folder_path)) { | |
| mkdir($save_folder_path); | |
| } | |
| foreach ($json as $row_data) { | |
| // check jobType | |
| if ($row_data['configuration']['jobType'] != $job_type) { | |
| continue; | |
| } | |
| $create_timestamp = $row_data['statistics']['creationTime'] / 1000; | |
| $taiwan_create_date = date("Y-m-d_H:i:s", $create_timestamp + 8 * 3600); | |
| $mb_size = round($row_data['statistics']['totalBytesProcessed'] / 1024 / 1024); | |
| $filename = sprintf( | |
| '%s_%s_%s.txt', | |
| date("Y-m-d_H:i:s", $create_timestamp), | |
| $mb_size, | |
| $row_data['id'] | |
| ); | |
| file_put_contents( | |
| $save_folder_path . '/' . $filename, | |
| json_encode($row_data, JSON_PRETTY_PRINT) | |
| ); | |
| echo 'Write filename: ' . $filename; | |
| echo PHP_EOL; | |
| } | |
| echo 'end'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment