コード例 #1
0
ファイル: _dataset.py プロジェクト: wangjiahong/datalab
    def _retrieve_items(self, page_token, item_type):
        try:
            list_info = self._api.tables_list(self._name_parts,
                                              page_token=page_token)
        except Exception as e:
            raise e

        tables = list_info.get('tables', [])
        contents = []
        if len(tables):
            try:
                for info in tables:
                    if info['type'] != item_type:
                        continue
                    if info['type'] == 'TABLE':
                        item = _table.Table(
                            (info['tableReference']['projectId'],
                             info['tableReference']['datasetId'],
                             info['tableReference']['tableId']), self._context)
                    else:
                        item = _view.View((info['tableReference']['projectId'],
                                           info['tableReference']['datasetId'],
                                           info['tableReference']['tableId']),
                                          self._context)
                    contents.append(item)
            except KeyError:
                raise Exception('Unexpected item list response')

        page_token = list_info.get('nextPageToken', None)
        return contents, page_token
コード例 #2
0
  def __init__(self, name, context=None):
    """Initializes an instance of a View object.

    Args:
      name: the name of the view either as a string or a 3-part tuple
          (projectid, datasetid, name). If a string, it must have the form
          '<project>:<dataset>.<view>' or '<dataset>.<view>'.
      context: an optional Context object providing project_id and credentials. If a specific
          project id or credentials are unspecified, the default ones configured at the global
          level are used.
    Raises:
      Exception if the name is invalid.
      """
    if context is None:
      context = gcp.Context.default()
    self._context = context
    self._table = _table.Table(name, context=context)
    self._materialization = _query.Query('SELECT * FROM %s' % self._repr_sql_(), context=context)