bigquery_validator/bigquery_validator.py
def dry_run_query(self, query):
        """Run a BigQuery query with dry_run set to True.
        If the query succeeds it is valid and will return the estimated processing bytes required for the query.
        An exception will be thrown if the query is not valid.
        """
        try:
            job_config = bigquery.QueryJobConfig(dry_run=True, use_query_cache=self.use_query_cache)

            # Start the query, passing in the extra configuration.
            query_job = self.bq_client.query(
                query,
                job_config=job_config,
            )  # Make an API request.

            # A dry run query completes immediately.
            total_bytes = query_job.total_bytes_processed
            logging.info("This query will process {} bytes.".format(total_bytes))

            byte = 1
            kilobyte = 1024
            megabyte = 1024 * 1024
            gigabyte = 1024 * 1024 * 1024
            terabyte = 1024 * 1024 * 1024 * 1024

            query_cost = {
                'b': round(total_bytes / byte, 2),
                'kb': round(total_bytes / kilobyte, 2),
                'mb': round(total_bytes / megabyte, 2),
                'gb': round(total_bytes / gigabyte, 2),
                'tb': round(total_bytes / terabyte, 2)
            }

            if total_bytes > terabyte:
                rounded_total = query_cost['b']
                byte_type = 'TB'
            elif total_bytes > gigabyte:
                rounded_total = query_cost['gb']
                byte_type = 'GB'
            elif total_bytes > megabyte:
                rounded_total = query_cost['mb']
                byte_type = 'MB'
            elif total_bytes > kilobyte:
                rounded_total = query_cost['kb']
                byte_type = 'KB'
            else:
                rounded_total = query_cost['b']
                byte_type = 'B'

            if self.return_query_cost_as_dict:
                return True, query_cost
            else:
                message = f'This query will process {rounded_total} {byte_type}.'
                return True, message

        except Exception as e:
            error_string = str(e)
            error_minus_job_url = error_string.split('jobs?prettyPrint=false:')
            split_error = error_minus_job_url[1].split('\n\n')
            syntax_error = split_error[0]
            return False, syntax_error
Run a BigQuery query with dry_run set to True.
        If the query succeeds it is valid and will return the estimated processing bytes required for the query.
        An exception will be thrown if the query is not valid.
        
Run a BigQuery query with dry_run set to True.
If the query succeeds it is valid and will return the estimated processing bytes required for the query.
An exception will be thrown if the query is not valid.
Run a BigQuery query with dry_run set to True . If the query succeeds it is valid and will return the estimated processing bytes required for the query . An exception will be thrown if the query is not valid .
def dry_run_query(self, query):
        try:
            job_config = bigquery.QueryJobConfig(dry_run=True, use_query_cache=self.use_query_cache)
            query_job = self.bq_client.query(
                query,
                job_config=job_config,
            )  
            total_bytes = query_job.total_bytes_processed
            logging.info("This query will process {} bytes.".format(total_bytes))
            byte = 1
            kilobyte = 1024
            megabyte = 1024 * 1024
            gigabyte = 1024 * 1024 * 1024
            terabyte = 1024 * 1024 * 1024 * 1024
            query_cost = {
                'b': round(total_bytes / byte, 2),
                'kb': round(total_bytes / kilobyte, 2),
                'mb': round(total_bytes / megabyte, 2),
                'gb': round(total_bytes / gigabyte, 2),
                'tb': round(total_bytes / terabyte, 2)
            }
            if total_bytes > terabyte:
                rounded_total = query_cost['b']
                byte_type = 'TB'
            elif total_bytes > gigabyte:
                rounded_total = query_cost['gb']
                byte_type = 'GB'
            elif total_bytes > megabyte:
                rounded_total = query_cost['mb']
                byte_type = 'MB'
            elif total_bytes > kilobyte:
                rounded_total = query_cost['kb']
                byte_type = 'KB'
            else:
                rounded_total = query_cost['b']
                byte_type = 'B'
            if self.return_query_cost_as_dict:
                return True, query_cost
            else:
                message = f'This query will process {rounded_total} {byte_type}.'
                return True, message
        except Exception as e:
            error_string = str(e)
            error_minus_job_url = error_string.split('jobs?prettyPrint=false:')
            split_error = error_minus_job_url[1].split('\n\n')
            syntax_error = split_error[0]
            return False, syntax_error
def dry_run_query ( self , query ) : try : job_config = bigquery . QueryJobConfig ( dry_run = True , use_query_cache = self . use_query_cache ) query_job = self . bq_client . query ( query , job_config = job_config , ) total_bytes = query_job . total_bytes_processed logging . info ( "This query will process {} bytes." . format ( total_bytes ) ) byte = 1 kilobyte = 1024 megabyte = 1024 * 1024 gigabyte = 1024 * 1024 * 1024 terabyte = 1024 * 1024 * 1024 * 1024 query_cost = { 'b' : round ( total_bytes / byte , 2 ) , 'kb' : round ( total_bytes / kilobyte , 2 ) , 'mb' : round ( total_bytes / megabyte , 2 ) , 'gb' : round ( total_bytes / gigabyte , 2 ) , 'tb' : round ( total_bytes / terabyte , 2 ) } if total_bytes > terabyte : rounded_total = query_cost [ 'b' ] byte_type = 'TB' elif total_bytes > gigabyte : rounded_total = query_cost [ 'gb' ] byte_type = 'GB' elif total_bytes > megabyte : rounded_total = query_cost [ 'mb' ] byte_type = 'MB' elif total_bytes > kilobyte : rounded_total = query_cost [ 'kb' ] byte_type = 'KB' else : rounded_total = query_cost [ 'b' ] byte_type = 'B' if self . return_query_cost_as_dict : return True , query_cost else : message = f'This query will process {rounded_total} {byte_type}.' return True , message except Exception as e : error_string = str ( e ) error_minus_job_url = error_string . split ( 'jobs?prettyPrint=false:' ) split_error = error_minus_job_url [ 1 ] . split ( '\n\n' ) syntax_error = split_error [ 0 ] return False , syntax_error
Run a BigQuery query with dry_run set to True.
Run a BigQuery query with dry_run set to True .
"""Run a BigQuery query with dry_run set to True.
        If the query succeeds it is valid and will return the estimated processing bytes required for the query.
        An exception will be thrown if the query is not valid.
        """ # Start the query, passing in the extra configuration. # Make an API request. # A dry run query completes immediately.
self
query