コード例 #1
0
 def mocked_execute(*args, **kwargs):
     if len(args) >= 1 and args[0].startswith('COPY INTO'):
         location = args[0].split(' ')[2]
         assert location == '"schema"."table"'
     cur = SnowflakeCursor(cnx)
     cur._result = iter([])
     return cur
コード例 #2
0
 def mocked_execute(*args, **kwargs):
     if len(args) >= 1 and args[0].startswith('COPY INTO'):
         location = args[0].split(' ')[2]
         if quote_identifiers:
             assert location == '"database"."schema"."table"'
         else:
             assert location == 'database.schema.table'
     cur = SnowflakeCursor(cnx)
     cur._result = iter([])
     return cur
コード例 #3
0
 def mocked_execute(*args, **kwargs):
     if len(args) >= 1 and args[0].startswith("COPY INTO"):
         location = args[0].split(" ")[2]
         if quote_identifiers:
             assert location == '"teble.table"'
         else:
             assert location == "teble.table"
     cur = SnowflakeCursor(cnx)
     cur._result = iter([])
     return cur
コード例 #4
0
def create_file_format(compression: str, compression_map: Dict[str, str],
                       cursor: SnowflakeCursor) -> str:
    file_format_name = (
        '"' + "".join(random.choice(string.ascii_lowercase)
                      for _ in range(5)) + '"')
    file_format_sql = (
        f"CREATE FILE FORMAT {file_format_name} "
        f"/* Python:snowflake.connector.pandas_tools.write_pandas() */ "
        f"TYPE=PARQUET COMPRESSION={compression_map[compression]}")
    logger.debug(f"creating file format with '{file_format_sql}'")
    cursor.execute(file_format_sql, _is_internal=True)
    return file_format_name
コード例 #5
0
def put(
    csr: SnowflakeCursor,
    file_path: str,
    stage_path: str,
    from_path: bool,
    sql_options: str | None = "",
    **kwargs,
) -> SnowflakeCursor:
    """Execute PUT <file> <stage> <options> query with given cursor.

    Args:
        csr: Snowflake cursor object.
        file_path: Path to the target file in local system; Or <filename>.<extension> when from_path is False.
        stage_path: Destination path of file on the stage.
        from_path: Whether the target file is fetched with given path, specify file_stream=<IO> if False.
        sql_options: Optional arguments to the PUT command.
        **kwargs: Optional arguments passed to SnowflakeCursor.execute()

    Returns:
        A result class with the results in it. This can either be json, or an arrow result class.
    """
    sql = "put 'file://{file}' @{stage} {sql_options}"
    if from_path:
        kwargs.pop("file_stream", None)
    else:
        # PUT from stream
        file_path = os.path.basename(file_path)
    if kwargs.pop("commented", False):
        sql = "--- test comments\n" + sql
    sql = sql.format(
        file=file_path.replace("\\", "\\\\"), stage=stage_path, sql_options=sql_options
    )
    return csr.execute(sql, **kwargs)
コード例 #6
0
def create_temporary_sfc_stage(cursor: SnowflakeCursor) -> str:
    stage_name = "".join(
        random.choice(string.ascii_lowercase) for _ in range(5))
    create_stage_sql = (
        "create temporary stage /* Python:snowflake.connector.pandas_tools.write_pandas() */ "
        '"{stage_name}"').format(stage_name=stage_name)
    logger.debug(f"creating stage with '{create_stage_sql}'")
    result_cursor = cursor.execute(create_stage_sql, _is_internal=True)
    if result_cursor is None:
        raise SnowflakeQueryUnknownError(create_stage_sql)
    result_cursor.fetchall()
    return stage_name
コード例 #7
0
def test_get_filetransfer_type(sql, _type):
    assert SnowflakeCursor.get_file_transfer_type(sql) == _type
コード例 #8
0
 def __init__(self, connection):
     SnowflakeCursor.__init__(self, connection)
     self._first_chunk_time = None