小编aar*_*ron的帖子

雪花存储过程,检查结果集是否为空而不抛出错误

与我打开的另一个雪花问题有些相关在雪花存储过程中,有没有办法检查结果集中有多少列?

有没有办法检查结果集是否为空?例如

var query = `SELECT * FROM somewhere`
var stmt = snowflake.createStatement({sqlText: query});
var result = stmt.execute();
result.next()
var colCount = stmt.getColumnCount();
Run Code Online (Sandbox Code Playgroud)

如果结果集中没有返回数据,则会出现错误。它说

Failed Code 100183 State P0000 Message ResultSet is empty or not prepared, call next() first

我尝试翻转它只是为了看看会发生什么。

var query = `SELECT * FROM somewhere`
var stmt = snowflake.createStatement({sqlText: query});
var result = stmt.execute(); 
var colCount = stmt.getColumnCount();
result.next();
Run Code Online (Sandbox Code Playgroud)

看起来这两行都var colCount = stmt.getColumnCount();抛出result.next();相同的错误,无论顺序如何。我怀疑该错误是因为结果集为空。如果我的怀疑是正确的,那么我需要另一种方法来检查。在引发此错误之前,是否有一种安全的方法来检查结果中是否有任何数据?

javascript stored-procedures snowflake-cloud-data-platform

5
推荐指数
1
解决办法
7535
查看次数

如何使用Python列出Azure Cloud Storage中特定子目录内的所有Blob?

我研究了Azure文档https://docs.microsoft.com/zh-cn/azure/storage/blobs/storage-quickstart-blobs-python中的示例代码

from azure.storage.blob import BlockBlobService
account_name = "x"
account_key = "x"
top_level_container_name = "top_container"

blob_service = BlockBlobService(account_name, account_key)

print("\nList blobs in the container")
generator = blob_service.list_blobs(top_level_container_name)
for blob in generator:
    print("\t Blob name: " + blob.name)
Run Code Online (Sandbox Code Playgroud)

现在,我想知道如何在集装箱行走中获得更多的细颗粒。我的容器top_level_container_name有几个子目录

  • top_level_container_name / dir1
  • top_level_container_name / dir2
  • 等那个模式

我希望能够列出这些目录之一中的所有Blob。例如

  • dir1 / a.jpg
  • dir1 / b.jpg
  • 等等

如何获得仅dir1内容的生成器,而不必遍历所有其他目录?(我也会带一个清单或字典)

我尝试将/ dir1添加到top_level_container_name的名称中,这样虽然可以,top_level_container_name = "top_container/dir1"但是没有用。我找回错误代码 azure.common.AzureHttpError: The requested URI does not represent any resource on the server. ErrorCode: InvalidUri

这些文档似乎甚至都没有关于BlockBlobService.list_blobs()的任何信息https://docs.microsoft.com/zh-cn/python/api/azure.storage.blob.blockblobservice.blockblobservice?view=azure-python

更新:list_blobs()来自https://github.com/Azure/azure-storage-python/blob/ff51954d1b9d11cd7ecd19143c1c0652ef1239cb/azure-storage-blob/azure/storage/blob/baseblobservice.py#L1202

python azure azure-storage

3
推荐指数
3
解决办法
5288
查看次数

Python Azure 队列,出现错误

我正在努力解决编码问题。我仍在尝试找出Python3的编码方案。我正在尝试将 json 对象从 Python 上传到 Azure 队列中。我正在使用Python3

我制作了 json 对象

response = {"UserImageId": 636667744866847370, "OutputImageName": "car-1807177_with_blue-2467336_size_1020_u38fa38.png"} 
queue_service.put_message(response_queue, json.dumps(response))
Run Code Online (Sandbox Code Playgroud)

当它到达队列时,我收到错误

{"imgResponse":"The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. ","log":null,"$return":""}
Run Code Online (Sandbox Code Playgroud)

所以我必须做其他事情,因为显然我需要对我的字符串进行 Base64 编码。所以我尝试

queue_service.put_message(response_queue, base64.b64encode(json.dumps(response).encode('utf-8')))
Run Code Online (Sandbox Code Playgroud)

我得到

TypeError: message should be of type str
Run Code Online (Sandbox Code Playgroud)

来自 Azure 存储队列包。如果我检查上述语句的类型,它是字节类型(有意义)。所以我的问题是,如何将 json 对象编码为队列服务能够理解的内容。我真的希望能够保留 _ 和 - 和 。图像名称中的字符。

python base64 azure python-3.x azure-storage-queues

3
推荐指数
1
解决办法
2396
查看次数

如何从bash shell执行.py脚本

我打开一个终端并cd到我的文件中,我的.py文件名为trianglearea.py,这是我试图执行的一个非常基本的程序.我在shell中键入/ Documents $ python trianglearea.py,没有任何反应; bash提示我输入另一个命令,好像我刚刚提示的那个不存在.我尝试./trianglearea.py但我得到一个语法错误,因为我没有进入交互式python和bash不理解我的python脚本.如果我去文件gui风格并双击并说在终端中运行一个窗口闪烁并消失,但这不是我想要的.我想让我的小程序在交互式python中运行,这样我就可以输入内容并实际使用我的函数了.这就是我在..文件中的全部内容

def area(base,height):
    ''' (number, number) - number
    Return area of a triangle with dimensions base * height

    >>>>area(10,5)
    25.0
    '''
    return base*height/2
Run Code Online (Sandbox Code Playgroud)

我知道这不应该那么难,但它让我很难过.

python bash shell

2
推荐指数
1
解决办法
1万
查看次数