You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Spark SQL中引用Synapse笔记本的全局常量?

在Synapse中通过Spark SQL SET引用PySpark全局常量的方法

PySpark定义的全局常量属于Python运行环境,Spark SQL无法直接读取,需要先将其同步到Spark配置中,再通过SET命令或直接引用:

  1. 修改global_constant笔记本
    在定义常量后,将其写入Spark配置:

    constant = 'test'
    # 将Python常量注册为Spark配置属性
    spark.conf.set("spark.custom.constant", constant)
    
  2. 在新笔记本中引用
    执行%run global_constant后,有两种方式调用:

    • 用SET命令将配置值转为SQL变量:

      SET my_sql_constant = ${spark.custom.constant};
      -- 使用变量
      SELECT '${my_sql_constant}' AS constant_value;
      
    • 直接在SQL中引用Spark配置:

      SELECT '${spark.custom.constant}' AS constant_value;
      

内容的提问来源于stack exchange,提问作者AzUser1

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 22:41:59