def create_metadata_json()

in nl2sql_src/nl2sql_generic.py [0:0]


    def create_metadata_json(self,
                             metadata_json_dest_path,
                             data_dict_path=None,
                             col_values_distribution=False,
                             enum_option_limit=10):
        """
        Creates metadata json file
        """
        try:
            data_dict = dict()
            if data_dict_path:
                f = open(data_dict_path, encoding="utf-8")
                data_dict = json.loads(f.read())
            table_ls = self.get_all_table_names()
            metadata_json = dict()
            for table_name in table_ls:
                table = client.get_table(f"{self.dataset_id}.{table_name}")
                table_description = ""
                if table_name in data_dict and data_dict[table_name].strip():
                    table_description = data_dict[table_name]
                elif table.description:
                    table_description = table.description
                columns_info = dict()

                for schema in table.schema:
                    schema_description = ""
                    if f"{table_name}.{schema.name}" in data_dict and \
                       data_dict[f"{table_name}.{schema.name}"].strip():
                        schema_description = data_dict[
                            f"{table_name}.{schema.name}"]
                    elif schema.description:
                        schema_description = schema.description

                    columns_info[schema.name] = {
                        "Name": schema.name,
                        "Type": schema.field_type,
                        "Description": schema_description,
                        "Examples": ""
                        }
                    if col_values_distribution and \
                       schema.field_type == "STRING":

                        all_examples = self.get_column_value_examples(
                            table_name, schema.name, enum_option_limit)
                        columns_info[schema.name]["Examples"] = all_examples
                metadata_json[table_name] = {"Name": table_name,
                                             "Description": table_description,
                                             "Columns": columns_info}
            with open(metadata_json_dest_path, 'w', encoding="utf-8") as f:
                json.dump(metadata_json, f)
            self.metadata_json = metadata_json
        except Exception as exc:
            raise Exception(traceback.print_exc()) from exc