Example #1
0
    def RunWithArgs(self, identifier=''):
        """Show all information about an object.

    All fields that are encrypted are of type ciphertext.

    Examples:
      ebq show -j <job_id>
      ebq show dataset
      ebq show dataset.table
    """
        # pylint: disable=g-doc-exception
        client = bq.Client.Get()
        if self.j:
            reference = client.GetJobReference(identifier)
        elif self.d:
            reference = client.GetDatasetReference(identifier)
        else:
            reference = client.GetReference(identifier)
        if reference is None:
            raise app.UsageError('Must provide an identifier for show.')

        object_info = client.GetObjectInfo(reference)
        # Remove prefixes that were prepended during load/query.
        object_info = show_lib.RewriteShowSchema(object_info)

        # The JSON formats are handled separately so that they don't print
        # the record as a list of one record.
        if FLAGS.format in ['prettyjson', 'json']:
            bq._PrintFormattedJsonObject(object_info)  # pylint: disable=protected-access
        elif FLAGS.format in [None, 'sparse', 'pretty']:
            formatter = bq._GetFormatterFromFlags()  # pylint: disable=protected-access
            bigquery_client.BigqueryClient.ConfigureFormatter(
                formatter, type(reference), print_format='show')
            object_info = bigquery_client.BigqueryClient.FormatInfoByKind(
                object_info)
            formatter.AddDict(object_info)
            print '%s %s\n' % (reference.typename.capitalize(), reference)
            formatter.Print()
            print
            if (isinstance(reference,
                           bigquery_client.ApiClientHelper.JobReference)
                    and object_info['State'] == 'FAILURE'):
                error_result = object_info['status']['errorResult']
                error_ls = object_info['status'].get('errors', [])
                error = bigquery_client.BigqueryError.Create(
                    error_result, error_result, error_ls)
                print 'Errors encountered during job execution. %s\n' % (
                    error, )
        else:
            formatter = bq._GetFormatterFromFlags()  # pylint: disable=protected-access
            formatter.AddColumns(object_info.keys())
            formatter.AddDict(object_info)
            formatter.Print()
  def RunWithArgs(self, identifier=''):
    """Show all information about an object.

    All fields that are encrypted are of type ciphertext.

    Examples:
      ebq show -j <job_id>
      ebq show dataset
      ebq show dataset.table
    """
    # pylint: disable=g-doc-exception
    client = bq.Client.Get()
    if self.j:
      reference = client.GetJobReference(identifier)
    elif self.d:
      reference = client.GetDatasetReference(identifier)
    else:
      reference = client.GetReference(identifier)
    if reference is None:
      raise app.UsageError('Must provide an identifier for show.')

    object_info = client.GetObjectInfo(reference)
    # Remove prefixes that were prepended during load/query.
    object_info = show_lib.RewriteShowSchema(object_info)

    # The JSON formats are handled separately so that they don't print
    # the record as a list of one record.
    if FLAGS.format in ['prettyjson', 'json']:
      bq._PrintFormattedJsonObject(object_info)  # pylint: disable=protected-access
    elif FLAGS.format in [None, 'sparse', 'pretty']:
      formatter = bq._GetFormatterFromFlags()  # pylint: disable=protected-access
      bigquery_client.BigqueryClient.ConfigureFormatter(
          formatter, type(reference), print_format='show')
      object_info = bigquery_client.BigqueryClient.FormatInfoByKind(object_info)
      formatter.AddDict(object_info)
      print '%s %s\n' % (reference.typename.capitalize(), reference)
      formatter.Print()
      print
      if (isinstance(reference, bigquery_client.ApiClientHelper.JobReference)
          and object_info['State'] == 'FAILURE'):
        error_result = object_info['status']['errorResult']
        error_ls = object_info['status'].get('errors', [])
        error = bigquery_client.BigqueryError.Create(
            error_result, error_result, error_ls)
        print 'Errors encountered during job execution. %s\n' % (error,)
    else:
      formatter = bq._GetFormatterFromFlags()  # pylint: disable=protected-access
      formatter.AddColumns(object_info.keys())
      formatter.AddDict(object_info)
      formatter.Print()
    def PrintTable(self, fields, rows):
        """Decrypts table values and then prints the table.

    Arguments:
      fields: Column names for table.
      rows: Table values for each column.
    """
        manifest = getattr(self, 'manifest', None)
        decrypted_queries = _DecryptRows(fields,
                                         rows,
                                         self.master_key,
                                         self.table_id,
                                         self.schema,
                                         self.encrypted_queries,
                                         self.aggregation_queries,
                                         self.unencrypted_queries,
                                         manifest=manifest)
        table_values = _ComputeRows(self.table_expressions, decrypted_queries)
        if self.order_by_clause:
            table_values = self.order_by_clause.SortTable(
                self.column_names, table_values)

        # pylint: disable=protected-access
        formatter = bq._GetFormatterFromFlags(secondary_format='pretty')
        formatter.AddFields(self.column_names)
        formatter.AddRows(table_values)
        formatter.Print()
  def PrintTable(self, fields, rows):
    """Decrypts table values and then prints the table.

    Arguments:
      fields: Column names for table.
      rows: Table values for each column.
    """
    decrypted_queries = _DecryptRows(
        fields, rows, self.master_key, self.table_id, self.schema,
        self.encrypted_queries, self.aggregation_queries,
        self.unencrypted_queries)
    table_values = _ComputeRows(self.table_expressions, decrypted_queries)
    if self.order_by_clause:
      table_values = self.order_by_clause.SortTable(self.column_names,
                                                    table_values)

    # pylint: disable=protected-access
    formatter = bq._GetFormatterFromFlags(secondary_format='pretty')
    formatter.AddFields(self.column_names)
    formatter.AddRows(table_values)
    formatter.Print()