コード例 #1
0
 def to_table(dataset_ref, model):
     schema = model.schema
     if schema:
         schema = tuple(
             BigQuerySchemaField.to_schema_field(s) for s in schema)
     else:
         schema = None
     table_ref = TableReference(dataset_ref, model.table_id)
     table = Table(table_ref, schema)
     table.friendly_name = model.friendly_name
     table.description = model.description
     table.expires = model.expires
     table.partitioning_type = model.partitioning_type
     if model.view_use_legacy_sql is not None:
         table.view_use_legacy_sql = model.view_use_legacy_sql
     if model.view_query is not None:
         table.view_query = model.view_query
     table.labels = model.labels if model.labels is not None else dict()
     return table
コード例 #2
0
    def create_table(self, is_temporary=False):
        stream_schema_message = self.stream_schema_message

        client = self.open_connection()
        project_id = self.connection_config['project_id']
        dataset_id = self.schema_name
        table_name = self.table_name(stream_schema_message['stream'],
                                     is_temporary,
                                     without_schema=True)

        schema = [
            column_type(name, schema)
            for (name, schema) in self.flatten_schema.items()
        ]

        table = Table('{}.{}.{}'.format(project_id, dataset_id, table_name),
                      schema)
        if is_temporary:
            table.expires = datetime.datetime.now() + datetime.timedelta(
                days=1)

        client.create_table(table, schema)