【发布时间】:2021-04-01 18:26:03
【问题描述】:
我有一个 CosmosDb 和一个 Synapse 工作区链接。几乎所有东西都使用 Synapse 为 Cosmos 数据创建 SQL 视图。
在 Cosmos 中,我有一个属性始终为零的数据集。我知道它实际上是一个小数,因为它是一个价格,未来的数据很可能包含小数价格。
在 Synapse 中,我需要将此数据投影到 SQL 视图中,其中该列正确为小数 (19,4)。
当我对 Cosmos 数据运行 OpenRowSet 查询并尝试指定此属性的类型时,我收到以下错误。
select *
from OPENROWSET(
'CosmosDb',
'account=myaccount;database=myDatabase;region=theRegion;key=xxxxxxxxxxxxxxx',
[myCollection])
with (
[salesPrice] float '$.salesPrice')
as testQuery
我得到错误:
Column 'salesPrice' of type 'FLOAT' is not compatible with external data type 'Parquet physical type: INT64', please try with 'BIGINT'.
很明显,一旦我得到一个真正的十进制价格,这里的 BIGINT 就会失败。
我认为 parquet 类型设置为 BIGINT,因为在 Cosmos 中,该列的所有值都为零。如果 Cosmos 属性都是非零整数,我想更一般地说,这将是同样的问题。
如何强制 salesPrice 的类型为小数或浮点数?
(我不想在浮点数与小数点的货币价值上被旁观,我理解其中的区别;无论哪种方式都会发生此错误)
更新
此问题也以另一种方式表现出来,而无需使用OPENROWSET 指定架构。
在一个新的 CosmosDb 集合中插入一个文档,例如:
{
"myid" : 1,
"price" : 0
}
如果我等待一分钟左右,我可以从 Synapse 查询此文档:
select *
from OPENROWSET(
'myCosmosDb',
'account=myAccount;database=myDatabase;region=myRegion;key=xxxxxxxxxxxxxxxxxxx',
[myCollection])
as testQuery;
我得到了预期的结果。
现在添加第二个文档:
{
"myid" : 1,
"price" : 1.1
}
然后重新运行查询,我得到同样的错误:
Column 'price' of type 'FLOAT' is not compatible with external data type 'Parquet physical type: INT64', please try with 'BIGINT'
有没有办法解决或防止此类错误?
【问题讨论】:
标签: azure-cosmosdb azure-synapse