in src/package/dataplexutils/metadata/wizard.py [0:0]
def _get_table_sample(self, table_fqn, num_rows_to_sample):
"""Retrieves a sample of rows from a BigQuery table.
Args:
table_fqn (str): The fully qualified name of the table
(e.g., 'project.dataset.table')
num_rows_to_sample (int): Number of rows to sample from the table
Returns:
str: JSON string containing the sampled rows data
Raises:
bigquery.exceptions.BadRequest: If the query is invalid
Exception: If there is an error retrieving the sample
"""
try:
bq_client = self._cloud_clients[constants["CLIENTS"]["BIGQUERY"]]
query = f"SELECT * FROM `{table_fqn}` LIMIT {num_rows_to_sample}"
return bq_client.query(query).to_dataframe().to_json()
except bigquery.exceptions.BadRequest as e:
print(f"BigQuery Bad Request: {e}")
return "[]"
except Exception as e:
logger.error(f"Exception: {e}.")
raise e