def __init__(self, yml, dir=""): self.yml = yml self.dir = dir # Gathering data self.parse_file = Parse_Yaml(self.yml, dir=self.dir) self.dataset_id = self.parse_file.dataset_id() self.labels = self.parse_file.labels() self.dataset_ref = client.dataset(self.dataset_id)
def __init__(self, yml, dir=""): self.yml = yml self.dir = dir # gathering data self.parse_file = Parse_Yaml(self.yml, self.dir) self.dataset_id = self.parse_file.dataset_id() self.table_id = self.parse_file.table_name() self.type = self.parse_file.type() # dataset reference self.dataset_ref = client.dataset(self.dataset_id, project=PROJECTID) # table reference self.table_ref = self.dataset_ref.table(self.table_id)
def delete_pack(self): yaml_files = get_files(self.dir) for yml in yaml_files: parse_file = Parse_Yaml(yml, dir=self.dir) yml_type = parse_file.type() dataset_id = parse_file.dataset_id() dataset_ref = client.dataset(dataset_id) if str(yml_type).endswith(".dataset"): dataset = BQDataset(yml, self.dir) dataset.delete_dataset() elif str(yml_type).endswith(".table"): if parse_file.schema(): table = BQTable(yml, self.dir) table.delete_table() else: view = BQView(yml, self.dir) view.delete_view() print("Execution completed!")
def is_exist(dataset_id, table_id=None, view_id=None): dataset_ref = client.dataset(dataset_id) try: # Checking whether dataset exists dataset = client.get_dataset(dataset_ref) if dataset and table_id != None: table_ref = dataset_ref.table(table_id) try: table = client.get_table(table_ref) if table: return True except NotFound as error: return False elif dataset and view_id != None: view_ref = dataset_ref.table(view_id) try: view = client.get_table(view_ref) if view: return True except NotFound as error: return False return True except NotFound as error: return False