当前位置: 首页>>代码示例>>Python>>正文


Python DataHubConnection.import_rows方法代码示例

本文整理汇总了Python中core.db.connection.DataHubConnection.import_rows方法的典型用法代码示例。如果您正苦于以下问题:Python DataHubConnection.import_rows方法的具体用法?Python DataHubConnection.import_rows怎么用?Python DataHubConnection.import_rows使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在core.db.connection.DataHubConnection的用法示例。


在下文中一共展示了DataHubConnection.import_rows方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from core.db.connection import DataHubConnection [as 别名]
# 或者: from core.db.connection.DataHubConnection import import_rows [as 别名]

#.........这里部分代码省略.........
        res = self.execute_sql(query)

        # determine the column_names and rows
        if select_query or res['row_count'] > 0:  # normal case
            column_names = [field['name'] for field in res['fields']]
            rows = res['tuples']
        else:  # query just returned a bool
            column_names = ['status']
            rows = [['success' if res['status'] else res['error']]]

        result = {
                'num_rows': num_rows,
                'time_cost': time_cost,
                'byte_width': byte_width,
                'total_pages': total_pages,
                'start_page': start_page,
                'end_page': end_page,
                'column_names': column_names,
                'rows': rows,
                'select_query': select_query
        }

        return result

    def select_table_query(self, repo, table):
        """
        Return a database query for selecting the table.

        Necessary for keeping sq/nosql queries out of views.
        """
        return self.user_con.select_table_query(
            repo_base=self.repo_base, repo=repo, table=table)

    def import_rows(self, repo, table, rows, delimiter=',', header=False):
        delimiter = delimiter.decode('string_escape')

        # column names are the extracted
        columns = rows[0].split(delimiter)
        if not header:
            # if there's not a header, they're replaced with the word 'col'
            columns = ['col' for c in columns]
        columns = rename_duplicates(columns)

        # prepare params and create the table
        params = [{'column_name': c, 'data_type': 'text'} for c in columns]
        self.create_table(repo=repo, table=table, params=params)

        # now, insert the data and return the result
        return self.user_con.import_rows(repo, table, rows, delimiter, header)

    """
    Static methods that don't require permissions
    """

    @staticmethod
    def create_user_data_folder(repo_base, repo=''):
        """
        Creates a user data folder for the given user.

        Optionally accepts a specific repo's folder to create.
        Fails silently if the folder already exists.
        Returns the deleted path.
        """
        repo_dir = os.path.abspath(
            os.path.join(os.sep, 'user_data', repo_base, repo))
        try:
开发者ID:datahuborg,项目名称:datahub,代码行数:70,代码来源:manager.py


注:本文中的core.db.connection.DataHubConnection.import_rows方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。