如何使用python api在googlebigquery中查找表中的分区类型


def partition(dataset1, dataset2):
try:
client.get_dataset(dataset2)
print("Dataset {} already exists".format(dataset2))
except NotFound:
print("Dataset {} not found".format(dataset2))
createDataset(dataset2)
table = client.get_table(dataset1) # get the source dataset
partition_column = table.time_partitioning.field #get the column name

我试着使用get_table描述,但最终没有返回。我在这里得到了谷歌api链接中的文档链接如何获取表使用的分区类型

您可以使用以下脚本来获取分区类型:

from google.cloud import bigquery
if __name__ == '__main__':
# Construct a BigQuery client object.
client = bigquery.Client()
# table_id = 'your-project.your_dataset.your_table'
table = client.get_table('your-project.your_dataset.your_table')  # Make an API request.
# View table properties
print(
"Got table '{}.{}.{}'.".format(table.project, table.dataset_id, table.table_id)
)
print("Table schema: {}".format(table.schema))
print("Table description: {}".format(table.description))
print("Table has {} rows".format(table.num_rows))
# Partition type and field.
partition_field: str = table.time_partitioning.field
partition_type: str = table.time_partitioning.type_
print("Table partition field {}".format(partition_field))
print("Table partition type {}".format(partition_type))
  • table.time_partitioning.field给出分区列名
  • table.time_partitioning.type_给出分区类型

相关内容

  • 没有找到相关文章

最新更新