【发布时间】:2021-06-27 12:27:09
【问题描述】:
我想使用空间查询来查询 cosmos db 集合。特别是ST_DISTANCE 查询。此查询使用azure-cosmos Python SDK 按预期工作。
我希望通过 Apache Spark 将此查询用于更复杂的查询模式。但是,在笔记本的 SQL 单元格中使用 ST_DISTANCE 查询会导致以下错误。
Error in SQL statement: AnalysisException: Undefined function: 'ST_DISTANCE'. This function is neither a registered temporary function nor a permanent function registered in the database 'default'.
笔记本初始化如下。
# Configure Catalog Api to be used
spark.conf.set("spark.sql.catalog.cosmosCatalog", "com.azure.cosmos.spark.CosmosCatalog")
spark.conf.set("spark.sql.catalog.cosmosCatalog.spark.cosmos.accountEndpoint", cosmosEndpoint)
spark.conf.set("spark.sql.catalog.cosmosCatalog.spark.cosmos.accountKey", cosmosMasterKey)
from pyspark.sql.functions import col
df = spark.read.format("cosmos.oltp").options(**cfg)\
.option("spark.cosmos.read.inferSchema.enabled", "true")\
.load()
df.createOrReplaceTempView("outlets")
_______________________________________________________________________
%sql
SELECT * FROM outlets f WHERE ST_DISTANCE(f.boundary, POINT(0,0)) < 600
【问题讨论】:
标签: apache-spark pyspark jupyter-notebook azure-cosmosdb azure-cosmosdb-sqlapi